1
0
Fork 0
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:
Nikolay Pultsin 2013-01-14 07:05:09 +04:00
parent d9b061117a
commit e588c37b3b
5 changed files with 22 additions and 18 deletions

View file

@ -319,7 +319,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
SQLiteUtil.bindString(myInsertBookInfoStatement, 1, encoding);
SQLiteUtil.bindString(myInsertBookInfoStatement, 2, language);
myInsertBookInfoStatement.bindString(3, title);
final FileInfoSet infoSet = new FileInfoSet(file);
final FileInfoSet infoSet = new FileInfoSet(this, file);
myInsertBookInfoStatement.bindLong(4, infoSet.getId(file));
return myInsertBookInfoStatement.executeInsert();
}
@ -981,7 +981,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
}
private void updateTables4() {
final FileInfoSet fileInfos = new FileInfoSet();
final FileInfoSet fileInfos = new FileInfoSet(this);
final Cursor cursor = myDatabase.rawQuery(
"SELECT file_name FROM Books", null
);
@ -1070,7 +1070,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
);
myDatabase.execSQL("DELETE FROM Files");
final FileInfoSet infoSet = new FileInfoSet();
final FileInfoSet infoSet = new FileInfoSet(this);
Cursor cursor = myDatabase.rawQuery(
"SELECT file_name FROM Books", null
);

View file

@ -55,7 +55,7 @@ public class Book {
return null;
}
FileInfoSet fileInfos = new FileInfoSet(physicalFile);
FileInfoSet fileInfos = new FileInfoSet(BooksDatabase.Instance(), physicalFile);
if (fileInfos.check(physicalFile, physicalFile != bookFile)) {
return book;
}
@ -79,7 +79,7 @@ public class Book {
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);
if (book != null) {
@ -411,7 +411,7 @@ public class Book {
database.executeAsATransaction(new Runnable() {
public void run() {
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);
} else {
myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle);

View file

@ -39,7 +39,7 @@ public abstract class BooksDatabase {
}
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);
}
protected Book createBook(long id, ZLFile file, String title, String encoding, String language) {

View file

@ -60,16 +60,21 @@ public final class FileInfoSet {
private final LinkedHashSet<FileInfo> myInfosToSave = new LinkedHashSet<FileInfo>();
private final LinkedHashSet<FileInfo> myInfosToRemove = new LinkedHashSet<FileInfo>();
public FileInfoSet() {
load(BooksDatabase.Instance().loadFileInfos());
private final BooksDatabase myDatabase;
public FileInfoSet(BooksDatabase database) {
myDatabase = database;
load(database.loadFileInfos());
}
public FileInfoSet(ZLFile file) {
load(BooksDatabase.Instance().loadFileInfos(file));
public FileInfoSet(BooksDatabase database, ZLFile file) {
myDatabase = database;
load(database.loadFileInfos(file));
}
FileInfoSet(long fileId) {
load(BooksDatabase.Instance().loadFileInfos(fileId));
FileInfoSet(BooksDatabase database, long fileId) {
myDatabase = database;
load(database.loadFileInfos(fileId));
}
private void load(Collection<FileInfo> infos) {
@ -80,16 +85,15 @@ public final class FileInfoSet {
}
public void save() {
final BooksDatabase database = BooksDatabase.Instance();
database.executeAsATransaction(new Runnable() {
myDatabase.executeAsATransaction(new Runnable() {
public void run() {
for (FileInfo info : myInfosToRemove) {
database.removeFileInfo(info.Id);
myDatabase.removeFileInfo(info.Id);
myInfosByPair.remove(new Pair(info.Name, info.Parent));
}
myInfosToRemove.clear();
for (FileInfo info : myInfosToSave) {
database.saveFileInfo(info);
myDatabase.saveFileInfo(info);
}
myInfosToSave.clear();
}

View file

@ -334,7 +334,7 @@ public final class Library {
private void build() {
// 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> savedBooksByBookId = new HashMap<Long,Book>();
for (Book b : savedBooksByFileId.values()) {