Session::Store::DBIC
Session::State::Cookie
+ +FrBr::Books::Plugin::Locks
+
+FrBr::Books::Plugin::Author
+FrBr::Books::Plugin::Bindungsart
+FrBr::Books::Plugin::BookAdd
use warnings;
use FrBr::Common;
-use FrBr::Books::Util::Locks;
our $VERSION = '0.2';
{
}
# Sperren der Autoren-Tabelle
- lock_tables( $c, 'write' => [ 'autoren', 'autoren', 'as', 'me' ] );
+ $c->lock_tables( 'write' => [ 'autoren', 'autoren', 'as', 'me' ] );
$saved_aid = $c->b_get_autor_id( $search_params );
if ( $saved_aid and ( $saved_aid != $autor->{'id'} ) ) {
$c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den übergebenen Angaben.';
$c->log->info( $K . "Es existiert bereits ein Autor mit den übergebenen Angaben." );
- unlock_tables($c);
+ $c->unlock_tables();
return undef;
}
}
if ( $saved_aid ) {
$c->stash->{'save_autor_result'} = 'Es existiert bereits ein Autor mit den uebergebenen Angaben.';
$c->log->info( $K . "Es existiert bereits ein Autor mit den uebergebenen Angaben." );
- unlock_tables($c);
+ $c->unlock_tables();
return undef;
}
}
if ( $@ ) {
$c->stash->{'save_autor_result'} = $@;
$c->log->info( $K . $@ );
- unlock_tables($c);
+ $c->unlock_tables();
return undef;
}
- unlock_tables($c);
+ $c->unlock_tables();
$c->stash->{'save_autor_result'} = 'OK';
return $new_id;
my $schema = $c->model('Schema')->{'schema'};
# # Sperren der Autoren- und der Buecher-Tabelle
-# lock_tables( $c, 'write' => [ 'autoren', 'autoren', 'as', 'me', ], 'read' => [ 'autor2buch', 'autor2buch', 'as', 'me', ] );
+# $c->lock_tables( 'write' => [ 'autoren', 'autoren', 'as', 'me', ], 'read' => [ 'autor2buch', 'autor2buch', 'as', 'me', ] );
# Raus, wenn der Autor noch Buecher hat ...
if ( $c->model('Schema::Autor2buch')->count( { 'autor_id' => $autor_id, } ) ) {
my $msg = 'Es existieren noch Buecher dieses Autors.';
-# unlock_tables($c);
+# $c->unlock_tables();
die $msg . "\n";
}
if ($@) { # Transaction failed
my $msg = $@ =~ /Rollback failed/i ? "Rollback nicht erfolgreich!" : $@;
-# unlock_tables($c);
+# $c->unlock_tables();
die $msg . "\n";
return undef;
}
-# unlock_tables($c);
+# $c->unlock_tables();
return 1;
}
# $Id$
# $URL$
+use strict;
+use warnings;
+
use Carp qw/croak/;
use FrBr::Common;
--- /dev/null
+package FrBr::Books::Plugin::Locks;
+
+# $Id$
+# $URL$
+
+=head1 NAME
+
+FrBr::Books::Plugin::Locks
+
+=head1 DESCRIPTION
+
+Modul fuer Hilfsroutinen zum Sperren und Entsperren von Tabellen
+
+=cut
+
+#---------------------------------------------------------------------------
+
+use strict;
+use warnings;
+
+use Carp qw/croak/;
+use FrBr::Common;
+
+our $VERSION = '0.2';
+{
+ my ($rev) = '$Revision$' =~ /(\d+)/;
+ $VERSION = sprintf( $VERSION . ".%d", $rev );
+}
+
+#-----------------------------------------------------------------------------------
+
+=head1 METHODS
+
+=cut
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->lock_tables( 'read' => [ 'table_1', 'table_2', 'AS', 'alias_2', ... ], 'write' => [ 'table_3', 'table_4', 'as', 'alias_4', ... ] )
+
+Sperrt Tabellen zum Lesen oder Schreiben.
+
+=cut
+
+sub lock_tables {
+
+ my $c = shift;
+ my $K = ( caller(0) )[3] . "(): ";
+
+ my $storage = $c->model('Schema')->storage;
+
+ $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
+
+ my $params = {};
+ if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) {
+ $params = $_[0];
+ }
+ else {
+ %$params = @_;
+ }
+ $c->log->debug( get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
+
+ my $read = undef;
+ my $write = undef;
+
+ $read = $params->{'read'} if $params->{'read'} and ref( $params->{'read'} ) and ref( $params->{'read'} ) eq 'ARRAY';
+ $write = $params->{'write'} if $params->{'write'} and ref( $params->{'write'} ) and ref( $params->{'write'} ) eq 'ARRAY';
+
+ unless ( $read or $write ) {
+ $c->log->debug( $K . "Ungueltige Parameteruebergabe." );
+ return undef;
+ }
+
+ my $sql = 'LOCK TABLES ';
+ my @Tables;
+
+ if ( $read ) {
+ my @A = @$read;
+ my $last_table;
+ while ( @A ) {
+ my $cur = shift @A;
+ if ( lc($cur) eq 'as' ) {
+ unless ( $last_table and @A ) {
+ $c->log->debug( $K . "Ungueltige Parameteruebergabe." );
+ return undef;
+ }
+ my $alias = shift @A;
+ push @Tables, "`" . $last_table . "` AS `" . $alias . "` READ";
+ $last_table = undef;
+ }
+ else {
+ if ( $last_table ) {
+ push @Tables, "`" . $last_table . "` READ";
+ }
+ $last_table = $cur;
+ }
+ }
+ if ( $last_table ) {
+ push @Tables, "`" . $last_table . "` READ";
+ }
+ }
+
+ if ( $write ) {
+ my @A = @$write;
+ my $last_table;
+ while ( @A ) {
+ my $cur = shift @A;
+ if ( lc($cur) eq 'as' ) {
+ unless ( $last_table and @A ) {
+ $c->log->debug( $K . "Ungueltige Parameteruebergabe." );
+ return undef;
+ }
+ my $alias = shift @A;
+ push @Tables, "`" . $last_table . "` AS `" . $alias . "` WRITE";
+ $last_table = undef;
+ }
+ else {
+ if ( $last_table ) {
+ push @Tables, "`" . $last_table . "` WRITE";
+ }
+ $last_table = $cur;
+ }
+ }
+ if ( $last_table ) {
+ push @Tables, "`" . $last_table . "` WRITE";
+ }
+ }
+
+ $sql .= join( ", ", @Tables );
+
+ my $save_func = sub {
+ my ( $storage, $dbh, $sql ) = @_;
+
+ if ( $storage->debug() ) {
+ my $text = $sql . "\n";
+ warn $text;
+ }
+
+ my $sth = $dbh->prepare($sql);
+ $sth->execute();
+ };
+
+ $storage->dbh_do( $save_func, $sql );
+
+ return 1;
+}
+
+#-----------------------------------------------------------------------------------
+
+=head2 $c->unlock_tables( )
+
+Entsperrt Tabellen.
+
+=cut
+
+sub unlock_tables {
+
+ my $c = shift;
+ my $K = ( caller(0) )[3] . "(): ";
+
+ my $save_func = sub {
+
+ my ( $storage, $dbh ) = @_;
+
+ my $sql = 'UNLOCK TABLES';
+ if ( $storage->debug() ) {
+ my $text = $sql . "\n";
+ warn $text;
+ }
+
+ my $sth = $dbh->prepare($sql);
+ $sth->execute();
+ };
+
+ my $storage = $c->model('Schema')->storage;
+
+ $storage->dbh_do( $save_func );
+
+ return 1;
+
+}
+
+#-----------------------------------------------------------------------------------
+
+=head1 AUTHOR
+
+Frank Brehm
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
+
+__END__
+
+# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :
+++ /dev/null
-package FrBr::Books::Util::Locks;
-
-# $Id$
-# $URL$
-
-=head1 NAME
-
-FrBr::Books::Util::Locks
-
-=head1 DESCRIPTION
-
-Modul fuer Hilfsroutinen zum Sperren und Entsperren von Tabellen
-
-=cut
-
-#---------------------------------------------------------------------------
-
-use strict;
-use warnings;
-
-use FrBr::Common;
-
-# Export-Deklarationen
-
-BEGIN {
-
- use Exporter();
- our ( $VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
-
- # set the version for version checking
- $VERSION = 0.1;
- my ($rev) = '$Revision$' =~ /(\d+)/;
- $VERSION = sprintf( $VERSION . ".%d", $rev );
-
- @ISA = qw(Exporter);
- @EXPORT = qw(
- &lock_tables
- &unlock_tables
- );
-
- #%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
-
- # your exported package globals go here,
- # as well as any optionally exported functions
- #@EXPORT_OK = qw($Var1 %Hashit &func3);
-} ## end BEGIN
-
-our @EXPORT_OK;
-
-=head1 METHODS
-
-=cut
-
-#-----------------------------------------------------------------------------------
-
-=head2 lock_tables( $c, 'read' => [ 'table_1', 'table_2', 'AS', 'alias_2', ... ], 'write' => [ 'table_3', 'table_4', 'as', 'alias_4', ... ] )
-
-Sperrt Tabellen zum Lesen oder Schreiben.
-
-=cut
-
-sub lock_tables {
-
- my $c = shift;
- my $K = ( caller(0) )[3] . "(): ";
-
- my $storage = $c->stash->{'storage'};
-
- $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
-
- my $params = {};
- if ( ref($_[0]) and ref($_[0]) eq 'HASH' ) {
- $params = $_[0];
- }
- else {
- %$params = @_;
- }
- $c->log->debug( get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
-
- my $read = undef;
- my $write = undef;
-
- $read = $params->{'read'} if $params->{'read'} and ref( $params->{'read'} ) and ref( $params->{'read'} ) eq 'ARRAY';
- $write = $params->{'write'} if $params->{'write'} and ref( $params->{'write'} ) and ref( $params->{'write'} ) eq 'ARRAY';
-
- unless ( $read or $write ) {
- $c->log->debug( $K . "Ungueltige Parameteruebergabe." );
- return undef;
- }
-
- my $sql = 'LOCK TABLES ';
- my @Tables;
-
- if ( $read ) {
- my @A = @$read;
- my $last_table;
- while ( @A ) {
- my $cur = shift @A;
- if ( lc($cur) eq 'as' ) {
- unless ( $last_table and @A ) {
- $c->log->debug( $K . "Ungueltige Parameteruebergabe." );
- return undef;
- }
- my $alias = shift @A;
- push @Tables, "`" . $last_table . "` AS `" . $alias . "` READ";
- $last_table = undef;
- }
- else {
- if ( $last_table ) {
- push @Tables, "`" . $last_table . "` READ";
- }
- $last_table = $cur;
- }
- }
- if ( $last_table ) {
- push @Tables, "`" . $last_table . "` READ";
- }
- }
-
- if ( $write ) {
- my @A = @$write;
- my $last_table;
- while ( @A ) {
- my $cur = shift @A;
- if ( lc($cur) eq 'as' ) {
- unless ( $last_table and @A ) {
- $c->log->debug( $K . "Ungueltige Parameteruebergabe." );
- return undef;
- }
- my $alias = shift @A;
- push @Tables, "`" . $last_table . "` AS `" . $alias . "` WRITE";
- $last_table = undef;
- }
- else {
- if ( $last_table ) {
- push @Tables, "`" . $last_table . "` WRITE";
- }
- $last_table = $cur;
- }
- }
- if ( $last_table ) {
- push @Tables, "`" . $last_table . "` WRITE";
- }
- }
-
- $sql .= join( ", ", @Tables );
-
- my $save_func = sub {
- my ( $storage, $dbh, $sql ) = @_;
-
- if ( $storage->debug() ) {
- my $text = $sql . "\n";
- warn $text;
- }
-
- my $sth = $dbh->prepare($sql);
- $sth->execute();
- };
-
- $storage->dbh_do( $save_func, $sql );
-
- return 1;
-}
-
-#-----------------------------------------------------------------------------------
-
-=head2 unlock_tables( $c )
-
-Entsperrt Tabellen.
-
-=cut
-
-sub unlock_tables {
-
- my $c = shift;
- my $K = ( caller(0) )[3] . "(): ";
-
- my $save_func = sub {
-
- my ( $storage, $dbh ) = @_;
-
- my $sql = 'UNLOCK TABLES';
- if ( $storage->debug() ) {
- my $text = $sql . "\n";
- warn $text;
- }
-
- my $sth = $dbh->prepare($sql);
- $sth->execute();
- };
-
- my $storage = $c->stash->{'storage'};
-
- $storage->dbh_do( $save_func );
-
- return 1;
-
-}
-
-#-----------------------------------------------------------------------------------
-
-=head1 AUTHOR
-
-Frank Brehm
-
-=head1 LICENSE
-
-This library is free software, you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-1;
-
-__END__
-
-# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :