[Bast-commits] r7222 - in
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage:
. DBI DBI/Oracle
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Wed Aug 5 10:09:07 GMT 2009
Author: ribasushi
Date: 2009-08-05 10:09:07 +0000 (Wed, 05 Aug 2009)
New Revision: 7222
Modified:
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI.pm
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/ODBC.pm
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle.pm
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Pg.pm
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Sybase.pm
DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/mysql.pm
Log:
Rename last_dbh and turn it into a public method
Modified: DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/ODBC.pm
===================================================================
--- DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/ODBC.pm 2009-08-05 09:48:04 UTC (rev 7221)
+++ DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/ODBC.pm 2009-08-05 10:09:07 UTC (rev 7222)
@@ -8,7 +8,7 @@
sub _rebless {
my ($self) = @_;
- my $dbtype = eval { $self->_get_dbh->get_info(17) };
+ my $dbtype = eval { $self->last_dbh->get_info(17) };
unless ( $@ ) {
# Translate the backend name into a perl identifier
Modified: DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm
===================================================================
--- DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2009-08-05 09:48:04 UTC (rev 7221)
+++ DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm 2009-08-05 10:09:07 UTC (rev 7222)
@@ -76,7 +76,7 @@
sub _sequence_fetch {
my ( $self, $type, $seq ) = @_;
- my ($id) = $self->_get_dbh->selectrow_array("SELECT ${seq}.${type} FROM DUAL");
+ my ($id) = $self->last_dbh->selectrow_array("SELECT ${seq}.${type} FROM DUAL");
return $id;
}
@@ -209,7 +209,7 @@
sub _svp_begin {
my ($self, $name) = @_;
- $self->_get_dbh->do("SAVEPOINT $name");
+ $self->last_dbh->do("SAVEPOINT $name");
}
=head2 source_bind_attributes
@@ -263,7 +263,7 @@
sub _svp_rollback {
my ($self, $name) = @_;
- $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
+ $self->last_dbh->do("ROLLBACK TO SAVEPOINT $name")
}
=head1 AUTHOR
Modified: DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle.pm
===================================================================
--- DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle.pm 2009-08-05 09:48:04 UTC (rev 7221)
+++ DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Oracle.pm 2009-08-05 10:09:07 UTC (rev 7222)
@@ -9,7 +9,7 @@
sub _rebless {
my ($self) = @_;
- my $version = eval { $self->_get_dbh->get_info(18); };
+ my $version = eval { $self->last_dbh->get_info(18); };
if ( !$@ ) {
my ($major, $minor, $patchlevel) = split(/\./, $version);
Modified: DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Pg.pm
===================================================================
--- DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Pg.pm 2009-08-05 09:48:04 UTC (rev 7221)
+++ DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Pg.pm 2009-08-05 10:09:07 UTC (rev 7222)
@@ -15,7 +15,7 @@
sub with_deferred_fk_checks {
my ($self, $sub) = @_;
- $self->_get_dbh->do('SET CONSTRAINTS ALL DEFERRED');
+ $self->last_dbh->do('SET CONSTRAINTS ALL DEFERRED');
$sub->();
}
@@ -82,26 +82,26 @@
sub _sequence_fetch {
my ( $self, $type, $seq ) = @_;
- my ($id) = $self->_get_dbh->selectrow_array("SELECT nextval('${seq}')");
+ my ($id) = $self->last_dbh->selectrow_array("SELECT nextval('${seq}')");
return $id;
}
sub _svp_begin {
my ($self, $name) = @_;
- $self->_get_dbh->pg_savepoint($name);
+ $self->last_dbh->pg_savepoint($name);
}
sub _svp_release {
my ($self, $name) = @_;
- $self->_get_dbh->pg_release($name);
+ $self->last_dbh->pg_release($name);
}
sub _svp_rollback {
my ($self, $name) = @_;
- $self->_get_dbh->pg_rollback_to($name);
+ $self->last_dbh->pg_rollback_to($name);
}
1;
Modified: DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Sybase.pm
===================================================================
--- DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-08-05 09:48:04 UTC (rev 7221)
+++ DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-08-05 10:09:07 UTC (rev 7222)
@@ -13,7 +13,7 @@
my $self = shift;
my $dbtype = eval {
- @{$self->_get_dbh
+ @{$self->last_dbh
->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})
}[2]
};
Modified: DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/mysql.pm
===================================================================
--- DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/mysql.pm 2009-08-05 09:48:04 UTC (rev 7221)
+++ DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI/mysql.pm 2009-08-05 10:09:07 UTC (rev 7222)
@@ -40,28 +40,28 @@
sub _svp_begin {
my ($self, $name) = @_;
- $self->_get_dbh->do("SAVEPOINT $name");
+ $self->last_dbh->do("SAVEPOINT $name");
}
sub _svp_release {
my ($self, $name) = @_;
- $self->_get_dbh->do("RELEASE SAVEPOINT $name");
+ $self->last_dbh->do("RELEASE SAVEPOINT $name");
}
sub _svp_rollback {
my ($self, $name) = @_;
- $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
+ $self->last_dbh->do("ROLLBACK TO SAVEPOINT $name")
}
sub is_replicating {
- my $status = shift->_get_dbh->selectrow_hashref('show slave status');
+ my $status = shift->last_dbh->selectrow_hashref('show slave status');
return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
}
sub lag_behind_master {
- return shift->_get_dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
+ return shift->last_dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
}
# MySql can not do subquery update/deletes, only way is slow per-row operations.
Modified: DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI.pm 2009-08-05 09:48:04 UTC (rev 7221)
+++ DBIx-Class/0.08/branches/reduce_pings/lib/DBIx/Class/Storage/DBI.pm 2009-08-05 10:09:07 UTC (rev 7222)
@@ -667,6 +667,22 @@
$sub->();
}
+=head2 connected
+
+=over
+
+=item Arguments: none
+
+=item Return Value: 1|0
+
+=back
+
+Verifies that the the current database handle is active and ready to execute
+an SQL statement (i.e. the connection did not get stale, server is still
+answering, etc.) This method is used internally by L</dbh>.
+
+=cut
+
sub connected {
my ($self) = @_;
@@ -718,7 +734,9 @@
=head2 dbh
-Returns the dbh - a data base handle of class L<DBI>.
+Returns a C<$dbh> - a data base handle of class L<DBI>. The returned handle
+is guaranteed to be healthy by implicitly calling L</connected>, and if
+necessary performing a reconnection before returning.
=cut
@@ -733,12 +751,19 @@
return $self->_dbh;
}
-sub _get_dbh {
+=head2 last_dbh
+
+This returns the B<last> available C<$dbh> if any, or attempts to
+connect and returns the resulting handle. This method differs from
+L</dbh> by not validating if a preexisting handle is still healthy
+via L</connected>. Make sure you take appropriate precautions
+when using this method, as the C<$dbh> may be useless at this point.
+
+=cut
+
+sub last_dbh {
my $self = shift;
-
- if (not $self->_dbh) {
- $self->_populate_dbh;
- }
+ $self->_populate_dbh unless $self->_dbh;
return $self->_dbh;
}
@@ -748,7 +773,7 @@
return (
bindtype=>'columns',
array_datatypes => 1,
- limit_dialect => $self->_get_dbh,
+ limit_dialect => $self->last_dbh,
%{$self->_sql_maker_opts}
);
}
@@ -1203,7 +1228,7 @@
$updated_cols->{$col} = $to_insert->{$col} = $self->_sequence_fetch(
'nextval',
$col_info->{sequence} ||
- $self->_dbh_get_autoinc_seq($self->_get_dbh, $source)
+ $self->_dbh_get_autoinc_seq($self->last_dbh, $source)
);
}
}
@@ -1993,7 +2018,7 @@
=cut
-sub sqlt_type { shift->_get_dbh->{Driver}->{Name} }
+sub sqlt_type { shift->last_dbh->{Driver}->{Name} }
=head2 bind_attribute_by_data_type
@@ -2240,7 +2265,7 @@
sub deployment_statements {
my ($self, $schema, $type, $version, $dir, $sqltargs) = @_;
# Need to be connected to get the correct sqlt_type
- $self->_get_dbh() unless $type;
+ $self->last_dbh() unless $type;
$type ||= $self->sqlt_type;
$version ||= $schema->schema_version || '1.x';
$dir ||= './';
@@ -2285,7 +2310,7 @@
return if $line =~ /^\s+$/; # skip whitespace only
$self->_query_start($line);
eval {
- $self->_get_dbh->do($line);
+ $self->last_dbh->do($line);
};
if ($@) {
carp qq{$@ (running "${line}")};
@@ -2314,7 +2339,7 @@
sub datetime_parser {
my $self = shift;
return $self->{datetime_parser} ||= do {
- $self->_get_dbh;
+ $self->last_dbh;
$self->build_datetime_parser(@_);
};
}
More information about the Bast-commits
mailing list