Search in sources :

Example 21 with TableDetails

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

the class UriMatcherHelper method init.

public void init(Context context, TableDetailsCache detailsCache) {
    mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    int matcherInterval = MATCHER_CODE_INTERVALS;
    for (Class<?> dataModelObject : ReflectionHelper.getDomainClasses(context, ReflectionHelper.TableType.TABLE)) {
        TableDetails tableDetails = detailsCache.findTableDetails(context, dataModelObject);
        mMatcherCodes.put(matcherInterval, tableDetails);
        mUriMatcher.addURI(mAuthority, tableDetails.getTableName(), matcherInterval + MATCHER_ALL);
        mUriMatcher.addURI(mAuthority, tableDetails.getTableName() + "/*", matcherInterval + MATCHER_SINGLE);
        matcherInterval += MATCHER_CODE_INTERVALS;
    }
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) UriMatcher(android.content.UriMatcher)

Example 22 with TableDetails

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

the class UriMatcherHelper method getType.

public String getType(Uri uri) {
    int matchCode = mUriMatcher.match(uri);
    TableDetails tableDetails = findTableDetails(matchCode);
    StringBuilder mimeType = new StringBuilder();
    mimeType.append("android.cursor.");
    if (isSingleItemRequested(matchCode))
        mimeType.append(".item");
    else
        mimeType.append(".dir");
    mimeType.append("/");
    mimeType.append("vnd.");
    mimeType.append(mAuthority);
    if (mimeType.charAt(mimeType.length() - 1) != '.')
        mimeType.append(".");
    mimeType.append(tableDetails.getTableName());
    return mimeType.toString();
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails)

Example 23 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(ContentProviderClient providerClient, List<T> dataModelObjects) throws RemoteException {
    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));
    }
    return providerClient.bulkInsert(insertUri, values);
}
Also used : ContentValues(android.content.ContentValues) TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) Uri(android.net.Uri)

Example 24 with TableDetails

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

the class QuantumFlux method delete.

public static <T> void delete(T dataModelObject) {
    TableDetails tableDetails = findTableDetails(dataModelObject.getClass());
    Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject);
    Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)).build();
    ContentResolver contentResolver = mApplicationContext.getContentResolver();
    contentResolver.delete(itemUri, null, null);
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 25 with TableDetails

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

the class QuantumFlux method deleteAll.

public static <T> void deleteAll(Class<T> dataModel) {
    TableDetails tableDetails = findTableDetails(dataModel);
    Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).build();
    ContentResolver contentResolver = getApplicationContext().getContentResolver();
    contentResolver.delete(itemUri, null, null);
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) 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