Search in sources :

Example 16 with TableDetails

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

Example 17 with TableDetails

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

Example 18 with TableDetails

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

Example 19 with TableDetails

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

Example 20 with TableDetails

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

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