@SuppressWarnings("unchecked") public AbstractDao(DaoConfig config, AbstractDaoSession daoSession) { this.config = config; this.session = daoSession; db = config.db; isStandardSQLite = db.getRawDatabase() instanceof SQLiteDatabase; identityScope = (IdentityScope<K, T>) config.getIdentityScope(); if (identityScope instanceof IdentityScopeLong) { identityScopeLong = (IdentityScopeLong<T>) identityScope; } else { identityScopeLong = null; } statements = config.statements; pkOrdinal = config.pkProperty != null ? config.pkProperty.ordinal : -1; }
/** * If using Android's embedded SQLite, this enables localized ordering of strings * (see {@link #orderAsc(Property...)} and {@link #orderDesc(Property...)}). This uses "COLLATE LOCALIZED", which * is unavailable in SQLCipher (in that case, the ordering is unchanged). * * @see #stringOrderCollation */ public QueryBuilder<T> preferLocalizedStringOrder() { // SQLCipher 3.5.0+ does not understand "COLLATE LOCALIZED" if (dao.getDatabase().getRawDatabase() instanceof SQLiteDatabase) { stringOrderCollation = " COLLATE LOCALIZED"; } return this; }
@Test public void testMockitoMocks() { mock(DaoMaster.class).newSession(); mock(DaoSession.class).getDatabase(); mock(Database.class).getRawDatabase(); mock(DatabaseStatement.class).execute(); mock(IdentityScope.class).clear(); mock(AbstractDao.class).queryBuilder(); mock(MinimalEntityDao.class).queryBuilder(); mock(MinimalEntity.class).getId(); mock(Query.class).forCurrentThread(); mock(QueryBuilder.class).build(); mock(CountQuery.class).forCurrentThread(); mock(DeleteQuery.class).forCurrentThread(); mock(Join.class).getTablePrefix(); mock(LazyList.class).getLoadedCount(); mock(WhereCondition.class).appendValuesTo(null); mock(Property.class).isNull(); mock(DaoException.class).getMessage(); }
public void testConcurrentLockAndQueryDuringTxWAL() throws InterruptedException { if (Build.VERSION.SDK_INT >= 16) { try { Object rawDatabase = db.getRawDatabase(); Method method = rawDatabase.getClass().getMethod("isWriteAheadLoggingEnabled"); boolean walEnabled = (Boolean) method.invoke(rawDatabase);
/** * If using Android's embedded SQLite, this enables localized ordering of strings * (see {@link #orderAsc(Property...)} and {@link #orderDesc(Property...)}). This uses "COLLATE LOCALIZED", which * is unavailable in SQLCipher (in that case, the ordering is unchanged). * * @see #stringOrderCollation */ public QueryBuilder<T> preferLocalizedStringOrder() { // SQLCipher 3.5.0+ does not understand "COLLATE LOCALIZED" if (dao.getDatabase().getRawDatabase() instanceof SQLiteDatabase) { stringOrderCollation = " COLLATE LOCALIZED"; } return this; }
/** * Customizes the ordering of strings used by {@link #orderAsc(Property...)} and {@link #orderDesc(Property...)}. * Default is "COLLATE NOCASE". * * @see #preferLocalizedStringOrder */ public QueryBuilder<T> stringOrderCollation(String stringOrderCollation) { // SQLCipher 3.5.0+ does not understand "COLLATE LOCALIZED" if (dao.getDatabase().getRawDatabase() instanceof SQLiteDatabase) { this.stringOrderCollation = stringOrderCollation == null || stringOrderCollation.startsWith(" ") ? stringOrderCollation : " " + stringOrderCollation; } return this; }
@SuppressWarnings("unchecked") public AbstractDao(DaoConfig config, AbstractDaoSession daoSession) { this.config = config; this.session = daoSession; db = config.db; isStandardSQLite = db.getRawDatabase() instanceof SQLiteDatabase; identityScope = (IdentityScope<K, T>) config.getIdentityScope(); if (identityScope instanceof IdentityScopeLong) { identityScopeLong = (IdentityScopeLong<T>) identityScope; } else { identityScopeLong = null; } statements = config.statements; pkOrdinal = config.pkProperty != null ? config.pkProperty.ordinal : -1; }
public ArticlesChangedEvent update(UpdateType updateType, long latestUpdatedItemTimestamp, UpdateListener updateListener) throws UnsuccessfulResponseException, IOException { boolean clean = updateType != UpdateType.FAST; Log.i(TAG, "update() started; clean: " + clean); ArticlesChangedEvent event = new ArticlesChangedEvent(); SQLiteDatabase sqliteDatabase = (SQLiteDatabase)daoSession.getDatabase().getRawDatabase(); sqliteDatabase.beginTransactionNonExclusive(); try { if(clean) { Log.d(TAG, "update() deleting old DB entries"); daoSession.getArticleTagsJoinDao().deleteAll(); daoSession.getArticleDao().deleteAll(); daoSession.getTagDao().deleteAll(); event.invalidateAll(ChangeType.DELETED); } Log.v(TAG, "update() latestUpdatedItemTimestamp: " + latestUpdatedItemTimestamp); Log.d(TAG, "update() updating articles"); latestUpdatedItemTimestamp = performUpdate( event, clean, latestUpdatedItemTimestamp, updateListener); Log.d(TAG, "update() articles updated"); Log.v(TAG, "update() latestUpdatedItemTimestamp: " + latestUpdatedItemTimestamp); sqliteDatabase.setTransactionSuccessful(); } finally { sqliteDatabase.endTransaction(); } if(updateListener != null) updateListener.onSuccess(latestUpdatedItemTimestamp); Log.i(TAG, "update() finished"); return event; }
public static DaoSession getSession() { if(Holder.session == null) { // enable some debugging if(BuildConfig.DEBUG) { QueryBuilder.LOG_SQL = true; QueryBuilder.LOG_VALUES = true; } String dbPath = new Settings(context).getDbPathForDbHelper(); Log.d(TAG, "creating new db session"); WallabagOpenHelper dbHelper = new WallabagOpenHelper(context, dbPath, null); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { dbHelper.setWriteAheadLoggingEnabled(true); } Database db = dbHelper.getWritableDb(); if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { if(!((SQLiteDatabase)db.getRawDatabase()).enableWriteAheadLogging()) { Log.w(TAG, "write ahead logging was not enabled"); } } DaoMaster daoMaster = new DaoMaster(db); Holder.session = daoMaster.newSession(); } else { Log.d(TAG, "using existing db session"); } return Holder.session; }
SQLiteDatabase sqliteDatabase = (SQLiteDatabase)daoSession.getDatabase().getRawDatabase(); sqliteDatabase.beginTransactionNonExclusive(); try {
SQLiteDatabase sqliteDatabase = (SQLiteDatabase)daoSession.getDatabase().getRawDatabase(); sqliteDatabase.beginTransactionNonExclusive(); try {