am f0a9181d: Merge "Clean up CursorWindow code. Bug: 5332296"
* commit 'f0a9181d0904cc50acf852a64be0c7279e098783': Clean up CursorWindow code. Bug: 5332296
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -18,17 +18,12 @@ package android.database;
|
||||
|
||||
/**
|
||||
* This exception is thrown when a CursorWindow couldn't be allocated,
|
||||
* most probably due to memory not being available
|
||||
* most probably due to memory not being available.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
class CursorWindowAllocationException extends java.lang.RuntimeException
|
||||
{
|
||||
public CursorWindowAllocationException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public CursorWindowAllocationException(String description)
|
||||
{
|
||||
public class CursorWindowAllocationException extends RuntimeException {
|
||||
public CursorWindowAllocationException(String description) {
|
||||
super(description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class SQLiteQuery extends SQLiteProgram {
|
||||
// if the start pos is not equal to 0, then most likely window is
|
||||
// too small for the data set, loading by another thread
|
||||
// is not safe in this situation. the native code will ignore maxRead
|
||||
int numRows = native_fill_window(window, window.getStartPosition(),
|
||||
int numRows = native_fill_window(window.mWindowPtr, window.getStartPosition(),
|
||||
mOffsetIndex, maxRead, lastPos);
|
||||
mDatabase.logTimeStat(mSql, timeStart);
|
||||
return numRows;
|
||||
@@ -154,7 +154,7 @@ public class SQLiteQuery extends SQLiteProgram {
|
||||
compileAndbindAllArgs();
|
||||
}
|
||||
|
||||
private final native int native_fill_window(CursorWindow window,
|
||||
private final native int native_fill_window(int windowPtr,
|
||||
int startPos, int offsetParam, int maxRead, int lastPos);
|
||||
|
||||
private final native int native_column_count();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -35,12 +35,6 @@
|
||||
|
||||
namespace android {
|
||||
|
||||
sqlite3_stmt * compile(JNIEnv* env, jobject object,
|
||||
sqlite3 * handle, jstring sqlString);
|
||||
|
||||
// From android_database_CursorWindow.cpp
|
||||
CursorWindow * get_window_from_object(JNIEnv * env, jobject javaWindow);
|
||||
|
||||
static jfieldID gHandleField;
|
||||
static jfieldID gStatementField;
|
||||
|
||||
@@ -105,7 +99,7 @@ static int finish_program_and_get_row_count(sqlite3_stmt *statement) {
|
||||
return numRows;
|
||||
}
|
||||
|
||||
static jint native_fill_window(JNIEnv* env, jobject object, jobject javaWindow,
|
||||
static jint native_fill_window(JNIEnv* env, jobject object, jint windowPtr,
|
||||
jint startPos, jint offsetParam, jint maxRead, jint lastPos)
|
||||
{
|
||||
int err;
|
||||
@@ -142,7 +136,7 @@ static jint native_fill_window(JNIEnv* env, jobject object, jobject javaWindow,
|
||||
}
|
||||
|
||||
// Get the native window
|
||||
window = get_window_from_object(env, javaWindow);
|
||||
window = reinterpret_cast<CursorWindow*>(windowPtr);
|
||||
if (!window) {
|
||||
LOGE("Invalid CursorWindow");
|
||||
jniThrowException(env, "java/lang/IllegalArgumentException",
|
||||
@@ -360,7 +354,7 @@ static jstring native_column_name(JNIEnv* env, jobject object, jint columnIndex)
|
||||
static JNINativeMethod sMethods[] =
|
||||
{
|
||||
/* name, signature, funcPtr */
|
||||
{"native_fill_window", "(Landroid/database/CursorWindow;IIII)I",
|
||||
{"native_fill_window", "(IIIII)I",
|
||||
(void *)native_fill_window},
|
||||
{"native_column_count", "()I", (void*)native_column_count},
|
||||
{"native_column_name", "(I)Ljava/lang/String;", (void *)native_column_name},
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
|
||||
namespace android {
|
||||
|
||||
class CursorWindow;
|
||||
|
||||
class AndroidRuntime
|
||||
{
|
||||
public:
|
||||
@@ -133,8 +131,6 @@ private:
|
||||
static int javaThreadShell(void* args);
|
||||
};
|
||||
|
||||
extern CursorWindow * get_window_from_object(JNIEnv * env, jobject javaWindow);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,8 +143,6 @@ public:
|
||||
*/
|
||||
uint32_t alloc(size_t size, bool aligned = false);
|
||||
|
||||
uint32_t read_field_slot(int row, int column, field_slot_t * slot);
|
||||
|
||||
/**
|
||||
* Copy data into the window at the given offset.
|
||||
*/
|
||||
@@ -181,6 +179,32 @@ public:
|
||||
return ((field_slot_t *)offsetToPtr(fieldDirOffset)) + column;
|
||||
}
|
||||
|
||||
int64_t getFieldSlotValueLong(field_slot_t* fieldSlot) {
|
||||
#if WINDOW_STORAGE_INLINE_NUMERICS
|
||||
return fieldSlot->data.l;
|
||||
#else
|
||||
return copyOutLong(fieldSlot->data.buffer.offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
double getFieldSlotValueDouble(field_slot_t* fieldSlot) {
|
||||
#if WINDOW_STORAGE_INLINE_NUMERICS
|
||||
return fieldSlot->data.d;
|
||||
#else
|
||||
return copyOutDouble(fieldSlot->data.buffer.offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if WINDOW_STORAGE_UTF8
|
||||
char* getFieldSlotValueString(field_slot_t* fieldSlot) {
|
||||
return reinterpret_cast<char*>(offsetToPtr(fieldSlot->data.buffer.offset));
|
||||
}
|
||||
#else
|
||||
char16_t* getFieldSlotValueString(field_slot_t* fieldSlot) {
|
||||
return reinterpret_cast<char16_t*>(offsetToPtr(fieldSlot->data.buffer.offset));
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
uint8_t * mData;
|
||||
size_t mSize;
|
||||
|
||||
@@ -236,33 +236,6 @@ field_slot_t * CursorWindow::getFieldSlotWithCheck(int row, int column)
|
||||
return ((field_slot_t *)offsetToPtr(fieldDirOffset)) + column;
|
||||
}
|
||||
|
||||
uint32_t CursorWindow::read_field_slot(int row, int column, field_slot_t * slotOut)
|
||||
{
|
||||
if (row < 0 || row >= mHeader->numRows || column < 0 || column >= mHeader->numColumns) {
|
||||
LOGE("Can't read row# %d, col# %d from CursorWindow. Make sure your Cursor is initialized correctly.",
|
||||
row, column);
|
||||
return -1;
|
||||
}
|
||||
row_slot_t * rowSlot = getRowSlot(row);
|
||||
if (!rowSlot) {
|
||||
LOGE("Failed to find rowSlot for row %d", row);
|
||||
return -1;
|
||||
}
|
||||
if (rowSlot->offset == 0 || rowSlot->offset >= mSize) {
|
||||
LOGE("Invalid rowSlot, offset = %d", rowSlot->offset);
|
||||
return -1;
|
||||
}
|
||||
LOG_WINDOW("Found field directory for %d,%d at rowSlot %d, offset %d", row, column, (uint8_t *)rowSlot - mData, rowSlot->offset);
|
||||
field_slot_t * fieldDir = (field_slot_t *)offsetToPtr(rowSlot->offset);
|
||||
LOG_WINDOW("Read field_slot_t %d,%d: offset = %d, size = %d, type = %d", row, column, fieldDir[column].data.buffer.offset, fieldDir[column].data.buffer.size, fieldDir[column].type);
|
||||
|
||||
// Copy the data to the out param
|
||||
slotOut->data.buffer.offset = fieldDir[column].data.buffer.offset;
|
||||
slotOut->data.buffer.size = fieldDir[column].data.buffer.size;
|
||||
slotOut->type = fieldDir[column].type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CursorWindow::copyIn(uint32_t offset, uint8_t const * data, size_t size)
|
||||
{
|
||||
assert(offset + size <= mSize);
|
||||
@@ -370,12 +343,8 @@ bool CursorWindow::getLong(unsigned int row, unsigned int col, int64_t * valueOu
|
||||
if (!fieldSlot || fieldSlot->type != FIELD_TYPE_INTEGER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if WINDOW_STORAGE_INLINE_NUMERICS
|
||||
*valueOut = fieldSlot->data.l;
|
||||
#else
|
||||
*valueOut = copyOutLong(fieldSlot->data.buffer.offset);
|
||||
#endif
|
||||
|
||||
*valueOut = getFieldSlotValueLong(fieldSlot);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -386,11 +355,7 @@ bool CursorWindow::getDouble(unsigned int row, unsigned int col, double * valueO
|
||||
return false;
|
||||
}
|
||||
|
||||
#if WINDOW_STORAGE_INLINE_NUMERICS
|
||||
*valueOut = fieldSlot->data.d;
|
||||
#else
|
||||
*valueOut = copyOutDouble(fieldSlot->data.buffer.offset);
|
||||
#endif
|
||||
*valueOut = getFieldSlotValueDouble(fieldSlot);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user