当前位置: 首页>>代码示例>>Java>>正文


Java ProcessModelTransaction类代码示例

本文整理汇总了Java中com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction的典型用法代码示例。如果您正苦于以下问题:Java ProcessModelTransaction类的具体用法?Java ProcessModelTransaction怎么用?Java ProcessModelTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProcessModelTransaction类属于com.raizlabs.android.dbflow.structure.database.transaction包,在下文中一共展示了ProcessModelTransaction类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Adds an item to this table
 *
 * @param model The model to save
 * @return always true
 */
@Override
public boolean add(@Nullable TModel model) {
    if (model != null) {
        Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
                .beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel)
                        .add(model).build())
                .error(internalErrorCallback)
                .success(internalSuccessCallback).build();

        if (transact) {
            transaction.execute();
        } else {
            transaction.executeSync();
        }
        return true;
    } else {
        return false;
    }
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:26,代码来源:FlowQueryList.java

示例2: addAll

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Adds all items to this table.
 *
 * @param collection The list of items to add to the table
 * @return always true
 */
@SuppressWarnings("unchecked")
@Override
public boolean addAll(@NonNull Collection<? extends TModel> collection) {
    // cast to normal collection, we do not want subclasses of this table saved
    final Collection<TModel> tmpCollection = (Collection<TModel>) collection;

    Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
            .beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel)
                    .addAll(tmpCollection).build())
            .error(internalErrorCallback)
            .success(internalSuccessCallback).build();

    if (transact) {
        transaction.execute();
    } else {
        transaction.executeSync();
    }
    return true;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:26,代码来源:FlowQueryList.java

示例3: remove

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Deletes a {@link TModel} at a specific position within the stored {@link Cursor}.
 * If {@link #transact} is true, the delete does not happen immediately. Avoid using this operation
 * many times. If you need to remove multiple, use {@link #removeAll(Collection)}
 *
 * @param location The location within the table to remove the item from
 * @return The removed item.
 */
@Override
public TModel remove(int location) {
    TModel model = internalCursorList.getItem(location);

    Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
            .beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
                    .add(model).build())
            .error(internalErrorCallback)
            .success(internalSuccessCallback).build();

    if (transact) {
        transaction.execute();
    } else {
        transaction.executeSync();
    }
    return model;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:26,代码来源:FlowQueryList.java

示例4: removeAll

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Removes all items from this table in one transaction based on the list passed. This may happen in the background
 * if {@link #transact} is true.
 *
 * @param collection The collection to remove.
 * @return Always true. Will cause a {@link ClassCastException} if the collection is not of type {@link TModel}
 */
@SuppressWarnings("unchecked")
@Override
public boolean removeAll(@NonNull Collection<?> collection) {

    // if its a ModelClass
    Collection<TModel> modelCollection = (Collection<TModel>) collection;
    Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
            .beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
                    .addAll(modelCollection).build())
            .error(internalErrorCallback)
            .success(internalSuccessCallback).build();

    if (transact) {
        transaction.execute();
    } else {
        transaction.executeSync();
    }

    return true;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:28,代码来源:FlowQueryList.java

示例5: retainAll

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Retrieves the full list of {@link TModel} items from the table, removes these from the list, and
 * then deletes the remaining members. This is not that efficient.
 *
 * @param collection The collection if models to keep in the table.
 * @return Always true.
 */
@Override
public boolean retainAll(@NonNull Collection<?> collection) {
    List<TModel> tableList = internalCursorList.getAll();
    tableList.removeAll(collection);
    Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
            .beginTransactionAsync(new ProcessModelTransaction.Builder<>(tableList, deleteModel)
                    .build())
            .error(internalErrorCallback)
            .success(internalSuccessCallback).build();

    if (transact) {
        transaction.execute();
    } else {
        transaction.executeSync();
    }
    return true;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:25,代码来源:FlowQueryList.java

示例6: set

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Updates a Model {@link Model#update()} . If {@link #transact}
 * is true, this update happens in the BG, otherwise it happens immediately.
 *
 * @param object The object to update
 * @return The updated model.
 */
public TModel set(TModel object) {
    Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
            .beginTransactionAsync(new ProcessModelTransaction.Builder<>(updateModel)
                    .add(object)
                    .build())
            .error(internalErrorCallback)
            .success(internalSuccessCallback).build();

    if (transact) {
        transaction.execute();
    } else {
        transaction.executeSync();
    }
    return object;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:23,代码来源:FlowQueryList.java

示例7: replaceDB

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Completely wipes a DB and adds all of the new objects to it
 *
 * @param context    App context
 * @param dbName     Name of the DB
 * @param type       Type of the class
 * @param newObjects List of the new objects to add to the DB
 * @param callback   Optional callback called when a transaction is finished
 * @param <T>        Object type
 */
public static <T extends BaseModel> void replaceDB(Context context, String dbName,
        Class<T> type, List<T> newObjects, @Nullable Callback callback) {
    // Delete the old database
    FlowManager.getDatabase(dbName).reset(context);

    // Set up the transaction to save all of the models
    ProcessModelTransaction<T> newObjectsTransaction = new ProcessModelTransaction
            .Builder<T>((tModel, wrapper) -> {
        if (tModel != null) {
            tModel.save();
        }
    })
            .addAll(newObjects)
            .build();

    // Execute the transaction
    FlowManager.getDatabase(dbName)
            .beginTransactionAsync(newObjectsTransaction)
            .success(transaction -> {
                if (callback != null) {
                    callback.onFinish();
                }
            })
            .error((transaction, error) -> {
                Timber.e(error);
                if (callback != null) {
                    callback.onFinish();
                }
            })
            .build()
            .execute();
}
 
开发者ID:jguerinet,项目名称:MyMartlet,代码行数:43,代码来源:DBUtils.java

示例8: save

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
@Override
public boolean save() {
    executeTransaction(new ProcessModelTransaction.Builder<>(
        new ProcessModelTransaction.ProcessModel<TModel>() {
            @Override
            public void processModel(TModel model, DatabaseWrapper wrapper) {
                getModelAdapter().save(model, wrapper);
            }
        }).add(model).build());
    return false;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:12,代码来源:AsyncModel.java

示例9: delete

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
@Override
public boolean delete() {
    executeTransaction(new ProcessModelTransaction.Builder<>(
        new ProcessModelTransaction.ProcessModel<TModel>() {
            @Override
            public void processModel(TModel model, DatabaseWrapper wrapper) {
                getModelAdapter().delete(model, wrapper);
            }
        }).add(model).build());
    return false;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:12,代码来源:AsyncModel.java

示例10: update

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
@Override
public boolean update() {
    executeTransaction(new ProcessModelTransaction.Builder<>(
        new ProcessModelTransaction.ProcessModel<TModel>() {
            @Override
            public void processModel(TModel model, DatabaseWrapper wrapper) {
                getModelAdapter().update(model, wrapper);
            }
        }).add(model).build());
    return false;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:12,代码来源:AsyncModel.java

示例11: insert

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
@Override
public long insert() {
    executeTransaction(new ProcessModelTransaction.Builder<>(
        new ProcessModelTransaction.ProcessModel<TModel>() {
            @Override
            public void processModel(TModel model, DatabaseWrapper wrapper) {
                getModelAdapter().insert(model, wrapper);
            }
        }).add(model).build());
    return INVALID_ROW_ID;
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:12,代码来源:AsyncModel.java

示例12: load

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
@Override
public void load() {
    executeTransaction(new ProcessModelTransaction.Builder<>(
        new ProcessModelTransaction.ProcessModel<TModel>() {
            @Override
            public void processModel(TModel model, DatabaseWrapper wrapper) {
                getModelAdapter().load(model, wrapper);
            }
        }).add(model).build());
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:11,代码来源:AsyncModel.java

示例13: run

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void run() {
    super.run();
    Looper.prepare();
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
    while (true) {
        final ArrayList<Object> tmpModels;
        synchronized (models) {
            tmpModels = new ArrayList<>(models);
            models.clear();
        }
        if (tmpModels.size() > 0) {
            databaseDefinition.beginTransactionAsync(
                    new ProcessModelTransaction.Builder(modelSaver)
                            .addAll(tmpModels)
                            .build())
                    .success(successCallback)
                    .error(errorCallback)
                    .build()
                    .execute();
        } else if (emptyTransactionListener != null) {
            emptyTransactionListener.run();
        }

        try {
            //sleep, and then check for leftovers
            Thread.sleep(modelSaveCheckTime);
        } catch (InterruptedException e) {
            FlowLog.log(FlowLog.Level.I, "DBRequestQueue Batch interrupted to start saving");
        }

        if (isQuitting) {
            return;
        }
    }
}
 
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:38,代码来源:DBBatchSaveQueue.java

示例14: updateDB

import com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction; //导入依赖的package包/类
/**
 * Updates the objects in a DB by updating existing objects, removing old objects, and
 *  inserting new ones.
 * Note: this only works with models that have correctly set up the equals() method
 *
 * @param type           Object type
 * @param newObjects     List of new objects/objects to update
 * @param condition      Optional condition to run when searching
 * @param dbClass        Class of the DB these will be stored in
 * @param updateCallback Optional callback to run any update code. If not, save() will be called
 * @param callback       Optional callback to call after update is finished
 * @param <T>            Object Type
 */
public static <T extends BaseModel> void updateDB(Class<T> type, List<T> newObjects,
        @Nullable SQLCondition condition, Class dbClass, UpdateCallback<T> updateCallback,
        @Nullable Callback callback) {
    From<T> select = SQLite.select()
            .from(type);

    BaseModelQueriable<T> query;
    if (condition != null) {
        // Add the conditions if necessary
        query = select.where(condition);
    } else {
        query = select.where();
    }

    query.async()
            .queryListResultCallback((transaction, tResult) -> {
                // Go through the existing objects
                for (T oldObject : tResult) {
                    // Check if the object still exists in the received objects
                    int index = newObjects.indexOf(oldObject);
                    if (index != -1) {
                        // Update it
                        T newObject = newObjects.get(index);

                        // If there's a callback, use it
                        if (updateCallback != null) {
                            updateCallback.update(newObject, oldObject);
                        } else {
                            // If not, call save
                            newObject.save();
                        }

                        // Delete that place from the body since we've dealt with it
                        newObjects.remove(newObject);
                    } else {
                        // Delete the old place
                        oldObject.delete();
                    }
                }

                // Set up the transaction to save all of the models
                ProcessModelTransaction<T> newObjectsTransaction = new ProcessModelTransaction
                        .Builder<T>((tModel, wrapper) -> {
                    if (tModel != null) {
                        tModel.save();
                    }
                })
                        .addAll(newObjects)
                        .build();

                FlowManager.getDatabase(dbClass)
                        .executeTransaction(newObjectsTransaction);

                if (callback != null) {
                    callback.onFinish();
                }
        })
            .execute();
}
 
开发者ID:jguerinet,项目名称:MyMartlet,代码行数:73,代码来源:DBUtils.java


注:本文中的com.raizlabs.android.dbflow.structure.database.transaction.ProcessModelTransaction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。