com.squareup.sqlbrite.BriteDatabase Java Examples
The following examples show how to use
com.squareup.sqlbrite.BriteDatabase.
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: DatabaseHelper.java From ribot-app-android with Apache License 2.0 | 6 votes |
public Observable<Void> setRegisteredBeacons(final List<RegisteredBeacon> beacons) { return Observable.create(new Observable.OnSubscribe<Void>() { @Override public void call(Subscriber<? super Void> subscriber) { BriteDatabase.Transaction transaction = mDb.newTransaction(); try { mDb.delete(Db.BeaconTable.TABLE_NAME, null); for (RegisteredBeacon beacon : beacons) { mDb.insert(Db.BeaconTable.TABLE_NAME, Db.BeaconTable.toContentValues(beacon)); } transaction.markSuccessful(); subscriber.onCompleted(); } finally { transaction.end(); } } }); }
Example #2
Source File: DatabaseHelper.java From ribot-app-android with Apache License 2.0 | 6 votes |
/** * Remove all the data from all the tables in the database. */ public Observable<Void> clearTables() { return Observable.create(new Observable.OnSubscribe<Void>() { @Override public void call(Subscriber<? super Void> subscriber) { BriteDatabase.Transaction transaction = mDb.newTransaction(); try { Cursor cursor = mDb.query("SELECT name FROM sqlite_master WHERE type='table'"); while (cursor.moveToNext()) { mDb.delete(cursor.getString(cursor.getColumnIndex("name")), null); } cursor.close(); transaction.markSuccessful(); subscriber.onCompleted(); } finally { transaction.end(); } } }); }
Example #3
Source File: PlaceModel.java From Fishing with GNU General Public License v3.0 | 6 votes |
public Observable<List<PlaceBrief>> syncPlace(){ return ServiceClient.getService().syncPlace(JUtils.getSharedPreference().getString(PLACE_LAST_SYNC_TIME, "0")) .doOnCompleted(() -> JUtils.getSharedPreference().edit().putString(PLACE_LAST_SYNC_TIME, System.currentTimeMillis() / 1000 + "").apply()) .doOnNext(placeBriefs -> { BriteDatabase.Transaction transaction = mDbBrite.newTransaction(); for (PlaceBrief placeBrief : placeBriefs) { try { mDbBrite.insert(PlaceDBTable.TABLE_NAME, PlaceDBTable.getInstance().to(placeBrief)); JUtils.Log("DB", "inserted:" + placeBrief.getName()); } catch (Exception e) { JUtils.Log("DB", "inserted ERROR:" + e.getLocalizedMessage()); try { mDbBrite.update(PlaceDBTable.TABLE_NAME, PlaceDBTable.getInstance().to(placeBrief), PlaceDBTable.COLUMN_ID + "=" + placeBrief.getId()); JUtils.Log("DB", "updated" + placeBrief.getName()); } catch (Exception e1) { JUtils.Log("DB", "updated ERROR:" + e1.getLocalizedMessage()); } } } transaction.markSuccessful(); transaction.end(); }); }
Example #4
Source File: SessionsDao.java From droidconat-2016 with Apache License 2.0 | 6 votes |
public void toggleSelectedSessionState(com.nilhcem.droidconat.data.app.model.Session session, boolean insert) { Preconditions.checkNotOnMainThread(); String slotTime = adapter.toText(session.getFromTime()); BriteDatabase.Transaction transaction = database.newTransaction(); try { database.delete(SelectedSession.TABLE, SelectedSession.SLOT_TIME + "=?", slotTime); if (insert) { database.insert(SelectedSession.TABLE, new SelectedSession.Builder().slotTime(slotTime).sessionId(session.getId()).build()); } selectedSessionsMemory.toggleSessionState(session, insert); transaction.markSuccessful(); } finally { transaction.end(); } }
Example #5
Source File: DaoSqlBriteIntegrationTest.java From sqlbrite-dao with Apache License 2.0 | 6 votes |
@Test public void runRawStatementQueryWithSingleTableNoAutoUpdates() { BriteDatabase db = PowerMockito.mock(BriteDatabase.class); userDao.setSqlBriteDb(db); String arg1 = "arg1", arg2 = "arg2"; String table = "Table"; String sql = "SELECT * FROM " + table; List<String> argsList = Arrays.asList(arg1, arg2); Set<String> emptySet = Collections.emptySet(); userDao.rawQuery(table, sql).args(arg1, arg2).autoUpdates(false).run(); ArgumentCaptor<String> varArgs = ArgumentCaptor.forClass(String.class); QueryObservable query = Mockito.verify(db, Mockito.times(1)) .createQuery(Mockito.eq(emptySet), Mockito.eq(sql), varArgs.capture()); Assert.assertEquals(argsList, varArgs.getAllValues()); }
Example #6
Source File: DaoSqlBriteIntegrationTest.java From sqlbrite-dao with Apache License 2.0 | 6 votes |
@Test public void runRawStatementQueryWithSingleTable() { BriteDatabase db = PowerMockito.mock(BriteDatabase.class); userDao.setSqlBriteDb(db); String arg1 = "arg1", arg2 = "arg2"; String table = "Table"; String sql = "SELECT * FROM " + table; List<String> argsList = Arrays.asList(arg1, arg2); Set<String> tables = Collections.singleton(table); userDao.rawQuery(table, sql).args(arg1, arg2).run(); ArgumentCaptor<String> varArgs = ArgumentCaptor.forClass(String.class); QueryObservable query = Mockito.verify(db, Mockito.times(1)) .createQuery(Mockito.eq(tables), Mockito.eq(sql), varArgs.capture()); Assert.assertEquals(argsList, varArgs.getAllValues()); }
Example #7
Source File: DaoSqlBriteIntegrationTest.java From sqlbrite-dao with Apache License 2.0 | 6 votes |
@Test public void runRawStatementQueryWithTablesNoAutoUpdates() { BriteDatabase db = PowerMockito.mock(BriteDatabase.class); userDao.setSqlBriteDb(db); String arg1 = "arg1", arg2 = "arg2"; String table = "Table"; String sql = "SELECT * FROM " + table; List<String> argsList = Arrays.asList(arg1, arg2); Set<String> tables = Collections.singleton(table); Set<String> emptySet = Collections.emptySet(); userDao.rawQueryOnManyTables(tables, sql).args(arg1, arg2).autoUpdates(false).run(); ArgumentCaptor<String> varArgs = ArgumentCaptor.forClass(String.class); QueryObservable query = Mockito.verify(db, Mockito.times(1)) .createQuery(Mockito.eq(emptySet), Mockito.eq(sql), varArgs.capture()); Assert.assertEquals(argsList, varArgs.getAllValues()); }
Example #8
Source File: DaoSqlBriteIntegrationTest.java From sqlbrite-dao with Apache License 2.0 | 6 votes |
@Test public void runRawStatementQueryWithTables() { BriteDatabase db = PowerMockito.mock(BriteDatabase.class); userDao.setSqlBriteDb(db); String arg1 = "arg1", arg2 = "arg2"; String table = "Table"; String sql = "SELECT * FROM " + table; List<String> argsList = Arrays.asList(arg1, arg2); Set<String> tables = Collections.singleton(table); userDao.rawQueryOnManyTables(tables, sql).args(arg1, arg2).run(); ArgumentCaptor<String> varArgs = ArgumentCaptor.forClass(String.class); QueryObservable query = Mockito.verify(db, Mockito.times(1)) .createQuery(Mockito.eq(tables), Mockito.eq(sql), varArgs.capture()); Assert.assertEquals(argsList, varArgs.getAllValues()); }
Example #9
Source File: DaoSqlBriteIntegrationTest.java From sqlbrite-dao with Apache License 2.0 | 6 votes |
@Test public void runRawStatementQueryNoTablesSpecified() { BriteDatabase db = PowerMockito.mock(BriteDatabase.class); userDao.setSqlBriteDb(db); String arg1 = "arg1", arg2 = "arg2"; String table = "Table"; String sql = "SELECT * FROM " + table; List<String> argsList = Arrays.asList(arg1, arg2); Set<String> emptySet = Collections.emptySet(); userDao.rawQuery(sql).args(arg1, arg2).run(); ArgumentCaptor<String> varArgs = ArgumentCaptor.forClass(String.class); QueryObservable query = Mockito.verify(db, Mockito.times(1)) .createQuery(Mockito.eq(emptySet), Mockito.eq(sql), varArgs.capture()); Assert.assertEquals(argsList, varArgs.getAllValues()); }
Example #10
Source File: DatabaseHelper.java From StatusSaver-for-Whatsapp with Apache License 2.0 | 5 votes |
public void additem(SampleModel item) { BriteDatabase.Transaction transaction = mDb.newTransaction(); try { long result = mDb.insert(Db.TheSampleTable.TABLE_NAME, Db.TheSampleTable.toContentValues(item)); if (result <0) Log.e(TAG, "addItem: Error inserting to table " + Db.TheSampleTable.TABLE_NAME); transaction.markSuccessful(); } finally { transaction.end(); } }
Example #11
Source File: ElifutDataStore.java From android with Apache License 2.0 | 5 votes |
public void create(List<? extends Persistable> persistables) { BriteDatabase.Transaction transaction = db.newTransaction(); try { for (Persistable persistable : persistables) { create(persistable); } transaction.markSuccessful(); } finally { transaction.end(); } }
Example #12
Source File: TodoActionCreator.java From TodoFluxArchitecture with Apache License 2.0 | 5 votes |
/** * 构造TodoActionCreator. * * @param actionDispatcher actionDispatcher * @param briteDatabase database */ @Inject public TodoActionCreator(@Named("actionDispatcher") Dispatcher actionDispatcher, BriteDatabase briteDatabase) { LogTool.debug("构造 TodoActionCreator"); this.actionDispatcher = actionDispatcher; this.database = briteDatabase; }
Example #13
Source File: StorageModule.java From TodoFluxArchitecture with Apache License 2.0 | 5 votes |
/** * 提供BriteDatabase注入. * * @return BriteDatabase */ @Provides BriteDatabase briteDatabase() { SqlBrite sqlBrite = SqlBrite.create(message -> LogTool.debug("Database", message)); SQLiteOpenHelper sqLiteOpenHelper = new DatabaseOpenHelper(application, userId); BriteDatabase db = sqlBrite.wrapDatabaseHelper(sqLiteOpenHelper); db.setLoggingEnabled(BuildConfig.DEBUG); return db; }
Example #14
Source File: SessionsDao.java From droidconat-2016 with Apache License 2.0 | 5 votes |
public void saveSessions(List<com.nilhcem.droidconat.data.app.model.Session> toSave) { Preconditions.checkNotOnMainThread(); BriteDatabase.Transaction transaction = database.newTransaction(); try { database.delete(Session.TABLE, null); for (com.nilhcem.droidconat.data.app.model.Session session : toSave) { database.insert(Session.TABLE, Session.createContentValues(dbMapper.fromAppSession(session))); } transaction.markSuccessful(); } finally { transaction.end(); } }
Example #15
Source File: SessionsDao.java From droidconat-2016 with Apache License 2.0 | 5 votes |
@Inject public SessionsDao(BriteDatabase database, DbMapper dbMapper, SpeakersDao speakersDao, LocalDateTimeAdapter adapter, SelectedSessionsMemory selectedSessionsMemory) { this.database = database; this.dbMapper = dbMapper; this.speakersDao = speakersDao; this.adapter = adapter; this.selectedSessionsMemory = selectedSessionsMemory; }
Example #16
Source File: SpeakersDao.java From droidconat-2016 with Apache License 2.0 | 5 votes |
public void saveSpeakers(List<com.nilhcem.droidconat.data.app.model.Speaker> toSave) { Preconditions.checkNotOnMainThread(); BriteDatabase.Transaction transaction = database.newTransaction(); try { database.delete(Speaker.TABLE, null); for (com.nilhcem.droidconat.data.app.model.Speaker speaker : toSave) { database.insert(Speaker.TABLE, Speaker.createContentValues(dbMapper.fromAppSpeaker(speaker))); } transaction.markSuccessful(); } finally { transaction.end(); } }
Example #17
Source File: ApplicationModule.java From FriendlyDemo with Apache License 2.0 | 4 votes |
@Provides @NonNull @Singleton public BriteDatabase provideDatabase(SqlBrite sqlBrite, Database helper) { return sqlBrite.wrapDatabaseHelper(helper, Schedulers.io()); }
Example #18
Source File: DatabaseModule.java From droidconat-2016 with Apache License 2.0 | 4 votes |
@Provides @Singleton BriteDatabase provideBriteDatabase(SqlBrite sqlBrite, SQLiteOpenHelper helper) { return sqlBrite.wrapDatabaseHelper(helper, Schedulers.immediate()); }
Example #19
Source File: DatabaseHelper.java From ribot-app-android with Apache License 2.0 | 4 votes |
public BriteDatabase getBriteDb() { return mDb; }
Example #20
Source File: SpeakersDao.java From droidconat-2016 with Apache License 2.0 | 4 votes |
@Inject public SpeakersDao(BriteDatabase database, DbMapper dbMapper, AppMapper appMapper) { this.database = database; this.dbMapper = dbMapper; this.appMapper = appMapper; }
Example #21
Source File: DatabaseHelper.java From StatusSaver-for-Whatsapp with Apache License 2.0 | 4 votes |
public BriteDatabase getBriteDb() { return mDb; }
Example #22
Source File: Dao.java From sqlbrite-dao with Apache License 2.0 | 2 votes |
/** * Set the {@link SQLiteOpenHelper}. This method will be called from the * {@link DaoManager} to inject the {@link SQLiteOpenHelper}. * <p> * You should not call this method directly. Let the {@link DaoManager} do * this, because it knows the right moment to invoke this method. * </p> * * @param db the database */ void setSqlBriteDb(BriteDatabase db) { this.db = db; }
Example #23
Source File: DaoManager.java From sqlbrite-dao with Apache License 2.0 | 2 votes |
/** * Get the underlying {@link BriteDatabase} instance * * @return The database */ public BriteDatabase getDatabase() { return db; }
Example #24
Source File: StorageComponent.java From TodoFluxArchitecture with Apache License 2.0 | 2 votes |
/** * 获得数据库. * * @return BriteDatabase */ BriteDatabase briteDatabase();