Tripletail
view release on metacpan or search on metacpan
lib/Tripletail/DB.pm view on Meta::CPAN
if($this->{default_set}) {
$set = $this->{default_set};
} else {
die __PACKAGE__."#_getDbSetName: do not omit the DB Set because no default DB Set has been specified." .
" (ããã©ã«ãã® DB Set ãæå®ããã¦ããªãå ´åã¯ãDB Set ã®æå®ãçç¥ã§ãã¾ãã)\n";
}
} else {
if($this->{dbh}{$setname}) {
$set = $setname;
} else {
die __PACKAGE__."#_getDbSetName: DB set [$setname] was not defined. Please check the INI file.".
" (DB Set [$setname] ãåå¨ãã¾ãã)\n";
}
}
$set;
}
sub _connect {
# ã¯ã©ã¹ã¡ã½ãããTL#startCgiï¼TL#trapErrorã®ã¿ãå¼ã¶ã
my $class = shift;
my $groups = shift;
foreach my $group (@$groups) {
if (!defined $group) {
die "TL#startCgi: -DB has an undefined value. (DBæå®ã«undefãå«ã¾ãã¾ã)\n";
}
elsif (ref $group) {
die "TL#startCgi: -DB has a reference. (DBæå®ã«ãªãã¡ã¬ã³ã¹ãå«ã¾ãã¾ã)\n";
}
$INSTANCES{$group} = __PACKAGE__->_new($group)->connect;
}
# initRequest, postRequest, term ãããã¯ãã
$TL->setHook(
'initRequest',
_INIT_REQUEST_HOOK_PRIORITY,
\&__initRequest,
);
$TL->setHook(
'postRequest',
_POST_REQUEST_HOOK_PRIORITY,
\&__postRequest,
);
$TL->setHook(
'term',
_TERM_HOOK_PRIORITY,
\&__term,
);
undef;
}
sub _new {
my $class = shift;
my $group = shift;
my $this = bless {} => $class;
$this->{group} = $group;
$this->{namequery} = $TL->INI->get($group => 'namequery' => undef);
$this->{autoreyry} = $TL->INI->get($group => 'autoretry' => undef);
$this->{type} = $TL->INI->get($group => 'type');
$this->{bufsize} = undef; # æ£ã®å¤ã§ãªããã°ç¡å¶é
$this->{types_symtable} = \%Tripletail::DB::SQL_TYPES::;
$this->{dbh} = {}; # {DBã»ããå => Tripletail::DB::Dbh}
$this->{dbname} = {}; # {DBã³ãã¯ã·ã§ã³å => Tripletail::DB::Dbh}
$this->{default_set} = $TL->INI->get($group => 'defaultset', undef); # ããã©ã«ãã®ã»ããå
$this->{locked_dbh} = undef; # Tripletail::DB::Dbh
$this->{trans_dbh} = undef; # Tripletail::DB::Dbh
do {
local $SIG{__DIE__} = 'DEFAULT';
eval q{
package Tripletail::DB::SQL_TYPES;
use DBI qw(:sql_types);
};
};
if($@) {
die $@;
}
# ããã§ã»ããå®ç¾©ãèªã
foreach my $setname ($TL->INI->getKeys($group)) {
$setname =~ m/^[a-z]+$/ and next; # äºç´æ¸
my @db = split /\s*,\s*/, $TL->INI->get($group => $setname);
if (!scalar(@db)) {
# ã¼ãåã®DBããæ§æãããDBã»ãããä½ã£ã¦ã¯ãªããªãã
die __PACKAGE__."#new: DB Set [$setname] has no databases. (DB Set [$setname] ã«DBã1ã¤ãããã¾ãã)\n";
}
my $dbname = $db[$$ % scalar(@db)];
if (!$this->{dbname}{$dbname}) {
my $type = $this->{type};
my $backend = exists $BACKEND_OF{$type}
? $BACKEND_OF{$type}
: die "TL#startCgi: DB type [$type] is not supported.".
" (DB type [$type] ã¯ãµãã¼ãããã¦ãã¾ãã)\n";
eval qq{
use $backend;
};
if ($@) {
local $SIG{__DIE__} = 'DEFAULT';
die $@;
}
my $class = $backend . '::Dbh';
$this->{dbname}{$dbname} = $class->new($setname, $dbname);
}
$this->{dbh}{$setname} = $this->{dbname}{$dbname};
}
$this;
( run in 3.913 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )