Search in sources :

Example 26 with TableDetails

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

Example 27 with TableDetails

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

Example 28 with TableDetails

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

Example 29 with TableDetails

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

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

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