mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
database parameter in FileInfoSet constructors
This commit is contained in:
parent
d9b061117a
commit
e588c37b3b
5 changed files with 22 additions and 18 deletions
|
@ -319,7 +319,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
SQLiteUtil.bindString(myInsertBookInfoStatement, 1, encoding);
|
SQLiteUtil.bindString(myInsertBookInfoStatement, 1, encoding);
|
||||||
SQLiteUtil.bindString(myInsertBookInfoStatement, 2, language);
|
SQLiteUtil.bindString(myInsertBookInfoStatement, 2, language);
|
||||||
myInsertBookInfoStatement.bindString(3, title);
|
myInsertBookInfoStatement.bindString(3, title);
|
||||||
final FileInfoSet infoSet = new FileInfoSet(file);
|
final FileInfoSet infoSet = new FileInfoSet(this, file);
|
||||||
myInsertBookInfoStatement.bindLong(4, infoSet.getId(file));
|
myInsertBookInfoStatement.bindLong(4, infoSet.getId(file));
|
||||||
return myInsertBookInfoStatement.executeInsert();
|
return myInsertBookInfoStatement.executeInsert();
|
||||||
}
|
}
|
||||||
|
@ -981,7 +981,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTables4() {
|
private void updateTables4() {
|
||||||
final FileInfoSet fileInfos = new FileInfoSet();
|
final FileInfoSet fileInfos = new FileInfoSet(this);
|
||||||
final Cursor cursor = myDatabase.rawQuery(
|
final Cursor cursor = myDatabase.rawQuery(
|
||||||
"SELECT file_name FROM Books", null
|
"SELECT file_name FROM Books", null
|
||||||
);
|
);
|
||||||
|
@ -1070,7 +1070,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
);
|
);
|
||||||
|
|
||||||
myDatabase.execSQL("DELETE FROM Files");
|
myDatabase.execSQL("DELETE FROM Files");
|
||||||
final FileInfoSet infoSet = new FileInfoSet();
|
final FileInfoSet infoSet = new FileInfoSet(this);
|
||||||
Cursor cursor = myDatabase.rawQuery(
|
Cursor cursor = myDatabase.rawQuery(
|
||||||
"SELECT file_name FROM Books", null
|
"SELECT file_name FROM Books", null
|
||||||
);
|
);
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class Book {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfoSet fileInfos = new FileInfoSet(physicalFile);
|
FileInfoSet fileInfos = new FileInfoSet(BooksDatabase.Instance(), physicalFile);
|
||||||
if (fileInfos.check(physicalFile, physicalFile != bookFile)) {
|
if (fileInfos.check(physicalFile, physicalFile != bookFile)) {
|
||||||
return book;
|
return book;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public class Book {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final FileInfoSet fileInfos = new FileInfoSet(bookFile);
|
final FileInfoSet fileInfos = new FileInfoSet(BooksDatabase.Instance(), bookFile);
|
||||||
|
|
||||||
Book book = BooksDatabase.Instance().loadBookByFile(fileInfos.getId(bookFile), bookFile);
|
Book book = BooksDatabase.Instance().loadBookByFile(fileInfos.getId(bookFile), bookFile);
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
|
@ -411,7 +411,7 @@ public class Book {
|
||||||
database.executeAsATransaction(new Runnable() {
|
database.executeAsATransaction(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (myId >= 0) {
|
if (myId >= 0) {
|
||||||
final FileInfoSet fileInfos = new FileInfoSet(File);
|
final FileInfoSet fileInfos = new FileInfoSet(database, File);
|
||||||
database.updateBookInfo(myId, fileInfos.getId(File), myEncoding, myLanguage, myTitle);
|
database.updateBookInfo(myId, fileInfos.getId(File), myEncoding, myLanguage, myTitle);
|
||||||
} else {
|
} else {
|
||||||
myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle);
|
myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle);
|
||||||
|
|
|
@ -39,7 +39,7 @@ public abstract class BooksDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Book createBook(long id, long fileId, String title, String encoding, String language) {
|
protected Book createBook(long id, long fileId, String title, String encoding, String language) {
|
||||||
final FileInfoSet infos = new FileInfoSet(fileId);
|
final FileInfoSet infos = new FileInfoSet(this, fileId);
|
||||||
return createBook(id, infos.getFile(fileId), title, encoding, language);
|
return createBook(id, infos.getFile(fileId), title, encoding, language);
|
||||||
}
|
}
|
||||||
protected Book createBook(long id, ZLFile file, String title, String encoding, String language) {
|
protected Book createBook(long id, ZLFile file, String title, String encoding, String language) {
|
||||||
|
|
|
@ -60,16 +60,21 @@ public final class FileInfoSet {
|
||||||
private final LinkedHashSet<FileInfo> myInfosToSave = new LinkedHashSet<FileInfo>();
|
private final LinkedHashSet<FileInfo> myInfosToSave = new LinkedHashSet<FileInfo>();
|
||||||
private final LinkedHashSet<FileInfo> myInfosToRemove = new LinkedHashSet<FileInfo>();
|
private final LinkedHashSet<FileInfo> myInfosToRemove = new LinkedHashSet<FileInfo>();
|
||||||
|
|
||||||
public FileInfoSet() {
|
private final BooksDatabase myDatabase;
|
||||||
load(BooksDatabase.Instance().loadFileInfos());
|
|
||||||
|
public FileInfoSet(BooksDatabase database) {
|
||||||
|
myDatabase = database;
|
||||||
|
load(database.loadFileInfos());
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileInfoSet(ZLFile file) {
|
public FileInfoSet(BooksDatabase database, ZLFile file) {
|
||||||
load(BooksDatabase.Instance().loadFileInfos(file));
|
myDatabase = database;
|
||||||
|
load(database.loadFileInfos(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfoSet(long fileId) {
|
FileInfoSet(BooksDatabase database, long fileId) {
|
||||||
load(BooksDatabase.Instance().loadFileInfos(fileId));
|
myDatabase = database;
|
||||||
|
load(database.loadFileInfos(fileId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load(Collection<FileInfo> infos) {
|
private void load(Collection<FileInfo> infos) {
|
||||||
|
@ -80,16 +85,15 @@ public final class FileInfoSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
final BooksDatabase database = BooksDatabase.Instance();
|
myDatabase.executeAsATransaction(new Runnable() {
|
||||||
database.executeAsATransaction(new Runnable() {
|
|
||||||
public void run() {
|
public void run() {
|
||||||
for (FileInfo info : myInfosToRemove) {
|
for (FileInfo info : myInfosToRemove) {
|
||||||
database.removeFileInfo(info.Id);
|
myDatabase.removeFileInfo(info.Id);
|
||||||
myInfosByPair.remove(new Pair(info.Name, info.Parent));
|
myInfosByPair.remove(new Pair(info.Name, info.Parent));
|
||||||
}
|
}
|
||||||
myInfosToRemove.clear();
|
myInfosToRemove.clear();
|
||||||
for (FileInfo info : myInfosToSave) {
|
for (FileInfo info : myInfosToSave) {
|
||||||
database.saveFileInfo(info);
|
myDatabase.saveFileInfo(info);
|
||||||
}
|
}
|
||||||
myInfosToSave.clear();
|
myInfosToSave.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -334,7 +334,7 @@ public final class Library {
|
||||||
|
|
||||||
private void build() {
|
private void build() {
|
||||||
// Step 0: get database books marked as "existing"
|
// Step 0: get database books marked as "existing"
|
||||||
final FileInfoSet fileInfos = new FileInfoSet();
|
final FileInfoSet fileInfos = new FileInfoSet(myDatabase);
|
||||||
final Map<Long,Book> savedBooksByFileId = myDatabase.loadBooks(fileInfos, true);
|
final Map<Long,Book> savedBooksByFileId = myDatabase.loadBooks(fileInfos, true);
|
||||||
final Map<Long,Book> savedBooksByBookId = new HashMap<Long,Book>();
|
final Map<Long,Book> savedBooksByBookId = new HashMap<Long,Book>();
|
||||||
for (Book b : savedBooksByFileId.values()) {
|
for (Book b : savedBooksByFileId.values()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue