Class MergeCursor
- java.lang.Object
-
- android.database.AbstractCursor
-
- android.database.MergeCursor
-
- All Implemented Interfaces:
CrossProcessCursor,Cursor,Closeable,AutoCloseable
public class MergeCursor extends AbstractCursor
A convience class that lets you present an array of Cursors as a single linear Cursor. The schema of the cursors presented is entirely up to the creator of the MergeCursor, and may be different if that is desired. Calls to getColumns, getColumnIndex, etc will return the value for the row that the MergeCursor is currently pointing at.
-
-
Field Summary
-
Fields inherited from class android.database.AbstractCursor
mClosed, mCurrentRowID, mPos, mRowIdColumnIndex, mUpdatedRows
-
Fields inherited from interface android.database.Cursor
FIELD_TYPE_BLOB, FIELD_TYPE_FLOAT, FIELD_TYPE_INTEGER, FIELD_TYPE_NULL, FIELD_TYPE_STRING
-
-
Constructor Summary
Constructors Constructor Description MergeCursor(Cursor[] cursors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the Cursor, releasing all of its resources and making it completely invalid.voiddeactivate()Deactivates the Cursor, making all calls on it fail untilCursor.requery()is called.byte[]getBlob(int column)Returns the value of the requested column as a byte array.String[]getColumnNames()Returns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.intgetCount()Returns the numbers of rows in the cursor.doublegetDouble(int column)Returns the value of the requested column as a double.floatgetFloat(int column)Returns the value of the requested column as a float.intgetInt(int column)Returns the value of the requested column as an int.longgetLong(int column)Returns the value of the requested column as a long.shortgetShort(int column)Returns the value of the requested column as a short.StringgetString(int column)Returns the value of the requested column as a String.intgetType(int column)Returns data type of the given column's value.booleanisNull(int column)Returnstrueif the value in the indicated column is null.booleanonMove(int oldPosition, int newPosition)This function is called every time the cursor is successfully scrolled to a new position, giving the subclass a chance to update any state it may have.voidregisterDataSetObserver(DataSetObserver observer)Register an observer that is called when changes happen to the contents of the this cursors data set, for example, when the data set is changed viaCursor.requery(),Cursor.deactivate(), orCursor.close().booleanrequery()Performs the query that created the cursor again, refreshing its contents.voidunregisterDataSetObserver(DataSetObserver observer)Unregister an observer that has previously been registered with this cursor via#registerContentObserver.-
Methods inherited from class android.database.AbstractCursor
checkPosition, copyStringToBuffer, fillWindow, finalize, getColumnCount, getColumnIndex, getColumnIndexOrThrow, getColumnName, getExtras, getPosition, getUpdatedField, getWantsAllOnMoveCalls, getWindow, isAfterLast, isBeforeFirst, isClosed, isFieldUpdated, isFirst, isLast, move, moveToFirst, moveToLast, moveToNext, moveToPosition, moveToPrevious, onChange, onDeactivateOrClose, respond, setExtras
-
-
-
-
Constructor Detail
-
MergeCursor
public MergeCursor(Cursor[] cursors)
-
-
Method Detail
-
getCount
public int getCount()
Description copied from interface:CursorReturns the numbers of rows in the cursor.- Specified by:
getCountin interfaceCursor- Specified by:
getCountin classAbstractCursor- Returns:
- the number of rows in the cursor.
-
onMove
public boolean onMove(int oldPosition, int newPosition)Description copied from class:AbstractCursorThis function is called every time the cursor is successfully scrolled to a new position, giving the subclass a chance to update any state it may have. If it returns false the move function will also do so and the cursor will scroll to the beforeFirst position.- Specified by:
onMovein interfaceCrossProcessCursor- Overrides:
onMovein classAbstractCursor- Parameters:
oldPosition- the position that we're moving fromnewPosition- the position that we're moving to- Returns:
- true if the move is successful, false otherwise
-
getString
public String getString(int column)
Description copied from interface:CursorReturns the value of the requested column as a String.The result and whether this method throws an exception when the column value is null or the column type is not a string type is implementation-defined.
- Specified by:
getStringin interfaceCursor- Specified by:
getStringin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a String.
-
getShort
public short getShort(int column)
Description copied from interface:CursorReturns the value of the requested column as a short.The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [
Short.MIN_VALUE,Short.MAX_VALUE] is implementation-defined.- Specified by:
getShortin interfaceCursor- Specified by:
getShortin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a short.
-
getInt
public int getInt(int column)
Description copied from interface:CursorReturns the value of the requested column as an int.The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [
Integer.MIN_VALUE,Integer.MAX_VALUE] is implementation-defined.- Specified by:
getIntin interfaceCursor- Specified by:
getIntin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as an int.
-
getLong
public long getLong(int column)
Description copied from interface:CursorReturns the value of the requested column as a long.The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [
Long.MIN_VALUE,Long.MAX_VALUE] is implementation-defined.- Specified by:
getLongin interfaceCursor- Specified by:
getLongin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a long.
-
getFloat
public float getFloat(int column)
Description copied from interface:CursorReturns the value of the requested column as a float.The result and whether this method throws an exception when the column value is null, the column type is not a floating-point type, or the floating-point value is not representable as a
floatvalue is implementation-defined.- Specified by:
getFloatin interfaceCursor- Specified by:
getFloatin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a float.
-
getDouble
public double getDouble(int column)
Description copied from interface:CursorReturns the value of the requested column as a double.The result and whether this method throws an exception when the column value is null, the column type is not a floating-point type, or the floating-point value is not representable as a
doublevalue is implementation-defined.- Specified by:
getDoublein interfaceCursor- Specified by:
getDoublein classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a double.
-
getType
public int getType(int column)
Description copied from interface:CursorReturns 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 asCursor.getInt(int),Cursor.getFloat(int)etc.Returned column types are
- Specified by:
getTypein interfaceCursor- Overrides:
getTypein classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- column value type
-
isNull
public boolean isNull(int column)
Description copied from interface:CursorReturnstrueif the value in the indicated column is null.- Specified by:
isNullin interfaceCursor- Specified by:
isNullin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- whether the column value is null.
-
getBlob
public byte[] getBlob(int column)
Description copied from interface:CursorReturns the value of the requested column as a byte array.The result and whether this method throws an exception when the column value is null or the column type is not a blob type is implementation-defined.
- Specified by:
getBlobin interfaceCursor- Overrides:
getBlobin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a byte array.
-
getColumnNames
public String[] getColumnNames()
Description copied from interface:CursorReturns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.- Specified by:
getColumnNamesin interfaceCursor- Specified by:
getColumnNamesin classAbstractCursor- Returns:
- the names of the columns returned in this query.
-
deactivate
public void deactivate()
Description copied from interface:CursorDeactivates the Cursor, making all calls on it fail untilCursor.requery()is called. Inactive Cursors use fewer resources than active Cursors. CallingCursor.requery()will make the cursor active again.- Specified by:
deactivatein interfaceCursor- Overrides:
deactivatein classAbstractCursor
-
close
public void close()
Description copied from interface:CursorCloses the Cursor, releasing all of its resources and making it completely invalid. UnlikeCursor.deactivate()a call toCursor.requery()will not make the Cursor valid again.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCursor- Overrides:
closein classAbstractCursor
-
registerDataSetObserver
public void registerDataSetObserver(DataSetObserver observer)
Description copied from interface:CursorRegister an observer that is called when changes happen to the contents of the this cursors data set, for example, when the data set is changed viaCursor.requery(),Cursor.deactivate(), orCursor.close().- Specified by:
registerDataSetObserverin interfaceCursor- Overrides:
registerDataSetObserverin classAbstractCursor- Parameters:
observer- the object that gets notified when the cursors data set changes.- See Also:
Cursor.unregisterDataSetObserver(DataSetObserver)
-
unregisterDataSetObserver
public void unregisterDataSetObserver(DataSetObserver observer)
Description copied from interface:CursorUnregister an observer that has previously been registered with this cursor via#registerContentObserver.- Specified by:
unregisterDataSetObserverin interfaceCursor- Overrides:
unregisterDataSetObserverin classAbstractCursor- Parameters:
observer- the object to unregister.- See Also:
Cursor.registerDataSetObserver(DataSetObserver)
-
requery
public boolean requery()
Description copied from interface:CursorPerforms the query that created the cursor again, refreshing its contents. This may be done at any time, including after a call toCursor.deactivate(). Since this method could execute a query on the database and potentially take a while, it could cause ANR if it is called on Main (UI) thread. A warning is printed if this method is being executed on Main thread.- Specified by:
requeryin interfaceCursor- Overrides:
requeryin classAbstractCursor- Returns:
- true if the requery succeeded, false if not, in which case the cursor becomes invalid.
-
-