my $name = shift || '';
-
- my $continue = 0;
try {
- _get_name_id($name);
+
+ my $continue = 0;
+ try {
+ _get_name_id($name);
- } catch Error with {
- $continue++;
- };
+ } catch Error with {
+ $continue++;
+ };
- throw OpenSRF::EX::WARN ("Duplicate key: object name [$name] already exists! " . $dbh->errstr)
- unless ($continue);
+ throw OpenSRF::EX::WARN ("Duplicate key: object name [$name] already exists! " . $dbh->errstr)
+ unless ($continue);
- my $sth = $dbh->prepare("INSERT INTO store_name (name) VALUES (?);");
- $sth->execute($name);
- $sth->finish;
+ my $sth = $dbh->prepare("INSERT INTO store_name (name) VALUES (?);");
+ $sth->execute($name);
+ $sth->finish;
- unless ($name) {
- my $last_id = $dbh->last_insert_id(undef, undef, 'store_name', 'id');
- $name = 'AUTOGENERATED!!'.$last_id;
- $dbh->do("UPDATE store_name SET name = '$name' WHERE id = '$last_id';");
- }
+ unless ($name) {
+ my $last_id = $dbh->last_insert_id(undef, undef, 'store_name', 'id');
+ $name = 'AUTOGENERATED!!'.$last_id;
+ $dbh->do("UPDATE store_name SET name = '$name' WHERE id = '$last_id';");
+ }
- _flush_by_name($name);
- return $name;
+ _flush_by_name($name);
+ return $name;
+ } catch Error with {
+ return undef;
+ };
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.slot.create',
my $time = shift || $default_expire_time;
try {
- __PACKAGE__->method_lookup( 'opensrf.persist.slot.create' )->run( $name );
+ $name = $self->method_lookup( 'opensrf.persist.slot.create' )->run( $name );
+ return undef unless $name;
+
+ $self->method_lookup('opensrf.persist.slot.set_expire')->run($name, $time);
+ return $name;
} catch Error with {
- my $e = shift;
- if ($e->message =~ /^Duplicate key/o) {
- throw $e;
- }
+ return undef;
};
- $self->method_lookup('opensrf.persist.slot.set_expire')->run($name, $time);
-
- return $name;
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.slot.create_expirable',
my $slot = shift;
my $new_interval = shift;
- my $etime = interval_to_seconds($new_interval);
- my $sid = _get_name_id($slot);
+ try {
+ my $etime = interval_to_seconds($new_interval);
+ my $sid = _get_name_id($slot);
- $dbh->do('DELETE FROM store_expire where id = ?', {}, $sid);
- return $slot if ($etime == 0);
+ $dbh->do('DELETE FROM store_expire where id = ?', {}, $sid);
+ return 0 if ($etime == 0);
- $dbh->do('INSERT INTO store_expire (id, atime, expire_interval) VALUES (?,?,?);',{},$sid,time(),$etime);
- return $slot;
+ $dbh->do('INSERT INTO store_expire (id, atime, expire_interval) VALUES (?,?,?);',{},$sid,time(),$etime);
+ return $etime;
+ }
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.slot.set_expire',
my $name = shift or do {
throw OpenSRF::EX::WARN ("No name specified!");
};
+
my $value = shift || '';
- my $name_id = _get_name_id($name);
+ try {
+ my $name_id = _get_name_id($name);
- if ($self->api_name =~ /object/) {
- $dbh->do('DELETE FROM storage WHERE name_id = ?;', {}, $name_id);
- }
+ if ($self->api_name =~ /object/) {
+ $dbh->do('DELETE FROM storage WHERE name_id = ?;', {}, $name_id);
+ }
- $dbh->do('INSERT INTO storage (name_id,value) VALUES (?,?);', {}, $name_id, JSON->perl2JSON($value));
+ $dbh->do('INSERT INTO storage (name_id,value) VALUES (?,?);', {}, $name_id, JSON->perl2JSON($value));
- _flush_by_name($name);
+ _flush_by_name($name);
- return 0 if ($dbh->err);
- return $name;
+ return $name;
+ } catch Error with {
+ return undef;
+ };
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.object.set',
my $name = shift;
- my $name_id = _get_name_id($name);
+ my $problem = 0;
+ try {
+ my $name_id = _get_name_id($name);
+
+ $dbh->do("DELETE FROM storage WHERE name_id = ?;", {}, $name_id);
+ $dbh->do("DELETE FROM store_name WHERE id = ?;", {}, $name_id);
+ $dbh->do("DELETE FROM store_expire WHERE id = ?;", {}, $name_id);
- $dbh->do("DELETE FROM storage WHERE name_id = ?;", {}, $name_id);
- $dbh->do("DELETE FROM store_name WHERE id = ?;", {}, $name_id);
- $dbh->do("DELETE FROM store_expire WHERE id = ?;", {}, $name_id);
- _sweep_expired_slots();
+ _sweep_expired_slots();
+ return $name;
+ } catch Error with {
+ return undef;
+ };
- return 1;
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.slot.destroy',
my $name = shift or do {
throw OpenSRF::EX::WARN ("No queue name specified!");
};
- my $name_id = _get_name_id($name);
- my $value = $dbh->selectrow_arrayref('SELECT id, value FROM storage WHERE name_id = ? ORDER BY id ASC LIMIT 1;', {}, $name_id);
- $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]) unless ($self->api_name =~ /peek$/);
+ try {
+ my $name_id = _get_name_id($name);
- _flush_by_name($name);
+ my $value = $dbh->selectrow_arrayref('SELECT id, value FROM storage WHERE name_id = ? ORDER BY id ASC LIMIT 1;', {}, $name_id);
+ $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]) unless ($self->api_name =~ /peek$/);
- return JSON->JSON2perl( $value->[1] );
+ _flush_by_name($name);
+
+ return JSON->JSON2perl( $value->[1] );
+ } catch Error with {
+ #my $e = shift;
+ #return $e;
+ return undef;
+ };
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.queue.peek',
my $client = shift;
my $name = shift or do {
- throw OpenSRF::EX::WARN ("No queue name specified!");
+ throw OpenSRF::EX::WARN ("No slot name specified!");
};
- my $name_id = _get_name_id($name);
- my $value = $dbh->selectrow_arrayref('SELECT id, value FROM storage WHERE name_id = ? ORDER BY id DESC LIMIT 1;', {}, $name_id);
- $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]) unless ($self->api_name =~ /peek$/);
+ try {
+ my $name_id = _get_name_id($name);
- _flush_by_name($name);
+ my $value = $dbh->selectrow_arrayref('SELECT id, value FROM storage WHERE name_id = ? ORDER BY id DESC LIMIT 1;', {}, $name_id);
+ $dbh->do('DELETE FROM storage WHERE id = ?;',{}, $value->[0]) unless ($self->api_name =~ /peek$/);
+
+ _flush_by_name($name);
- return JSON->JSON2perl( $value->[1] );
+ return JSON->JSON2perl( $value->[1] );
+ } catch Error with {
+ my $e = shift;
+ return undef;
+ };
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.stack.peek',
throw OpenSRF::EX::WARN ("No object name specified!");
};
- my $name_id = _get_name_id($name);
+ try {
+ my $name_id = _get_name_id($name);
- my $value = $dbh->selectrow_arrayref('SELECT name_id, value FROM storage WHERE name_id = ? ORDER BY id DESC LIMIT 1;', {}, $name_id);
- $dbh->do('DELETE FROM storage WHERE name_id = ?',{}, $value->[0]) unless ($self->api_name =~ /peek$/);
+ my $value = $dbh->selectrow_arrayref('SELECT name_id, value FROM storage WHERE name_id = ? ORDER BY id DESC LIMIT 1;', {}, $name_id);
+ $dbh->do('DELETE FROM storage WHERE name_id = ?',{}, $value->[0]) unless ($self->api_name =~ /peek$/);
- _flush_by_name($name);
+ _flush_by_name($name);
- return JSON->JSON2perl( $value->[1] );
+ return JSON->JSON2perl( $value->[1] );
+ } catch Error with {
+ return undef;
+ };
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.object.peek',