use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method defaultSchedulerReturnsNullIfSpecifiedSchedulerNull.
@Test
public void defaultSchedulerReturnsNullIfSpecifiedSchedulerNull() {
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).defaultRxScheduler(null).build();
assertThat(storIOSQLite.defaultRxScheduler()).isNull();
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method getTypeMappingFinder.
@Nullable
private static TypeMappingFinder getTypeMappingFinder(@NonNull DefaultStorIOSQLite storIOSQLite) throws NoSuchFieldException, IllegalAccessException {
Field field = DefaultStorIOSQLite.LowLevelImpl.class.getDeclaredField("typeMappingFinder");
field.setAccessible(true);
return (TypeMappingFinder) field.get(storIOSQLite.lowLevel());
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultPutResolver method performPut.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public PutResult performPut(@NonNull StorIOSQLite storIOSQLite, @NonNull T object) {
final UpdateQuery updateQuery = mapToUpdateQuery(object);
final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
// for data consistency in concurrent environment, encapsulate Put Operation into transaction
lowLevel.beginTransaction();
try {
final Cursor cursor = lowLevel.query(Query.builder().table(updateQuery.table()).where(nullableString(updateQuery.where())).whereArgs((Object[]) nullableArrayOfStringsFromListOfStrings(updateQuery.whereArgs())).build());
final PutResult putResult;
try {
final ContentValues contentValues = mapToContentValues(object);
if (cursor.getCount() == 0) {
final InsertQuery insertQuery = mapToInsertQuery(object);
final long insertedId = lowLevel.insert(insertQuery, contentValues);
putResult = PutResult.newInsertResult(insertedId, insertQuery.table(), insertQuery.affectsTags());
} else {
final int numberOfRowsUpdated = lowLevel.update(updateQuery, contentValues);
putResult = PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table(), updateQuery.affectsTags());
}
} finally {
cursor.close();
}
// everything okay
lowLevel.setTransactionSuccessful();
return putResult;
} finally {
// in case of bad situations, db won't be affected
lowLevel.endTransaction();
}
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultDeleteResolver method performDelete.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public DeleteResult performDelete(@NonNull StorIOSQLite storIOSQLite, @NonNull T object) {
final DeleteQuery deleteQuery = mapToDeleteQuery(object);
final int numberOfRowsDeleted = storIOSQLite.lowLevel().delete(deleteQuery);
return DeleteResult.newInstance(numberOfRowsDeleted, deleteQuery.table(), deleteQuery.affectsTags());
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class TweetsSQLiteFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final FragmentActivity activity = getActivity();
SampleApp.get(activity).appComponent().inject(this);
tweetsAdapter = new TweetsAdapter(LayoutInflater.from(activity), this);
new Relations(storIOSQLite).getTweetWithUser();
}
Aggregations