Permalink
Browse files

enhance Collection.empty? & Collection.get of DataMapper to prevent s…

…qlite3 local db from the error: database is locked

Change-Id: I6b49984f00673f40b884d4ee2120ee7e6d9a6fa7
  • Loading branch information...
mflu committed Mar 7, 2012
1 parent 0aa2bfb commit bc079711d49161c52ba009c00b04bcbb51953c0d
Binary file not shown.
@@ -45,10 +45,6 @@ def synchronize
# The following code will overwrite DataMapper's functions, and replace
# them with a synchronized version of the same function.
- #
- # NOTICE: some functions will be called twice, for instance, save a resource
- # with foreign keys, so the synchronize function needs to be careful on
- # deadlock.
module Resource
alias original_save save
alias original_destroy destroy
@@ -86,6 +82,8 @@ def all(*args)
class Collection
alias original_each each
alias original_at []
+ alias original_get get
+ alias original_empty? empty?
def each(&block)
instances = []
@@ -102,6 +100,18 @@ def [](*args)
original_at(*args)
end
end
+
+ def get(*args)
+ LOCK.synchronize do
+ original_get(*args)
+ end
+ end
+
+ def empty?()
+ LOCK.synchronize do
+ original_empty?()
+ end
+ end
end
# For auto_upgrade!
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit bc07971

Please sign in to comment.