diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-04-13 17:03:16 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-04-13 17:03:16 +0100 |
commit | 89a67770e66d11740948e90a41db6cee0482cf8e (patch) | |
tree | be858515fb789a89d68f94975690ab019813726c /lib/dm-sqlite-adapter-with-mutex.rb |
new version.
Diffstat (limited to 'lib/dm-sqlite-adapter-with-mutex.rb')
-rw-r--r-- | lib/dm-sqlite-adapter-with-mutex.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/dm-sqlite-adapter-with-mutex.rb b/lib/dm-sqlite-adapter-with-mutex.rb new file mode 100644 index 0000000..2842c5e --- /dev/null +++ b/lib/dm-sqlite-adapter-with-mutex.rb @@ -0,0 +1,28 @@ +# +# Add a mutex so that we can avoid the 'database is locked' Sqlite3Error +# exception. +# +require 'dm-sqlite-adapter' +require 'monitor' + +ADAPTER = DataMapper::Adapters::SqliteAdapter + +# better way to alias a private method? (other than "don't"? :) ) +ADAPTER.__send__(:alias_method, :initialize_old, :initialize) +ADAPTER.__send__(:undef_method, :initialize) +ADAPTER.__send__(:alias_method, :with_connection_old, :with_connection) +ADAPTER.__send__(:undef_method, :with_connection) + +class ADAPTER + + def initialize(*a) + extend(MonitorMixin) + initialize_old(*a) + end + + private + + def with_connection(&block) + synchronize { with_connection_old(&block) } + end +end |