public static void execSQL(String sql, Object[] bindArgs) { Cache.openDatabase().execSQL(sql, bindArgs); } }
public final void delete() { Cache.openDatabase().delete(mTableInfo.getTableName(), idName+"=?", new String[] { getId().toString() }); Cache.removeEntity(this); Cache.getContext().getContentResolver() .notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null); }
public Model() { mTableInfo = Cache.getTableInfo(getClass()); idName = mTableInfo.getIdName(); }
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { final Class<? extends Model> type = getModelType(uri); final int count = Cache.openDatabase().update(Cache.getTableName(type), values, selection, selectionArgs); notifyChange(uri); return count; }
public final Long save() { final SQLiteDatabase db = Cache.openDatabase(); final ContentValues values = new ContentValues(); final TypeSerializer typeSerializer = Cache.getParserForType(fieldType); if (typeSerializer != null) { Cache.getContext().getContentResolver() .notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null); return mId;
protected void mockActiveAndroidContext() { PowerMockito.mockStatic(Cache.class); PowerMockito.mockStatic(ContentProvider.class); TableInfo tableInfo = PowerMockito.mock(TableInfo.class); Context context = PowerMockito.mock(Context.class); ContentResolver resolver = PowerMockito.mock(ContentResolver.class); SQLiteDatabase sqliteDb = PowerMockito.mock(SQLiteDatabase.class); ContentValues vals = PowerMockito.mock(ContentValues.class); try { PowerMockito.whenNew(ContentValues.class).withNoArguments().thenReturn(vals); } catch (Exception e) { e.printStackTrace(); } when(Cache.openDatabase()).thenReturn(sqliteDb); when(context.getContentResolver()).thenReturn(resolver); doNothing().when(resolver).notifyChange(any(Uri.class), any(ContentObserver.class)); when(tableInfo.getFields()).thenReturn(new ArrayList<>()); when(tableInfo.getTableName()).thenReturn("TestTable"); when(Cache.getTableInfo(any(Class.class))).thenReturn(tableInfo); when(Cache.getContext()).thenReturn(context); when(ContentProvider.createUri(anyObject(), anyLong())).thenReturn(null); }
TypeSerializer typeSerializer = Cache.getParserForType(fieldType); Object value = null; final Class<? extends Model> entityType = (Class<? extends Model>) fieldType; Model entity = Cache.getEntity(entityType, entityId); if (entity == null) { entity = new Select().from(entityType).where(idName+"=?", entityId).executeSingle(); Cache.addEntity(this);
private void executeSqlScript(SQLiteDatabase db, String file) { InputStream stream = null; try { stream = Cache.getContext().getAssets().open(MIGRATION_PATH + "/" + file); if (Configuration.SQL_PARSER_DELIMITED.equalsIgnoreCase(mSqlParser)) { executeDelimitedSqlScript(db, stream); } else { executeLegacySqlScript(db, stream); } } catch (IOException e) { Log.e("Failed to execute " + file, e); } finally { IOUtils.closeQuietly(stream); } }
@SuppressWarnings("unchecked") public static <T extends Model> List<T> processCursor(Class<? extends Model> type, Cursor cursor) { TableInfo tableInfo = Cache.getTableInfo(type); String idName = tableInfo.getIdName(); final List<T> entities = new ArrayList<T>(); Model entity = Cache.getEntity(type, cursor.getLong(columnsOrdered.indexOf(idName))); if (entity == null) { entity = (T) entityConstructor.newInstance();
final TypeSerializer typeSerializer = Cache.getParserForType(field.getType()); final Column column = field.getAnnotation(Column.class); definition.append(Cache.getTableInfo((Class<? extends Model>) type).getTableName()); definition.append("("+tableInfo.getIdName()+")"); definition.append(" ON DELETE ");
public static String getIdentifier(Model entity) { return getIdentifier(entity.getClass(), entity.getId()); }
public static synchronized void dispose() { closeDatabase(); sEntities = null; sModelInfo = null; sDatabaseHelper = null; sIsInitialized = false; Log.v("ActiveAndroid disposed. Call initialize to use library."); }
public static void dispose() { Cache.dispose(); }
public static void clearCache() { Cache.clear(); }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { final Class<? extends Model> type = getModelType(uri); final int count = Cache.openDatabase().delete(Cache.getTableName(type), selection, selectionArgs); notifyChange(uri); return count; }
final SQLiteDatabase db = Cache.openDatabase(); final ContentValues values = new ContentValues(); final TypeSerializer typeSerializer = Cache.getParserForType(fieldType); if (typeSerializer != null) { Cache.getContext().getContentResolver() .notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null); return mId;
TypeSerializer typeSerializer = Cache.getParserForType(fieldType); Object value = null; final Class<? extends Model> entityType = (Class<? extends Model>) fieldType; Model entity = Cache.getEntity(entityType, entityId); if (entity == null) { entity = new Select().from(entityType).where(idName+"=?", entityId).executeSingle(); Cache.addEntity(this);
private void executeSqlScript(SQLiteDatabase db, String file) { InputStream stream = null; try { stream = Cache.getContext().getAssets().open(MIGRATION_PATH + "/" + file); if (Configuration.SQL_PARSER_DELIMITED.equalsIgnoreCase(mSqlParser)) { executeDelimitedSqlScript(db, stream); } else { executeLegacySqlScript(db, stream); } } catch (IOException e) { Log.e("Failed to execute " + file, e); } finally { IOUtils.closeQuietly(stream); } }
@SuppressWarnings("unchecked") public static <T extends Model> List<T> processCursor(Class<? extends Model> type, Cursor cursor) { TableInfo tableInfo = Cache.getTableInfo(type); String idName = tableInfo.getIdName(); final List<T> entities = new ArrayList<T>(); Model entity = Cache.getEntity(type, cursor.getLong(columnsOrdered.indexOf(idName))); if (entity == null) { entity = (T) entityConstructor.newInstance();
final TypeSerializer typeSerializer = Cache.getParserForType(field.getType()); final Column column = field.getAnnotation(Column.class); definition.append(Cache.getTableInfo((Class<? extends Model>) type).getTableName()); definition.append("("+tableInfo.getIdName()+")"); definition.append(" ON DELETE ");