Class AbstractWindowedCursor
- java.lang.Object
-
- android.database.AbstractCursor
-
- android.database.AbstractWindowedCursor
-
- All Implemented Interfaces:
CrossProcessCursor,Cursor,Closeable,AutoCloseable
- Direct Known Subclasses:
SQLiteCursor
public abstract class AbstractWindowedCursor extends AbstractCursor
A base class for Cursors that store their data inCursorWindows.The cursor owns the cursor window it uses. When the cursor is closed, its window is also closed. Likewise, when the window used by the cursor is changed, its old window is closed. This policy of strict ownership ensures that cursor windows are not leaked.
Subclasses are responsible for filling the cursor window with data during
AbstractCursor.onMove(int, int), allocating a new cursor window if necessary. DuringAbstractCursor.requery(), the existing cursor window should be cleared and filled with new data.If the contents of the cursor change or become invalid, the old window must be closed (because it is owned by the cursor) and set to null.
-
-
Field Summary
Fields Modifier and Type Field Description protected CursorWindowmWindowThe cursor window owned by this cursor.-
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 AbstractWindowedCursor()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidcheckPosition()This function throws CursorIndexOutOfBoundsException if the cursor position is out of bounds.protected voidclearOrCreateWindow(String name)If there is a window, clear it.protected voidcloseWindow()Closes the cursor window and setsmWindowto null.voidcopyStringToBuffer(int columnIndex, CharArrayBuffer buffer)Retrieves the requested column text and stores it in the buffer provided.byte[]getBlob(int columnIndex)Returns the value of the requested column as a byte array.doublegetDouble(int columnIndex)Returns the value of the requested column as a double.floatgetFloat(int columnIndex)Returns the value of the requested column as a float.intgetInt(int columnIndex)Returns the value of the requested column as an int.longgetLong(int columnIndex)Returns the value of the requested column as a long.shortgetShort(int columnIndex)Returns the value of the requested column as a short.StringgetString(int columnIndex)Returns the value of the requested column as a String.intgetType(int columnIndex)Returns data type of the given column's value.CursorWindowgetWindow()If the cursor is backed by aCursorWindow, returns a pre-filled window with the contents of the cursor, otherwise null.booleanhasWindow()Returns true if the cursor has an associated cursor window.booleanisBlob(int columnIndex)Deprecated.UsegetType(int)booleanisFloat(int columnIndex)Deprecated.UsegetType(int)booleanisLong(int columnIndex)Deprecated.UsegetType(int)booleanisNull(int columnIndex)Returnstrueif the value in the indicated column is null.booleanisString(int columnIndex)Deprecated.UsegetType(int)protected voidonDeactivateOrClose()voidsetWindow(CursorWindow window)Sets a new cursor window for the cursor to use.-
Methods inherited from class android.database.AbstractCursor
close, deactivate, fillWindow, finalize, getColumnCount, getColumnIndex, getColumnIndexOrThrow, getColumnName, getColumnNames, getCount, getExtras, getPosition, getUpdatedField, getWantsAllOnMoveCalls, isAfterLast, isBeforeFirst, isClosed, isFieldUpdated, isFirst, isLast, move, moveToFirst, moveToLast, moveToNext, moveToPosition, moveToPrevious, onChange, onMove, registerDataSetObserver, requery, respond, setExtras, unregisterDataSetObserver
-
-
-
-
Field Detail
-
mWindow
protected CursorWindow mWindow
The cursor window owned by this cursor.
-
-
Method Detail
-
getBlob
public byte[] getBlob(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- the value of that column as a byte array.
-
getString
public String getString(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- the value of that column as a String.
-
copyStringToBuffer
public void copyStringToBuffer(int columnIndex, CharArrayBuffer buffer)Description copied from interface:CursorRetrieves the requested column text and stores it in the buffer provided. If the buffer size is not sufficient, a new char buffer will be allocated and assigned to CharArrayBuffer.data- Specified by:
copyStringToBufferin interfaceCursor- Overrides:
copyStringToBufferin classAbstractCursor- Parameters:
columnIndex- the zero-based index of the target column. if the target column is null, return bufferbuffer- the buffer to copy the text into.
-
getShort
public short getShort(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- the value of that column as a short.
-
getInt
public int getInt(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- the value of that column as an int.
-
getLong
public long getLong(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- the value of that column as a long.
-
getFloat
public float getFloat(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- the value of that column as a float.
-
getDouble
public double getDouble(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- the value of that column as a double.
-
isNull
public boolean isNull(int columnIndex)
Description copied from interface:CursorReturnstrueif the value in the indicated column is null.- Specified by:
isNullin interfaceCursor- Specified by:
isNullin classAbstractCursor- Parameters:
columnIndex- the zero-based index of the target column.- Returns:
- whether the column value is null.
-
isBlob
@Deprecated public boolean isBlob(int columnIndex)
Deprecated.UsegetType(int)
-
isString
@Deprecated public boolean isString(int columnIndex)
Deprecated.UsegetType(int)
-
isLong
@Deprecated public boolean isLong(int columnIndex)
Deprecated.UsegetType(int)
-
isFloat
@Deprecated public boolean isFloat(int columnIndex)
Deprecated.UsegetType(int)
-
getType
public int getType(int columnIndex)
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:
columnIndex- the zero-based index of the target column.- Returns:
- column value type
-
checkPosition
protected void checkPosition()
Description copied from class:AbstractCursorThis function throws CursorIndexOutOfBoundsException if the cursor position is out of bounds. Subclass implementations of the get functions should call this before attempting to retrieve data.- Overrides:
checkPositionin classAbstractCursor
-
getWindow
public CursorWindow getWindow()
Description copied from class:AbstractCursorIf the cursor is backed by aCursorWindow, returns a pre-filled window with the contents of the cursor, otherwise null.- Specified by:
getWindowin interfaceCrossProcessCursor- Overrides:
getWindowin classAbstractCursor- Returns:
- The pre-filled window that backs this cursor, or null if none.
-
setWindow
public void setWindow(CursorWindow window)
Sets a new cursor window for the cursor to use.The cursor takes ownership of the provided cursor window; the cursor window will be closed when the cursor is closed or when the cursor adopts a new cursor window.
If the cursor previously had a cursor window, then it is closed when the new cursor window is assigned.
- Parameters:
window- The new cursor window, typically a remote cursor window.
-
hasWindow
public boolean hasWindow()
Returns true if the cursor has an associated cursor window.- Returns:
- True if the cursor has an associated cursor window.
-
closeWindow
protected void closeWindow()
Closes the cursor window and setsmWindowto null.
-
clearOrCreateWindow
protected void clearOrCreateWindow(String name)
If there is a window, clear it. Otherwise, creates a new window.- Parameters:
name- The window name.
-
onDeactivateOrClose
protected void onDeactivateOrClose()
- Overrides:
onDeactivateOrClosein classAbstractCursor
-
-