Java Code Examples for com.raizlabs.android.dbflow.config.FlowManager#getModelAdapter()

The following examples show how to use com.raizlabs.android.dbflow.config.FlowManager#getModelAdapter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBLocalDataSourceManager.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
public static void addLocalHistory(String url){
    ModelAdapter<LocalHistoryModel> manager =
            FlowManager.getModelAdapter(LocalHistoryModel.class);

    LocalHistoryModel oldModel = new Select()
            .from(LocalHistoryModel.class)
            .where(LocalHistoryModel_Table.url.eq(url))
            .querySingle();

    if (oldModel != null){
        manager.delete(oldModel);
    }

    LocalHistoryModel model = new LocalHistoryModel();
    model.setUrl(url);
    manager.insert(model);
    judgeHistoryNum();
}
 
Example 2
Source File: DBLocalSearchManager.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
public static void addLocalHistory(String label){
    Log.d("DBLocalSearchManager", "执行到这了");
    ModelAdapter<LocalLabel> manager =
            FlowManager.getModelAdapter(LocalLabel.class);

    LocalLabel oldModel = new Select()
            .from(LocalLabel.class)
            .where(LocalLabel_Table.label.eq(label))
            .querySingle();

    if (oldModel != null){
        manager.delete(oldModel);
    }

    LocalLabel model = new LocalLabel();
    model.setLabel(label);
    manager.insert(model);
    judgeHistoryNum();
}
 
Example 3
Source File: DBLocalDataSourceManager.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
public static void judgeHistoryNum(){
    List<LocalHistoryModel> list = new Select().from(LocalHistoryModel.class).queryList();
    ModelAdapter<LocalHistoryModel> manager = FlowManager.getModelAdapter(LocalHistoryModel.class);
    if (list.size() <= Constant.DATABASE_NUM){
        return;
    }

    manager.delete(list.get(0));
}
 
Example 4
Source File: DBLocalSearchManager.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
public static void judgeHistoryNum(){
    List<LocalLabel> list = new Select().from(LocalLabel.class).queryList();
    ModelAdapter<LocalLabel> manager = FlowManager.getModelAdapter(LocalLabel.class);
    if (list.size() <= Constant.LOCAL_LABEL_NUM){
        return;
    }

    manager.delete(list.get(0));
}
 
Example 5
Source File: BaseModel.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * @return The associated {@link ModelAdapter}. The {@link FlowManager}
 * may throw a {@link InvalidDBConfiguration} for this call if this class
 * is not associated with a table, so be careful when using this method.
 */
public ModelAdapter getModelAdapter() {
    if (modelAdapter == null) {
        modelAdapter = FlowManager.getModelAdapter(getClass());
    }
    return modelAdapter;
}
 
Example 6
Source File: AsyncModel.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
private ModelAdapter<TModel> getModelAdapter() {
    if (modelAdapter == null) {
        //noinspection unchecked
        modelAdapter = (ModelAdapter<TModel>) FlowManager.getModelAdapter(model.getClass());
    }
    return modelAdapter;
}
 
Example 7
Source File: ContentUtils.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts the model into the {@link android.content.ContentResolver}. Uses the insertUri to resolve
 * the reference and the model to convert its data into {@link android.content.ContentValues}
 *
 * @param contentResolver The content resolver to use (if different from {@link FlowManager#getContext()})
 * @param insertUri       A {@link android.net.Uri} from the {@link ContentProvider} class definition.
 * @param model           The model to insert.
 * @return The Uri of the inserted data.
 */
@SuppressWarnings("unchecked")
public static <TableClass> Uri insert(ContentResolver contentResolver, Uri insertUri, TableClass model) {
    ModelAdapter<TableClass> adapter = (ModelAdapter<TableClass>) FlowManager.getModelAdapter(model.getClass());

    ContentValues contentValues = new ContentValues();
    adapter.bindToInsertValues(contentValues, model);
    Uri uri = contentResolver.insert(insertUri, contentValues);
    adapter.updateAutoIncrement(model, Long.valueOf(uri.getPathSegments().get(uri.getPathSegments().size() - 1)));
    return uri;
}
 
Example 8
Source File: ContentUtils.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts the list of model into the {@link ContentResolver}. Binds all of the models to {@link ContentValues}
 * and runs the {@link ContentResolver#bulkInsert(Uri, ContentValues[])} method. Note: if any of these use
 * autoIncrementing primary keys the ROWID will not be properly updated from this method. If you care
 * use {@link #insert(ContentResolver, Uri, Object)} instead.
 *
 * @param contentResolver The content resolver to use (if different from {@link FlowManager#getContext()})
 * @param bulkInsertUri   The URI to bulk insert with
 * @param table           The table to insert into
 * @param models          The models to insert.
 * @return The count of the rows affected by the insert.
 */
public static <TableClass> int bulkInsert(ContentResolver contentResolver, Uri bulkInsertUri,
                                          Class<TableClass> table, List<TableClass> models) {
    ContentValues[] contentValues = new ContentValues[models == null ? 0 : models.size()];
    ModelAdapter<TableClass> adapter = FlowManager.getModelAdapter(table);

    if (models != null) {
        for (int i = 0; i < contentValues.length; i++) {
            contentValues[i] = new ContentValues();
            adapter.bindToInsertValues(contentValues[i], models.get(i));
        }
    }
    return contentResolver.bulkInsert(bulkInsertUri, contentValues);
}
 
Example 9
Source File: ContentUtils.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the model through the {@link android.content.ContentResolver}. Uses the updateUri to
 * resolve the reference and the model to convert its data in {@link android.content.ContentValues}
 *
 * @param contentResolver The content resolver to use (if different from {@link FlowManager#getContext()})
 * @param updateUri       A {@link android.net.Uri} from the {@link ContentProvider}
 * @param model           The model to update
 * @return The number of rows updated.
 */
@SuppressWarnings("unchecked")
public static <TableClass> int update(ContentResolver contentResolver, Uri updateUri, TableClass model) {
    ModelAdapter<TableClass> adapter = (ModelAdapter<TableClass>) FlowManager.getModelAdapter(model.getClass());

    ContentValues contentValues = new ContentValues();
    adapter.bindToContentValues(contentValues, model);
    int count = contentResolver.update(updateUri, contentValues, adapter.getPrimaryConditionClause(model).getQuery(), null);
    if (count == 0) {
        FlowLog.log(FlowLog.Level.W, "Updated failed of: " + model.getClass());
    }
    return count;
}
 
Example 10
Source File: ContentUtils.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the specified model through the {@link android.content.ContentResolver}. Uses the deleteUri
 * to resolve the reference and the model to {@link ModelAdapter#getPrimaryConditionClause(Object)}
 *
 * @param contentResolver The content resolver to use (if different from {@link FlowManager#getContext()})
 * @param deleteUri       A {@link android.net.Uri} from the {@link ContentProvider}
 * @param model           The model to delete
 * @return The number of rows deleted.
 */
@SuppressWarnings("unchecked")
public static <TableClass> int delete(ContentResolver contentResolver, Uri deleteUri, TableClass model) {
    ModelAdapter<TableClass> adapter = (ModelAdapter<TableClass>) FlowManager.getModelAdapter(model.getClass());

    int count = contentResolver.delete(deleteUri, adapter.getPrimaryConditionClause(model).getQuery(), null);

    // reset autoincrement to 0
    if (count > 0) {
        adapter.updateAutoIncrement(model, 0);
    } else {
        FlowLog.log(FlowLog.Level.W, "A delete on " + model.getClass() + " within the ContentResolver appeared to fail.");
    }
    return count;
}
 
Example 11
Source File: DBLocalDataSourceManager.java    From tysq-android with GNU General Public License v3.0 4 votes vote down vote up
public static void deleteLocalHistory(LocalHistoryModel model){
    ModelAdapter<LocalHistoryModel> manager =
            FlowManager.getModelAdapter(LocalHistoryModel.class);
    manager.delete(model);
}
 
Example 12
Source File: DBLocalSearchManager.java    From tysq-android with GNU General Public License v3.0 4 votes vote down vote up
public static void deleteLocalHistory(LocalLabel model){
    ModelAdapter<LocalLabel> manager =
            FlowManager.getModelAdapter(LocalLabel.class);
    manager.delete(model);
}
 
Example 13
Source File: PerfTestDbFlow.java    From android-database-performance with Apache License 2.0 4 votes vote down vote up
@NonNull
private <TModel extends Model> ITransaction insertTransaction(Collection entities, Class<TModel> clazz) {
    ModelAdapter<? extends Model> modelAdapter = FlowManager.getModelAdapter(clazz);
    return FastStoreModelTransaction.insertBuilder(modelAdapter).addAll(entities).build();
}
 
Example 14
Source File: PerfTestDbFlow.java    From android-database-performance with Apache License 2.0 4 votes vote down vote up
@NonNull
private <TModel extends Model> ITransaction updateTransaction(Collection entities, Class<TModel> clazz) {
    ModelAdapter<? extends Model> modelAdapter = FlowManager.getModelAdapter(clazz);
    return FastStoreModelTransaction.updateBuilder(modelAdapter).addAll(entities).build();
}