Index: /trunk/Nebulous-Server/Changes
===================================================================
--- /trunk/Nebulous-Server/Changes	(revision 13070)
+++ /trunk/Nebulous-Server/Changes	(revision 13071)
@@ -2,4 +2,5 @@
 
 0.05
+    - add Nebulous::Server->rename_object()
     - add neb-rm
     - add neb-cp
Index: /trunk/Nebulous-Server/MANIFEST
===================================================================
--- /trunk/Nebulous-Server/MANIFEST	(revision 13070)
+++ /trunk/Nebulous-Server/MANIFEST	(revision 13071)
@@ -88,4 +88,5 @@
 t/11_server_is_valid_class_id.t
 t/12_server_find_objects.t
+t/13_server_rename_object.t
 t/50_client_new.t
 t/51_client_create.t
Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13070)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13071)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.25 2007-04-26 23:45:03 jhoblitt Exp $
+# $Id: Server.pm,v 1.26 2007-04-28 00:44:38 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -236,4 +236,51 @@
 }
 
+sub rename_object {
+    my $self = shift;
+
+    my ( $key, $newkey ) = validate_pos( @_,
+        {
+            type        => SCALAR,
+        },
+        {
+            type        => SCALAR,
+        },
+    );
+
+    my $log = $self->log;
+    my $sql = $self->sql;
+    my $db  =$self->db;
+
+    $log->debug( "entered - @_" );
+
+    eval {
+        # rename storage_object
+        my $query = $db->prepare_cached($sql->rename_object); 
+        # this SQL statment takes the new key name as the first param
+        my $rows = $query->execute($newkey, $key);
+
+        # if we affected more then one row something very bad has happened.
+        unless ( $rows == 1 ) {
+            $log->logdie( "affected row count is $rows instead of 1" );
+        }
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    eval { 
+        $db->commit;
+    };
+    if ( $@ ) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    $log->debug( "leaving" );
+
+    return $newkey;
+}
+
 sub replicate_object {
     my $self = shift;
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13070)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13071)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.27 2007-04-26 23:45:03 jhoblitt Exp $
+# $Id: SQL.pm,v 1.28 2007-04-28 00:44:38 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -153,4 +153,9 @@
         FROM storage_object
         WHERE ext_id REGEXP ?
+    },
+    rename_object => qq{
+        UPDATE storage_object
+        SET ext_id = ?
+        WHERE ext_id = ?
     },
 );
Index: /trunk/Nebulous-Server/t/13_server_rename_object.t
===================================================================
--- /trunk/Nebulous-Server/t/13_server_rename_object.t	(revision 13071)
+++ /trunk/Nebulous-Server/t/13_server_rename_object.t	(revision 13071)
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+# Copryight (C) 2007  Joshua Hoblitt
+#
+# $Id: 13_server_rename_object.t,v 1.1 2007-04-28 00:44:58 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use Test::More tests => 5;
+
+use lib qw( ./t ./lib );
+
+use Nebulous::Server;
+use Nebulous::Util qw( :standard );
+use Test::Nebulous;
+
+my $neb = Nebulous::Server->new(
+    dsn         => "DBI:mysql:database=test:host=localhost",
+    dbuser      => "test",
+    dbpasswd    => "",
+);
+
+Test::Nebulous->setup;
+
+{
+    my $uri = $neb->create_object("foo");
+
+    $neb->rename_object("foo", "bar");
+
+    my $keys = $neb->find_objects('^foo$');
+    is(scalar @$keys, 0, 'number of keys found');
+    $keys = $neb->find_objects('^bar$');
+    is(scalar @$keys, 1, 'number of keys found');
+}
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->rename_object();
+};
+like($@, qr/2 were expected/, "no params");
+
+Test::Nebulous->cleanup;
+
+eval {
+    $neb->rename_object("foo");
+};
+like($@, qr/2 were expected/, "too few params");
+
+Test::Nebulous->cleanup;
+
+eval {
+    $neb->rename_object("foo", "bar", "baz");
+};
+like($@, qr/2 were expected/, "too many params");
+
+Test::Nebulous->cleanup;
Index: /trunk/Nebulous/Changes
===================================================================
--- /trunk/Nebulous/Changes	(revision 13070)
+++ /trunk/Nebulous/Changes	(revision 13071)
@@ -2,4 +2,5 @@
 
 0.05
+    - add Nebulous::Server->rename_object()
     - add neb-rm
     - add neb-cp
Index: /trunk/Nebulous/MANIFEST
===================================================================
--- /trunk/Nebulous/MANIFEST	(revision 13070)
+++ /trunk/Nebulous/MANIFEST	(revision 13071)
@@ -88,4 +88,5 @@
 t/11_server_is_valid_class_id.t
 t/12_server_find_objects.t
+t/13_server_rename_object.t
 t/50_client_new.t
 t/51_client_create.t
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13070)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13071)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.25 2007-04-26 23:45:03 jhoblitt Exp $
+# $Id: Server.pm,v 1.26 2007-04-28 00:44:38 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -236,4 +236,51 @@
 }
 
+sub rename_object {
+    my $self = shift;
+
+    my ( $key, $newkey ) = validate_pos( @_,
+        {
+            type        => SCALAR,
+        },
+        {
+            type        => SCALAR,
+        },
+    );
+
+    my $log = $self->log;
+    my $sql = $self->sql;
+    my $db  =$self->db;
+
+    $log->debug( "entered - @_" );
+
+    eval {
+        # rename storage_object
+        my $query = $db->prepare_cached($sql->rename_object); 
+        # this SQL statment takes the new key name as the first param
+        my $rows = $query->execute($newkey, $key);
+
+        # if we affected more then one row something very bad has happened.
+        unless ( $rows == 1 ) {
+            $log->logdie( "affected row count is $rows instead of 1" );
+        }
+    };
+    if ($@) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    eval { 
+        $db->commit;
+    };
+    if ( $@ ) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    $log->debug( "leaving" );
+
+    return $newkey;
+}
+
 sub replicate_object {
     my $self = shift;
Index: /trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13070)
+++ /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 13071)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.27 2007-04-26 23:45:03 jhoblitt Exp $
+# $Id: SQL.pm,v 1.28 2007-04-28 00:44:38 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -153,4 +153,9 @@
         FROM storage_object
         WHERE ext_id REGEXP ?
+    },
+    rename_object => qq{
+        UPDATE storage_object
+        SET ext_id = ?
+        WHERE ext_id = ?
     },
 );
Index: /trunk/Nebulous/t/13_server_rename_object.t
===================================================================
--- /trunk/Nebulous/t/13_server_rename_object.t	(revision 13071)
+++ /trunk/Nebulous/t/13_server_rename_object.t	(revision 13071)
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+# Copryight (C) 2007  Joshua Hoblitt
+#
+# $Id: 13_server_rename_object.t,v 1.1 2007-04-28 00:44:58 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use Test::More tests => 5;
+
+use lib qw( ./t ./lib );
+
+use Nebulous::Server;
+use Nebulous::Util qw( :standard );
+use Test::Nebulous;
+
+my $neb = Nebulous::Server->new(
+    dsn         => "DBI:mysql:database=test:host=localhost",
+    dbuser      => "test",
+    dbpasswd    => "",
+);
+
+Test::Nebulous->setup;
+
+{
+    my $uri = $neb->create_object("foo");
+
+    $neb->rename_object("foo", "bar");
+
+    my $keys = $neb->find_objects('^foo$');
+    is(scalar @$keys, 0, 'number of keys found');
+    $keys = $neb->find_objects('^bar$');
+    is(scalar @$keys, 1, 'number of keys found');
+}
+
+Test::Nebulous->setup;
+
+eval {
+    $neb->rename_object();
+};
+like($@, qr/2 were expected/, "no params");
+
+Test::Nebulous->cleanup;
+
+eval {
+    $neb->rename_object("foo");
+};
+like($@, qr/2 were expected/, "too few params");
+
+Test::Nebulous->cleanup;
+
+eval {
+    $neb->rename_object("foo", "bar", "baz");
+};
+like($@, qr/2 were expected/, "too many params");
+
+Test::Nebulous->cleanup;
