use of android.database.SQLException in project aware-client by denzilferreira.
the class Network_Provider method insert.
/**
* Insert entry to the database
*/
@Override
public synchronized Uri insert(Uri uri, ContentValues initialValues) {
initialiseDatabase();
ContentValues values = (initialValues != null) ? new ContentValues(initialValues) : new ContentValues();
database.beginTransaction();
switch(sUriMatcher.match(uri)) {
case NETWORK:
long network_id = database.insertWithOnConflict(DATABASE_TABLES[0], Network_Data.DEVICE_ID, values, SQLiteDatabase.CONFLICT_IGNORE);
database.setTransactionSuccessful();
database.endTransaction();
if (network_id > 0) {
Uri networkUri = ContentUris.withAppendedId(Network_Data.CONTENT_URI, network_id);
getContext().getContentResolver().notifyChange(networkUri, null, false);
return networkUri;
}
database.endTransaction();
throw new SQLException("Failed to insert row into " + uri);
default:
database.endTransaction();
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
use of android.database.SQLException in project aware-client by denzilferreira.
the class Processor_Provider method insert.
/**
* Insert entry to the database
*/
@Override
public synchronized Uri insert(Uri uri, ContentValues initialValues) {
initialiseDatabase();
ContentValues values = (initialValues != null) ? new ContentValues(initialValues) : new ContentValues();
database.beginTransaction();
switch(sUriMatcher.match(uri)) {
case PROCESSOR:
long processor_id = database.insertWithOnConflict(DATABASE_TABLES[0], Processor_Data.DEVICE_ID, values, SQLiteDatabase.CONFLICT_IGNORE);
database.setTransactionSuccessful();
database.endTransaction();
if (processor_id > 0) {
Uri processorUri = ContentUris.withAppendedId(Processor_Data.CONTENT_URI, processor_id);
getContext().getContentResolver().notifyChange(processorUri, null, false);
return processorUri;
}
database.endTransaction();
throw new SQLException("Failed to insert row into " + uri);
default:
database.endTransaction();
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
use of android.database.SQLException in project aware-client by denzilferreira.
the class Rotation_Provider method insert.
/**
* Insert entry to the database
*/
@Override
public synchronized Uri insert(Uri uri, ContentValues initialValues) {
initialiseDatabase();
ContentValues values = (initialValues != null) ? new ContentValues(initialValues) : new ContentValues();
database.beginTransaction();
switch(sUriMatcher.match(uri)) {
case SENSOR_DEV:
long accel_id = database.insertWithOnConflict(DATABASE_TABLES[0], Rotation_Sensor.DEVICE_ID, values, SQLiteDatabase.CONFLICT_IGNORE);
database.setTransactionSuccessful();
database.endTransaction();
if (accel_id > 0) {
Uri accelUri = ContentUris.withAppendedId(Rotation_Sensor.CONTENT_URI, accel_id);
getContext().getContentResolver().notifyChange(accelUri, null, false);
return accelUri;
}
database.endTransaction();
throw new SQLException("Failed to insert row into " + uri);
case SENSOR_DATA:
long accelData_id = database.insertWithOnConflict(DATABASE_TABLES[1], Rotation_Data.DEVICE_ID, values, SQLiteDatabase.CONFLICT_IGNORE);
database.setTransactionSuccessful();
database.endTransaction();
if (accelData_id > 0) {
Uri accelDataUri = ContentUris.withAppendedId(Rotation_Data.CONTENT_URI, accelData_id);
getContext().getContentResolver().notifyChange(accelDataUri, null, false);
return accelDataUri;
}
database.endTransaction();
throw new SQLException("Failed to insert row into " + uri);
default:
database.endTransaction();
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
use of android.database.SQLException in project aware-client by denzilferreira.
the class Rotation_Provider method bulkInsert.
/**
* Batch insert for high performance sensors (e.g., accelerometer, etc)
*
* @param uri
* @param values
* @return values.length
*/
@Override
public synchronized int bulkInsert(Uri uri, ContentValues[] values) {
initialiseDatabase();
database.beginTransaction();
int count = 0;
switch(sUriMatcher.match(uri)) {
case SENSOR_DEV:
for (ContentValues v : values) {
long id;
try {
id = database.insertOrThrow(DATABASE_TABLES[0], Rotation_Sensor.DEVICE_ID, v);
} catch (SQLException e) {
id = database.replace(DATABASE_TABLES[0], Rotation_Sensor.DEVICE_ID, v);
}
if (id <= 0) {
Log.w(Accelerometer.TAG, "Failed to insert/replace row into " + uri);
} else {
count++;
}
}
break;
case SENSOR_DATA:
for (ContentValues v : values) {
long id;
try {
id = database.insertOrThrow(DATABASE_TABLES[1], Rotation_Data.DEVICE_ID, v);
} catch (SQLException e) {
id = database.replace(DATABASE_TABLES[1], Rotation_Data.DEVICE_ID, v);
}
if (id <= 0) {
Log.w(Accelerometer.TAG, "Failed to insert/replace row into " + uri);
} else {
count++;
}
}
break;
default:
database.endTransaction();
throw new IllegalArgumentException("Unknown URI " + uri);
}
database.setTransactionSuccessful();
database.endTransaction();
getContext().getContentResolver().notifyChange(uri, null, false);
return count;
}
use of android.database.SQLException in project aware-client by denzilferreira.
the class Screen_Provider method insert.
/**
* Insert entry to the database
*/
@Override
public synchronized Uri insert(Uri uri, ContentValues initialValues) {
initialiseDatabase();
ContentValues values = (initialValues != null) ? new ContentValues(initialValues) : new ContentValues();
database.beginTransaction();
switch(sUriMatcher.match(uri)) {
case SCREEN:
long screen_id = database.insertWithOnConflict(DATABASE_TABLES[0], Screen_Data.DEVICE_ID, values, SQLiteDatabase.CONFLICT_IGNORE);
database.setTransactionSuccessful();
database.endTransaction();
if (screen_id > 0) {
Uri screenUri = ContentUris.withAppendedId(Screen_Data.CONTENT_URI, screen_id);
getContext().getContentResolver().notifyChange(screenUri, null, false);
return screenUri;
}
database.endTransaction();
throw new SQLException("Failed to insert row into " + uri);
case TOUCH:
long touch_id = database.insertWithOnConflict(DATABASE_TABLES[1], Screen_Touch.DEVICE_ID, values, SQLiteDatabase.CONFLICT_IGNORE);
database.setTransactionSuccessful();
database.endTransaction();
if (touch_id > 0) {
Uri screenUri = ContentUris.withAppendedId(Screen_Touch.CONTENT_URI, touch_id);
getContext().getContentResolver().notifyChange(screenUri, null, false);
return screenUri;
}
database.endTransaction();
throw new SQLException("Failed to insert row into " + uri);
default:
database.endTransaction();
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
Aggregations