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

manual merging with steffen branch: visited hyperlinks engine

This commit is contained in:
Nikolay Pultsin 2011-03-25 22:17:02 +00:00
parent 343f0818a2
commit f9a3335ce5
7 changed files with 94 additions and 10 deletions

View file

@ -61,7 +61,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
private void migrate(Context context) {
final int version = myDatabase.getVersion();
final int currentVersion = 15;
final int currentVersion = 16;
if (version >= currentVersion) {
return;
}
@ -100,6 +100,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
updateTables13();
case 14:
updateTables14();
case 15:
updateTables15();
}
myDatabase.setTransactionSuccessful();
myDatabase.endTransaction();
@ -158,7 +160,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
return;
}
myTagCacheIsInitialized = true;
Cursor cursor = myDatabase.rawQuery("SELECT tag_id,parent_id,name FROM Tags ORDER BY tag_id", null);
while (cursor.moveToNext()) {
long id = cursor.getLong(0);
@ -838,6 +840,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
}
myDeleteFromBookListStatement.bindLong(1, bookId);
myDeleteFromBookListStatement.execute();
deleteVisitedHyperlinks(bookId);
return true;
}
@ -852,6 +855,41 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
return myCheckBookListStatement.simpleQueryForLong() > 0;
}
private SQLiteStatement myDeleteVisitedHyperlinksStatement;
private void deleteVisitedHyperlinks(long bookId) {
if (myDeleteVisitedHyperlinksStatement == null) {
myDeleteVisitedHyperlinksStatement = myDatabase.compileStatement(
"DELETE FROM VisitedHyperlinks WHERE book_id = ?"
);
}
myDeleteVisitedHyperlinksStatement.bindLong(1, bookId);
myDeleteVisitedHyperlinksStatement.execute();
}
private SQLiteStatement myStoreVisitedHyperlinksStatement;
protected void addVisitedHyperlink(long bookId, String hyperlinkId) {
if (myStoreVisitedHyperlinksStatement == null) {
myStoreVisitedHyperlinksStatement = myDatabase.compileStatement(
"INSERT OR IGNORE INTO VisitedHyperlinks(book_id,hyperlink_id) VALUES (?,?)"
);
}
myStoreVisitedHyperlinksStatement.bindLong(1, bookId);
myStoreVisitedHyperlinksStatement.bindString(2, hyperlinkId);
myStoreVisitedHyperlinksStatement.execute();
}
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 });
while (cursor.moveToNext()) {
links.add(cursor.getString(0));
}
cursor.close();
return links;
}
private void createTables() {
myDatabase.execSQL(
@ -1140,4 +1178,12 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
myDatabase.execSQL("INSERT INTO BookSeries (series_id,book_id,book_index) SELECT series_id,book_id,book_index FROM BookSeries_Obsolete");
myDatabase.execSQL("DROP TABLE BookSeries_Obsolete");
}
private void updateTables15() {
myDatabase.execSQL(
"CREATE TABLE IF NOT EXISTS VisitedHyperlinks(" +
"book_id INTEGER NOT NULL REFERENCES Books(book_id)," +
"hyperlink_id TEXT NOT NULL," +
"CONSTRAINT VisitedHyperlinks_Unique UNIQUE (book_id, hyperlink_id))");
}
}