Rename tables classes

This commit is contained in:
inorichi 2015-11-24 20:45:37 +01:00
parent 725f70a54c
commit da7d5886da
9 changed files with 73 additions and 80 deletions

View File

@ -24,8 +24,8 @@ import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteDeleteResolver; import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteDeleteResolver;
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLitePutResolver; import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.database.resolvers.MangaWithUnreadGetResolver; import eu.kanade.mangafeed.data.database.resolvers.MangaWithUnreadGetResolver;
import eu.kanade.mangafeed.data.database.tables.ChaptersTable; import eu.kanade.mangafeed.data.database.tables.ChapterTable;
import eu.kanade.mangafeed.data.database.tables.MangasTable; import eu.kanade.mangafeed.data.database.tables.MangaTable;
import eu.kanade.mangafeed.util.ChapterRecognition; import eu.kanade.mangafeed.util.ChapterRecognition;
import eu.kanade.mangafeed.util.PostResult; import eu.kanade.mangafeed.util.PostResult;
import rx.Observable; import rx.Observable;
@ -57,20 +57,20 @@ public class DatabaseHelper {
"SELECT %1$s.*, COUNT(C.%4$s) AS %5$s FROM %1$s LEFT JOIN " + "SELECT %1$s.*, COUNT(C.%4$s) AS %5$s FROM %1$s LEFT JOIN " +
"(SELECT %4$s FROM %2$s WHERE %6$s = 0) AS C ON %3$s = C.%4$s " + "(SELECT %4$s FROM %2$s WHERE %6$s = 0) AS C ON %3$s = C.%4$s " +
"WHERE %7$s = 1 GROUP BY %3$s", "WHERE %7$s = 1 GROUP BY %3$s",
MangasTable.TABLE, MangaTable.TABLE,
ChaptersTable.TABLE, ChapterTable.TABLE,
MangasTable.TABLE + "." + MangasTable.COLUMN_ID, MangaTable.TABLE + "." + MangaTable.COLUMN_ID,
ChaptersTable.COLUMN_MANGA_ID, ChapterTable.COLUMN_MANGA_ID,
MangasTable.COLUMN_UNREAD, MangaTable.COLUMN_UNREAD,
ChaptersTable.COLUMN_READ, ChapterTable.COLUMN_READ,
MangasTable.COLUMN_FAVORITE MangaTable.COLUMN_FAVORITE
); );
public PreparedGetListOfObjects<Manga> getMangas() { public PreparedGetListOfObjects<Manga> getMangas() {
return db.get() return db.get()
.listOfObjects(Manga.class) .listOfObjects(Manga.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(MangasTable.TABLE) .table(MangaTable.TABLE)
.build()) .build())
.prepare(); .prepare();
} }
@ -80,7 +80,7 @@ public class DatabaseHelper {
.listOfObjects(Manga.class) .listOfObjects(Manga.class)
.withQuery(RawQuery.builder() .withQuery(RawQuery.builder()
.query(favoriteMangasWithUnreadQuery) .query(favoriteMangasWithUnreadQuery)
.observesTables(MangasTable.TABLE, ChaptersTable.TABLE) .observesTables(MangaTable.TABLE, ChapterTable.TABLE)
.build()) .build())
.prepare(); .prepare();
} }
@ -89,8 +89,8 @@ public class DatabaseHelper {
return db.get() return db.get()
.listOfObjects(Manga.class) .listOfObjects(Manga.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(MangasTable.TABLE) .table(MangaTable.TABLE)
.where(MangasTable.COLUMN_FAVORITE + "=?") .where(MangaTable.COLUMN_FAVORITE + "=?")
.whereArgs(1) .whereArgs(1)
.build()) .build())
.prepare(); .prepare();
@ -100,8 +100,8 @@ public class DatabaseHelper {
return db.get() return db.get()
.listOfObjects(Manga.class) .listOfObjects(Manga.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(MangasTable.TABLE) .table(MangaTable.TABLE)
.where(MangasTable.COLUMN_URL + "=?") .where(MangaTable.COLUMN_URL + "=?")
.whereArgs(url) .whereArgs(url)
.build()) .build())
.prepare(); .prepare();
@ -111,8 +111,8 @@ public class DatabaseHelper {
return db.get() return db.get()
.listOfObjects(Manga.class) .listOfObjects(Manga.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(MangasTable.TABLE) .table(MangaTable.TABLE)
.where(MangasTable.COLUMN_ID + "=?") .where(MangaTable.COLUMN_ID + "=?")
.whereArgs(id) .whereArgs(id)
.build()) .build())
.prepare(); .prepare();
@ -149,8 +149,8 @@ public class DatabaseHelper {
return db.get() return db.get()
.listOfObjects(Chapter.class) .listOfObjects(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(ChaptersTable.TABLE) .table(ChapterTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=?") .where(ChapterTable.COLUMN_MANGA_ID + "=?")
.whereArgs(manga.id) .whereArgs(manga.id)
.build()) .build())
.prepare(); .prepare();
@ -158,15 +158,15 @@ public class DatabaseHelper {
public PreparedGetListOfObjects<Chapter> getChapters(long manga_id, boolean sortAToZ, boolean onlyUnread) { public PreparedGetListOfObjects<Chapter> getChapters(long manga_id, boolean sortAToZ, boolean onlyUnread) {
Query.CompleteBuilder query = Query.builder() Query.CompleteBuilder query = Query.builder()
.table(ChaptersTable.TABLE) .table(ChapterTable.TABLE)
.orderBy(ChaptersTable.COLUMN_CHAPTER_NUMBER + (sortAToZ ? " ASC" : " DESC")); .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER + (sortAToZ ? " ASC" : " DESC"));
if (onlyUnread) { if (onlyUnread) {
query = query.where(ChaptersTable.COLUMN_MANGA_ID + "=? AND " + ChaptersTable.COLUMN_READ + "=?") query = query.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " + ChapterTable.COLUMN_READ + "=?")
.whereArgs(manga_id, 0); .whereArgs(manga_id, 0);
} else { } else {
query = query.where(ChaptersTable.COLUMN_MANGA_ID + "=?") query = query.where(ChapterTable.COLUMN_MANGA_ID + "=?")
.whereArgs(manga_id); .whereArgs(manga_id);
} }
@ -180,12 +180,12 @@ public class DatabaseHelper {
return db.get() return db.get()
.listOfObjects(Chapter.class) .listOfObjects(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(ChaptersTable.TABLE) .table(ChapterTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=? AND " + .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + ">? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + ">? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + "<=?") ChapterTable.COLUMN_CHAPTER_NUMBER + "<=?")
.whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number + 1) .whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number + 1)
.orderBy(ChaptersTable.COLUMN_CHAPTER_NUMBER) .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER)
.limit(1) .limit(1)
.build()) .build())
.prepare(); .prepare();
@ -195,12 +195,12 @@ public class DatabaseHelper {
return db.get() return db.get()
.listOfObjects(Chapter.class) .listOfObjects(Chapter.class)
.withQuery(Query.builder() .withQuery(Query.builder()
.table(ChaptersTable.TABLE) .table(ChapterTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=? AND " + .where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + "<? AND " + ChapterTable.COLUMN_CHAPTER_NUMBER + "<? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + ">=?") ChapterTable.COLUMN_CHAPTER_NUMBER + ">=?")
.whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number - 1) .whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number - 1)
.orderBy(ChaptersTable.COLUMN_CHAPTER_NUMBER + " DESC") .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER + " DESC")
.limit(1) .limit(1)
.build()) .build())
.prepare(); .prepare();

View File

@ -5,8 +5,8 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import eu.kanade.mangafeed.data.database.tables.ChaptersTable; import eu.kanade.mangafeed.data.database.tables.ChapterTable;
import eu.kanade.mangafeed.data.database.tables.MangasTable; import eu.kanade.mangafeed.data.database.tables.MangaTable;
public class DbOpenHelper extends SQLiteOpenHelper { public class DbOpenHelper extends SQLiteOpenHelper {
@ -19,8 +19,8 @@ public class DbOpenHelper extends SQLiteOpenHelper {
@Override @Override
public void onCreate(@NonNull SQLiteDatabase db) { public void onCreate(@NonNull SQLiteDatabase db) {
db.execSQL(MangasTable.getCreateTableQuery()); db.execSQL(MangaTable.getCreateTableQuery());
db.execSQL(ChaptersTable.getCreateTableQuery()); db.execSQL(ChapterTable.getCreateTableQuery());
} }
@Override @Override

View File

@ -3,36 +3,36 @@ package eu.kanade.mangafeed.data.database.models;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
import eu.kanade.mangafeed.data.database.tables.ChaptersTable; import eu.kanade.mangafeed.data.database.tables.ChapterTable;
@StorIOSQLiteType(table = ChaptersTable.TABLE) @StorIOSQLiteType(table = ChapterTable.TABLE)
public class Chapter { public class Chapter {
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_ID, key = true) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_ID, key = true)
public Long id; public Long id;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_MANGA_ID) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_MANGA_ID)
public Long manga_id; public Long manga_id;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_URL) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_URL)
public String url; public String url;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_NAME) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_NAME)
public String name; public String name;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_READ) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_READ)
public boolean read; public boolean read;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_LAST_PAGE_READ) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_LAST_PAGE_READ)
public int last_page_read; public int last_page_read;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_DATE_FETCH) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_DATE_FETCH)
public long date_fetch; public long date_fetch;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_DATE_UPLOAD) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_DATE_UPLOAD)
public long date_upload; public long date_upload;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_CHAPTER_NUMBER) @StorIOSQLiteColumn(name = ChapterTable.COLUMN_CHAPTER_NUMBER)
public float chapter_number; public float chapter_number;
public int downloaded; public int downloaded;

View File

@ -3,54 +3,54 @@ package eu.kanade.mangafeed.data.database.models;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
import eu.kanade.mangafeed.data.database.tables.MangasTable; import eu.kanade.mangafeed.data.database.tables.MangaTable;
@StorIOSQLiteType(table = MangasTable.TABLE) @StorIOSQLiteType(table = MangaTable.TABLE)
public class Manga { public class Manga {
@StorIOSQLiteColumn(name = MangasTable.COLUMN_ID, key = true) @StorIOSQLiteColumn(name = MangaTable.COLUMN_ID, key = true)
public Long id; public Long id;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_SOURCE) @StorIOSQLiteColumn(name = MangaTable.COLUMN_SOURCE)
public int source; public int source;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_URL) @StorIOSQLiteColumn(name = MangaTable.COLUMN_URL)
public String url; public String url;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_ARTIST) @StorIOSQLiteColumn(name = MangaTable.COLUMN_ARTIST)
public String artist; public String artist;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_AUTHOR) @StorIOSQLiteColumn(name = MangaTable.COLUMN_AUTHOR)
public String author; public String author;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_DESCRIPTION) @StorIOSQLiteColumn(name = MangaTable.COLUMN_DESCRIPTION)
public String description; public String description;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_GENRE) @StorIOSQLiteColumn(name = MangaTable.COLUMN_GENRE)
public String genre; public String genre;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_TITLE) @StorIOSQLiteColumn(name = MangaTable.COLUMN_TITLE)
public String title; public String title;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_STATUS) @StorIOSQLiteColumn(name = MangaTable.COLUMN_STATUS)
public String status; public String status;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_THUMBNAIL_URL) @StorIOSQLiteColumn(name = MangaTable.COLUMN_THUMBNAIL_URL)
public String thumbnail_url; public String thumbnail_url;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_FAVORITE) @StorIOSQLiteColumn(name = MangaTable.COLUMN_FAVORITE)
public boolean favorite; public boolean favorite;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_LAST_UPDATE) @StorIOSQLiteColumn(name = MangaTable.COLUMN_LAST_UPDATE)
public long last_update; public long last_update;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_INITIALIZED) @StorIOSQLiteColumn(name = MangaTable.COLUMN_INITIALIZED)
public boolean initialized; public boolean initialized;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_VIEWER) @StorIOSQLiteColumn(name = MangaTable.COLUMN_VIEWER)
public int viewer; public int viewer;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_CHAPTER_ORDER) @StorIOSQLiteColumn(name = MangaTable.COLUMN_CHAPTER_ORDER)
public int chapter_order; public int chapter_order;
public int unread; public int unread;

View File

@ -5,15 +5,14 @@ import android.support.annotation.NonNull;
import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.database.models.Manga;
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteGetResolver; import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteGetResolver;
import eu.kanade.mangafeed.data.database.tables.MangasTable; import eu.kanade.mangafeed.data.database.tables.MangaTable;
public class MangaWithUnreadGetResolver extends MangaStorIOSQLiteGetResolver { public class MangaWithUnreadGetResolver extends MangaStorIOSQLiteGetResolver {
@Override @Override
public Manga mapFromCursor(@NonNull Cursor cursor) { public Manga mapFromCursor(@NonNull Cursor cursor) {
Manga manga = super.mapFromCursor(cursor); Manga manga = super.mapFromCursor(cursor);
int unreadColumn = cursor.getColumnIndex(MangasTable.COLUMN_UNREAD); int unreadColumn = cursor.getColumnIndex(MangaTable.COLUMN_UNREAD);
if (unreadColumn != -1) if (unreadColumn != -1)
manga.unread = cursor.getInt(unreadColumn); manga.unread = cursor.getInt(unreadColumn);
return manga; return manga;

View File

@ -2,10 +2,7 @@ package eu.kanade.mangafeed.data.database.tables;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
/** public class CategoryTable {
* Created by len on 23/09/2015.
*/
public class CategoriesTable {
@NonNull @NonNull
public static final String TABLE = "categories"; public static final String TABLE = "categories";

View File

@ -2,7 +2,7 @@ package eu.kanade.mangafeed.data.database.tables;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
public class ChaptersTable { public class ChapterTable {
@NonNull @NonNull
public static final String TABLE = "chapters"; public static final String TABLE = "chapters";
@ -46,7 +46,7 @@ public class ChaptersTable {
+ COLUMN_CHAPTER_NUMBER + " FLOAT NOT NULL, " + COLUMN_CHAPTER_NUMBER + " FLOAT NOT NULL, "
+ COLUMN_DATE_FETCH + " LONG NOT NULL, " + COLUMN_DATE_FETCH + " LONG NOT NULL, "
+ COLUMN_DATE_UPLOAD + " LONG NOT NULL, " + COLUMN_DATE_UPLOAD + " LONG NOT NULL, "
+ "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangasTable.TABLE + "(" + MangasTable.COLUMN_ID + ") " + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") "
+ "ON DELETE CASCADE" + "ON DELETE CASCADE"
+ ");" + ");"
+ "CREATE INDEX " + TABLE + "_" + COLUMN_MANGA_ID + "_index ON " + TABLE + "(" + COLUMN_MANGA_ID + ");"; + "CREATE INDEX " + TABLE + "_" + COLUMN_MANGA_ID + "_index ON " + TABLE + "(" + COLUMN_MANGA_ID + ");";

View File

@ -2,10 +2,7 @@ package eu.kanade.mangafeed.data.database.tables;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
/** public class MangaCategoryTable {
* Created by len on 23/09/2015.
*/
public class MangasCategoriesTable {
@NonNull @NonNull
public static final String TABLE = "mangas_categories"; public static final String TABLE = "mangas_categories";

View File

@ -2,7 +2,7 @@ package eu.kanade.mangafeed.data.database.tables;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
public class MangasTable { public class MangaTable {
@NonNull @NonNull
public static final String TABLE = "mangas"; public static final String TABLE = "mangas";
@ -56,7 +56,7 @@ public class MangasTable {
public static final String COLUMN_UNREAD = "unread"; public static final String COLUMN_UNREAD = "unread";
// This is just class with Meta Data, we don't need instances // This is just class with Meta Data, we don't need instances
private MangasTable() { private MangaTable() {
throw new IllegalStateException("No instances please"); throw new IllegalStateException("No instances please");
} }