|
@@ -3,13 +3,13 @@ package eu.kanade.mangafeed.data.database;
|
|
|
import android.content.Context;
|
|
|
|
|
|
import com.pushtorefresh.storio.Queries;
|
|
|
-import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping;
|
|
|
import com.pushtorefresh.storio.sqlite.StorIOSQLite;
|
|
|
import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite;
|
|
|
import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteByQuery;
|
|
|
import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteCollectionOfObjects;
|
|
|
import com.pushtorefresh.storio.sqlite.operations.delete.PreparedDeleteObject;
|
|
|
import com.pushtorefresh.storio.sqlite.operations.get.PreparedGetListOfObjects;
|
|
|
+import com.pushtorefresh.storio.sqlite.operations.get.PreparedGetObject;
|
|
|
import com.pushtorefresh.storio.sqlite.operations.put.PreparedPutCollectionOfObjects;
|
|
|
import com.pushtorefresh.storio.sqlite.operations.put.PreparedPutObject;
|
|
|
import com.pushtorefresh.storio.sqlite.operations.put.PutResults;
|
|
@@ -20,25 +20,15 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery;
|
|
|
import java.util.List;
|
|
|
|
|
|
import eu.kanade.mangafeed.data.database.models.Category;
|
|
|
-import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLiteDeleteResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLiteGetResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.CategoryStorIOSQLitePutResolver;
|
|
|
+import eu.kanade.mangafeed.data.database.models.CategorySQLiteTypeMapping;
|
|
|
import eu.kanade.mangafeed.data.database.models.Chapter;
|
|
|
-import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteDeleteResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLiteGetResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.ChapterStorIOSQLitePutResolver;
|
|
|
+import eu.kanade.mangafeed.data.database.models.ChapterSQLiteTypeMapping;
|
|
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
|
|
import eu.kanade.mangafeed.data.database.models.MangaCategory;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLiteDeleteResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLiteGetResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaCategoryStorIOSQLitePutResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteDeleteResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteGetResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLitePutResolver;
|
|
|
+import eu.kanade.mangafeed.data.database.models.MangaCategorySQLiteTypeMapping;
|
|
|
+import eu.kanade.mangafeed.data.database.models.MangaSQLiteTypeMapping;
|
|
|
import eu.kanade.mangafeed.data.database.models.MangaSync;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLiteDeleteResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLiteGetResolver;
|
|
|
-import eu.kanade.mangafeed.data.database.models.MangaSyncStorIOSQLitePutResolver;
|
|
|
+import eu.kanade.mangafeed.data.database.models.MangaSyncSQLiteTypeMapping;
|
|
|
import eu.kanade.mangafeed.data.database.resolvers.LibraryMangaGetResolver;
|
|
|
import eu.kanade.mangafeed.data.database.tables.CategoryTable;
|
|
|
import eu.kanade.mangafeed.data.database.tables.ChapterTable;
|
|
@@ -58,31 +48,11 @@ public class DatabaseHelper {
|
|
|
|
|
|
db = DefaultStorIOSQLite.builder()
|
|
|
.sqliteOpenHelper(new DbOpenHelper(context))
|
|
|
- .addTypeMapping(Manga.class, SQLiteTypeMapping.<Manga>builder()
|
|
|
- .putResolver(new MangaStorIOSQLitePutResolver())
|
|
|
- .getResolver(new MangaStorIOSQLiteGetResolver())
|
|
|
- .deleteResolver(new MangaStorIOSQLiteDeleteResolver())
|
|
|
- .build())
|
|
|
- .addTypeMapping(Chapter.class, SQLiteTypeMapping.<Chapter>builder()
|
|
|
- .putResolver(new ChapterStorIOSQLitePutResolver())
|
|
|
- .getResolver(new ChapterStorIOSQLiteGetResolver())
|
|
|
- .deleteResolver(new ChapterStorIOSQLiteDeleteResolver())
|
|
|
- .build())
|
|
|
- .addTypeMapping(MangaSync.class, SQLiteTypeMapping.<MangaSync>builder()
|
|
|
- .putResolver(new MangaSyncStorIOSQLitePutResolver())
|
|
|
- .getResolver(new MangaSyncStorIOSQLiteGetResolver())
|
|
|
- .deleteResolver(new MangaSyncStorIOSQLiteDeleteResolver())
|
|
|
- .build())
|
|
|
- .addTypeMapping(Category.class, SQLiteTypeMapping.<Category>builder()
|
|
|
- .putResolver(new CategoryStorIOSQLitePutResolver())
|
|
|
- .getResolver(new CategoryStorIOSQLiteGetResolver())
|
|
|
- .deleteResolver(new CategoryStorIOSQLiteDeleteResolver())
|
|
|
- .build())
|
|
|
- .addTypeMapping(MangaCategory.class, SQLiteTypeMapping.<MangaCategory>builder()
|
|
|
- .putResolver(new MangaCategoryStorIOSQLitePutResolver())
|
|
|
- .getResolver(new MangaCategoryStorIOSQLiteGetResolver())
|
|
|
- .deleteResolver(new MangaCategoryStorIOSQLiteDeleteResolver())
|
|
|
- .build())
|
|
|
+ .addTypeMapping(Manga.class, new MangaSQLiteTypeMapping())
|
|
|
+ .addTypeMapping(Chapter.class, new ChapterSQLiteTypeMapping())
|
|
|
+ .addTypeMapping(MangaSync.class, new MangaSyncSQLiteTypeMapping())
|
|
|
+ .addTypeMapping(Category.class, new CategorySQLiteTypeMapping())
|
|
|
+ .addTypeMapping(MangaCategory.class, new MangaCategorySQLiteTypeMapping())
|
|
|
.build();
|
|
|
}
|
|
|
|
|
@@ -115,13 +85,14 @@ public class DatabaseHelper {
|
|
|
.table(MangaTable.TABLE)
|
|
|
.where(MangaTable.COLUMN_FAVORITE + "=?")
|
|
|
.whereArgs(1)
|
|
|
+ .orderBy(MangaTable.COLUMN_TITLE)
|
|
|
.build())
|
|
|
.prepare();
|
|
|
}
|
|
|
|
|
|
- public PreparedGetListOfObjects<Manga> getManga(String url, int sourceId) {
|
|
|
+ public PreparedGetObject<Manga> getManga(String url, int sourceId) {
|
|
|
return db.get()
|
|
|
- .listOfObjects(Manga.class)
|
|
|
+ .object(Manga.class)
|
|
|
.withQuery(Query.builder()
|
|
|
.table(MangaTable.TABLE)
|
|
|
.where(MangaTable.COLUMN_URL + "=? AND " + MangaTable.COLUMN_SOURCE + "=?")
|
|
@@ -130,9 +101,9 @@ public class DatabaseHelper {
|
|
|
.prepare();
|
|
|
}
|
|
|
|
|
|
- public PreparedGetListOfObjects<Manga> getManga(long id) {
|
|
|
+ public PreparedGetObject<Manga> getManga(long id) {
|
|
|
return db.get()
|
|
|
- .listOfObjects(Manga.class)
|
|
|
+ .object(Manga.class)
|
|
|
.withQuery(Query.builder()
|
|
|
.table(MangaTable.TABLE)
|
|
|
.where(MangaTable.COLUMN_ID + "=?")
|
|
@@ -199,13 +170,13 @@ public class DatabaseHelper {
|
|
|
.prepare();
|
|
|
}
|
|
|
|
|
|
- public PreparedGetListOfObjects<Chapter> getNextChapter(Chapter chapter) {
|
|
|
+ public PreparedGetObject<Chapter> getNextChapter(Chapter chapter) {
|
|
|
// Add a delta to the chapter number, because binary decimal representation
|
|
|
// can retrieve the same chapter again
|
|
|
double chapterNumber = chapter.chapter_number + 0.00001;
|
|
|
|
|
|
return db.get()
|
|
|
- .listOfObjects(Chapter.class)
|
|
|
+ .object(Chapter.class)
|
|
|
.withQuery(Query.builder()
|
|
|
.table(ChapterTable.TABLE)
|
|
|
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
|
|
@@ -218,13 +189,13 @@ public class DatabaseHelper {
|
|
|
.prepare();
|
|
|
}
|
|
|
|
|
|
- public PreparedGetListOfObjects<Chapter> getPreviousChapter(Chapter chapter) {
|
|
|
+ public PreparedGetObject<Chapter> getPreviousChapter(Chapter chapter) {
|
|
|
// Add a delta to the chapter number, because binary decimal representation
|
|
|
// can retrieve the same chapter again
|
|
|
double chapterNumber = chapter.chapter_number - 0.00001;
|
|
|
|
|
|
return db.get()
|
|
|
- .listOfObjects(Chapter.class)
|
|
|
+ .object(Chapter.class)
|
|
|
.withQuery(Query.builder()
|
|
|
.table(ChapterTable.TABLE)
|
|
|
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
|
|
@@ -237,9 +208,9 @@ public class DatabaseHelper {
|
|
|
.prepare();
|
|
|
}
|
|
|
|
|
|
- public PreparedGetListOfObjects<Chapter> getNextUnreadChapter(Manga manga) {
|
|
|
+ public PreparedGetObject<Chapter> getNextUnreadChapter(Manga manga) {
|
|
|
return db.get()
|
|
|
- .listOfObjects(Chapter.class)
|
|
|
+ .object(Chapter.class)
|
|
|
.withQuery(Query.builder()
|
|
|
.table(ChapterTable.TABLE)
|
|
|
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
|
|
@@ -312,9 +283,9 @@ public class DatabaseHelper {
|
|
|
|
|
|
// Manga sync related queries
|
|
|
|
|
|
- public PreparedGetListOfObjects<MangaSync> getMangaSync(Manga manga, MangaSyncService sync) {
|
|
|
+ public PreparedGetObject<MangaSync> getMangaSync(Manga manga, MangaSyncService sync) {
|
|
|
return db.get()
|
|
|
- .listOfObjects(MangaSync.class)
|
|
|
+ .object(MangaSync.class)
|
|
|
.withQuery(Query.builder()
|
|
|
.table(MangaSyncTable.TABLE)
|
|
|
.where(MangaSyncTable.COLUMN_MANGA_ID + "=? AND " +
|
|
@@ -324,7 +295,7 @@ public class DatabaseHelper {
|
|
|
.prepare();
|
|
|
}
|
|
|
|
|
|
- public PreparedGetListOfObjects<MangaSync> getMangaSync(Manga manga) {
|
|
|
+ public PreparedGetListOfObjects<MangaSync> getMangasSync(Manga manga) {
|
|
|
return db.get()
|
|
|
.listOfObjects(MangaSync.class)
|
|
|
.withQuery(Query.builder()
|