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();
}
}
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);
}
}
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;
}
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();
}
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();
}
}
Aggregations