Search in sources :

Example 11 with TableDetails

use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.

the class QuantumFlux method insertAndReturn.

public static <T> T insertAndReturn(T dataModelObject) {
    TableDetails tableDetails = findTableDetails(dataModelObject.getClass());
    ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject);
    Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).build();
    ContentResolver contentResolver = mApplicationContext.getContentResolver();
    Uri itemUri = contentResolver.insert(insertUri, contentValues);
    return findSingleItem(itemUri, tableDetails);
}
Also used : ContentValues(android.content.ContentValues) TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 12 with TableDetails

use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.

the class QuantumFlux method updateColumnsExcluding.

public static <T> void updateColumnsExcluding(T dataModelObject, String... columnsToExclude) {
    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 columnToExclude : columnsToExclude) {
        contentValues.remove(columnToExclude);
    }
    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 13 with TableDetails

use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.

the class QuantumFlux method prepareDelete.

public static <T> ContentProviderOperation prepareDelete(T dataModelObject) {
    TableDetails tableDetails = findTableDetails(dataModelObject.getClass());
    Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject);
    Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)).build();
    return ContentProviderOperation.newDelete(itemUri).withExpectedCount(1).build();
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) Uri(android.net.Uri)

Example 14 with TableDetails

use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.

the class QuantumFlux method prepareUpdate.

public static <T> ContentProviderOperation prepareUpdate(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();
    return ContentProviderOperation.newUpdate(itemUri).withExpectedCount(1).withValues(contentValues).build();
}
Also used : ContentValues(android.content.ContentValues) TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) Uri(android.net.Uri)

Example 15 with TableDetails

use of me.himanshusoni.quantumflux.model.generate.TableDetails in project QuantumFlux by himanshu-soni.

the class QuantumFlux method findAll.

public static <T> Iterator<T> findAll(Class<T> dataModel) {
    TableDetails tableDetails = findTableDetails(dataModel);
    Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).build();
    ContentResolver contentResolver = mApplicationContext.getContentResolver();
    Cursor cursor = contentResolver.query(itemUri, null, null, null, null);
    return new CursorIterator<T>(tableDetails, cursor);
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) CursorIterator(me.himanshusoni.quantumflux.model.util.CursorIterator) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

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