Class CursorWindow
- java.lang.Object
-
- android.database.sqlite.SQLiteClosable
-
- android.database.CursorWindow
-
- All Implemented Interfaces:
Parcelable,Closeable,AutoCloseable
public class CursorWindow extends SQLiteClosable implements Parcelable
A buffer containing multiple cursor rows.A
CursorWindowis read-write when initially created and used locally. When sent to a remote process (by writing it to aParcel), the remote process receives a read-only view of the cursor window. Typically the cursor window will be allocated by the producer, filled with data, and then sent to the consumer for reading.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
-
-
Field Summary
Fields Modifier and Type Field Description static Parcelable.Creator<CursorWindow>CREATORlongmWindowPtrThe native CursorWindow object pointer.-
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
-
-
Constructor Summary
Constructors Constructor Description CursorWindow(boolean localWindow)Deprecated.There is no longer a distinction between local and remote cursor windows.CursorWindow(String name)Creates a new empty cursor window and gives it a name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanallocRow()Allocates a new row at the end of this cursor window.voidclear()Clears out the existing contents of the window, making it safe to reuse for new data.voidcopyStringToBuffer(int row, int column, CharArrayBuffer buffer)Copies the text of the field at the specified row and column index into aCharArrayBuffer.intdescribeContents()Describe the kinds of special objects contained in this Parcelable's marshalled representation.protected voidfinalize()Invoked when the garbage collector has detected that this instance is no longer reachable.voidfreeLastRow()Frees the last row in this cursor window.byte[]getBlob(int row, int column)Gets the value of the field at the specified row and column index as a byte array.doublegetDouble(int row, int column)Gets the value of the field at the specified row and column index as adouble.floatgetFloat(int row, int column)Gets the value of the field at the specified row and column index as afloat.intgetInt(int row, int column)Gets the value of the field at the specified row and column index as anint.longgetLong(int row, int column)Gets the value of the field at the specified row and column index as along.StringgetName()Gets the name of this cursor window, never null.intgetNumRows()Gets the number of rows in this window.shortgetShort(int row, int column)Gets the value of the field at the specified row and column index as ashort.intgetStartPosition()Gets the start position of this cursor window.StringgetString(int row, int column)Gets the value of the field at the specified row and column index as a string.intgetType(int row, int column)Returns the type of the field at the specified row and column index.booleanisBlob(int row, int column)Deprecated.UsegetType(int, int)instead.booleanisFloat(int row, int column)Deprecated.UsegetType(int, int)instead.booleanisLong(int row, int column)Deprecated.UsegetType(int, int)instead.booleanisNull(int row, int column)Deprecated.UsegetType(int, int)instead.booleanisString(int row, int column)Deprecated.UsegetType(int, int)instead.static CursorWindownewFromParcel(Parcel p)protected voidonAllReferencesReleased()Called when the last reference to the object was released by a call toSQLiteClosable.releaseReference()orSQLiteClosable.close().booleanputBlob(byte[] value, int row, int column)Copies a byte array into the field at the specified row and column index.booleanputDouble(double value, int row, int column)Puts a double-precision floating point value into the field at the specified row and column index.booleanputLong(long value, int row, int column)Puts a long integer into the field at the specified row and column index.booleanputNull(int row, int column)Puts a null value into the field at the specified row and column index.booleanputString(String value, int row, int column)Copies a string into the field at the specified row and column index.booleansetNumColumns(int columnNum)Sets the number of columns in this window.voidsetStartPosition(int pos)Sets the start position of this cursor window.StringtoString()Returns a string containing a concise, human-readable description of this object.voidwriteToParcel(Parcel dest, int flags)Flatten this object in to a Parcel.-
Methods inherited from class android.database.sqlite.SQLiteClosable
acquireReference, close, onAllReferencesReleasedFromContainer, releaseReference, releaseReferenceFromContainer
-
-
-
-
Field Detail
-
mWindowPtr
public long mWindowPtr
The native CursorWindow object pointer. (FOR INTERNAL USE ONLY)
-
CREATOR
public static final Parcelable.Creator<CursorWindow> CREATOR
-
-
Constructor Detail
-
CursorWindow
public CursorWindow(String name)
Creates a new empty cursor window and gives it a name.The cursor initially has no rows or columns. Call
setNumColumns(int)to set the number of columns before adding any rows to the cursor.- Parameters:
name- The name of the cursor window, or null if none.
-
CursorWindow
@Deprecated public CursorWindow(boolean localWindow)
Deprecated.There is no longer a distinction between local and remote cursor windows. Use theCursorWindow(String)constructor instead.Creates a new empty cursor window.The cursor initially has no rows or columns. Call
setNumColumns(int)to set the number of columns before adding any rows to the cursor.- Parameters:
localWindow- True if this window will be used in this process only, false if it might be sent to another processes. This argument is ignored.
-
-
Method Detail
-
finalize
protected void finalize() throws ThrowableDescription copied from class:ObjectInvoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.Note that objects that override
finalizeare significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicitclosemethod (and implementCloseable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like aBigIntegerwhere typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.If you must use finalizers, consider at least providing your own
ReferenceQueueand having your own thread process that queue.Unlike constructors, finalizers are not automatically chained. You are responsible for calling
super.finalize()yourself.Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
-
getName
public String getName()
Gets the name of this cursor window, never null.
-
clear
public void clear()
Clears out the existing contents of the window, making it safe to reuse for new data.The start position (
getStartPosition()), number of rows (getNumRows()), and number of columns in the cursor are all reset to zero.
-
getStartPosition
public int getStartPosition()
Gets the start position of this cursor window.The start position is the zero-based index of the first row that this window contains relative to the entire result set of the
Cursor.- Returns:
- The zero-based start position.
-
setStartPosition
public void setStartPosition(int pos)
Sets the start position of this cursor window.The start position is the zero-based index of the first row that this window contains relative to the entire result set of the
Cursor.- Parameters:
pos- The new zero-based start position.
-
getNumRows
public int getNumRows()
Gets the number of rows in this window.- Returns:
- The number of rows in this cursor window.
-
setNumColumns
public boolean setNumColumns(int columnNum)
Sets the number of columns in this window.This method must be called before any rows are added to the window, otherwise it will fail to set the number of columns if it differs from the current number of columns.
- Parameters:
columnNum- The new number of columns.- Returns:
- True if successful.
-
allocRow
public boolean allocRow()
Allocates a new row at the end of this cursor window.- Returns:
- True if successful, false if the cursor window is out of memory.
-
freeLastRow
public void freeLastRow()
Frees the last row in this cursor window.
-
isNull
@Deprecated public boolean isNull(int row, int column)
Deprecated.UsegetType(int, int)instead.Returns true if the field at the specified row and column index has typeCursor.FIELD_TYPE_NULL.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- True if the field has type
Cursor.FIELD_TYPE_NULL.
-
isBlob
@Deprecated public boolean isBlob(int row, int column)
Deprecated.UsegetType(int, int)instead.Returns true if the field at the specified row and column index has typeCursor.FIELD_TYPE_BLOBorCursor.FIELD_TYPE_NULL.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- True if the field has type
Cursor.FIELD_TYPE_BLOBorCursor.FIELD_TYPE_NULL.
-
isLong
@Deprecated public boolean isLong(int row, int column)
Deprecated.UsegetType(int, int)instead.Returns true if the field at the specified row and column index has typeCursor.FIELD_TYPE_INTEGER.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- True if the field has type
Cursor.FIELD_TYPE_INTEGER.
-
isFloat
@Deprecated public boolean isFloat(int row, int column)
Deprecated.UsegetType(int, int)instead.Returns true if the field at the specified row and column index has typeCursor.FIELD_TYPE_FLOAT.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- True if the field has type
Cursor.FIELD_TYPE_FLOAT.
-
isString
@Deprecated public boolean isString(int row, int column)
Deprecated.UsegetType(int, int)instead.Returns true if the field at the specified row and column index has typeCursor.FIELD_TYPE_STRINGorCursor.FIELD_TYPE_NULL.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- True if the field has type
Cursor.FIELD_TYPE_STRINGorCursor.FIELD_TYPE_NULL.
-
getType
public int getType(int row, int column)Returns the type of the field at the specified row and column index.The returned field types are:
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The field type.
-
getBlob
public byte[] getBlob(int row, int column)Gets the value of the field at the specified row and column index as a byte array.The result is determined as follows:
- If the field is of type
Cursor.FIELD_TYPE_NULL, then the result isnull. - If the field is of type
Cursor.FIELD_TYPE_BLOB, then the result is the blob value. - If the field is of type
Cursor.FIELD_TYPE_STRING, then the result is the array of bytes that make up the internal representation of the string value. - If the field is of type
Cursor.FIELD_TYPE_INTEGERorCursor.FIELD_TYPE_FLOAT, then aSQLiteExceptionis thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The value of the field as a byte array.
- If the field is of type
-
getString
public String getString(int row, int column)
Gets the value of the field at the specified row and column index as a string.The result is determined as follows:
- If the field is of type
Cursor.FIELD_TYPE_NULL, then the result isnull. - If the field is of type
Cursor.FIELD_TYPE_STRING, then the result is the string value. - If the field is of type
Cursor.FIELD_TYPE_INTEGER, then the result is a string representation of the integer in decimal, obtained by formatting the value with theprintffamily of functions using format specifier%lld. - If the field is of type
Cursor.FIELD_TYPE_FLOAT, then the result is a string representation of the floating-point value in decimal, obtained by formatting the value with theprintffamily of functions using format specifier%g. - If the field is of type
Cursor.FIELD_TYPE_BLOB, then aSQLiteExceptionis thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The value of the field as a string.
- If the field is of type
-
copyStringToBuffer
public void copyStringToBuffer(int row, int column, CharArrayBuffer buffer)Copies the text of the field at the specified row and column index into aCharArrayBuffer.The buffer is populated as follows:
- If the buffer is too small for the value to be copied, then it is automatically resized.
- If the field is of type
Cursor.FIELD_TYPE_NULL, then the buffer is set to an empty string. - If the field is of type
Cursor.FIELD_TYPE_STRING, then the buffer is set to the contents of the string. - If the field is of type
Cursor.FIELD_TYPE_INTEGER, then the buffer is set to a string representation of the integer in decimal, obtained by formatting the value with theprintffamily of functions using format specifier%lld. - If the field is of type
Cursor.FIELD_TYPE_FLOAT, then the buffer is set to a string representation of the floating-point value in decimal, obtained by formatting the value with theprintffamily of functions using format specifier%g. - If the field is of type
Cursor.FIELD_TYPE_BLOB, then aSQLiteExceptionis thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.buffer- TheCharArrayBufferto hold the string. It is automatically resized if the requested string is larger than the buffer's current capacity.
-
getLong
public long getLong(int row, int column)Gets the value of the field at the specified row and column index as along.The result is determined as follows:
- If the field is of type
Cursor.FIELD_TYPE_NULL, then the result is0L. - If the field is of type
Cursor.FIELD_TYPE_STRING, then the result is the value obtained by parsing the string value withstrtoll. - If the field is of type
Cursor.FIELD_TYPE_INTEGER, then the result is thelongvalue. - If the field is of type
Cursor.FIELD_TYPE_FLOAT, then the result is the floating-point value converted to along. - If the field is of type
Cursor.FIELD_TYPE_BLOB, then aSQLiteExceptionis thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The value of the field as a
long.
- If the field is of type
-
getDouble
public double getDouble(int row, int column)Gets the value of the field at the specified row and column index as adouble.The result is determined as follows:
- If the field is of type
Cursor.FIELD_TYPE_NULL, then the result is0.0. - If the field is of type
Cursor.FIELD_TYPE_STRING, then the result is the value obtained by parsing the string value withstrtod. - If the field is of type
Cursor.FIELD_TYPE_INTEGER, then the result is the integer value converted to adouble. - If the field is of type
Cursor.FIELD_TYPE_FLOAT, then the result is thedoublevalue. - If the field is of type
Cursor.FIELD_TYPE_BLOB, then aSQLiteExceptionis thrown.
- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The value of the field as a
double.
- If the field is of type
-
getShort
public short getShort(int row, int column)Gets the value of the field at the specified row and column index as ashort.The result is determined by invoking
getLong(int, int)and converting the result toshort.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The value of the field as a
short.
-
getInt
public int getInt(int row, int column)Gets the value of the field at the specified row and column index as anint.The result is determined by invoking
getLong(int, int)and converting the result toint.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The value of the field as an
int.
-
getFloat
public float getFloat(int row, int column)Gets the value of the field at the specified row and column index as afloat.The result is determined by invoking
getDouble(int, int)and converting the result tofloat.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- The value of the field as an
float.
-
putBlob
public boolean putBlob(byte[] value, int row, int column)Copies a byte array into the field at the specified row and column index.- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
- True if successful.
-
putString
public boolean putString(String value, int row, int column)
Copies a string into the field at the specified row and column index.- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
- True if successful.
-
putLong
public boolean putLong(long value, int row, int column)Puts a long integer into the field at the specified row and column index.- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
- True if successful.
-
putDouble
public boolean putDouble(double value, int row, int column)Puts a double-precision floating point value into the field at the specified row and column index.- Parameters:
value- The value to store.row- The zero-based row index.column- The zero-based column index.- Returns:
- True if successful.
-
putNull
public boolean putNull(int row, int column)Puts a null value into the field at the specified row and column index.- Parameters:
row- The zero-based row index.column- The zero-based column index.- Returns:
- True if successful.
-
newFromParcel
public static CursorWindow newFromParcel(Parcel p)
-
describeContents
public int describeContents()
Description copied from interface:ParcelableDescribe the kinds of special objects contained in this Parcelable's marshalled representation.- Specified by:
describeContentsin interfaceParcelable- Returns:
- a bitmask indicating the set of special object types marshalled by the Parcelable.
-
writeToParcel
public void writeToParcel(Parcel dest, int flags)
Description copied from interface:ParcelableFlatten this object in to a Parcel.- Specified by:
writeToParcelin interfaceParcelable- Parameters:
dest- The Parcel in which the object should be written.flags- Additional flags about how the object should be written. May be 0 orParcelable.PARCELABLE_WRITE_RETURN_VALUE.
-
onAllReferencesReleased
protected void onAllReferencesReleased()
Description copied from class:SQLiteClosableCalled when the last reference to the object was released by a call toSQLiteClosable.releaseReference()orSQLiteClosable.close().- Specified by:
onAllReferencesReleasedin classSQLiteClosable
-
toString
public String toString()
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod.
-
-