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.MangaStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.database.resolvers.MangaWithUnreadGetResolver;
import eu.kanade.mangafeed.data.database.tables.ChaptersTable;
import eu.kanade.mangafeed.data.database.tables.MangasTable;
import eu.kanade.mangafeed.data.database.tables.ChapterTable;
import eu.kanade.mangafeed.data.database.tables.MangaTable;
import eu.kanade.mangafeed.util.ChapterRecognition;
import eu.kanade.mangafeed.util.PostResult;
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 %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",
MangasTable.TABLE,
ChaptersTable.TABLE,
MangasTable.TABLE + "." + MangasTable.COLUMN_ID,
ChaptersTable.COLUMN_MANGA_ID,
MangasTable.COLUMN_UNREAD,
ChaptersTable.COLUMN_READ,
MangasTable.COLUMN_FAVORITE
MangaTable.TABLE,
ChapterTable.TABLE,
MangaTable.TABLE + "." + MangaTable.COLUMN_ID,
ChapterTable.COLUMN_MANGA_ID,
MangaTable.COLUMN_UNREAD,
ChapterTable.COLUMN_READ,
MangaTable.COLUMN_FAVORITE
);
public PreparedGetListOfObjects<Manga> getMangas() {
return db.get()
.listOfObjects(Manga.class)
.withQuery(Query.builder()
.table(MangasTable.TABLE)
.table(MangaTable.TABLE)
.build())
.prepare();
}
@ -80,7 +80,7 @@ public class DatabaseHelper {
.listOfObjects(Manga.class)
.withQuery(RawQuery.builder()
.query(favoriteMangasWithUnreadQuery)
.observesTables(MangasTable.TABLE, ChaptersTable.TABLE)
.observesTables(MangaTable.TABLE, ChapterTable.TABLE)
.build())
.prepare();
}
@ -89,8 +89,8 @@ public class DatabaseHelper {
return db.get()
.listOfObjects(Manga.class)
.withQuery(Query.builder()
.table(MangasTable.TABLE)
.where(MangasTable.COLUMN_FAVORITE + "=?")
.table(MangaTable.TABLE)
.where(MangaTable.COLUMN_FAVORITE + "=?")
.whereArgs(1)
.build())
.prepare();
@ -100,8 +100,8 @@ public class DatabaseHelper {
return db.get()
.listOfObjects(Manga.class)
.withQuery(Query.builder()
.table(MangasTable.TABLE)
.where(MangasTable.COLUMN_URL + "=?")
.table(MangaTable.TABLE)
.where(MangaTable.COLUMN_URL + "=?")
.whereArgs(url)
.build())
.prepare();
@ -111,8 +111,8 @@ public class DatabaseHelper {
return db.get()
.listOfObjects(Manga.class)
.withQuery(Query.builder()
.table(MangasTable.TABLE)
.where(MangasTable.COLUMN_ID + "=?")
.table(MangaTable.TABLE)
.where(MangaTable.COLUMN_ID + "=?")
.whereArgs(id)
.build())
.prepare();
@ -149,8 +149,8 @@ public class DatabaseHelper {
return db.get()
.listOfObjects(Chapter.class)
.withQuery(Query.builder()
.table(ChaptersTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=?")
.table(ChapterTable.TABLE)
.where(ChapterTable.COLUMN_MANGA_ID + "=?")
.whereArgs(manga.id)
.build())
.prepare();
@ -158,15 +158,15 @@ public class DatabaseHelper {
public PreparedGetListOfObjects<Chapter> getChapters(long manga_id, boolean sortAToZ, boolean onlyUnread) {
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) {
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);
} else {
query = query.where(ChaptersTable.COLUMN_MANGA_ID + "=?")
query = query.where(ChapterTable.COLUMN_MANGA_ID + "=?")
.whereArgs(manga_id);
}
@ -180,12 +180,12 @@ public class DatabaseHelper {
return db.get()
.listOfObjects(Chapter.class)
.withQuery(Query.builder()
.table(ChaptersTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + ">? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + "<=?")
.table(ChapterTable.TABLE)
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + ">? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + "<=?")
.whereArgs(chapter.manga_id, chapter.chapter_number, chapter.chapter_number + 1)
.orderBy(ChaptersTable.COLUMN_CHAPTER_NUMBER)
.orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER)
.limit(1)
.build())
.prepare();
@ -195,12 +195,12 @@ public class DatabaseHelper {
return db.get()
.listOfObjects(Chapter.class)
.withQuery(Query.builder()
.table(ChaptersTable.TABLE)
.where(ChaptersTable.COLUMN_MANGA_ID + "=? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + "<? AND " +
ChaptersTable.COLUMN_CHAPTER_NUMBER + ">=?")
.table(ChapterTable.TABLE)
.where(ChapterTable.COLUMN_MANGA_ID + "=? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + "<? AND " +
ChapterTable.COLUMN_CHAPTER_NUMBER + ">=?")
.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)
.build())
.prepare();

View file

@ -5,8 +5,8 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import eu.kanade.mangafeed.data.database.tables.ChaptersTable;
import eu.kanade.mangafeed.data.database.tables.MangasTable;
import eu.kanade.mangafeed.data.database.tables.ChapterTable;
import eu.kanade.mangafeed.data.database.tables.MangaTable;
public class DbOpenHelper extends SQLiteOpenHelper {
@ -19,8 +19,8 @@ public class DbOpenHelper extends SQLiteOpenHelper {
@Override
public void onCreate(@NonNull SQLiteDatabase db) {
db.execSQL(MangasTable.getCreateTableQuery());
db.execSQL(ChaptersTable.getCreateTableQuery());
db.execSQL(MangaTable.getCreateTableQuery());
db.execSQL(ChapterTable.getCreateTableQuery());
}
@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.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 {
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_ID, key = true)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_ID, key = true)
public Long id;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_MANGA_ID)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_MANGA_ID)
public Long manga_id;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_URL)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_URL)
public String url;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_NAME)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_NAME)
public String name;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_READ)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_READ)
public boolean read;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_LAST_PAGE_READ)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_LAST_PAGE_READ)
public int last_page_read;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_DATE_FETCH)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_DATE_FETCH)
public long date_fetch;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_DATE_UPLOAD)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_DATE_UPLOAD)
public long date_upload;
@StorIOSQLiteColumn(name = ChaptersTable.COLUMN_CHAPTER_NUMBER)
@StorIOSQLiteColumn(name = ChapterTable.COLUMN_CHAPTER_NUMBER)
public float chapter_number;
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.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 {
@StorIOSQLiteColumn(name = MangasTable.COLUMN_ID, key = true)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_ID, key = true)
public Long id;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_SOURCE)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_SOURCE)
public int source;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_URL)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_URL)
public String url;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_ARTIST)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_ARTIST)
public String artist;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_AUTHOR)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_AUTHOR)
public String author;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_DESCRIPTION)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_DESCRIPTION)
public String description;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_GENRE)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_GENRE)
public String genre;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_TITLE)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_TITLE)
public String title;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_STATUS)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_STATUS)
public String status;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_THUMBNAIL_URL)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_THUMBNAIL_URL)
public String thumbnail_url;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_FAVORITE)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_FAVORITE)
public boolean favorite;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_LAST_UPDATE)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_LAST_UPDATE)
public long last_update;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_INITIALIZED)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_INITIALIZED)
public boolean initialized;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_VIEWER)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_VIEWER)
public int viewer;
@StorIOSQLiteColumn(name = MangasTable.COLUMN_CHAPTER_ORDER)
@StorIOSQLiteColumn(name = MangaTable.COLUMN_CHAPTER_ORDER)
public int chapter_order;
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.MangaStorIOSQLiteGetResolver;
import eu.kanade.mangafeed.data.database.tables.MangasTable;
import eu.kanade.mangafeed.data.database.tables.MangaTable;
public class MangaWithUnreadGetResolver extends MangaStorIOSQLiteGetResolver {
@Override
public Manga mapFromCursor(@NonNull Cursor cursor) {
Manga manga = super.mapFromCursor(cursor);
int unreadColumn = cursor.getColumnIndex(MangasTable.COLUMN_UNREAD);
int unreadColumn = cursor.getColumnIndex(MangaTable.COLUMN_UNREAD);
if (unreadColumn != -1)
manga.unread = cursor.getInt(unreadColumn);
return manga;

View file

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

View file

@ -2,7 +2,7 @@ package eu.kanade.mangafeed.data.database.tables;
import android.support.annotation.NonNull;
public class ChaptersTable {
public class ChapterTable {
@NonNull
public static final String TABLE = "chapters";
@ -46,7 +46,7 @@ public class ChaptersTable {
+ COLUMN_CHAPTER_NUMBER + " FLOAT NOT NULL, "
+ COLUMN_DATE_FETCH + " 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"
+ ");"
+ "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;
/**
* Created by len on 23/09/2015.
*/
public class MangasCategoriesTable {
public class MangaCategoryTable {
@NonNull
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;
public class MangasTable {
public class MangaTable {
@NonNull
public static final String TABLE = "mangas";
@ -56,7 +56,7 @@ public class MangasTable {
public static final String COLUMN_UNREAD = "unread";
// This is just class with Meta Data, we don't need instances
private MangasTable() {
private MangaTable() {
throw new IllegalStateException("No instances please");
}