| 1 |
package Cornea::RecallTable; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use Cornea::Config; |
|---|
| 4 |
use DBI; |
|---|
| 5 |
|
|---|
| 6 |
sub new { |
|---|
| 7 |
my $class = shift; |
|---|
| 8 |
$class = ref($class) ? ref $class : $class; |
|---|
| 9 |
|
|---|
| 10 |
my $config = Cornea::Config->new(); |
|---|
| 11 |
my $dbh = DBI->connect($config->dsn(), |
|---|
| 12 |
$config->dbuser(), |
|---|
| 13 |
$config->dbpass(), |
|---|
| 14 |
{ PrintError => 0, RaiseError => 1 }, |
|---|
| 15 |
); |
|---|
| 16 |
|
|---|
| 17 |
bless {}, $class; |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
sub insert { |
|---|
| 21 |
my $self = shift; |
|---|
| 22 |
my ($serviceId, $assetId, $repId, $snl) = @_; |
|---|
| 23 |
die 'bad parameters' unless UNIVERSAL::ISA($snl, 'Cornea::StorageNodeList'); |
|---|
| 24 |
my $sth = $self->{dbh}->prepare("select storeAsset(?,?,?,?)"); |
|---|
| 25 |
$sth->execute($serviceId, $assetId, $repId, $snl); |
|---|
| 26 |
$sth->finish(); |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
sub getOpenNodes { |
|---|
| 30 |
my $self = shift; |
|---|
| 31 |
my $snl = Cornea::StorageNodeList->new(); |
|---|
| 32 |
my $sth = $self->{dbh}->prepare("select * from getOpenNodes()"); |
|---|
| 33 |
$sth->execute(); |
|---|
| 34 |
while(my $row = $sth->fetchrow_hashref()) { |
|---|
| 35 |
$snl->add(Cornea::StorageNode->new_from_row($row)); |
|---|
| 36 |
} |
|---|
| 37 |
$sth->finish(); |
|---|
| 38 |
return $snl; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
sub repInfo { |
|---|
| 42 |
my $self = shift; |
|---|
| 43 |
my ($serviceId, $repId) = @_; |
|---|
| 44 |
my $sth = $self->{dbh}->prepare("select * from getRepInfo(?,?)"); |
|---|
| 45 |
$sth->execute($serviceId, $repId); |
|---|
| 46 |
my $row = $sth->fetchrow_hashref(); |
|---|
| 47 |
$sth->finish(); |
|---|
| 48 |
return Cornea::RepresentationInfo->new_from_row($row); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
sub repInfoDependents { |
|---|
| 52 |
my $self = shift; |
|---|
| 53 |
my ($serviceId, $repId) = @_; |
|---|
| 54 |
my @deps; |
|---|
| 55 |
|
|---|
| 56 |
my $sth = $self->{dbh}->prepare("select * from getRepInfoDependents(?,?)"); |
|---|
| 57 |
$sth->execute($serviceId, $repId); |
|---|
| 58 |
while(my $row = $sth->fetchrow_hashref()) { |
|---|
| 59 |
push @deps, Cornea::RepresentationInfo->new_from_row($row); |
|---|
| 60 |
} |
|---|
| 61 |
$sth->finish(); |
|---|
| 62 |
return @deps; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
1; |
|---|