Moved ImapDB-specific callback and const into ImapDB.Database

This commit is contained in:
Jim Nelson 2012-07-12 17:58:51 -07:00
parent 94ec845841
commit 510c68ea6f
2 changed files with 20 additions and 11 deletions

View file

@ -5,8 +5,6 @@
*/
private class Geary.ImapDB.Account : Object {
private const int BUSY_TIMEOUT_MSEC = 1000;
private class FolderReference : Geary.SmartReference {
public Geary.FolderPath path;
@ -47,8 +45,8 @@ private class Geary.ImapDB.Account : Object {
db.post_upgrade.connect(on_post_upgrade);
try {
db.open(Db.DatabaseFlags.CREATE_DIRECTORY | Db.DatabaseFlags.CREATE_FILE,
on_prepare_database_connection, cancellable);
db.open(Db.DatabaseFlags.CREATE_DIRECTORY | Db.DatabaseFlags.CREATE_FILE, null,
cancellable);
} catch (Error err) {
warning("Unable to open database: %s", err.message);
@ -81,13 +79,6 @@ private class Geary.ImapDB.Account : Object {
outbox = null;
}
private void on_prepare_database_connection(Db.Connection cx) throws Error {
cx.set_busy_timeout_msec(BUSY_TIMEOUT_MSEC);
cx.set_foreign_keys(true);
cx.set_recursive_triggers(true);
cx.set_synchronous(Db.SynchronousMode.OFF);
}
public async void clone_folder_async(Geary.Imap.Folder imap_folder, Cancellable? cancellable = null)
throws Error {
check_open();

View file

@ -6,9 +6,27 @@
private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
private const string DB_FILENAME = "geary.db";
private const int BUSY_TIMEOUT_MSEC = 1000;
public Database(File db_dir, File schema_dir) {
base (db_dir.get_child(DB_FILENAME), schema_dir);
}
public override void open(Db.DatabaseFlags flags, Db.PrepareConnection? prepare_cb,
Cancellable? cancellable = null) throws Error {
// have to do it this way because delegates don't play well with the ternary or nullable
// operators
if (prepare_cb != null)
base.open(flags, prepare_cb, cancellable);
else
base.open(flags, on_prepare_database_connection, cancellable);
}
private void on_prepare_database_connection(Db.Connection cx) throws Error {
cx.set_busy_timeout_msec(BUSY_TIMEOUT_MSEC);
cx.set_foreign_keys(true);
cx.set_recursive_triggers(true);
cx.set_synchronous(Db.SynchronousMode.OFF);
}
}