Changeset 5167
- Timestamp:
- Sep 27, 2005, 6:32:21 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm
r5157 r5167 1 1 # Copyright (C) 2005 Joshua Hoblitt 2 2 # 3 # $Id: MetaDB.pm,v 1. 1.1.1 2005-09-28 01:21:27jhoblitt Exp $3 # $Id: MetaDB.pm,v 1.2 2005-09-28 04:32:21 jhoblitt Exp $ 4 4 5 5 package PS::IPP::MetaDB; … … 13 13 use base qw( Class::DBI::mysql ); 14 14 15 use Carp qw( croak ); 16 15 17 __PACKAGE__->set_db('Main', 'dbi:mysql:test', 'test', ''); 18 19 # lifted from Class::DBI docs (modified) 20 sub do_transaction { 21 my $class = shift; 22 my ( $code ) = @_; 23 24 # Turn off AutoCommit for this scope. 25 # A commit will occur at the exit of this block automatically, 26 # when the local AutoCommit goes out of scope. 27 local $class->db_Main->{ AutoCommit }; 28 29 # Execute the required code inside the transaction. 30 eval { $code->() }; 31 if ( $@ ) { 32 my $commit_error = $@; 33 eval { $class->dbi_rollback }; # might also die! 34 croak $commit_error; 35 } 36 } 37 38 sub add_new { 39 my $class = shift; 40 my %p = @_; 41 42 PS::IPP::MetaDB::Image::New->create({ 43 exp_id => $p{exp_id}, 44 class_id => $p{class_id}, 45 camera => $p{camera}, 46 class => $p{class}, 47 url => $p{url}, 48 }); 49 } 50 51 52 sub new2newed { 53 my $class = shift; 54 my %p = @_; 55 56 $class->do_transaction(sub { $class->_new2newed(%p) }); 57 } 58 59 sub _new2newed { 60 my $class = shift; 61 my %p = @_; 62 63 "${class}::Image::New"->search( 64 exp_id => $p{exp_id}, 65 class_id => $p{class_id}, 66 )->delete_all; 67 68 "${class}::Image::Newed"->create({ 69 exp_id => $p{exp_id}, 70 class_id => $p{class_id}, 71 url => $p{url}, 72 }); 73 } 74 16 75 17 76 #package PS::IPP::MetaDB::Image::Prepared;
Note:
See TracChangeset
for help on using the changeset viewer.
