mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
book uid (in progress)
This commit is contained in:
parent
3f956fbc51
commit
c870e32055
8 changed files with 54 additions and 7 deletions
|
@ -282,6 +282,17 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized Book getBookByUid(UID uid) {
|
||||
if (myInterface == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return SerializerUtil.deserializeBook(myInterface.getBookByUid(uid.Type, uid.Id));
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized List<Author> authors() {
|
||||
if (myInterface == null) {
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -23,8 +23,10 @@ interface LibraryInterface {
|
|||
boolean hasBooksForPattern(in String pattern);
|
||||
List<String> booksForPattern(in String pattern);
|
||||
List<String> recentBooks();
|
||||
|
||||
String getBookByFile(in String file);
|
||||
String getBookById(in long id);
|
||||
String getBookByUid(in String type, in String id);
|
||||
String getRecentBook(in int index);
|
||||
|
||||
List<String> authors();
|
||||
|
|
|
@ -192,6 +192,10 @@ public class LibraryService extends Service {
|
|||
return SerializerUtil.serialize(myCollection.getBookById(id));
|
||||
}
|
||||
|
||||
public String getBookByUid(String type, String id) {
|
||||
return SerializerUtil.serialize(myCollection.getBookByUid(new UID(type, id)));
|
||||
}
|
||||
|
||||
public List<String> authors() {
|
||||
final List<Author> authors = myCollection.authors();
|
||||
final List<String> strings = new ArrayList<String>(authors.size());
|
||||
|
|
|
@ -361,7 +361,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
protected List<Author> listAuthors(long bookId) {
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT Authors.name,Authors.sort_key FROM BookAuthor INNER JOIN Authors ON Authors.author_id = BookAuthor.author_id WHERE BookAuthor.book_id = ?", new String[] { "" + bookId });
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT Authors.name,Authors.sort_key FROM BookAuthor INNER JOIN Authors ON Authors.author_id = BookAuthor.author_id WHERE BookAuthor.book_id = ?", new String[] { String.valueOf(bookId) });
|
||||
if (!cursor.moveToNext()) {
|
||||
cursor.close();
|
||||
return null;
|
||||
|
@ -440,7 +440,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
private Tag getTagById(long id) {
|
||||
Tag tag = myTagById.get(id);
|
||||
if (tag == null) {
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT parent_id,name FROM Tags WHERE tag_id = ?", new String[] { "" + id });
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT parent_id,name FROM Tags WHERE tag_id = ?", new String[] { String.valueOf(id) });
|
||||
if (cursor.moveToNext()) {
|
||||
final Tag parent = cursor.isNull(0) ? null : getTagById(cursor.getLong(0));
|
||||
tag = Tag.getTag(parent, cursor.getString(1));
|
||||
|
@ -453,7 +453,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
protected List<Tag> listTags(long bookId) {
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT Tags.tag_id FROM BookTag INNER JOIN Tags ON Tags.tag_id = BookTag.tag_id WHERE BookTag.book_id = ?", new String[] { "" + bookId });
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT Tags.tag_id FROM BookTag INNER JOIN Tags ON Tags.tag_id = BookTag.tag_id WHERE BookTag.book_id = ?", new String[] { String.valueOf(bookId) });
|
||||
if (!cursor.moveToNext()) {
|
||||
cursor.close();
|
||||
return null;
|
||||
|
@ -467,6 +467,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
private SQLiteStatement myInsertBookUidStatement;
|
||||
@Override
|
||||
protected void saveBookUid(long bookId, UID uid) {
|
||||
if (myInsertBookUidStatement == null) {
|
||||
myInsertBookUidStatement = myDatabase.compileStatement(
|
||||
|
@ -482,16 +483,28 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<UID> listUids(long bookId) {
|
||||
final ArrayList<UID> list = new ArrayList<UID>();
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT type,uid FROM BookUid WHERE book_id = ?", new String[] { "" + bookId });
|
||||
if (cursor.moveToNext()) {
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT type,uid FROM BookUid WHERE book_id = ?", new String[] { String.valueOf(bookId) });
|
||||
while (cursor.moveToNext()) {
|
||||
list.add(new UID(cursor.getString(0), cursor.getString(1)));
|
||||
}
|
||||
cursor.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long bookIdByUid(UID uid) {
|
||||
Long bookId = null;
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT book_id FROM BookUid WHERE type = ? AND uid = ?", new String[] { uid.Type, uid.Id });
|
||||
if (cursor.moveToNext()) {
|
||||
bookId = cursor.getLong(0);
|
||||
}
|
||||
cursor.close();
|
||||
return bookId;
|
||||
}
|
||||
|
||||
private SQLiteStatement myGetSeriesIdStatement;
|
||||
private SQLiteStatement myInsertSeriesStatement;
|
||||
private SQLiteStatement myInsertBookSeriesStatement;
|
||||
|
@ -535,7 +548,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
protected SeriesInfo getSeriesInfo(long bookId) {
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT Series.name,BookSeries.book_index FROM BookSeries INNER JOIN Series ON Series.series_id = BookSeries.series_id WHERE BookSeries.book_id = ?", new String[] { "" + bookId });
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT Series.name,BookSeries.book_index FROM BookSeries INNER JOIN Series ON Series.series_id = BookSeries.series_id WHERE BookSeries.book_id = ?", new String[] { String.valueOf(bookId) });
|
||||
SeriesInfo info = null;
|
||||
if (cursor.moveToNext()) {
|
||||
info = SeriesInfo.createSeriesInfo(cursor.getString(0), cursor.getString(1));
|
||||
|
@ -991,7 +1004,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
protected Collection<String> loadVisitedHyperlinks(long bookId) {
|
||||
final TreeSet<String> links = new TreeSet<String>();
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT hyperlink_id FROM VisitedHyperlinks WHERE book_id = ?", new String[] { "" + bookId });
|
||||
final Cursor cursor = myDatabase.rawQuery("SELECT hyperlink_id FROM VisitedHyperlinks WHERE book_id = ?", new String[] { String.valueOf(bookId) });
|
||||
while (cursor.moveToNext()) {
|
||||
links.add(cursor.getString(0));
|
||||
}
|
||||
|
|
|
@ -310,6 +310,10 @@ public class Book extends TitledEntity {
|
|||
addTag(Tag.getTag(null, tagName));
|
||||
}
|
||||
|
||||
public boolean matchesUid(UID uid) {
|
||||
return myUids.contains(uid);
|
||||
}
|
||||
|
||||
public boolean matches(String pattern) {
|
||||
if (MiscUtil.matchesIgnoreCase(getTitle(), pattern)) {
|
||||
return true;
|
||||
|
|
|
@ -146,6 +146,16 @@ public class BookCollection extends AbstractBookCollection {
|
|||
}
|
||||
}
|
||||
|
||||
public Book getBookByUid(UID uid) {
|
||||
for (Book book : myBooksById.values()) {
|
||||
if (book.matchesUid(uid)) {
|
||||
return book;
|
||||
}
|
||||
}
|
||||
final Long bookId = myDatabase.bookIdByUid(uid);
|
||||
return bookId != null ? getBookById(bookId) : null;
|
||||
}
|
||||
|
||||
private void addBook(Book book, boolean force) {
|
||||
if (book == null || book.getId() == -1) {
|
||||
return;
|
||||
|
|
|
@ -56,6 +56,8 @@ public abstract class BooksDatabase {
|
|||
protected abstract SeriesInfo getSeriesInfo(long bookId);
|
||||
protected abstract List<UID> listUids(long bookId);
|
||||
|
||||
protected abstract Long bookIdByUid(UID uid);
|
||||
|
||||
protected abstract void updateBookInfo(long bookId, long fileId, String encoding, String language, String title);
|
||||
protected abstract long insertBookInfo(ZLFile file, String encoding, String language, String title);
|
||||
protected abstract void deleteAllBookAuthors(long bookId);
|
||||
|
|
|
@ -71,6 +71,7 @@ public interface IBookCollection {
|
|||
|
||||
Book getBookByFile(ZLFile file);
|
||||
Book getBookById(long id);
|
||||
Book getBookByUid(UID uid);
|
||||
|
||||
List<Author> authors();
|
||||
boolean hasSeries();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue