use of com.raizlabs.android.dbflow.structure.ModelViewAdapter in project DBFlow by Raizlabs.
the class FlowManager method getTableName.
/**
* Returns the table name for the specific model class
*
* @param table The class that implements {@link Model}
* @return The table name, which can be different than the {@link Model} class name
*/
@SuppressWarnings("unchecked")
public static String getTableName(Class<?> table) {
ModelAdapter modelAdapter = getModelAdapter(table);
String tableName = null;
if (modelAdapter == null) {
ModelViewAdapter modelViewAdapter = getDatabaseForTable(table).getModelViewAdapterForTable(table);
if (modelViewAdapter != null) {
tableName = modelViewAdapter.getViewName();
}
} else {
tableName = modelAdapter.getTableName();
}
return tableName;
}
use of com.raizlabs.android.dbflow.structure.ModelViewAdapter in project DBFlow by Raizlabs.
the class BaseDatabaseHelper method executeCreations.
/**
* This method executes CREATE TABLE statements as well as CREATE VIEW on the database passed.
*/
protected void executeCreations(final DatabaseWrapper database) {
try {
database.beginTransaction();
List<ModelAdapter> modelAdapters = databaseDefinition.getModelAdapters();
for (ModelAdapter modelAdapter : modelAdapters) {
try {
database.execSQL(modelAdapter.getCreationQuery());
} catch (SQLiteException e) {
FlowLog.logError(e);
}
}
// create our model views
List<ModelViewAdapter> modelViews = databaseDefinition.getModelViewAdapters();
for (ModelViewAdapter modelView : modelViews) {
QueryBuilder queryBuilder = new QueryBuilder().append("CREATE VIEW IF NOT EXISTS").appendSpaceSeparated(modelView.getViewName()).append("AS ").append(modelView.getCreationQuery());
try {
database.execSQL(queryBuilder.getQuery());
} catch (SQLiteException e) {
FlowLog.logError(e);
}
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
}
Aggregations