use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class ModelInflater method deflate.
public static ContentValues deflate(TableDetails tableDetails, Object dataModelObject) {
List<TableDetails.ColumnDetails> columns = tableDetails.getColumns();
ContentValues contentValues = new ContentValues(columns.size());
for (int i = 0; i < columns.size(); i++) {
TableDetails.ColumnDetails columnDetails = columns.get(i);
if (columnDetails.isAutoIncrement())
continue;
try {
columnDetails.setContentValue(contentValues, dataModelObject);
} catch (IllegalAccessException e) {
throw new QuantumFluxException("Unable to access protected field, change the access level: " + columnDetails.getColumnName());
}
}
return contentValues;
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxContentProvider method delete.
@Override
public int delete(@NonNull Uri uri, String where, String[] args) {
TableDetails tableDetails = mUriMatcherHelper.getTableDetails(uri);
SQLiteDatabase db = mDatabase.getWritableDatabase();
if (mDebugEnabled) {
QuantumFluxLog.d("********* Delete **********");
QuantumFluxLog.d("Uri: " + uri);
QuantumFluxLog.d("Where: " + where);
QuantumFluxLog.d("Args: " + Arrays.toString(args));
}
int deleteCount;
if (mUriMatcherHelper.isSingleItemRequested(uri)) {
String itemId = uri.getLastPathSegment();
TableDetails.ColumnDetails primaryKeyColumn = tableDetails.findPrimaryKeyColumn();
deleteCount = db.delete(tableDetails.getTableName(), primaryKeyColumn.getColumnName() + " = ?", new String[] { itemId });
} else {
deleteCount = db.delete(tableDetails.getTableName(), where, args);
}
if (deleteCount == 0) {
return deleteCount;
}
notifyChanges(uri, tableDetails);
return deleteCount;
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxContentProvider method query.
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
TableDetails tableDetails = mUriMatcherHelper.getTableDetails(uri);
SQLiteDatabase db = mDatabase.getReadableDatabase();
String limit = constructLimit(uri);
if (mDebugEnabled) {
QuantumFluxLog.d("********* Query **********");
QuantumFluxLog.d("Uri: " + uri);
QuantumFluxLog.d("Projection: " + Arrays.toString(projection));
QuantumFluxLog.d("Selection: " + selection);
QuantumFluxLog.d("Args: " + Arrays.toString(selectionArgs));
QuantumFluxLog.d("Sort: " + sortOrder);
QuantumFluxLog.d("Limit: " + limit);
}
Cursor cursor;
if (mUriMatcherHelper.isSingleItemRequested(uri)) {
String itemId = uri.getLastPathSegment();
TableDetails.ColumnDetails primaryKeyColumn = tableDetails.findPrimaryKeyColumn();
cursor = db.query(tableDetails.getTableName(), projection, primaryKeyColumn.getColumnName() + " = ?", new String[] { itemId }, null, sortOrder, limit);
} else {
cursor = db.query(tableDetails.getTableName(), projection, selection, selectionArgs, null, null, sortOrder, limit);
}
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxContentProvider method bulkInsert.
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
if (values.length == 0)
return 0;
TableDetails tableDetails = mUriMatcherHelper.getTableDetails(uri);
SQLiteDatabase db = mDatabase.getWritableDatabase();
if (mDebugEnabled) {
QuantumFluxLog.d("********* Bulk Insert **********");
QuantumFluxLog.d("Uri: " + uri);
}
int count = 0;
try {
db.beginTransactionNonExclusive();
String tableName = tableDetails.getTableName();
for (ContentValues value : values) {
db.insertOrThrow(tableName, null, value);
count++;
}
db.setTransactionSuccessful();
notifyChanges(uri, tableDetails);
} finally {
db.endTransaction();
}
return count;
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxContentProvider method insert.
@Override
public Uri insert(@NonNull Uri uri, ContentValues contentValues) {
TableDetails tableDetails = mUriMatcherHelper.getTableDetails(uri);
SQLiteDatabase db = mDatabase.getWritableDatabase();
if (mDebugEnabled) {
QuantumFluxLog.d("********* Insert **********");
QuantumFluxLog.d("Uri: " + uri);
QuantumFluxLog.d("Content Values: " + contentValues);
}
long insertId = db.insertOrThrow(tableDetails.getTableName(), null, contentValues);
if (insertId == -1) {
throw new QuantumFluxException("Failed to insert row for into table " + tableDetails.getTableName() + " using values " + contentValues);
}
notifyChanges(uri, tableDetails);
TableDetails.ColumnDetails primaryKeyColumn = tableDetails.findPrimaryKeyColumn();
if (primaryKeyColumn.isAutoIncrement()) {
return mUriMatcherHelper.generateSingleItemUri(tableDetails, insertId);
} else {
String primaryKeyValue = contentValues.getAsString(primaryKeyColumn.getColumnName());
return mUriMatcherHelper.generateSingleItemUri(tableDetails, primaryKeyValue);
}
}
Aggregations