protected Book createBook(long id, long fileId, String title, String encoding, String language) { final FileInfoSet infos = new FileInfoSet(fileId); return createBook(id, infos.getFile(fileId), title, encoding, language); }
@Override protected Map<Long, Book> loadBooks(FileInfoSet infos, boolean existing) { Cursor cursor = myDatabase.rawQuery( "SELECT book_id,file_id,title,encoding,language FROM Books WHERE `exists` = " + (existing ? 1 : 0), null); final HashMap<Long, Book> booksById = new HashMap<Long, Book>(); final HashMap<Long, Book> booksByFileId = new HashMap<Long, Book>(); while (cursor.moveToNext()) { final long id = cursor.getLong(0); final long fileId = cursor.getLong(1); final Book book = createBook( id, infos.getFile(fileId), cursor.getString(2), cursor.getString(3), cursor.getString(4)); if (book != null) { booksById.put(id, book); booksByFileId.put(fileId, book); } } cursor.close(); initTagCache(); cursor = myDatabase.rawQuery("SELECT author_id,name,sort_key FROM Authors", null); final HashMap<Long, Author> authorById = new HashMap<Long, Author>(); while (cursor.moveToNext()) { authorById.put(cursor.getLong(0), new Author(cursor.getString(1), cursor.getString(2))); } cursor.close(); cursor = myDatabase.rawQuery("SELECT book_id,author_id FROM BookAuthor ORDER BY author_index", null); while (cursor.moveToNext()) { Book book = booksById.get(cursor.getLong(0)); if (book != null) { Author author = authorById.get(cursor.getLong(1)); if (author != null) { addAuthor(book, author); } } } cursor.close(); cursor = myDatabase.rawQuery("SELECT book_id,tag_id FROM BookTag", null); while (cursor.moveToNext()) { Book book = booksById.get(cursor.getLong(0)); if (book != null) { addTag(book, getTagById(cursor.getLong(1))); } } cursor.close(); cursor = myDatabase.rawQuery("SELECT series_id,name FROM Series", null); final HashMap<Long, String> seriesById = new HashMap<Long, String>(); while (cursor.moveToNext()) { seriesById.put(cursor.getLong(0), cursor.getString(1)); } cursor.close(); cursor = myDatabase.rawQuery("SELECT book_id,series_id,book_index FROM BookSeries", null); while (cursor.moveToNext()) { Book book = booksById.get(cursor.getLong(0)); if (book != null) { final String series = seriesById.get(cursor.getLong(1)); if (series != null) { setSeriesInfo(book, series, cursor.getString(2)); } } } cursor.close(); return booksByFileId; }