本文整理匯總了Java中com.raizlabs.android.dbflow.config.FlowManager.getDatabase方法的典型用法代碼示例。如果您正苦於以下問題:Java FlowManager.getDatabase方法的具體用法?Java FlowManager.getDatabase怎麽用?Java FlowManager.getDatabase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.raizlabs.android.dbflow.config.FlowManager
的用法示例。
在下文中一共展示了FlowManager.getDatabase方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: save
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
/**
* 新增或者修改數據庫的統一方法
* @param tClass 傳遞一個class信息
* @param models 這個class對應的實例的數組
* @param <Model> 這個實例的泛型 限定條件是BaseModel
*/
public static<Model extends BaseModel> void save(final Class<Model> tClass, final Model... models) {
if (models==null||models.length==0) return;
// 當前數據庫的一個管理者
DatabaseDefinition definition = FlowManager.getDatabase(AppDatabase.class);
// 提交一個事務
definition.beginTransactionAsync(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// 執行
ModelAdapter<Model> adapter = FlowManager.getModelAdapter(tClass);
// 保存
adapter.saveAll(Arrays.asList(models));
// 喚起通知
instance.notifySave(tClass,models);
}
}).build().execute();
}
示例2: delete
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
/**
* 刪除數據庫的的統一方法
* @param tClass 傳遞一個class信息
* @param models 這個class對應的實例的數組
* @param <Model> 這個實例的泛型 限定條件是BaseModel
*/
public static<Model extends BaseModel> void delete(final Class<Model> tClass, final Model... models) {
if (models==null||models.length==0) return;
// 當前數據庫的一個管理者
DatabaseDefinition definition = FlowManager.getDatabase(AppDatabase.class);
// 提交一個事務
definition.beginTransactionAsync(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// 執行
ModelAdapter<Model> adapter = FlowManager.getModelAdapter(tClass);
// 刪除
adapter.deleteAll(Arrays.asList(models));
// 喚起通知
instance.notifyDelete(tClass,models);
}
}).build().execute();
}
示例3: updateGroup
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
/**
* 從成員中找出成員對應的群,並對群進行更新
*
* @param members 群成員列表
*/
private void updateGroup(GroupMember... members) {
// 不重複集合
final Set<String> groupIds = new HashSet<>();
for (GroupMember member : members) {
// 添加群Id
groupIds.add(member.getGroup().getId());
}
// 異步的數據庫查詢,並異步的發起二次通知
DatabaseDefinition definition = FlowManager.getDatabase(AppDatabase.class);
definition.beginTransactionAsync(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// 找到需要通知的群
List<Group> groups = SQLite.select()
.from(Group.class)
.where(Group_Table.id.in(groupIds))
.queryList();
// 調用直接進行一次通知分發
instance.notifySave(Group.class, groups.toArray(new Group[0]));
}
}).build().execute();
}
示例4: upDataBySynchronous
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
public static void upDataBySynchronous(final ArrayList<SOListBean.ListBean> mListBeans, final String type){
DatabaseDefinition database = FlowManager.getDatabase(LueansDB.class);
database.executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// do something here
deleteSoDdata(type);
saveSoData(mListBeans,type);
}
});
}
示例5: deleteSQLiteMetadata
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
/**
* This method removes the sqlite_sequence table that contains the last autoincrement value for
* each table
*/
private void deleteSQLiteMetadata() {
String sqlCopy = "Delete from sqlite_sequence";
DatabaseDefinition databaseDefinition =
FlowManager.getDatabase(AppDatabase.class);
databaseDefinition.getWritableDatabase().execSQL(sqlCopy);
}
示例6: saveAllItems
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
protected static void saveAllItems(final List<Model> models) {
DatabaseDefinition databaseDefinition =
FlowManager.getDatabase(AppDatabase.class); // execute transaction
databaseDefinition.executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
for (Model model : models) {
model.insert();
}
}
});
}
示例7: saveBatch
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
public static void saveBatch(final List<Model> insertModels) {
//Save questions in batch
DatabaseDefinition databaseDefinition =
FlowManager.getDatabase(AppDatabase.class);
databaseDefinition.executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
for (Model model : insertModels) {
model.insert();
}
}
});
}
示例8: deleteSQLiteMetadata
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
/**
* This method removes the sqlite_sequence table that contains the last autoincrement value for
* each table
*/
private static void deleteSQLiteMetadata() {
String sqlCopy = "Delete from sqlite_sequence";
DatabaseDefinition databaseDefinition =
FlowManager.getDatabase(AppDatabase.class);
databaseDefinition.getWritableDatabase().execSQL(sqlCopy);
}
示例9: getDatabase
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
@NonNull
protected DatabaseDefinition getDatabase() {
if (database == null) {
database = FlowManager.getDatabase(getDatabaseName());
}
return database;
}
示例10: getData
import com.raizlabs.android.dbflow.config.FlowManager; //導入方法依賴的package包/類
public ArrayList<Cursor> getData(String Query){
//get writable database
// TODO: Add Your Database Class Here
if (myClass == null)
{
throw new RuntimeException("myClass is not initialized yet!");
}
FlowSQLiteOpenHelper fom = new FlowSQLiteOpenHelper(FlowManager.getDatabase(myClass), null);
//SQLiteDatabase sqlDB = this.getWritableDatabase();
SQLiteDatabase sqlDB = fom.getWritableDatabase();
String[] columns = new String[] { "mesage" };
//an array list of cursor to save two cursors one has results from the query
//other cursor stores error message if any errors are triggered
ArrayList<Cursor> alc = new ArrayList<Cursor>(2);
MatrixCursor Cursor2= new MatrixCursor(columns);
alc.add(null);
alc.add(null);
try{
String maxQuery = Query ;
//execute the query results will be save in Cursor c
Cursor c = sqlDB.rawQuery(maxQuery, null);
//add value to cursor2
Cursor2.addRow(new Object[] { "Success" });
alc.set(1,Cursor2);
if (null != c && c.getCount() > 0) {
alc.set(0,c);
c.moveToFirst();
return alc ;
}
return alc;
} catch(SQLException sqlEx){
Log.d("printing exception", sqlEx.getMessage());
//if any exceptions are triggered save the error message to cursor an return the arraylist
Cursor2.addRow(new Object[] { ""+sqlEx.getMessage() });
alc.set(1,Cursor2);
return alc;
} catch(Exception ex){
Log.d("printing exception", ex.getMessage());
//if any exceptions are triggered save the error message to cursor an return the arraylist
Cursor2.addRow(new Object[] { ""+ex.getMessage() });
alc.set(1,Cursor2);
return alc;
}
}