Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac7ae9cc authored by Vasu Nori's avatar Vasu Nori Committed by Android (Google) Code Review
Browse files

Merge "add API to Cursor to get column value type"

parents e4c8aa60 8b0dd7da
Loading
Loading
Loading
Loading
+127 −5
Original line number Diff line number Diff line
@@ -55658,6 +55658,19 @@
<parameter name="column" type="int">
</parameter>
</method>
<method name="getType"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="column" type="int">
</parameter>
</method>
<method name="getUpdatedField"
 return="java.lang.Object"
 abstract="false"
@@ -56681,6 +56694,19 @@
<parameter name="columnIndex" type="int">
</parameter>
</method>
<method name="getType"
 return="int"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="columnIndex" type="int">
</parameter>
</method>
<method name="getWantsAllOnMoveCalls"
 return="boolean"
 abstract="true"
@@ -56921,6 +56947,61 @@
<parameter name="observer" type="android.database.DataSetObserver">
</parameter>
</method>
<field name="FIELD_TYPE_BLOB"
 type="int"
 transient="false"
 volatile="false"
 value="4"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="FIELD_TYPE_FLOAT"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="FIELD_TYPE_INTEGER"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="FIELD_TYPE_NULL"
 type="int"
 transient="false"
 volatile="false"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="FIELD_TYPE_STRING"
 type="int"
 transient="false"
 volatile="false"
 value="3"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</interface>
<class name="CursorIndexOutOfBoundsException"
 extends="java.lang.IndexOutOfBoundsException"
@@ -57278,6 +57359,21 @@
<parameter name="col" type="int">
</parameter>
</method>
<method name="getType"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="row" type="int">
</parameter>
<parameter name="col" type="int">
</parameter>
</method>
<method name="isBlob"
 return="boolean"
 abstract="false"
@@ -57285,7 +57381,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="row" type="int">
@@ -57300,7 +57396,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="row" type="int">
@@ -57315,7 +57411,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="row" type="int">
@@ -57330,7 +57426,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="row" type="int">
@@ -57345,7 +57441,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="row" type="int">
@@ -57756,6 +57852,19 @@
<parameter name="columnIndex" type="int">
</parameter>
</method>
<method name="getType"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="columnIndex" type="int">
</parameter>
</method>
<method name="getWantsAllOnMoveCalls"
 return="boolean"
 abstract="false"
@@ -155557,6 +155666,19 @@
<parameter name="columnIndex" type="int">
</parameter>
</method>
<method name="getType"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="columnIndex" type="int">
</parameter>
</method>
<method name="getWantsAllOnMoveCalls"
 return="boolean"
 abstract="false"
+4 −0
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ public abstract class AbstractCursor implements CrossProcessCursor {
    abstract public double getDouble(int column);
    abstract public boolean isNull(int column);

    public int getType(int column) {
        throw new UnsupportedOperationException();
    }

    // TODO implement getBlob in all cursor types
    public byte[] getBlob(int column) {
        throw new UnsupportedOperationException("getBlob is not supported");
+14 −41
Original line number Diff line number Diff line
@@ -149,63 +149,36 @@ public abstract class AbstractWindowedCursor extends AbstractCursor
            }
        }

        return mWindow.isNull(mPos, columnIndex);
        return mWindow.getType(mPos, columnIndex) == Cursor.FIELD_TYPE_NULL;
    }

    public boolean isBlob(int columnIndex)
    {
        checkPosition();

        synchronized(mUpdatedRows) {
            if (isFieldUpdated(columnIndex)) {
                Object object = getUpdatedField(columnIndex);
                return object == null || object instanceof byte[];
            }
        }

        return mWindow.isBlob(mPos, columnIndex);
    }

    public boolean isString(int columnIndex)
    {
        checkPosition();

        synchronized(mUpdatedRows) {
            if (isFieldUpdated(columnIndex)) {
                Object object = getUpdatedField(columnIndex);
                return object == null || object instanceof String;
            }
    public boolean isBlob(int columnIndex) {
        return getType(columnIndex) == Cursor.FIELD_TYPE_BLOB;
    }

        return mWindow.isString(mPos, columnIndex);
    public boolean isString(int columnIndex) {
        return getType(columnIndex) == Cursor.FIELD_TYPE_STRING;
    }

    public boolean isLong(int columnIndex)
    {
        checkPosition();

        synchronized(mUpdatedRows) {
            if (isFieldUpdated(columnIndex)) {
                Object object = getUpdatedField(columnIndex);
                return object != null && (object instanceof Integer || object instanceof Long);
            }
    public boolean isLong(int columnIndex) {
        return getType(columnIndex) == Cursor.FIELD_TYPE_INTEGER;
    }

        return mWindow.isLong(mPos, columnIndex);
    public boolean isFloat(int columnIndex) {
        return getType(columnIndex) == Cursor.FIELD_TYPE_FLOAT;
    }

    public boolean isFloat(int columnIndex)
    @Override
    public int getType(int columnIndex)
    {
        checkPosition();

        synchronized(mUpdatedRows) {
            if (isFieldUpdated(columnIndex)) {
                Object object = getUpdatedField(columnIndex);
                return object != null && (object instanceof Float || object instanceof Double);
                return DatabaseUtils.getTypeOfObject(getUpdatedField(columnIndex));
            }
        }

        return mWindow.isFloat(mPos, columnIndex);
        return mWindow.getType(mPos, columnIndex);
    }

    @Override
+40 −0
Original line number Diff line number Diff line
@@ -30,6 +30,25 @@ import java.util.Map;
 * threads should perform its own synchronization when using the Cursor.
 */
public interface Cursor {
    /*
     * Values returned by {@link #getType(int)}.
     * These should be consistent with the corresponding types defined in CursorWindow.h
     */
    /** Value returned by {@link #getType(int)} if the specified column is null */
    static final int FIELD_TYPE_NULL = 0;

    /** Value returned by {@link #getType(int)} if the specified  column type is integer */
    static final int FIELD_TYPE_INTEGER = 1;

    /** Value returned by {@link #getType(int)} if the specified column type is float */
    static final int FIELD_TYPE_FLOAT = 2;

    /** Value returned by {@link #getType(int)} if the specified column type is string */
    static final int FIELD_TYPE_STRING = 3;

    /** Value returned by {@link #getType(int)} if the specified column type is blob */
    static final int FIELD_TYPE_BLOB = 4;

    /**
     * Returns the numbers of rows in the cursor.
     *
@@ -278,6 +297,27 @@ public interface Cursor {
     */
    double getDouble(int columnIndex);

    /**
     * Returns data type of the given column's value.
     * The preferred type of the column is returned but the data may be converted to other types
     * as documented in the get-type methods such as {@link #getInt(int)}, {@link #getFloat(int)}
     * etc.
     *<p>
     * Returned column types are
     * <ul>
     *   <li>{@link #FIELD_TYPE_NULL}</li>
     *   <li>{@link #FIELD_TYPE_INTEGER}</li>
     *   <li>{@link #FIELD_TYPE_FLOAT}</li>
     *   <li>{@link #FIELD_TYPE_STRING}</li>
     *   <li>{@link #FIELD_TYPE_BLOB}</li>
     *</ul>
     *</p>
     *
     * @param columnIndex the zero-based index of the target column.
     * @return column value type
     */
    int getType(int columnIndex);

    /**
     * Returns <code>true</code> if the value in the indicated column is null.
     *
+40 −28
Original line number Diff line number Diff line
@@ -217,14 +217,11 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
     * @param row the row to read from, row - getStartPosition() being the actual row in the window
     * @param col the column to read from
     * @return {@code true} if given field is {@code NULL}
     * @deprecated use {@link #getType(int, int)} instead
     */
    @Deprecated
    public boolean isNull(int row, int col) {
        acquireReference();
        try {
            return isNull_native(row - mStartPos, col);
        } finally {
            releaseReference();
        }
        return getType(row, col) == Cursor.FIELD_TYPE_NULL;
    }
    
    private native boolean isNull_native(int row, int col);
@@ -248,35 +245,55 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
    private native byte[] getBlob_native(int row, int col);

    /**
     * Checks if a field contains either a blob or is null.
     * Returns data type of the given column's value.
     *<p>
     * Returned column types are
     * <ul>
     *   <li>{@link Cursor#FIELD_TYPE_NULL}</li>
     *   <li>{@link Cursor#FIELD_TYPE_INTEGER}</li>
     *   <li>{@link Cursor#FIELD_TYPE_FLOAT}</li>
     *   <li>{@link Cursor#FIELD_TYPE_STRING}</li>
     *   <li>{@link Cursor#FIELD_TYPE_BLOB}</li>
     *</ul>
     *</p>
     *
     * @param row the row to read from, row - getStartPosition() being the actual row in the window
     * @param col the column to read from
     * @return {@code true} if given field is {@code NULL} or a blob
     * @return the value type
     */
    public boolean isBlob(int row, int col) {
    public int getType(int row, int col) {
        acquireReference();
        try {
            return isBlob_native(row - mStartPos, col);
            return getType_native(row - mStartPos, col);
        } finally {
            releaseReference();
        }
    }

    /**
     * Checks if a field contains either a blob or is null.
     *
     * @param row the row to read from, row - getStartPosition() being the actual row in the window
     * @param col the column to read from
     * @return {@code true} if given field is {@code NULL} or a blob
     * @deprecated use {@link #getType(int, int)} instead
     */
    @Deprecated
    public boolean isBlob(int row, int col) {
        return getType(row, col) == Cursor.FIELD_TYPE_BLOB;
    }

    /**
     * Checks if a field contains a long
     *
     * @param row the row to read from, row - getStartPosition() being the actual row in the window
     * @param col the column to read from
     * @return {@code true} if given field is a long
     * @deprecated use {@link #getType(int, int)} instead
     */
    @Deprecated
    public boolean isLong(int row, int col) {
        acquireReference();
        try {
            return isInteger_native(row - mStartPos, col);
        } finally {
            releaseReference();
        }
        return getType(row, col) == Cursor.FIELD_TYPE_INTEGER;
    }

    /**
@@ -285,14 +302,11 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
     * @param row the row to read from, row - getStartPosition() being the actual row in the window
     * @param col the column to read from
     * @return {@code true} if given field is a float
     * @deprecated use {@link #getType(int, int)} instead
     */
    @Deprecated
    public boolean isFloat(int row, int col) {
        acquireReference();
        try {
            return isFloat_native(row - mStartPos, col);
        } finally {
            releaseReference();
        }
        return getType(row, col) == Cursor.FIELD_TYPE_FLOAT;
    }

    /**
@@ -301,20 +315,18 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
     * @param row the row to read from, row - getStartPosition() being the actual row in the window
     * @param col the column to read from
     * @return {@code true} if given field is {@code NULL} or a String
     * @deprecated use {@link #getType(int, int)} instead
     */
    @Deprecated
    public boolean isString(int row, int col) {
        acquireReference();
        try {
            return isString_native(row - mStartPos, col);
        } finally {
            releaseReference();
        }
        return getType(row, col) == Cursor.FIELD_TYPE_STRING;
    }

    private native boolean isBlob_native(int row, int col);
    private native boolean isString_native(int row, int col);
    private native boolean isInteger_native(int row, int col);
    private native boolean isFloat_native(int row, int col);
    private native int getType_native(int row, int col);

    /**
     * Returns a String for the given field.
Loading