1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

book uid (in progress)

This commit is contained in:
Nikolay Pultsin 2013-03-17 03:46:27 +04:00
parent 3f956fbc51
commit c870e32055
8 changed files with 54 additions and 7 deletions

View file

@ -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() { public synchronized List<Author> authors() {
if (myInterface == null) { if (myInterface == null) {
return Collections.emptyList(); return Collections.emptyList();

View file

@ -23,8 +23,10 @@ interface LibraryInterface {
boolean hasBooksForPattern(in String pattern); boolean hasBooksForPattern(in String pattern);
List<String> booksForPattern(in String pattern); List<String> booksForPattern(in String pattern);
List<String> recentBooks(); List<String> recentBooks();
String getBookByFile(in String file); String getBookByFile(in String file);
String getBookById(in long id); String getBookById(in long id);
String getBookByUid(in String type, in String id);
String getRecentBook(in int index); String getRecentBook(in int index);
List<String> authors(); List<String> authors();

View file

@ -192,6 +192,10 @@ public class LibraryService extends Service {
return SerializerUtil.serialize(myCollection.getBookById(id)); 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() { public List<String> authors() {
final List<Author> authors = myCollection.authors(); final List<Author> authors = myCollection.authors();
final List<String> strings = new ArrayList<String>(authors.size()); final List<String> strings = new ArrayList<String>(authors.size());

View file

@ -361,7 +361,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
} }
protected List<Author> listAuthors(long bookId) { 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()) { if (!cursor.moveToNext()) {
cursor.close(); cursor.close();
return null; return null;
@ -440,7 +440,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
private Tag getTagById(long id) { private Tag getTagById(long id) {
Tag tag = myTagById.get(id); Tag tag = myTagById.get(id);
if (tag == null) { 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()) { if (cursor.moveToNext()) {
final Tag parent = cursor.isNull(0) ? null : getTagById(cursor.getLong(0)); final Tag parent = cursor.isNull(0) ? null : getTagById(cursor.getLong(0));
tag = Tag.getTag(parent, cursor.getString(1)); tag = Tag.getTag(parent, cursor.getString(1));
@ -453,7 +453,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
} }
protected List<Tag> listTags(long bookId) { 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()) { if (!cursor.moveToNext()) {
cursor.close(); cursor.close();
return null; return null;
@ -467,6 +467,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
} }
private SQLiteStatement myInsertBookUidStatement; private SQLiteStatement myInsertBookUidStatement;
@Override
protected void saveBookUid(long bookId, UID uid) { protected void saveBookUid(long bookId, UID uid) {
if (myInsertBookUidStatement == null) { if (myInsertBookUidStatement == null) {
myInsertBookUidStatement = myDatabase.compileStatement( myInsertBookUidStatement = myDatabase.compileStatement(
@ -482,16 +483,28 @@ final class SQLiteBooksDatabase extends BooksDatabase {
} }
} }
@Override
protected List<UID> listUids(long bookId) { protected List<UID> listUids(long bookId) {
final ArrayList<UID> list = new ArrayList<UID>(); final ArrayList<UID> list = new ArrayList<UID>();
final Cursor cursor = myDatabase.rawQuery("SELECT type,uid FROM BookUid WHERE book_id = ?", new String[] { "" + bookId }); final Cursor cursor = myDatabase.rawQuery("SELECT type,uid FROM BookUid WHERE book_id = ?", new String[] { String.valueOf(bookId) });
if (cursor.moveToNext()) { while (cursor.moveToNext()) {
list.add(new UID(cursor.getString(0), cursor.getString(1))); list.add(new UID(cursor.getString(0), cursor.getString(1)));
} }
cursor.close(); cursor.close();
return list; 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 myGetSeriesIdStatement;
private SQLiteStatement myInsertSeriesStatement; private SQLiteStatement myInsertSeriesStatement;
private SQLiteStatement myInsertBookSeriesStatement; private SQLiteStatement myInsertBookSeriesStatement;
@ -535,7 +548,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
} }
protected SeriesInfo getSeriesInfo(long bookId) { 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; SeriesInfo info = null;
if (cursor.moveToNext()) { if (cursor.moveToNext()) {
info = SeriesInfo.createSeriesInfo(cursor.getString(0), cursor.getString(1)); info = SeriesInfo.createSeriesInfo(cursor.getString(0), cursor.getString(1));
@ -991,7 +1004,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
protected Collection<String> loadVisitedHyperlinks(long bookId) { protected Collection<String> loadVisitedHyperlinks(long bookId) {
final TreeSet<String> links = new TreeSet<String>(); 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()) { while (cursor.moveToNext()) {
links.add(cursor.getString(0)); links.add(cursor.getString(0));
} }

View file

@ -310,6 +310,10 @@ public class Book extends TitledEntity {
addTag(Tag.getTag(null, tagName)); addTag(Tag.getTag(null, tagName));
} }
public boolean matchesUid(UID uid) {
return myUids.contains(uid);
}
public boolean matches(String pattern) { public boolean matches(String pattern) {
if (MiscUtil.matchesIgnoreCase(getTitle(), pattern)) { if (MiscUtil.matchesIgnoreCase(getTitle(), pattern)) {
return true; return true;

View file

@ -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) { private void addBook(Book book, boolean force) {
if (book == null || book.getId() == -1) { if (book == null || book.getId() == -1) {
return; return;

View file

@ -56,6 +56,8 @@ public abstract class BooksDatabase {
protected abstract SeriesInfo getSeriesInfo(long bookId); protected abstract SeriesInfo getSeriesInfo(long bookId);
protected abstract List<UID> listUids(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 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 long insertBookInfo(ZLFile file, String encoding, String language, String title);
protected abstract void deleteAllBookAuthors(long bookId); protected abstract void deleteAllBookAuthors(long bookId);

View file

@ -71,6 +71,7 @@ public interface IBookCollection {
Book getBookByFile(ZLFile file); Book getBookByFile(ZLFile file);
Book getBookById(long id); Book getBookById(long id);
Book getBookByUid(UID uid);
List<Author> authors(); List<Author> authors();
boolean hasSeries(); boolean hasSeries();