Permalink
Please sign in to comment.
Showing
with
873 additions
and 51 deletions.
- +1 −2 README.md
- +2 −15 build.gradle
- +1 −1 checkstyle/checkstyle.xml
- +0 −1 docs/StorIOSQLite.md
- +4 −0 storio-content-resolver/build.gradle
- +69 −9 ...ver/src/main/java/com/pushtorefresh/storio/contentresolver/impl/DefaultStorIOContentResolver.java
- +1 −0 ...io-content-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/DeleteQuery.java
- +1 −0 ...io-content-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/InsertQuery.java
- +1 −0 storio-content-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/Query.java
- +1 −0 ...io-content-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/UpdateQuery.java
- +223 −0 ...src/test/java/com/pushtorefresh/storio/contentresolver/impl/DefaultStorIOContentResolverTest.java
- +1 −1 ...ontent-resolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/DeleteQueryTest.java
- +1 −1 ...ontent-resolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/InsertQueryTest.java
- +1 −1 storio-content-resolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/QueryTest.java
- +1 −1 ...ontent-resolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/UpdateQueryTest.java
- +3 −0 storio-sqlite/build.gradle
- +4 −0 storio-sqlite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/UserTableMeta.java
- +160 −0 ...-sqlite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/AutoParcelTest.java
- +38 −0 storio-sqlite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/Book.java
- +99 −0 ...o-sqlite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/BookTableMeta.java
- +23 −0 storio-sqlite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/OpenHelper.java
- +71 −9 storio-sqlite/src/main/java/com/pushtorefresh/storio/sqlite/impl/DefaultStorIOSQLite.java
- +167 −10 storio-sqlite/src/test/java/com/pushtorefresh/storio/sqlite/impl/DefaultStorIOSQLiteTest.java
3
README.md
17
build.gradle
2
checkstyle/checkstyle.xml
1
docs/StorIOSQLite.md
4
storio-content-resolver/build.gradle
78
...main/java/com/pushtorefresh/storio/contentresolver/impl/DefaultStorIOContentResolver.java
1
...nt-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/DeleteQuery.java
1
...nt-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/InsertQuery.java
1
...-content-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/Query.java
1
...nt-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/query/UpdateQuery.java
223
.../java/com/pushtorefresh/storio/contentresolver/impl/DefaultStorIOContentResolverTest.java
@@ -0,0 +1,223 @@ | ||
+package com.pushtorefresh.storio.contentresolver.impl; | ||
+ | ||
+import android.content.ContentResolver; | ||
+ | ||
+import com.pushtorefresh.storio.contentresolver.ContentResolverTypeMapping; | ||
+import com.pushtorefresh.storio.contentresolver.StorIOContentResolver; | ||
+import com.pushtorefresh.storio.contentresolver.operation.delete.DeleteResolver; | ||
+import com.pushtorefresh.storio.contentresolver.operation.get.GetResolver; | ||
+import com.pushtorefresh.storio.contentresolver.operation.put.PutResolver; | ||
+ | ||
+import org.junit.Test; | ||
+ | ||
+import static org.junit.Assert.assertNull; | ||
+import static org.junit.Assert.assertSame; | ||
+import static org.mockito.Mockito.mock; | ||
+ | ||
+public class DefaultStorIOContentResolverTest { | ||
+ | ||
+ @SuppressWarnings("ConstantConditions") | ||
+ @Test(expected = NullPointerException.class) | ||
+ public void nullContentResolver() { | ||
+ new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(null); | ||
+ } | ||
+ | ||
+ @SuppressWarnings({"unchecked", "ConstantConditions"}) | ||
+ @Test(expected = NullPointerException.class) | ||
+ public void addTypeMappingNullType() { | ||
+ new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .addTypeMapping(null, new ContentResolverTypeMapping.Builder<Object>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build()); | ||
+ } | ||
+ | ||
+ @SuppressWarnings("ConstantConditions") | ||
+ @Test(expected = NullPointerException.class) | ||
+ public void addTypeMappingNullMapping() { | ||
+ new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .addTypeMapping(Object.class, null); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public void shouldReturnNullIfNoTypeMappingsRegistered() { | ||
+ class TestItem { | ||
+ | ||
+ } | ||
+ | ||
+ final StorIOContentResolver storIOContentResolver = new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .build(); | ||
+ | ||
+ assertNull(storIOContentResolver.internal().typeMapping(TestItem.class)); | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Test | ||
+ public void shouldReturnNullIfNotTypeMappingRegisteredForType() { | ||
+ class TestItem { | ||
+ | ||
+ } | ||
+ | ||
+ class Entity { | ||
+ | ||
+ } | ||
+ | ||
+ final ContentResolverTypeMapping<Entity> entityContentResolverTypeMapping = new ContentResolverTypeMapping.Builder<Entity>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build(); | ||
+ | ||
+ final StorIOContentResolver storIOContentResolver = new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .addTypeMapping(Entity.class, entityContentResolverTypeMapping) | ||
+ .build(); | ||
+ | ||
+ assertSame(entityContentResolverTypeMapping, storIOContentResolver.internal().typeMapping(Entity.class)); | ||
+ | ||
+ assertNull(storIOContentResolver.internal().typeMapping(TestItem.class)); | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Test | ||
+ public void directTypeMappingShouldWork() { | ||
+ class TestItem { | ||
+ | ||
+ } | ||
+ | ||
+ final ContentResolverTypeMapping<TestItem> typeMapping = new ContentResolverTypeMapping.Builder<TestItem>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build(); | ||
+ | ||
+ final StorIOContentResolver storIOContentResolver = new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .addTypeMapping(TestItem.class, typeMapping) | ||
+ .build(); | ||
+ | ||
+ assertSame(typeMapping, storIOContentResolver.internal().typeMapping(TestItem.class)); | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Test | ||
+ public void indirectTypeMappingShouldWork() { | ||
+ class TestItem { | ||
+ | ||
+ } | ||
+ | ||
+ final ContentResolverTypeMapping<TestItem> typeMapping = new ContentResolverTypeMapping.Builder<TestItem>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build(); | ||
+ | ||
+ final StorIOContentResolver storIOContentResolver = new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .addTypeMapping(TestItem.class, typeMapping) | ||
+ .build(); | ||
+ | ||
+ class TestItemSubclass extends TestItem { | ||
+ | ||
+ } | ||
+ | ||
+ // Direct type mapping should still work | ||
+ assertSame(typeMapping, storIOContentResolver.internal().typeMapping(TestItem.class)); | ||
+ | ||
+ // Indirect type mapping should give same type mapping as for parent class | ||
+ assertSame(typeMapping, storIOContentResolver.internal().typeMapping(TestItemSubclass.class)); | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Test | ||
+ public void typeMappingShouldWorkInCaseOfMoreConcreteTypeMapping() { | ||
+ class TestItem { | ||
+ | ||
+ } | ||
+ | ||
+ final ContentResolverTypeMapping<TestItem> typeMapping = new ContentResolverTypeMapping.Builder<TestItem>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build(); | ||
+ | ||
+ class TestItemSubclass extends TestItem { | ||
+ | ||
+ } | ||
+ | ||
+ final ContentResolverTypeMapping<TestItemSubclass> subclassTypeMapping = new ContentResolverTypeMapping.Builder<TestItemSubclass>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build(); | ||
+ | ||
+ final StorIOContentResolver storIOContentResolver = new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .addTypeMapping(TestItem.class, typeMapping) | ||
+ .addTypeMapping(TestItemSubclass.class, subclassTypeMapping) | ||
+ .build(); | ||
+ | ||
+ // Parent class should have its own type mapping | ||
+ assertSame(typeMapping, storIOContentResolver.internal().typeMapping(TestItem.class)); | ||
+ | ||
+ // Child class should have its own type mapping | ||
+ assertSame(subclassTypeMapping, storIOContentResolver.internal().typeMapping(TestItemSubclass.class)); | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Test | ||
+ public void typeMappingShouldFindIndirectTypeMappingInCaseOfComplexInheritance() { | ||
+ // Good test case — inheritance with AutoValue/AutoParcel | ||
+ | ||
+ class Entity { | ||
+ | ||
+ } | ||
+ | ||
+ class AutoValue_Entity extends Entity { | ||
+ | ||
+ } | ||
+ | ||
+ class ConcreteEntity extends Entity { | ||
+ | ||
+ } | ||
+ | ||
+ class AutoValue_ConcreteEntity extends ConcreteEntity { | ||
+ | ||
+ } | ||
+ | ||
+ final ContentResolverTypeMapping<Entity> entitySQLiteTypeMapping = new ContentResolverTypeMapping.Builder<Entity>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build(); | ||
+ | ||
+ final ContentResolverTypeMapping<ConcreteEntity> concreteEntitySQLiteTypeMapping = new ContentResolverTypeMapping.Builder<ConcreteEntity>() | ||
+ .putResolver(mock(PutResolver.class)) | ||
+ .getResolver(mock(GetResolver.class)) | ||
+ .deleteResolver(mock(DeleteResolver.class)) | ||
+ .build(); | ||
+ | ||
+ final StorIOContentResolver storIOContentResolver = new DefaultStorIOContentResolver.Builder() | ||
+ .contentResolver(mock(ContentResolver.class)) | ||
+ .addTypeMapping(Entity.class, entitySQLiteTypeMapping) | ||
+ .addTypeMapping(ConcreteEntity.class, concreteEntitySQLiteTypeMapping) | ||
+ .build(); | ||
+ | ||
+ // Direct type mapping for Entity should work | ||
+ assertSame(entitySQLiteTypeMapping, storIOContentResolver.internal().typeMapping(Entity.class)); | ||
+ | ||
+ // Direct type mapping for ConcreteEntity should work | ||
+ assertSame(concreteEntitySQLiteTypeMapping, storIOContentResolver.internal().typeMapping(ConcreteEntity.class)); | ||
+ | ||
+ // Indirect type mapping for AutoValue_Entity should get type mapping for Entity | ||
+ assertSame(entitySQLiteTypeMapping, storIOContentResolver.internal().typeMapping(AutoValue_Entity.class)); | ||
+ | ||
+ // Indirect type mapping for AutoValue_ConcreteEntity should get type mapping for ConcreteEntity, not for Entity! | ||
+ assertSame(concreteEntitySQLiteTypeMapping, storIOContentResolver.internal().typeMapping(AutoValue_ConcreteEntity.class)); | ||
+ } | ||
+} |
2
...esolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/DeleteQueryTest.java
2
...esolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/InsertQueryTest.java
2
...tent-resolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/QueryTest.java
2
...esolver/src/test/java/com/pushtorefresh/storio/contentresolver/query/UpdateQueryTest.java
3
storio-sqlite/build.gradle
4
storio-sqlite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/UserTableMeta.java
160
...src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/AutoParcelTest.java
@@ -0,0 +1,160 @@ | ||
+package com.pushtorefresh.storio.sqlite.impl.auto_parcel; | ||
+ | ||
+import android.support.annotation.NonNull; | ||
+import android.support.test.InstrumentationRegistry; | ||
+import android.support.test.runner.AndroidJUnit4; | ||
+ | ||
+import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping; | ||
+import com.pushtorefresh.storio.sqlite.StorIOSQLite; | ||
+import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite; | ||
+import com.pushtorefresh.storio.sqlite.operation.delete.DeleteResult; | ||
+import com.pushtorefresh.storio.sqlite.operation.put.PutResult; | ||
+import com.pushtorefresh.storio.sqlite.query.DeleteQuery; | ||
+import com.pushtorefresh.storio.sqlite.query.Query; | ||
+ | ||
+import org.junit.Before; | ||
+import org.junit.Test; | ||
+import org.junit.runner.RunWith; | ||
+ | ||
+import java.util.List; | ||
+ | ||
+import static org.junit.Assert.assertEquals; | ||
+import static org.junit.Assert.assertTrue; | ||
+ | ||
+@RunWith(AndroidJUnit4.class) | ||
+public class AutoParcelTest { | ||
+ | ||
+ @NonNull // Initialized in @Before | ||
+ private StorIOSQLite storIOSQLite; | ||
+ | ||
+ @Before | ||
+ public void setUp() { | ||
+ storIOSQLite = new DefaultStorIOSQLite.Builder() | ||
+ .sqliteOpenHelper(new OpenHelper(InstrumentationRegistry.getContext())) | ||
+ .addTypeMapping(Book.class, new SQLiteTypeMapping.Builder<Book>() | ||
+ .putResolver(BookTableMeta.PUT_RESOLVER) | ||
+ .getResolver(BookTableMeta.GET_RESOLVER) | ||
+ .deleteResolver(BookTableMeta.DELETE_RESOLVER) | ||
+ .build()) | ||
+ .build(); | ||
+ | ||
+ // Clearing books table before each test case | ||
+ storIOSQLite | ||
+ .delete() | ||
+ .byQuery(new DeleteQuery.Builder() | ||
+ .table(BookTableMeta.TABLE) | ||
+ .build()) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public void insertObject() { | ||
+ final Book book = Book.builder() | ||
+ .id(1) | ||
+ .title("What a great book") | ||
+ .author("Somebody") | ||
+ .build(); | ||
+ | ||
+ final PutResult putResult = storIOSQLite | ||
+ .put() | ||
+ .object(book) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertTrue(putResult.wasInserted()); | ||
+ | ||
+ final List<Book> storedBooks = storIOSQLite | ||
+ .get() | ||
+ .listOfObjects(Book.class) | ||
+ .withQuery(new Query.Builder() | ||
+ .table(BookTableMeta.TABLE) | ||
+ .build()) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertEquals(1, storedBooks.size()); | ||
+ | ||
+ assertEquals(book, storedBooks.get(0)); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public void updateObject() { | ||
+ final Book book = Book.builder() | ||
+ .id(1) | ||
+ .title("What a great book") | ||
+ .author("Somebody") | ||
+ .build(); | ||
+ | ||
+ final PutResult putResult1 = storIOSQLite | ||
+ .put() | ||
+ .object(book) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertTrue(putResult1.wasInserted()); | ||
+ | ||
+ final Book bookWithUpdatedInfo = Book.builder() | ||
+ .id(1) // Same id, should be updated | ||
+ .title("Corrected title") | ||
+ .author("Corrected author") | ||
+ .build(); | ||
+ | ||
+ final PutResult putResult2 = storIOSQLite | ||
+ .put() | ||
+ .object(bookWithUpdatedInfo) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertTrue(putResult2.wasUpdated()); | ||
+ | ||
+ final List<Book> storedBooks = storIOSQLite | ||
+ .get() | ||
+ .listOfObjects(Book.class) | ||
+ .withQuery(new Query.Builder() | ||
+ .table(BookTableMeta.TABLE) | ||
+ .build()) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertEquals(1, storedBooks.size()); | ||
+ | ||
+ assertEquals(bookWithUpdatedInfo, storedBooks.get(0)); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public void deleteObject() { | ||
+ final Book book = Book.builder() | ||
+ .id(1) | ||
+ .title("What a great book") | ||
+ .author("Somebody") | ||
+ .build(); | ||
+ | ||
+ final PutResult putResult = storIOSQLite | ||
+ .put() | ||
+ .object(book) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertTrue(putResult.wasInserted()); | ||
+ | ||
+ final DeleteResult deleteResult = storIOSQLite | ||
+ .delete() | ||
+ .object(book) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertEquals(1, deleteResult.numberOfRowsDeleted()); | ||
+ | ||
+ final List<Book> storedBooks = storIOSQLite | ||
+ .get() | ||
+ .listOfObjects(Book.class) | ||
+ .withQuery(new Query.Builder() | ||
+ .table(BookTableMeta.TABLE) | ||
+ .build()) | ||
+ .prepare() | ||
+ .executeAsBlocking(); | ||
+ | ||
+ assertEquals(0, storedBooks.size()); | ||
+ } | ||
+} |
38
...io-sqlite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/Book.java
@@ -0,0 +1,38 @@ | ||
+package com.pushtorefresh.storio.sqlite.impl.auto_parcel; | ||
+ | ||
+import android.support.annotation.NonNull; | ||
+ | ||
+import auto.parcel.AutoParcel; | ||
+ | ||
+@AutoParcel | ||
+abstract class Book { | ||
+ | ||
+ abstract int id(); | ||
+ | ||
+ @NonNull | ||
+ abstract String title(); | ||
+ | ||
+ @NonNull | ||
+ abstract String author(); | ||
+ | ||
+ @NonNull | ||
+ static Builder builder() { | ||
+ return new AutoParcel_Book.Builder(); | ||
+ } | ||
+ | ||
+ @AutoParcel.Builder | ||
+ abstract static class Builder { | ||
+ | ||
+ @NonNull | ||
+ abstract Builder id(int id); | ||
+ | ||
+ @NonNull | ||
+ abstract Builder title(@NonNull String title); | ||
+ | ||
+ @NonNull | ||
+ abstract Builder author(@NonNull String author); | ||
+ | ||
+ @NonNull | ||
+ abstract Book build(); | ||
+ } | ||
+} |
99
.../src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/BookTableMeta.java
@@ -0,0 +1,99 @@ | ||
+package com.pushtorefresh.storio.sqlite.impl.auto_parcel; | ||
+ | ||
+import android.content.ContentValues; | ||
+import android.database.Cursor; | ||
+import android.support.annotation.NonNull; | ||
+ | ||
+import com.pushtorefresh.storio.sqlite.operation.delete.DefaultDeleteResolver; | ||
+import com.pushtorefresh.storio.sqlite.operation.delete.DeleteResolver; | ||
+import com.pushtorefresh.storio.sqlite.operation.get.DefaultGetResolver; | ||
+import com.pushtorefresh.storio.sqlite.operation.get.GetResolver; | ||
+import com.pushtorefresh.storio.sqlite.operation.put.DefaultPutResolver; | ||
+import com.pushtorefresh.storio.sqlite.operation.put.PutResolver; | ||
+import com.pushtorefresh.storio.sqlite.query.DeleteQuery; | ||
+import com.pushtorefresh.storio.sqlite.query.InsertQuery; | ||
+import com.pushtorefresh.storio.sqlite.query.UpdateQuery; | ||
+ | ||
+final class BookTableMeta { | ||
+ | ||
+ private BookTableMeta() { | ||
+ throw new IllegalStateException("No instances please."); | ||
+ } | ||
+ | ||
+ @NonNull | ||
+ static final String TABLE = "books"; | ||
+ | ||
+ @NonNull | ||
+ static final String COLUMN_ID = "_id"; | ||
+ | ||
+ @NonNull | ||
+ static final String COLUMN_TITLE = "title"; | ||
+ | ||
+ @NonNull | ||
+ static final String COLUMN_AUTHOR = "author"; | ||
+ | ||
+ @NonNull | ||
+ static final String SQL_CREATE_TABLE = "CREATE TABLE " + TABLE + "(" + | ||
+ COLUMN_ID + " INTEGER PRIMARY KEY, " + | ||
+ COLUMN_TITLE + " TEXT NOT NULL," + | ||
+ COLUMN_AUTHOR + " TEXT NOT NULL);"; | ||
+ | ||
+ @NonNull | ||
+ static final PutResolver<Book> PUT_RESOLVER = new DefaultPutResolver<Book>() { | ||
+ @NonNull | ||
+ @Override | ||
+ protected InsertQuery mapToInsertQuery(@NonNull Book object) { | ||
+ return new InsertQuery.Builder() | ||
+ .table(TABLE) | ||
+ .build(); | ||
+ } | ||
+ | ||
+ @NonNull | ||
+ @Override | ||
+ protected UpdateQuery mapToUpdateQuery(@NonNull Book book) { | ||
+ return new UpdateQuery.Builder() | ||
+ .table(TABLE) | ||
+ .where(COLUMN_ID + " = ?") | ||
+ .whereArgs(book.id()) | ||
+ .build(); | ||
+ } | ||
+ | ||
+ @NonNull | ||
+ @Override | ||
+ protected ContentValues mapToContentValues(@NonNull Book book) { | ||
+ final ContentValues contentValues = new ContentValues(3); | ||
+ | ||
+ contentValues.put(COLUMN_ID, book.id()); | ||
+ contentValues.put(COLUMN_TITLE, book.title()); | ||
+ contentValues.put(COLUMN_AUTHOR, book.author()); | ||
+ | ||
+ return contentValues; | ||
+ } | ||
+ }; | ||
+ | ||
+ @NonNull | ||
+ static final GetResolver<Book> GET_RESOLVER = new DefaultGetResolver<Book>() { | ||
+ @NonNull | ||
+ @Override | ||
+ public Book mapFromCursor(@NonNull Cursor cursor) { | ||
+ return Book.builder() | ||
+ .id(cursor.getInt(cursor.getColumnIndex(COLUMN_ID))) | ||
+ .title(cursor.getString(cursor.getColumnIndex(COLUMN_TITLE))) | ||
+ .author(cursor.getString(cursor.getColumnIndex(COLUMN_AUTHOR))) | ||
+ .build(); | ||
+ } | ||
+ }; | ||
+ | ||
+ @NonNull | ||
+ static final DeleteResolver<Book> DELETE_RESOLVER = new DefaultDeleteResolver<Book>() { | ||
+ @NonNull | ||
+ @Override | ||
+ protected DeleteQuery mapToDeleteQuery(@NonNull Book book) { | ||
+ return new DeleteQuery.Builder() | ||
+ .table(TABLE) | ||
+ .where(COLUMN_ID + " = ?") | ||
+ .whereArgs(book.id()) | ||
+ .build(); | ||
+ } | ||
+ }; | ||
+} |
23
...ite/src/androidTest/java/com/pushtorefresh/storio/sqlite/impl/auto_parcel/OpenHelper.java
@@ -0,0 +1,23 @@ | ||
+package com.pushtorefresh.storio.sqlite.impl.auto_parcel; | ||
+ | ||
+import android.content.Context; | ||
+import android.database.sqlite.SQLiteDatabase; | ||
+import android.database.sqlite.SQLiteOpenHelper; | ||
+import android.support.annotation.NonNull; | ||
+ | ||
+class OpenHelper extends SQLiteOpenHelper { | ||
+ | ||
+ OpenHelper(@NonNull Context context) { | ||
+ super(context, "auto_parcel_db", null, 1); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public void onCreate(SQLiteDatabase db) { | ||
+ db.execSQL(BookTableMeta.SQL_CREATE_TABLE); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
+ | ||
+ } | ||
+} |
80
storio-sqlite/src/main/java/com/pushtorefresh/storio/sqlite/impl/DefaultStorIOSQLite.java
177
...io-sqlite/src/test/java/com/pushtorefresh/storio/sqlite/impl/DefaultStorIOSQLiteTest.java
0 comments on commit
98664c1