Search in sources :

Example 1 with QuantumFluxException

use of me.himanshusoni.quantumflux.model.util.QuantumFluxException in project QuantumFlux by himanshu-soni.

the class TableDetails method addColumn.

public void addColumn(ColumnDetails column) {
    mColumns.add(column);
    boolean hasPrimaryKey = false;
    for (ColumnDetails columnDetails : mColumns) {
        if (hasPrimaryKey && columnDetails.isPrimaryKey())
            throw new QuantumFluxException("Table may only have one primary key constraint on column definition, is a table mConstraints to specify more than one");
        hasPrimaryKey = hasPrimaryKey || columnDetails.isPrimaryKey();
    }
}
Also used : QuantumFluxException(me.himanshusoni.quantumflux.model.util.QuantumFluxException)

Example 2 with QuantumFluxException

use of me.himanshusoni.quantumflux.model.util.QuantumFluxException in project QuantumFlux by himanshu-soni.

the class QuantumFluxContentProvider method insert.

@Override
public Uri insert(@NonNull Uri uri, ContentValues contentValues) {
    TableDetails tableDetails = mUriMatcherHelper.getTableDetails(uri);
    SQLiteDatabase db = mDatabase.getWritableDatabase();
    if (mDebugEnabled) {
        QuantumFluxLog.d("********* Insert **********");
        QuantumFluxLog.d("Uri: " + uri);
        QuantumFluxLog.d("Content Values: " + contentValues);
    }
    long insertId = db.insertOrThrow(tableDetails.getTableName(), null, contentValues);
    if (insertId == -1) {
        throw new QuantumFluxException("Failed to insert row for into table " + tableDetails.getTableName() + " using values " + contentValues);
    }
    notifyChanges(uri, tableDetails);
    TableDetails.ColumnDetails primaryKeyColumn = tableDetails.findPrimaryKeyColumn();
    if (primaryKeyColumn.isAutoIncrement()) {
        return mUriMatcherHelper.generateSingleItemUri(tableDetails, insertId);
    } else {
        String primaryKeyValue = contentValues.getAsString(primaryKeyColumn.getColumnName());
        return mUriMatcherHelper.generateSingleItemUri(tableDetails, primaryKeyValue);
    }
}
Also used : TableDetails(me.himanshusoni.quantumflux.model.generate.TableDetails) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) QuantumFluxException(me.himanshusoni.quantumflux.model.util.QuantumFluxException)

Example 3 with QuantumFluxException

use of me.himanshusoni.quantumflux.model.util.QuantumFluxException in project QuantumFlux by himanshu-soni.

the class DataFilterCriterion method buildWhereClause.

@Override
public QueryBuilder buildWhereClause(SqlColumnMappingFactory columnMappingFactory) {
    QueryBuilder builder = new QueryBuilder();
    builder.append(mFilterColumn);
    builder.append(" ");
    builder.append(mFilterOperator.getSqlRepresentation());
    if (mFilterValue != null) {
        if (mFilterValue instanceof Collection) {
            Iterator collectionIterator = ((Collection) mFilterValue).iterator();
            builder.append(" (");
            while (collectionIterator.hasNext()) {
                builder.append("?", convertToSQLFormat(columnMappingFactory, collectionIterator.next()));
                if (collectionIterator.hasNext())
                    builder.append(", ");
            }
            builder.append(")");
        } else if (mFilterValue instanceof Select) {
            Select innerSelect = (Select) mFilterValue;
            if (!innerSelect.isSingleColumnProjection())
                throw new QuantumFluxException("Inner select can only contain a single column selection");
            builder.append(" (");
            builder.append((innerSelect).getSelectQuery());
            builder.append(")");
        } else
            builder.append(" ?", convertToSQLFormat(columnMappingFactory, mFilterValue));
    }
    return builder;
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) QuantumFluxException(me.himanshusoni.quantumflux.model.util.QuantumFluxException)

Example 4 with QuantumFluxException

use of me.himanshusoni.quantumflux.model.util.QuantumFluxException in project QuantumFlux by himanshu-soni.

the class DataFilterCriterion method getWhereClause.

@Override
public String getWhereClause() {
    QueryBuilder builder = new QueryBuilder();
    builder.append(mFilterColumn);
    builder.append(" ");
    builder.append(mFilterOperator.getSqlRepresentation());
    if (mFilterValue != null) {
        if (mFilterValue instanceof Collection) {
            Iterator collectionIterator = ((Collection) mFilterValue).iterator();
            builder.append(" (");
            while (collectionIterator.hasNext()) {
                builder.append("?");
                if (collectionIterator.hasNext())
                    builder.append(", ");
            }
            builder.append(")");
        } else if (mFilterValue instanceof Select) {
            Select innerSelect = (Select) mFilterValue;
            if (!innerSelect.isSingleColumnProjection())
                throw new QuantumFluxException("Inner select can only contain a single column selection");
            builder.append(" (");
            builder.append((innerSelect).getSelectQuery());
            builder.append(")");
        } else
            builder.append(" ?");
    }
    return builder.toString();
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) QuantumFluxException(me.himanshusoni.quantumflux.model.util.QuantumFluxException)

Example 5 with QuantumFluxException

use of me.himanshusoni.quantumflux.model.util.QuantumFluxException in project QuantumFlux by himanshu-soni.

the class QuantumFlux method findSingleItem.

protected static <T> T findSingleItem(Uri itemUri, TableDetails tableDetails) {
    ContentResolver contentResolver = mApplicationContext.getContentResolver();
    Cursor cursor = null;
    try {
        cursor = contentResolver.query(itemUri, tableDetails.getColumnNames(), null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            return ModelInflater.inflate(cursor, tableDetails);
        } else {
            throw new QuantumFluxException("No row found with the key " + itemUri.getLastPathSegment());
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : QuantumFluxException(me.himanshusoni.quantumflux.model.util.QuantumFluxException) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Aggregations

QuantumFluxException (me.himanshusoni.quantumflux.model.util.QuantumFluxException)6 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 TableDetails (me.himanshusoni.quantumflux.model.generate.TableDetails)1