vonghia / sqlite4java

Automatically exported from code.google.com/p/sqlite4java
0 stars 0 forks source link

Patch to support the Unlock Notify feature for shared-cache mode: blocking prepare and step #36

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I've just begun to investigate using sqlite4java as a database backend for a 
web application.

I noticed in shared cache mode that I was getting a lot SQLITE_LOCKED errors.

I realized I needed sqlite3_unlock_notify() to implement blocking prepare() and 
step() and that sqlite4java hadn't implemented it yet.

So here's a patch for it!

I implemented it based on the documentation/code presented at 
http://www.sqlite.org/unlock_notify.html.

Here's how to enable blocking prepare() and step() (I added Javadoc documention 
too):

SQLiteConnection db = new SQLiteConnection(new File("test.db"));

// must be in shared cache mode to use unlock notify blocking
db.openV2(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE);

// call setBlocking(true) to turn on blocking of prepare() and step()
db.setBlocking(true);

// prepare() and step() will now attempt to block when locked in accordance 
with sqlite3_unlock_notify() documentation

I have tested on my web application in a test environment and I no longer get 
the SQLITE_LOCKED (or SQLITE_LOCKED_SHARECACHE) errors so it's looking good, 
but granted it hasn't been battle-tested yet in any kind of high-traffic 
production environment.

It's my hope you can merge this into the mainline after reviewing it.

Original issue reported on code.google.com by bko...@gmail.com on 22 Sep 2011 at 9:39

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the patch! We'll review it and possibly merge it next time we have 
an iteration on sqlite4java.

Cheers
Igor

Original comment by ser...@gmail.com on 22 Sep 2011 at 10:12

GoogleCodeExporter commented 8 years ago
Due to Google closing Google Code, we have moved sqlite4java project to 
BitBucket. New project home page: 
https://bitbucket.org/almworks/sqlite4java/overview

All issues have been transferred. Unfortunately, it wasn't possible to transfer 
Reporter, Votes and Watches. Please check the issues you are interested in at 
https://bitbucket.org/almworks/sqlite4java/issues?status=new&status=open

Note that the issue tracker on Google Code is no longer tracked and any further 
comments or new issues posted here will be lost when Google Code shuts down.

I apologize for the inconvenience.
Igor Sereda

Original comment by ser...@almworks.com on 28 Jun 2015 at 4:21