Revision 7cfa1f2a
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/DB.pm | ||
---|---|---|
126 | 126 |
return %flattened; |
127 | 127 |
} |
128 | 128 |
|
129 |
sub with_transaction { |
|
130 |
my ($self, $code, @args) = @_; |
|
131 |
|
|
132 |
return $self->in_transaction ? $code->(@args) : $self->do_transaction(sub { $code->(@args) }); |
|
133 |
} |
|
134 |
|
|
129 | 135 |
1; |
136 |
__END__ |
|
137 |
|
|
138 |
=pod |
|
139 |
|
|
140 |
=encoding utf8 |
|
141 |
|
|
142 |
=head1 NAME |
|
143 |
|
|
144 |
SL::DB - Database access class for all RDB objects |
|
145 |
|
|
146 |
=head1 FUNCTIONS |
|
147 |
|
|
148 |
=over 4 |
|
149 |
|
|
150 |
=item C<create $domain, $type> |
|
151 |
|
|
152 |
Registers the database information with Rose, creates a cached |
|
153 |
connection and executes initial SQL statements. Those can include |
|
154 |
setting the time & date format to the user's preferences. |
|
155 |
|
|
156 |
=item C<dbi_connect $dsn, $login, $password, $options> |
|
157 |
|
|
158 |
Forwards the call to L<SL::DBConnect/connect> which connects to the |
|
159 |
database. This indirection allows L<SL::DBConnect/connect> to route |
|
160 |
the calls through L<DBIx::Log4Perl> if this is enabled in the |
|
161 |
configuration. |
|
162 |
|
|
163 |
=item C<with_transaction $code_ref, @args> |
|
164 |
|
|
165 |
Executes C<$code_ref> within a transaction, starting one if none is |
|
166 |
currently active. This is just a shortcut for the following code: |
|
167 |
|
|
168 |
# Verbose code in caller (an RDBO instance): |
|
169 |
my $worker = sub { |
|
170 |
# do stuff with $self |
|
171 |
}; |
|
172 |
return $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); |
|
173 |
|
|
174 |
Now the version using C<with_transaction>: |
|
175 |
|
|
176 |
return $self->db->with_transaction(sub { |
|
177 |
# do stuff with $self |
|
178 |
}); |
|
179 |
|
|
180 |
=back |
|
181 |
|
|
182 |
=head1 BUGS |
|
183 |
|
|
184 |
Nothing here yet. |
|
185 |
|
|
186 |
=head1 AUTHOR |
|
187 |
|
|
188 |
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt> |
|
189 |
|
|
190 |
=cut |
Auch abrufbar als: Unified diff
SL::DB: Hilfsfunktion 'with_transaction'; Dokumentation