| | 7 | sub __connect { |
|---|
| | 8 | my $self = shift; |
|---|
| | 9 | my $config = Cornea::Config->new(); |
|---|
| | 10 | my $dbh; |
|---|
| | 11 | my $dsns = $config->get_list("DB::dsn"); |
|---|
| | 12 | Cornea::Utils::shuffle($dsns); |
|---|
| | 13 | foreach my $dsn (@$dsns) { |
|---|
| | 14 | eval { |
|---|
| | 15 | $dbh = DBI->connect($config->get("DB::dsn"), |
|---|
| | 16 | $config->get("DB::user"), |
|---|
| | 17 | $config->get("DB::pass"), |
|---|
| | 18 | { PrintError => 0, RaiseError => 1 }, |
|---|
| | 19 | ); |
|---|
| | 20 | }; |
|---|
| | 21 | last unless ($@); |
|---|
| | 22 | } |
|---|
| | 23 | $self->{dbh} = shift; |
|---|
| | 24 | } |
|---|
| | 25 | sub __reconnect { |
|---|
| | 26 | my $self = shift; |
|---|
| | 27 | $self->{dbh} = undef; |
|---|
| | 28 | $self->__connect(); |
|---|
| | 29 | } |
|---|
| 8 | | $class = ref($class) ? ref $class : $class; |
|---|
| 9 | | |
|---|
| 10 | | my $config = Cornea::Config->new(); |
|---|
| 11 | | my $dbh = DBI->connect($config->get("DB::dsn"), |
|---|
| 12 | | $config->get("DB::user"), |
|---|
| 13 | | $config->get("DB::pass"), |
|---|
| 14 | | { PrintError => 0, RaiseError => 1 }, |
|---|
| 15 | | ); |
|---|
| 16 | | |
|---|
| 17 | | bless {}, $class; |
|---|
| | 32 | my $self = bless { }, $class; |
|---|
| | 33 | $self->__connect; |
|---|
| 24 | | my $sth = $self->{dbh}->prepare("select storeAsset(?,?,?,?)"); |
|---|
| 25 | | $sth->execute($serviceId, $assetId, $repId, $snl); |
|---|
| 26 | | $sth->finish(); |
|---|
| | 41 | again: |
|---|
| | 42 | eval { |
|---|
| | 43 | my $sth = $self->{dbh}->prepare("select storeAsset(?,?,?,?)"); |
|---|
| | 44 | $sth->execute($serviceId, $assetId, $repId, $snl); |
|---|
| | 45 | $sth->finish(); |
|---|
| | 46 | }; |
|---|
| | 47 | if ($@) { |
|---|
| | 48 | unless ($tried++) { $self->{dbh}->__reconnect(); goto again; } |
|---|
| | 49 | die $@ if $@; |
|---|
| | 50 | } |
|---|
| | 51 | return 1; |
|---|
| 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)); |
|---|
| | 56 | my ($serviceId, $assetId, $repId) = @_; |
|---|
| | 57 | my $sth = $self->{dbh}->prepare("select findAsset(?,?,?)"); |
|---|
| | 58 | my $tried = 0; |
|---|
| | 59 | my $C; |
|---|
| | 60 | again: |
|---|
| | 61 | eval { |
|---|
| | 62 | $C = Cornea::StorageNodeList->new(); |
|---|
| | 63 | $sth->execute($serviceId, $assetId, $repId); |
|---|
| | 64 | while(my $node = $sth->fetchrow_hashref()) { |
|---|
| | 65 | $C->add(Cornea::StorageNode->new_from_row($node)); |
|---|
| | 66 | } |
|---|
| | 67 | $sth->finish(); |
|---|
| | 68 | }; |
|---|
| | 69 | if ($@) { |
|---|
| | 70 | unless ($tried++) { $self->{dbh}->__reconnect(); goto again; } |
|---|
| | 71 | die $@ if $@; |
|---|
| 44 | | my $sth = $self->{dbh}->prepare("select * from getRepInfo(?,?)"); |
|---|
| 45 | | $sth->execute($serviceId, $repId); |
|---|
| 46 | | my $row = $sth->fetchrow_hashref(); |
|---|
| 47 | | $sth->finish(); |
|---|
| | 101 | my $tried = 0; |
|---|
| | 102 | my $row; |
|---|
| | 103 | again: |
|---|
| | 104 | eval { |
|---|
| | 105 | my $sth = $self->{dbh}->prepare("select * from getRepInfo(?,?)"); |
|---|
| | 106 | $sth->execute($serviceId, $repId); |
|---|
| | 107 | $row = $sth->fetchrow_hashref(); |
|---|
| | 108 | $sth->finish(); |
|---|
| | 109 | }; |
|---|
| | 110 | if ($@) { |
|---|
| | 111 | unless ($tried++) { $self->{dbh}->__reconnect(); goto again; } |
|---|
| | 112 | die $@ if $@; |
|---|
| | 113 | } |
|---|
| 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); |
|---|
| | 123 | eval { |
|---|
| | 124 | @deps = (); |
|---|
| | 125 | my $sth = $self->{dbh}->prepare("select * from getRepInfoDependents(?,?)"); |
|---|
| | 126 | $sth->execute($serviceId, $repId); |
|---|
| | 127 | while(my $row = $sth->fetchrow_hashref()) { |
|---|
| | 128 | push @deps, Cornea::RepresentationInfo->new_from_row($row); |
|---|
| | 129 | } |
|---|
| | 130 | $sth->finish(); |
|---|
| | 131 | }; |
|---|
| | 132 | if ($@) { |
|---|
| | 133 | unless ($tried++) { $self->{dbh}->__reconnect(); goto again; } |
|---|
| | 134 | die $@ if $@; |
|---|