mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
network database refactoring; SQLiteUtil class
This commit is contained in:
parent
b7cc36530b
commit
7c679882f4
6 changed files with 90 additions and 55 deletions
|
@ -37,6 +37,7 @@ import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
|||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
import org.geometerplus.android.util.UIUtil;
|
||||
import org.geometerplus.android.util.SQLiteUtil;
|
||||
|
||||
public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||
private final String myInstanceId;
|
||||
|
@ -107,29 +108,6 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}, context);
|
||||
}
|
||||
|
||||
private static void bindString(SQLiteStatement statement, int index, String value) {
|
||||
if (value != null) {
|
||||
statement.bindString(index, value);
|
||||
} else {
|
||||
statement.bindNull(index);
|
||||
}
|
||||
}
|
||||
|
||||
private static void bindDate(SQLiteStatement statement, int index, Date value) {
|
||||
if (value != null) {
|
||||
statement.bindLong(index, value.getTime());
|
||||
} else {
|
||||
statement.bindNull(index);
|
||||
}
|
||||
}
|
||||
|
||||
private static Date getDate(Cursor cursor, int index) {
|
||||
if (cursor.isNull(index)) {
|
||||
return null;
|
||||
}
|
||||
return new Date(cursor.getLong(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Book loadBook(long bookId) {
|
||||
Book book = null;
|
||||
|
@ -278,8 +256,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
);
|
||||
}
|
||||
myUpdateBookInfoStatement.bindLong(1, fileId);
|
||||
bindString(myUpdateBookInfoStatement, 2, encoding);
|
||||
bindString(myUpdateBookInfoStatement, 3, language);
|
||||
SQLiteUtil.bindString(myUpdateBookInfoStatement, 2, encoding);
|
||||
SQLiteUtil.bindString(myUpdateBookInfoStatement, 3, language);
|
||||
myUpdateBookInfoStatement.bindString(4, title);
|
||||
myUpdateBookInfoStatement.bindLong(5, bookId);
|
||||
myUpdateBookInfoStatement.execute();
|
||||
|
@ -292,8 +270,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
"INSERT OR IGNORE INTO Books (encoding,language,title,file_id) VALUES (?,?,?,?)"
|
||||
);
|
||||
}
|
||||
bindString(myInsertBookInfoStatement, 1, encoding);
|
||||
bindString(myInsertBookInfoStatement, 2, language);
|
||||
SQLiteUtil.bindString(myInsertBookInfoStatement, 1, encoding);
|
||||
SQLiteUtil.bindString(myInsertBookInfoStatement, 2, language);
|
||||
myInsertBookInfoStatement.bindString(3, title);
|
||||
final FileInfoSet infoSet = new FileInfoSet(file);
|
||||
myInsertBookInfoStatement.bindLong(4, infoSet.getId(file));
|
||||
|
@ -709,9 +687,9 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
cursor.getLong(1),
|
||||
cursor.getString(2),
|
||||
cursor.getString(3),
|
||||
getDate(cursor, 4),
|
||||
getDate(cursor, 5),
|
||||
getDate(cursor, 6),
|
||||
SQLiteUtil.getDate(cursor, 4),
|
||||
SQLiteUtil.getDate(cursor, 5),
|
||||
SQLiteUtil.getDate(cursor, 6),
|
||||
(int)cursor.getLong(7),
|
||||
cursor.getString(8),
|
||||
(int)cursor.getLong(9),
|
||||
|
@ -737,9 +715,9 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
cursor.getLong(1),
|
||||
cursor.getString(2),
|
||||
cursor.getString(3),
|
||||
getDate(cursor, 4),
|
||||
getDate(cursor, 5),
|
||||
getDate(cursor, 6),
|
||||
SQLiteUtil.getDate(cursor, 4),
|
||||
SQLiteUtil.getDate(cursor, 5),
|
||||
SQLiteUtil.getDate(cursor, 6),
|
||||
(int)cursor.getLong(7),
|
||||
cursor.getString(8),
|
||||
(int)cursor.getLong(9),
|
||||
|
@ -775,11 +753,11 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
statement.bindLong(1, bookmark.getBookId());
|
||||
statement.bindString(2, bookmark.getText());
|
||||
bindDate(statement, 3, bookmark.getTime(Bookmark.CREATION));
|
||||
bindDate(statement, 4, bookmark.getTime(Bookmark.MODIFICATION));
|
||||
bindDate(statement, 5, bookmark.getTime(Bookmark.ACCESS));
|
||||
SQLiteUtil.bindDate(statement, 3, bookmark.getTime(Bookmark.CREATION));
|
||||
SQLiteUtil.bindDate(statement, 4, bookmark.getTime(Bookmark.MODIFICATION));
|
||||
SQLiteUtil.bindDate(statement, 5, bookmark.getTime(Bookmark.ACCESS));
|
||||
statement.bindLong(6, bookmark.getAccessCount());
|
||||
bindString(statement, 7, bookmark.ModelId);
|
||||
SQLiteUtil.bindString(statement, 7, bookmark.ModelId);
|
||||
statement.bindLong(8, bookmark.ParagraphIndex);
|
||||
statement.bindLong(9, bookmark.ElementIndex);
|
||||
statement.bindLong(10, bookmark.CharIndex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue