IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13071


Ignore:
Timestamp:
Apr 27, 2007, 2:44:58 PM (19 years ago)
Author:
jhoblitt
Message:

add Nebulous::Server->rename_object()

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r13069 r13071  
    22
    330.05
     4    - add Nebulous::Server->rename_object()
    45    - add neb-rm
    56    - add neb-cp
  • trunk/Nebulous-Server/MANIFEST

    r13069 r13071  
    8888t/11_server_is_valid_class_id.t
    8989t/12_server_find_objects.t
     90t/13_server_rename_object.t
    9091t/50_client_new.t
    9192t/51_client_create.t
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r13047 r13071  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.25 2007-04-26 23:45:03 jhoblitt Exp $
     3# $Id: Server.pm,v 1.26 2007-04-28 00:44:38 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    236236}
    237237
     238sub rename_object {
     239    my $self = shift;
     240
     241    my ( $key, $newkey ) = validate_pos( @_,
     242        {
     243            type        => SCALAR,
     244        },
     245        {
     246            type        => SCALAR,
     247        },
     248    );
     249
     250    my $log = $self->log;
     251    my $sql = $self->sql;
     252    my $db  =$self->db;
     253
     254    $log->debug( "entered - @_" );
     255
     256    eval {
     257        # rename storage_object
     258        my $query = $db->prepare_cached($sql->rename_object);
     259        # this SQL statment takes the new key name as the first param
     260        my $rows = $query->execute($newkey, $key);
     261
     262        # if we affected more then one row something very bad has happened.
     263        unless ( $rows == 1 ) {
     264            $log->logdie( "affected row count is $rows instead of 1" );
     265        }
     266    };
     267    if ($@) {
     268        $db->rollback;
     269        $log->logdie( "database error: $@" );
     270    }
     271
     272    eval {
     273        $db->commit;
     274    };
     275    if ( $@ ) {
     276        $db->rollback;
     277        $log->logdie( "database error: $@" );
     278    }
     279
     280    $log->debug( "leaving" );
     281
     282    return $newkey;
     283}
     284
    238285sub replicate_object {
    239286    my $self = shift;
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r13047 r13071  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.27 2007-04-26 23:45:03 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.28 2007-04-28 00:44:38 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    153153        FROM storage_object
    154154        WHERE ext_id REGEXP ?
     155    },
     156    rename_object => qq{
     157        UPDATE storage_object
     158        SET ext_id = ?
     159        WHERE ext_id = ?
    155160    },
    156161);
  • trunk/Nebulous/Changes

    r13069 r13071  
    22
    330.05
     4    - add Nebulous::Server->rename_object()
    45    - add neb-rm
    56    - add neb-cp
  • trunk/Nebulous/MANIFEST

    r13069 r13071  
    8888t/11_server_is_valid_class_id.t
    8989t/12_server_find_objects.t
     90t/13_server_rename_object.t
    9091t/50_client_new.t
    9192t/51_client_create.t
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r13047 r13071  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.25 2007-04-26 23:45:03 jhoblitt Exp $
     3# $Id: Server.pm,v 1.26 2007-04-28 00:44:38 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    236236}
    237237
     238sub rename_object {
     239    my $self = shift;
     240
     241    my ( $key, $newkey ) = validate_pos( @_,
     242        {
     243            type        => SCALAR,
     244        },
     245        {
     246            type        => SCALAR,
     247        },
     248    );
     249
     250    my $log = $self->log;
     251    my $sql = $self->sql;
     252    my $db  =$self->db;
     253
     254    $log->debug( "entered - @_" );
     255
     256    eval {
     257        # rename storage_object
     258        my $query = $db->prepare_cached($sql->rename_object);
     259        # this SQL statment takes the new key name as the first param
     260        my $rows = $query->execute($newkey, $key);
     261
     262        # if we affected more then one row something very bad has happened.
     263        unless ( $rows == 1 ) {
     264            $log->logdie( "affected row count is $rows instead of 1" );
     265        }
     266    };
     267    if ($@) {
     268        $db->rollback;
     269        $log->logdie( "database error: $@" );
     270    }
     271
     272    eval {
     273        $db->commit;
     274    };
     275    if ( $@ ) {
     276        $db->rollback;
     277        $log->logdie( "database error: $@" );
     278    }
     279
     280    $log->debug( "leaving" );
     281
     282    return $newkey;
     283}
     284
    238285sub replicate_object {
    239286    my $self = shift;
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r13047 r13071  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.27 2007-04-26 23:45:03 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.28 2007-04-28 00:44:38 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    153153        FROM storage_object
    154154        WHERE ext_id REGEXP ?
     155    },
     156    rename_object => qq{
     157        UPDATE storage_object
     158        SET ext_id = ?
     159        WHERE ext_id = ?
    155160    },
    156161);
Note: See TracChangeset for help on using the changeset viewer.