X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated.pm;h=b3247abff02dceb070b95f2233898965ae9ef583;hb=3440100bc0455cf0e7ccbba03754a29ad26ec6d1;hp=bf5bb47caf290a84e47d2d34a6bd680af17da6d8;hpb=9720202815dbafee0d9e944e3f8258d4aca446d4;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index bf5bb47..b3247ab 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -37,7 +37,7 @@ also define your arguments, such as which balancer you want and any arguments that the Pool object should get. my $schema = Schema::Class->clone; - $schema->storage_type( ['::DBI::Replicated', {balancer=>'::Random'}] ); + $schema->storage_type(['::DBI::Replicated', { balancer_type => '::Random' }]); $schema->connection(...); Next, you need to add in the Replicants. Basically this is an array of @@ -265,7 +265,6 @@ my $method_dispatch = { build_datetime_parser last_insert_id insert - insert_bulk update delete dbh @@ -315,10 +314,10 @@ my $method_dispatch = { _native_data_type _get_dbh sql_maker_class + insert_bulk + _insert_bulk _execute _do_query - _sth - _dbh_sth _dbh_execute /, Class::MOP::Class->initialize('DBIx::Class::Storage::DBIHacks')->get_method_list ], reader => [qw/ @@ -340,6 +339,7 @@ my $method_dispatch = { _dbh_get_info _determine_connector_driver + _extract_driver_from_connect_info _describe_connection _warn_undetermined_driver @@ -359,7 +359,8 @@ my $method_dispatch = { _is_binary_type _is_text_lob_type - sth + _prepare_sth + _bind_sth_params /,( # the capability framework # not sure if CMOP->initialize does evil things to DBIC::S::DBI, fix if a problem @@ -398,13 +399,13 @@ if (DBIx::Class::_ENV_::DBICTEST) { for my $method (@{$method_dispatch->{unimplemented}}) { __PACKAGE__->meta->add_method($method, sub { my $self = shift; - $self->throw_exception("$method must not be called on ".(blessed $self).' objects'); + $self->throw_exception("$method() must not be called on ".(blessed $self).' objects'); }); } =head2 read_handler -Defines an object that implements the read side of L. +Defines an object that implements the read side of L. =cut @@ -417,7 +418,7 @@ has 'read_handler' => ( =head2 write_handler -Defines an object that implements the write side of L, +Defines an object that implements the write side of L, as well as methods that don't write or read that can be called on only one storage, methods that return a C<$dbh>, and any methods that don't make sense to run on a replicant. @@ -589,7 +590,8 @@ sub _build_read_handler { =head2 around: connect_replicants All calls to connect_replicants needs to have an existing $schema tacked onto -top of the args, since L needs it, and any C +top of the args, since L needs it, and any +L options merged with the master, with replicant opts having higher priority. =cut @@ -644,8 +646,8 @@ around connect_replicants => sub { =head2 all_storages -Returns an array of of all the connected storage backends. The first element -in the returned array is the master, and the remainings are each of the +Returns an array of all the connected storage backends. The first element +in the returned array is the master, and the rest are each of the replicants. =cut @@ -1080,7 +1082,8 @@ sub _get_server_version { Due to the fact that replicants can lag behind a master, you must take care to make sure you use one of the methods to force read queries to a master should you need realtime data integrity. For example, if you insert a row, and then -immediately re-read it from the database (say, by doing $row->discard_changes) +immediately re-read it from the database (say, by doing +L<< $result->discard_changes|DBIx::Class::Row/discard_changes >>) or you insert a row and then immediately build a query that expects that row to be an item, you should force the master to handle reads. Otherwise, due to the lag, there is no certainty your data will be in the expected state. @@ -1092,9 +1095,9 @@ method to force the master to handle all read queries. Otherwise, you can force a single query to use the master with the 'force_pool' attribute: - my $row = $resultset->search(undef, {force_pool=>'master'})->find($pk); + my $result = $resultset->search(undef, {force_pool=>'master'})->find($pk); -This attribute will safely be ignore by non replicated storages, so you can use +This attribute will safely be ignored by non replicated storages, so you can use the same code for both types of systems. Lastly, you can use the L method, which works very much like @@ -1118,8 +1121,8 @@ using the Schema clone method. Based on code originated by: - Norbert Csongrádi - Peter Siklósi + Norbert Csongrádi + Peter Siklósi =head1 LICENSE