mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
new database field: marks if book was found on the disk during last scan
This commit is contained in:
parent
911c99fce8
commit
05365b01d1
3 changed files with 36 additions and 5 deletions
|
@ -61,7 +61,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
|
|
||||||
private void migrate(Context context) {
|
private void migrate(Context context) {
|
||||||
final int version = myDatabase.getVersion();
|
final int version = myDatabase.getVersion();
|
||||||
final int currentVersion = 16;
|
final int currentVersion = 17;
|
||||||
if (version >= currentVersion) {
|
if (version >= currentVersion) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
updateTables14();
|
updateTables14();
|
||||||
case 15:
|
case 15:
|
||||||
updateTables15();
|
updateTables15();
|
||||||
|
case 16:
|
||||||
|
updateTables16();
|
||||||
}
|
}
|
||||||
myDatabase.setTransactionSuccessful();
|
myDatabase.setTransactionSuccessful();
|
||||||
myDatabase.endTransaction();
|
myDatabase.endTransaction();
|
||||||
|
@ -174,9 +176,9 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<Long,Book> loadBooks(FileInfoSet infos) {
|
protected Map<Long,Book> loadBooks(FileInfoSet infos, boolean existing) {
|
||||||
Cursor cursor = myDatabase.rawQuery(
|
Cursor cursor = myDatabase.rawQuery(
|
||||||
"SELECT book_id,file_id,title,encoding,language FROM Books", null
|
"SELECT book_id,file_id,title,encoding,language FROM Books WHERE `exists` = " + (existing ? 1 : 0), null
|
||||||
);
|
);
|
||||||
final HashMap<Long,Book> booksById = new HashMap<Long,Book>();
|
final HashMap<Long,Book> booksById = new HashMap<Long,Book>();
|
||||||
final HashMap<Long,Book> booksByFileId = new HashMap<Long,Book>();
|
final HashMap<Long,Book> booksByFileId = new HashMap<Long,Book>();
|
||||||
|
@ -252,7 +254,29 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
return booksByFileId;
|
return booksByFileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setExistingFlag(Collection<Book> books, boolean flag) {
|
||||||
|
if (books.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final StringBuilder bookSet = new StringBuilder("(");
|
||||||
|
boolean first = true;
|
||||||
|
for (Book b : books) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
bookSet.append(",");
|
||||||
|
}
|
||||||
|
bookSet.append(b.getId());
|
||||||
|
}
|
||||||
|
bookSet.append(")");
|
||||||
|
myDatabase.execSQL(
|
||||||
|
"UPDATE Books SET `exists` = " + (flag ? 1 : 0) + " WHERE book_id IN " + bookSet
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private SQLiteStatement myUpdateBookInfoStatement;
|
private SQLiteStatement myUpdateBookInfoStatement;
|
||||||
|
@Override
|
||||||
protected void updateBookInfo(long bookId, long fileId, String encoding, String language, String title) {
|
protected void updateBookInfo(long bookId, long fileId, String encoding, String language, String title) {
|
||||||
if (myUpdateBookInfoStatement == null) {
|
if (myUpdateBookInfoStatement == null) {
|
||||||
myUpdateBookInfoStatement = myDatabase.compileStatement(
|
myUpdateBookInfoStatement = myDatabase.compileStatement(
|
||||||
|
@ -1186,4 +1210,10 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
"hyperlink_id TEXT NOT NULL," +
|
"hyperlink_id TEXT NOT NULL," +
|
||||||
"CONSTRAINT VisitedHyperlinks_Unique UNIQUE (book_id, hyperlink_id))");
|
"CONSTRAINT VisitedHyperlinks_Unique UNIQUE (book_id, hyperlink_id))");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateTables16() {
|
||||||
|
myDatabase.execSQL(
|
||||||
|
"ALTER TABLE Books ADD COLUMN `exists` INTEGER DEFAULT 1"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,8 @@ public abstract class BooksDatabase {
|
||||||
protected abstract void executeAsATransaction(Runnable actions);
|
protected abstract void executeAsATransaction(Runnable actions);
|
||||||
|
|
||||||
// returns map fileId -> book
|
// returns map fileId -> book
|
||||||
protected abstract Map<Long,Book> loadBooks(FileInfoSet infos);
|
protected abstract Map<Long,Book> loadBooks(FileInfoSet infos, boolean existing);
|
||||||
|
protected abstract void setExistingFlag(Collection<Book> books, boolean flag);
|
||||||
protected abstract Book loadBook(long bookId);
|
protected abstract Book loadBook(long bookId);
|
||||||
protected abstract void reloadBook(Book book);
|
protected abstract void reloadBook(Book book);
|
||||||
protected abstract Book loadBookByFile(long fileId, ZLFile file);
|
protected abstract Book loadBookByFile(long fileId, ZLFile file);
|
||||||
|
|
|
@ -209,7 +209,7 @@ public final class Library {
|
||||||
|
|
||||||
FileInfoSet fileInfos = new FileInfoSet();
|
FileInfoSet fileInfos = new FileInfoSet();
|
||||||
|
|
||||||
final Map<Long,Book> savedBooks = BooksDatabase.Instance().loadBooks(fileInfos);
|
final Map<Long,Book> savedBooks = BooksDatabase.Instance().loadBooks(fileInfos, true);
|
||||||
|
|
||||||
for (ZLPhysicalFile file : physicalFilesList) {
|
for (ZLPhysicalFile file : physicalFilesList) {
|
||||||
// TODO: better value for this flag
|
// TODO: better value for this flag
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue