Index: trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm
===================================================================
--- trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm	(revision 5157)
+++ trunk/PS-IPP-MetaDB/lib/PS/IPP/MetaDB.pm	(revision 5167)
@@ -1,5 +1,5 @@
 # Copyright (C) 2005  Joshua Hoblitt
 #
-# $Id: MetaDB.pm,v 1.1.1.1 2005-09-28 01:21:27 jhoblitt Exp $
+# $Id: MetaDB.pm,v 1.2 2005-09-28 04:32:21 jhoblitt Exp $
 
 package PS::IPP::MetaDB;
@@ -13,5 +13,64 @@
 use base qw( Class::DBI::mysql );
 
+use Carp qw( croak );
+
 __PACKAGE__->set_db('Main', 'dbi:mysql:test', 'test', '');
+
+# lifted from Class::DBI docs (modified)
+sub do_transaction {
+    my $class = shift;
+    my ( $code ) = @_;
+
+    # Turn off AutoCommit for this scope.
+    # A commit will occur at the exit of this block automatically,
+    # when the local AutoCommit goes out of scope.
+    local $class->db_Main->{ AutoCommit };
+
+    # Execute the required code inside the transaction.
+    eval { $code->() };
+    if ( $@ ) {
+        my $commit_error = $@;
+        eval { $class->dbi_rollback }; # might also die!
+        croak $commit_error;
+    }
+}
+
+sub add_new {
+    my $class = shift;
+    my %p = @_;
+
+    PS::IPP::MetaDB::Image::New->create({
+        exp_id      => $p{exp_id},
+        class_id    => $p{class_id},
+        camera      => $p{camera},
+        class       => $p{class},
+        url         => $p{url},
+    });
+}
+
+
+sub new2newed {
+    my $class = shift;
+    my %p = @_;
+
+    $class->do_transaction(sub { $class->_new2newed(%p) });
+}
+
+sub _new2newed {
+    my $class = shift;
+    my %p = @_;
+
+    "${class}::Image::New"->search(
+        exp_id      => $p{exp_id},
+        class_id    => $p{class_id},
+    )->delete_all;
+
+    "${class}::Image::Newed"->create({
+        exp_id      => $p{exp_id},
+        class_id    => $p{class_id},
+        url         => $p{url},
+    });
+}
+
 
 #package PS::IPP::MetaDB::Image::Prepared;
