Search in sources :

Example 1 with TableDetails

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);
        }
    }
}
Also used : ContentValues(android.content.ContentValues) TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) Uri(android.net.Uri)

Example 2 with TableDetails

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);
}
Also used : ContentValues(android.content.ContentValues) TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) Uri(android.net.Uri)

Example 3 with 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());
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) ContentResolverValues(me.himanshusoni.quantumflux.model.util.ContentResolverValues) Uri(android.net.Uri)

Example 4 with TableDetails

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;
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails)

Example 5 with TableDetails

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;
}
Also used : ContentValues(android.content.ContentValues) TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails)

Aggregations

TableDetails (me.himanshusoni.quantumflux.model.generate.TableDetails)32 Uri (android.net.Uri)22 ContentValues (android.content.ContentValues)17 ContentResolver (android.content.ContentResolver)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)5 Cursor (android.database.Cursor)2 UriMatcher (android.content.UriMatcher)1 ContentResolverValues (me.himanshusoni.quantumflux.model.util.ContentResolverValues)1 CursorIterator (me.himanshusoni.quantumflux.model.util.CursorIterator)1 QuantumFluxException (me.himanshusoni.quantumflux.model.util.QuantumFluxException)1