use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFlux method prepareInsert.
public static <T> ContentProviderOperation prepareInsert(T dataModelObject) {
TableDetails tableDetails = findTableDetails(dataModelObject.getClass());
ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).build();
return ContentProviderOperation.newInsert(insertUri).withExpectedCount(1).withValues(contentValues).build();
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFlux method insert.
public static <T> void insert(T dataModelObject) {
TableDetails tableDetails = findTableDetails(dataModelObject.getClass());
ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).build();
ContentResolver contentResolver = mApplicationContext.getContentResolver();
contentResolver.insert(insertUri, contentValues);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxSyncHelper method update.
public static <T> void update(Context context, ContentProviderClient provider, T dataModelObject) throws RemoteException {
TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObject.getClass());
ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject);
Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)).appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build();
provider.update(itemUri, contentValues, null, null);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxSyncHelper method updateColumns.
public static <T> void updateColumns(Context context, ContentProviderClient provider, T dataModelObject, String... columns) throws RemoteException {
TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObject.getClass());
ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject);
Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)).appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build();
for (String contentColumn : tableDetails.getColumnNames()) {
boolean includeColumn = false;
for (String column : columns) {
if (contentColumn.equals(column)) {
includeColumn = true;
break;
}
}
if (!includeColumn)
contentValues.remove(contentColumn);
}
provider.update(itemUri, contentValues, null, null);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxContentProvider method update.
@Override
public int update(@NonNull Uri uri, ContentValues contentValues, String where, String[] args) {
TableDetails tableDetails = mUriMatcherHelper.getTableDetails(uri);
SQLiteDatabase db = mDatabase.getWritableDatabase();
if (mDebugEnabled) {
QuantumFluxLog.d("********* Update **********");
QuantumFluxLog.d("Uri: " + uri);
QuantumFluxLog.d("Content Values: " + contentValues);
QuantumFluxLog.d("Where: " + where);
QuantumFluxLog.d("Args: " + Arrays.toString(args));
}
int updateCount;
if (mUriMatcherHelper.isSingleItemRequested(uri)) {
String itemId = uri.getLastPathSegment();
TableDetails.ColumnDetails primaryKeyColumn = tableDetails.findPrimaryKeyColumn();
updateCount = db.update(tableDetails.getTableName(), contentValues, primaryKeyColumn.getColumnName() + " = ?", new String[] { itemId });
} else {
updateCount = db.update(tableDetails.getTableName(), contentValues, where, args);
}
if (updateCount > 0 && shouldChangesBeNotified(tableDetails, contentValues)) {
notifyChanges(uri, tableDetails);
}
return updateCount;
}
Aggregations