Changeset 20056
- Timestamp:
- Oct 10, 2008, 3:16:50 PM (18 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 2 edited
-
Changes (modified) (1 diff)
-
lib/Nebulous/Server.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r20046 r20056 27 27 - change neb-admin to properly cleanup it's semaphore file 28 28 - retry system call failures 29 - change Nebulous::Server->new() to not setup the db handle on object 30 construction, modify Nebulous::Server->db() to be considtent with this 31 change 29 32 30 33 0.15 Thu Sep 11 13:00:59 HST 2008 -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r20046 r20056 1 1 # Copyright (c) 2004-2008 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1. 89 2008-10-10 21:42:59jhoblitt Exp $3 # $Id: Server.pm,v 1.90 2008-10-11 01:16:50 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 45 45 $log->debug( "entered - @_" ); 46 46 47 my $self = bless {}, ref $class || $class; 48 $self->log($log); 49 $self->sql($sql); 50 $self->config($config); 51 52 $log->debug( "leaving" ); 53 54 return $self; 55 } 56 57 sub db { 58 my $self = shift; 59 60 if (@_) { 61 $self->{db} = $_[0]; 62 return $self; 63 } 64 65 my $log = $self->log; 66 my $sql = $self->sql; 67 my $config = $self->config; 68 69 # if the dbh is still alive, return it 70 if (defined $self->{db} and $self->{db}->ping) { 71 $log->debug("db handle is still alive"); 72 return $self->{db}; 73 } 74 # otherwise create a new connection 75 $log->debug("db handle is dead/unopened"); 76 77 # if we're running under mod_perl & Apache::DBI is loaded we want to 78 # reconnect to the database everytime the dbh is requested. The rational is 79 # that if we're running under mod_perl this is probably a log running 80 # processes and the database might have gone away on us. Apache::DBI will 81 # take care of getting a valid dbh back. 47 82 my $db; 48 83 eval { 49 $db = DBI->connect (84 $db = DBI->connect_cached( 50 85 $config->dsn, 51 86 $config->dbuser, … … 59 94 60 95 $db->do( $sql->set_transaction_model ); 61 96 $log->debug( "connected to database: ", sub { $db->data_sources; } ); 62 97 $db->commit; 63 98 $log->debug("commit"); … … 69 104 } 70 105 71 $log->debug( "connected to database: ", sub { $db->data_sources; } ); 72 73 my $self = bless {}, ref $class || $class; 74 $self->log($log); 75 $self->sql($sql); 76 $self->db($db); 77 $self->config($config); 78 79 $log->debug( "leaving" ); 80 81 return $self; 82 } 83 84 sub db { 85 my $self = shift; 86 87 if (@_) { 88 $self->{db} = $_[0]; 89 return $self; 90 } 91 92 my $log = $self->log; 93 my $sql = $self->sql; 94 my $config = $self->config; 95 96 # if the dbh is still alive, return it 97 if (defined $self->{db} and $self->{db}->ping) { 98 $log->debug("db handle is still alive"); 99 return $self->{db}; 100 } 101 # otherwise create a new connection 102 $log->debug("db handle is dead"); 103 104 # if we're running under mod_perl & Apache::DBI is loaded we want to 105 # reconnect to the database everytime the dbh is requested. The rational is 106 # that if we're running under mod_perl this is probably a log running 107 # processes and the database might have gone away on us. Apache::DBI will 108 # take care of getting a valid dbh back. 109 if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) { 110 my $db; 111 eval { 112 $db = DBI->connect( 113 $config->dsn, 114 $config->dbuser, 115 $config->dbpasswd, 116 { 117 RaiseError => 1, 118 PrintError => 0, 119 AutoCommit => 0, 120 }, 121 ); 122 123 $db->do( $sql->set_transaction_model ); 124 125 $db->commit; 126 $log->debug("commit"); 127 }; 128 if ( $@ ) { 129 $db->rollback if $db; 130 $log->debug("rollback"); 131 $log->logdie( "database error: $@" ); 132 } 133 134 $self->{db} = $db; 135 136 return $db; 137 } 138 139 return $self->{db}; 106 $self->{db} = $db; 107 108 return $db; 140 109 } 141 110 … … 1181 1150 my $log = $self->log; 1182 1151 my $sql = $self->sql; 1183 my $db = $self->db;1152 my $db = $self->db; 1184 1153 1185 1154 no warnings qw( uninitialized );
Note:
See TracChangeset
for help on using the changeset viewer.
