public boolean save() { if (myIsSaved) { return false; } final BooksDatabase database = BooksDatabase.Instance(); database.executeAsATransaction( new Runnable() { public void run() { if (myId >= 0) { final FileInfoSet fileInfos = new FileInfoSet(File); database.updateBookInfo(myId, fileInfos.getId(File), myEncoding, myLanguage, myTitle); } else { myId = database.insertBookInfo(File, myEncoding, myLanguage, myTitle); storeAllVisitedHyperinks(); } long index = 0; database.deleteAllBookAuthors(myId); for (Author author : authors()) { database.saveBookAuthorInfo(myId, index++, author); } database.deleteAllBookTags(myId); for (Tag tag : tags()) { database.saveBookTagInfo(myId, tag); } database.saveBookSeriesInfo(myId, mySeriesInfo); } }); myIsSaved = true; return true; }
public static Book getByFile(ZLFile bookFile) { if (bookFile == null) { return null; } final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile(); if (physicalFile != null && !physicalFile.exists()) { return null; } final FileInfoSet fileInfos = new FileInfoSet(bookFile); Book book = BooksDatabase.Instance().loadBookByFile(fileInfos.getId(bookFile), bookFile); if (book != null) { book.loadLists(); } if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) { return book; } fileInfos.save(); if (book == null) { book = new Book(bookFile); } if (book.readMetaInfo()) { book.save(); return book; } return null; }
private void storeAllVisitedHyperinks() { if (myId != -1 && myVisitedHyperlinks != null) { for (String linkId : myVisitedHyperlinks) { BooksDatabase.Instance().addVisitedHyperlink(myId, linkId); } } }
private void loadLists() { final BooksDatabase database = BooksDatabase.Instance(); myAuthors = database.loadAuthors(myId); myTags = database.loadTags(myId); mySeriesInfo = database.loadSeriesInfo(myId); myIsSaved = true; }
private void initHyperlinkSet() { if (myVisitedHyperlinks == null) { myVisitedHyperlinks = new TreeSet<String>(); if (myId != -1) { myVisitedHyperlinks.addAll(BooksDatabase.Instance().loadVisitedHyperlinks(myId)); } } }
public void reloadInfoFromDatabase() { final BooksDatabase database = BooksDatabase.Instance(); database.reloadBook(this); myAuthors = database.loadAuthors(myId); myTags = database.loadTags(myId); mySeriesInfo = database.loadSeriesInfo(myId); myIsSaved = true; }
public void markHyperlinkAsVisited(String linkId) { initHyperlinkSet(); if (!myVisitedHyperlinks.contains(linkId)) { myVisitedHyperlinks.add(linkId); if (myId != -1) { BooksDatabase.Instance().addVisitedHyperlink(myId, linkId); } } }
public static Book getById(long bookId) { final Book book = BooksDatabase.Instance().loadBook(bookId); if (book == null) { return null; } book.loadLists(); final ZLFile bookFile = book.File; final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile(); if (physicalFile == null) { return book; } if (!physicalFile.exists()) { return null; } FileInfoSet fileInfos = new FileInfoSet(physicalFile); if (fileInfos.check(physicalFile, physicalFile != bookFile)) { return book; } fileInfos.save(); return book.readMetaInfo() ? book : null; }
public void insertIntoBookList() { if (myId != -1) { BooksDatabase.Instance().insertIntoBookList(myId); } }
public void storePosition(ZLTextPosition position) { if (myId != -1) { BooksDatabase.Instance().storePosition(myId, position); } }
public ZLTextPosition getStoredPosition() { return BooksDatabase.Instance().getStoredPosition(myId); }