";
}
+
/**
* Creates a new empty cursor window.
*
@@ -144,33 +100,14 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
this((String)null);
}
- @Override
- protected void finalize() throws Throwable {
- try {
- if (mCloseGuard != null) {
- mCloseGuard.warnIfOpen();
- }
- dispose();
- } finally {
- super.finalize();
- }
- }
- private void dispose() {
- if (mCloseGuard != null) {
- mCloseGuard.close();
- }
- if (mWindowPtr != 0) {
- nativeDispose(mWindowPtr);
- mWindowPtr = 0;
- }
- }
/**
* Gets the name of this cursor window, never null.
* @hide
*/
public String getName() {
- return mName;
+ return name;
}
+
/**
* Clears out the existing contents of the window, making it safe to reuse
* for new data.
@@ -180,14 +117,10 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
*
*/
public void clear() {
- acquireReference();
- try {
- mStartPos = 0;
- nativeClear(mWindowPtr);
- } finally {
- releaseReference();
- }
+ startPos = 0;
+ rows.clear();
}
+
/**
* Gets the start position of this cursor window.
*
@@ -198,8 +131,9 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @return The zero-based start position.
*/
public int getStartPosition() {
- return mStartPos;
+ return startPos;
}
+
/**
* Sets the start position of this cursor window.
*
@@ -210,21 +144,18 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @param pos The new zero-based start position.
*/
public void setStartPosition(int pos) {
- mStartPos = pos;
+ startPos = pos;
}
+
/**
* Gets the number of rows in this window.
*
* @return The number of rows in this cursor window.
*/
public int getNumRows() {
- acquireReference();
- try {
- return nativeGetNumRows(mWindowPtr);
- } finally {
- releaseReference();
- }
+ return rows.size();
}
+
/**
* Sets the number of columns in this window.
*
@@ -237,37 +168,27 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @return True if successful.
*/
public boolean setNumColumns(int columnNum) {
- acquireReference();
- try {
- return nativeSetNumColumns(mWindowPtr, columnNum);
- } finally {
- releaseReference();
- }
+ this.numColumns = columnNum;
+ return true;
}
+
/**
* Allocates a new row at the end of this cursor window.
*
* @return True if successful, false if the cursor window is out of memory.
*/
public boolean allocRow(){
- acquireReference();
- try {
- return nativeAllocRow(mWindowPtr);
- } finally {
- releaseReference();
- }
+ rows.add(new Object[numColumns]);
+ return true;
}
+
/**
* Frees the last row in this cursor window.
*/
public void freeLastRow(){
- acquireReference();
- try {
- nativeFreeLastRow(mWindowPtr);
- } finally {
- releaseReference();
- }
+ rows.remove(rows.size() - 1);
}
+
/**
* Returns true if the field at the specified row and column index
* has type {@link Cursor#FIELD_TYPE_NULL}.
@@ -281,6 +202,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
public boolean isNull(int row, int column) {
return getType(row, column) == Cursor.FIELD_TYPE_NULL;
}
+
/**
* Returns true if the field at the specified row and column index
* has type {@link Cursor#FIELD_TYPE_BLOB} or {@link Cursor#FIELD_TYPE_NULL}.
@@ -296,6 +218,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
int type = getType(row, column);
return type == Cursor.FIELD_TYPE_BLOB || type == Cursor.FIELD_TYPE_NULL;
}
+
/**
* Returns true if the field at the specified row and column index
* has type {@link Cursor#FIELD_TYPE_INTEGER}.
@@ -309,6 +232,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
public boolean isLong(int row, int column) {
return getType(row, column) == Cursor.FIELD_TYPE_INTEGER;
}
+
/**
* Returns true if the field at the specified row and column index
* has type {@link Cursor#FIELD_TYPE_FLOAT}.
@@ -322,6 +246,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
public boolean isFloat(int row, int column) {
return getType(row, column) == Cursor.FIELD_TYPE_FLOAT;
}
+
/**
* Returns true if the field at the specified row and column index
* has type {@link Cursor#FIELD_TYPE_STRING} or {@link Cursor#FIELD_TYPE_NULL}.
@@ -337,6 +262,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
int type = getType(row, column);
return type == Cursor.FIELD_TYPE_STRING || type == Cursor.FIELD_TYPE_NULL;
}
+
/**
* Returns the type of the field at the specified row and column index.
*
@@ -344,15 +270,21 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @param column The zero-based column index.
* @return The field type.
*/
- public int getType(int row,
- int column) {
- acquireReference();
- try {
- return nativeGetType(mWindowPtr, row - mStartPos, column);
- } finally {
- releaseReference();
+ public int getType(int row, int column) {
+ Object value = rows.get(row - startPos)[column];
+ if (value instanceof String) {
+ return Cursor.FIELD_TYPE_STRING;
+ } else if (value instanceof Long) {
+ return Cursor.FIELD_TYPE_INTEGER;
+ } else if (value instanceof Double) {
+ return Cursor.FIELD_TYPE_FLOAT;
+ } else if (value instanceof byte[]) {
+ return Cursor.FIELD_TYPE_BLOB;
+ } else {
+ return Cursor.FIELD_TYPE_NULL;
}
}
+
/**
* Gets the value of the field at the specified row and column index as a byte array.
*
@@ -375,13 +307,9 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @return The value of the field as a byte array.
*/
public byte[] getBlob(int row, int column) {
- acquireReference();
- try {
- return nativeGetBlob(mWindowPtr, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ return (byte[])rows.get(row - startPos)[column];
}
+
/**
* Gets the value of the field at the specified row and column index as a string.
*
@@ -409,13 +337,9 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @return The value of the field as a string.
*/
public String getString(int row, int column) {
- acquireReference();
- try {
- return nativeGetString(mWindowPtr, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ return (String)rows.get(row - startPos)[column];
}
+
/**
* Copies the text of the field at the specified row and column index into
* a {@link CharArrayBuffer}.
@@ -446,18 +370,15 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @param buffer The {@link CharArrayBuffer} to hold the string. It is automatically
* resized if the requested string is larger than the buffer's current capacity.
*/
- public void copyStringToBuffer(int row, int column,
- CharArrayBuffer buffer) {
+ public void copyStringToBuffer(int row, int column, CharArrayBuffer buffer) {
if (buffer == null) {
throw new IllegalArgumentException("CharArrayBuffer should not be null");
}
- acquireReference();
- try {
- nativeCopyStringToBuffer(mWindowPtr, row - mStartPos, column, buffer);
- } finally {
- releaseReference();
- }
+ String result = String.valueOf(rows.get(row - startPos)[column]);
+ buffer.data = result.toCharArray();
+ buffer.sizeCopied = result.length();
}
+
/**
* Gets the value of the field at the specified row and column index as a long.
*
@@ -481,13 +402,9 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @return The value of the field as a long.
*/
public long getLong(int row, int column) {
- acquireReference();
- try {
- return nativeGetLong(mWindowPtr, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ return (Long)rows.get(row - startPos)[column];
}
+
/**
* Gets the value of the field at the specified row and column index as a
* double.
@@ -512,13 +429,9 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @return The value of the field as a double.
*/
public double getDouble(int row, int column) {
- acquireReference();
- try {
- return nativeGetDouble(mWindowPtr, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ return (Double)rows.get(row - startPos)[column];
}
+
/**
* Gets the value of the field at the specified row and column index as a
* short.
@@ -534,6 +447,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
public short getShort(int row, int column) {
return (short) getLong(row, column);
}
+
/**
* Gets the value of the field at the specified row and column index as an
* int.
@@ -549,6 +463,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
public int getInt(int row, int column) {
return (int) getLong(row, column);
}
+
/**
* Gets the value of the field at the specified row and column index as a
* float.
@@ -564,6 +479,7 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
public float getFloat(int row, int column) {
return (float) getDouble(row, column);
}
+
/**
* Copies a byte array into the field at the specified row and column index.
*
@@ -572,15 +488,11 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @param column The zero-based column index.
* @return True if successful.
*/
- public boolean putBlob(byte[] value,
- int row, int column) {
- acquireReference();
- try {
- return nativePutBlob(mWindowPtr, value, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ public boolean putBlob(byte[] value, int row, int column) {
+ rows.get(row - startPos)[column] = value;
+ return true;
}
+
/**
* Copies a string into the field at the specified row and column index.
*
@@ -589,15 +501,11 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @param column The zero-based column index.
* @return True if successful.
*/
- public boolean putString(String value,
- int row, int column) {
- acquireReference();
- try {
- return nativePutString(mWindowPtr, value, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ public boolean putString(String value, int row, int column) {
+ rows.get(row - startPos)[column] = value;
+ return true;
}
+
/**
* Puts a long integer into the field at the specified row and column index.
*
@@ -606,15 +514,11 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @param column The zero-based column index.
* @return True if successful.
*/
- public boolean putLong(long value,
- int row, int column) {
- acquireReference();
- try {
- return nativePutLong(mWindowPtr, value, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ public boolean putLong(long value, int row, int column) {
+ rows.get(row - startPos)[column] = value;
+ return true;
}
+
/**
* Puts a double-precision floating point value into the field at the
* specified row and column index.
@@ -624,15 +528,11 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @param column The zero-based column index.
* @return True if successful.
*/
- public boolean putDouble(double value,
- int row, int column) {
- acquireReference();
- try {
- return nativePutDouble(mWindowPtr, value, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ public boolean putDouble(double value, int row, int column) {
+ rows.get(row - startPos)[column] = value;
+ return true;
}
+
/**
* Puts a null value into the field at the specified row and column index.
*
@@ -641,20 +541,18 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
* @return True if successful.
*/
public boolean putNull(int row, int column) {
- acquireReference();
- try {
- return nativePutNull(mWindowPtr, row - mStartPos, column);
- } finally {
- releaseReference();
- }
+ rows.get(row - startPos)[column] = null;
+ return true;
}
+
public int describeContents() {
return 0;
}
+
@Override
protected void onAllReferencesReleased() {
- dispose();
}
+
private static int getCursorWindowSize() {
if (sCursorWindowSize < 0) {
// The cursor window size. resource xml file specifies the value in kB.
@@ -664,8 +562,9 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
}
return sCursorWindowSize;
}
+
@Override
public String toString() {
- return getName() + " {" + Long.toHexString(mWindowPtr) + "}";
+ return getName() + " {" + rows + "}";
}
-}
\ No newline at end of file
+}