From da7d5886da355ca438e3f3fbfef70545f668d2e6 Mon Sep 17 00:00:00 2001 From: inorichi Date: Tue, 24 Nov 2015 20:45:37 +0100 Subject: [PATCH] Rename tables classes --- .../data/database/DatabaseHelper.java | 66 +++++++++---------- .../mangafeed/data/database/DbOpenHelper.java | 8 +-- .../data/database/models/Chapter.java | 22 +++---- .../mangafeed/data/database/models/Manga.java | 34 +++++----- .../resolvers/MangaWithUnreadGetResolver.java | 5 +- ...ategoriesTable.java => CategoryTable.java} | 5 +- .../{ChaptersTable.java => ChapterTable.java} | 4 +- ...riesTable.java => MangaCategoryTable.java} | 5 +- .../{MangasTable.java => MangaTable.java} | 4 +- 9 files changed, 73 insertions(+), 80 deletions(-) rename app/src/main/java/eu/kanade/mangafeed/data/database/tables/{CategoriesTable.java => CategoryTable.java} (80%) rename app/src/main/java/eu/kanade/mangafeed/data/database/tables/{ChaptersTable.java => ChapterTable.java} (94%) rename app/src/main/java/eu/kanade/mangafeed/data/database/tables/{MangasCategoriesTable.java => MangaCategoryTable.java} (80%) rename app/src/main/java/eu/kanade/mangafeed/data/database/tables/{MangasTable.java => MangaTable.java} (97%) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java index c675962e16..0b475f9e2a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DatabaseHelper.java @@ -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 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 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 + "=?") + .table(ChapterTable.TABLE) + .where(ChapterTable.COLUMN_MANGA_ID + "=? 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(); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java index 65b0cdd172..bfebf5ed8c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java @@ -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 diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java index a4e03f465e..a89855557f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java @@ -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; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java index 86ab303327..c51eeba1e4 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java @@ -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; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/resolvers/MangaWithUnreadGetResolver.java b/app/src/main/java/eu/kanade/mangafeed/data/database/resolvers/MangaWithUnreadGetResolver.java index a5a2f91a65..e438513e73 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/resolvers/MangaWithUnreadGetResolver.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/resolvers/MangaWithUnreadGetResolver.java @@ -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; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/CategoriesTable.java b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/CategoryTable.java similarity index 80% rename from app/src/main/java/eu/kanade/mangafeed/data/database/tables/CategoriesTable.java rename to app/src/main/java/eu/kanade/mangafeed/data/database/tables/CategoryTable.java index bc56409e67..2134a8ac91 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/CategoriesTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/CategoryTable.java @@ -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"; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/ChaptersTable.java b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/ChapterTable.java similarity index 94% rename from app/src/main/java/eu/kanade/mangafeed/data/database/tables/ChaptersTable.java rename to app/src/main/java/eu/kanade/mangafeed/data/database/tables/ChapterTable.java index 548e6b8740..e5337564e7 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/ChaptersTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/ChapterTable.java @@ -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 + ");"; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangasCategoriesTable.java b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaCategoryTable.java similarity index 80% rename from app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangasCategoriesTable.java rename to app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaCategoryTable.java index 4799710f4b..173ebbd548 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangasCategoriesTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaCategoryTable.java @@ -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"; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangasTable.java b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaTable.java similarity index 97% rename from app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangasTable.java rename to app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaTable.java index 57a1b64453..df6a7f2fed 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangasTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaTable.java @@ -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"); }