Search in sources :

Example 1 with ModelViewAdapter

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;
}
Also used : QueryModelAdapter(com.raizlabs.android.dbflow.structure.QueryModelAdapter) ModelAdapter(com.raizlabs.android.dbflow.structure.ModelAdapter) ModelViewAdapter(com.raizlabs.android.dbflow.structure.ModelViewAdapter)

Example 2 with ModelViewAdapter

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();
    }
}
Also used : ModelAdapter(com.raizlabs.android.dbflow.structure.ModelAdapter) QueryBuilder(com.raizlabs.android.dbflow.sql.QueryBuilder) SQLiteException(android.database.sqlite.SQLiteException) ModelViewAdapter(com.raizlabs.android.dbflow.structure.ModelViewAdapter)

Aggregations

ModelAdapter (com.raizlabs.android.dbflow.structure.ModelAdapter)2 ModelViewAdapter (com.raizlabs.android.dbflow.structure.ModelViewAdapter)2 SQLiteException (android.database.sqlite.SQLiteException)1 QueryBuilder (com.raizlabs.android.dbflow.sql.QueryBuilder)1 QueryModelAdapter (com.raizlabs.android.dbflow.structure.QueryModelAdapter)1