DBIx-Locker-0.100117

NAME

DBIx::Locker - locks for db resources that might not be totally insane

VERSION

version 0.100117

DESCRIPTION

...and a warning.

DBIx::Locker was written to replace some lousy database resource locking code. The code would establish a MySQL lock with GET_LOCK to lock arbitrary resources. Unfortunately, the code would also silently reconnect in case of database connection failure, silently losing the connection-based lock. DBIx::Locker locks by creating a persistent row in a "locks" table.

Because DBIx::Locker locks are stored in a table, they won't go away. They have to be purged regularly. (A program for doing this, dbix_locker_purge, is included.) The locked resource is just a string. All records in the lock (or semaphore) table are unique on the lock string.

This is the entire mechanism. This is quick and dirty and quite effective, but it's not highly efficient. If you need high speed locks with multiple levels of resolution, or anything other than a quick and brutal solution, keep looking.

METHODS

new

my $locker = DBIx::Locker->new(\%arg);

This returns a new locker.

Valid arguments are:

dbh - a database handle to use for locking
dbi_args - an arrayref of args to pass to DBI->connect to reconnect to db
table - the table for locks

default_dbi_args

default_table

These methods may be defined in subclasses to provide defaults to be used when constructing a new locker.

dbh

This method returns the locker's dbh.

table

This method returns the name of the table in the database in which locks are stored.

lock

my $lock = $locker->lock($lockstring, \%arg);

This method attempts to return a new DBIx::Locker::Lock.

purge_expired_locks

This method deletes expired semaphores.

last_insert_id

This method exists so that subclasses can do something else to support their DBD for getting the id of the created lock. For example, with DBD::ODBC and SQL Server it should be: