DBIx::Class::Storage - Generic Storage Handler |
DBIx::Class::Storage - Generic Storage Handler
A base implementation of common Storage methods. For specific information about the DBI manpage-based storage, see the DBIx::Class::Storage::DBI manpage.
Arguments: $schema
Instantiates the Storage object.
Used to reset the schema class or object which owns this storage object, such as during clone in the DBIx::Class::Schema manpage.
Returns true if we have an open storage connection, false if it is not (yet) open.
Closes any open storage connection unconditionally.
Initiate a connection to the storage if one isn't already open.
Throws an exception - croaks.
$coderef
, @coderef_args?Executes $coderef
with (optional) arguments @coderef_args
atomically,
returning its result (if any). If an exception is caught, a rollback is issued
and the exception is rethrown. If the rollback fails, (i.e. throws an
exception) an exception is thrown that includes a ``Rollback failed'' message.
For example,
my $author_rs = $schema->resultset('Author')->find(1); my @titles = qw/Night Day It/;
my $coderef = sub { # If any one of these fails, the entire transaction fails $author_rs->create_related('books', { title => $_ }) foreach (@titles);
return $author->books; };
my $rs; eval { $rs = $schema->txn_do($coderef); };
if ($@) { # Transaction failed die "something terrible has happened!" # if ($@ =~ /Rollback failed/); # Rollback failed
deal_with_failed_transaction(); }
In a nested transaction (calling txn_do()
from within a txn_do()
coderef) only
the outermost transaction will issue a txn_commit, and txn_do()
can be
called in void, scalar and list context and it will behave as expected.
Please note that all of the code in your coderef, including non-DBIx::Class code, is part of a transaction. This transaction may fail out halfway, or it may get partially double-executed (in the case that our DB connection failed halfway through the transaction, in which case we reconnect and restart the txn). Therefore it is best that any side-effects in your coderef are idempotent (that is, can be re-executed multiple times and get the same result), and that you check up on your side-effects in the case of transaction failure.
Starts a transaction.
See the preferred txn_do method, which allows for an entire code block to be executed transactionally.
Issues a commit of the current transaction.
Issues a rollback of the current transaction. A nested rollback will throw a the DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION manpage exception, which allows the rollback to propagate to the outermost transaction.
Returns a sql_maker
object - normally an object of class
DBIC::SQL::Abstract
.
Causes trace information to be emitted on the debugobj
object.
(or STDERR
if debugobj
has not specifically been set).
This is the equivalent to setting DBIC_TRACE in your shell environment.
Set or retrieve the filehandle used for trace/debug output. This should be
an IO::Handle compatible ojbect (only the print
method is used. Initially
set to be STDERR - although see information on the
DBIC_TRACE environment variable.
Sets or retrieves the object used for metric collection. Defaults to an instance of the DBIx::Class::Storage::Statistics manpage that is compatible with the original method of using a coderef as a callback. See the aforementioned Statistics class for more information.
Sets a callback to be executed each time a statement is run; takes a sub reference. Callback is executed as $sub->($op, $info) where $op is SELECT/INSERT/UPDATE/DELETE and $info is what would normally be printed.
See the debugobj manpage for a better way.
The cursor class for this Storage object.
Deploy the tables to storage (CREATE TABLE and friends in a SQL-based Storage class). This would normally be called through deploy in the DBIx::Class::Schema manpage.
The arguments of connect_info
are always a single array reference,
and are Storage-handler specific.
This is normally accessed via connection in the DBIx::Class::Schema manpage, which
encapsulates its argument list in an arrayref before calling
connect_info
here.
Handle a select statement.
Handle an insert statement.
Handle an update statement.
Handle a delete statement.
Performs a select, fetch and return of data - handles a single row only.
Returns metadata for the given source's columns. This is *deprecated*, and will be removed before 1.0. You should be specifying the metadata yourself if you need it.
If DBIC_TRACE
is set then trace information
is produced (as when the the debug manpage method is set).
If the value is of the form 1=/path/name
then the trace output is
written to the file /path/name
.
This environment variable is checked when the storage object is first created (when you call connect on your schema). So, run-time changes to this environment variable will not take effect unless you also re-connect on your schema.
Old name for DBIC_TRACE
Matt S. Trout <mst@shadowcatsystems.co.uk>
Andy Grundman <andy@hybridized.org>
You may distribute this code under the same terms as Perl itself.
DBIx::Class::Storage - Generic Storage Handler |