use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFlux method update.
public static <T> void update(T dataModelObject) {
TableDetails tableDetails = 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)).build();
ContentResolver contentResolver = mApplicationContext.getContentResolver();
contentResolver.update(itemUri, contentValues, null, null);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFlux method insertAll.
public static <T> int insertAll(List<T> dataModelObjects) {
if (dataModelObjects == null || dataModelObjects.isEmpty())
return 0;
TableDetails tableDetails = findTableDetails(dataModelObjects.get(0).getClass());
Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).build();
ContentValues[] values = new ContentValues[dataModelObjects.size()];
for (int i = 0; i < dataModelObjects.size(); i++) {
values[i] = ModelInflater.deflate(tableDetails, dataModelObjects.get(i));
}
ContentResolver contentResolver = mApplicationContext.getContentResolver();
return contentResolver.bulkInsert(insertUri, values);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFlux method updateColumns.
public static <T> void updateColumns(T dataModelObject, String... columns) {
TableDetails tableDetails = 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)).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);
}
}
ContentResolver contentResolver = mApplicationContext.getContentResolver();
contentResolver.update(itemUri, contentValues, null, null);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFlux method findByPrimaryKey.
public static <T> T findByPrimaryKey(Class<T> dataModel, Object key) {
TableDetails tableDetails = findTableDetails(dataModel);
TableDetails.ColumnDetails primaryKeyColumn = tableDetails.findPrimaryKeyColumn();
Object columnValue = primaryKeyColumn.getColumnTypeMapping().toSqlType(key);
Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)).build();
return findSingleItem(itemUri, tableDetails);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxSyncHelper method updateColumnsExcluding.
public static <T> void updateColumnsExcluding(Context context, ContentProviderClient provider, T dataModelObject, String... columnsToExclude) 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 columnToExclude : columnsToExclude) {
contentValues.remove(columnToExclude);
}
provider.update(itemUri, contentValues, null, null);
}
Aggregations