@Override public Void visitString(Property<String> property, T dst, ViewModel src) { Property<String> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
private void closeAndDeleteInternal(boolean deleteAfterClose) { clearPreparedStatementCache(); if (isOpen()) { onClose(database); database.close(); } setDatabase(null); if (deleteAfterClose) { getOpenHelper().deleteDatabase(); } helper = null; }
@Override public Object visitInteger(Property<Integer> property, SquidCursor<?> cursor) { int column = columnIndex(property, cursor); if (cursor.isNull(column)) { return null; } return cursor.getInt(column); }
private void ensureSqlCompiles(String sql) { acquireNonExclusiveLock(); try { getDatabase().ensureSqlCompiles(sql); } finally { releaseNonExclusiveLock(); } }
private void readFieldIntoModel(SquidCursor<?> cursor, com.yahoo.squidb.sql.Field<?> field) { try { if (field instanceof Property<?>) { Property<?> property = (Property<?>) field; saver.save(property, values, cursor.get(property)); } } catch (IllegalArgumentException e) { // underlying cursor may have changed, suppress } }
@Override public Void visitBoolean(Property<Boolean> property, ISQLitePreparedStatement preparedStatement, ModelAndIndex data) { Boolean val = data.model.get(property, false); if (val == null) { preparedStatement.bindNull(data.index); } else { preparedStatement.bindLong(data.index, val ? 1 : 0); } return null; }
@Override public Void visitDouble(Property<Double> property, ISQLitePreparedStatement preparedStatement, ModelAndIndex data) { Double val = data.model.get(property, false); if (val == null) { preparedStatement.bindNull(data.index); } else { preparedStatement.bindDouble(data.index, val); } return null; }
@Override public Void visitString(Property<String> property, ISQLitePreparedStatement preparedStatement, ModelAndIndex data) { String val = data.model.get(property, false); if (val == null) { preparedStatement.bindNull(data.index); } else { preparedStatement.bindString(data.index, val); } return null; }
@Override public Void visitBlob(Property<byte[]> property, ISQLitePreparedStatement preparedStatement, ModelAndIndex data) { byte[] val = data.model.get(property, false); if (val == null) { preparedStatement.bindNull(data.index); } else { preparedStatement.bindBlob(data.index, val); } return null; } }
private void setDatabase(ISQLiteDatabase db) { synchronized (databaseInstanceLock) { // If we're already holding a reference to the same object, don't need to update or recalculate the version if (database != null && db != null && db.getWrappedObject() == database.getWrappedObject()) { return; } sqliteVersion = db != null ? readSqliteVersionLocked(db) : null; database = db; } }
/** * Copies values from the given Map. The values will be added to the model as read values (i.e. will not be * considered set values or mark the model as dirty). */ public void readPropertiesFromMap(Map<String, Object> values, Property<?>... properties) { if (values == null) { return; } readPropertiesFromValuesStorage(new MapValuesStorage(values), properties); }
/** * Analogous to {@link #readPropertiesFromMap(Map, Property[])} but adds the values to the model as set values, * i.e. marks the model as dirty with these values. */ public void setPropertiesFromMap(Map<String, Object> values, Property<?>... properties) { if (values == null) { return; } setPropertiesFromValuesStorage(new MapValuesStorage(values), properties); }
/** * @return the path to the underlying database file. */ public String getDatabasePath() { return getOpenHelper().getDatabasePath(); }
@Override public Void visitInteger(Property<Integer> property, T dst, ViewModel src) { Property<Integer> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Object visitBoolean(Property<Boolean> property, SquidCursor<?> cursor) { int column = columnIndex(property, cursor); if (cursor.isNull(column)) { return null; } int value = cursor.getInt(column); return value != 0; }
@Override public Void visitInteger(Property<Integer> property, ISQLitePreparedStatement preparedStatement, ModelAndIndex data) { Integer val = data.model.get(property, false); if (val == null) { preparedStatement.bindNull(data.index); } else { preparedStatement.bindLong(data.index, val); } return null; }
@Override public Void visitLong(Property<Long> property, T dst, ViewModel src) { Property<Long> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitDouble(Property<Double> property, T dst, ViewModel src) { Property<Double> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitBoolean(Property<Boolean> property, T dst, ViewModel src) { Property<Boolean> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitBlob(Property<byte[]> property, T dst, ViewModel src) { Property<byte[]> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }