use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxSyncHelper method insert.
@SafeVarargs
public static <T> void insert(ContentProviderClient provider, T... dataModelObjects) throws RemoteException {
if (dataModelObjects.length == 1) {
T modelObject = dataModelObjects[0];
TableDetails tableDetails = QuantumFlux.findTableDetails(modelObject.getClass());
ContentValues contentValues = ModelInflater.deflate(tableDetails, modelObject);
Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build();
provider.insert(insertUri, contentValues);
} else {
TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObjects[0].getClass());
ContentValues[] insertObjects = ModelInflater.deflateAll(tableDetails, dataModelObjects);
if (tableDetails != null) {
Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build();
provider.bulkInsert(insertUri, insertObjects);
}
}
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class QuantumFluxSyncHelper method insertAndReturn.
public static <T> T insertAndReturn(ContentProviderClient provider, T dataModelObject) throws RemoteException {
TableDetails tableDetails = QuantumFlux.findTableDetails(dataModelObject.getClass());
ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).appendQueryParameter(QuantumFluxContentProvider.PARAMETER_SYNC, "false").build();
Uri itemUri = provider.insert(insertUri, contentValues);
return QuantumFlux.findSingleItem(itemUri, tableDetails);
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class Select method asContentResolverValue.
/**
* Packages this select into a {@link ContentResolverValues} package, this will contain all of the required arguments to run this query on
* a content resolver, it is used internally by all of the as* methods.
*
* @return The {@link ContentResolverValues} containing the arguments needed by the content resolver query method
*/
public ContentResolverValues asContentResolverValue() {
TableDetails tableDetails = QuantumFlux.findTableDetails(mDataObjectClass);
QueryBuilder where = buildWhereClause(QuantumFlux.getColumnMappingFactory());
QueryBuilder sort = buildSort();
Uri.Builder itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails);
if (mOffset != null)
itemUri.appendQueryParameter(QuantumFluxContentProvider.PARAMETER_OFFSET, mOffset.toString());
if (mLimit != null)
itemUri.appendQueryParameter(QuantumFluxContentProvider.PARAMETER_LIMIT, mLimit.toString());
return new ContentResolverValues(tableDetails, itemUri.build(), getProjection(tableDetails), where.getQueryString(), where.getQueryArgsAsArray(), sort.getQueryString());
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class Select method getSelectQuery.
protected QueryBuilder getSelectQuery() {
TableDetails tableDetails = QuantumFlux.findTableDetails(mDataObjectClass);
QueryBuilder select = new QueryBuilder();
QueryBuilder where = buildWhereClause(QuantumFlux.getColumnMappingFactory());
select.append("SELECT ");
Iterator<String> columnIterator = Arrays.asList(getProjection(tableDetails)).iterator();
while (columnIterator.hasNext()) {
select.append(columnIterator.next());
if (columnIterator.hasNext())
select.append(", ");
}
select.append(" FROM ");
select.append(tableDetails.getTableName());
if (hasFilterValue()) {
select.append(" WHERE ");
select.append(where);
}
return select;
}
use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.
the class ModelInflater method deflateAll.
public static ContentValues[] deflateAll(TableDetails tableDetails, Object... dataModelObjects) {
List<TableDetails.ColumnDetails> columns = tableDetails.getColumns();
ContentValues[] contentValuesArray = new ContentValues[dataModelObjects.length];
for (int i = 0; i < dataModelObjects.length; i++) {
contentValuesArray[i] = new ContentValues(columns.size());
}
for (int i = 0; i < columns.size(); i++) {
TableDetails.ColumnDetails columnDetails = columns.get(i);
if (columnDetails.isAutoIncrement())
continue;
for (int j = 0; j < dataModelObjects.length; j++) {
try {
columnDetails.setContentValue(contentValuesArray[j], dataModelObjects[j]);
} catch (IllegalAccessException e) {
throw new QuantumFluxException("Unable to access protected field, change the access level: " + columnDetails.getColumnName());
}
}
}
return contentValuesArray;
}
Aggregations