| 1 | package Bio::ConnectDots::DB::ConnectDots; | ||
| 2 | use vars qw(@ISA @AUTO_ATTRIBUTES @OTHER_ATTRIBUTES %SYNONYMS); | ||
| 3 | use strict; | ||
| 4 | use DBI; | ||
| 5 | use Bio::ConnectDots::DotSet; | ||
| 6 | use Bio::ConnectDots::ConnectorSet; | ||
| 7 | use Bio::ConnectDots::DB::DotTable; | ||
| 8 | use Bio::ConnectDots::DB::ConnectorTable; | ||
| 9 | use Bio::ConnectDots::ConnectDots; | ||
| 10 | @ISA = qw(Class::AutoClass::Root); | ||
| 11 | |||
| 12 | # get ConnectDots | ||
| 13 | sub get { | ||
| 14 | my($class,$cd)=@_; | ||
| 15 | my $db=$cd->db; | ||
| 16 | my ($connectorsets,$dotsets)=$class->get_sets($cd); | ||
| 17 | $cd->set(connectorsets=>$connectorsets,dotsets=>$dotsets); | ||
| 18 | my $dottables=Bio::ConnectDots::DB::DotTable->get_all($cd); | ||
| 19 | my $connectortables=Bio::ConnectDots::DB::ConnectorTable->get_all($cd); | ||
| 20 | $cd->set(connectortables=>$connectortables,dottables=>$dottables); | ||
| 21 | } | ||
| 22 | |||
| 23 | # fetch all ConnectorSets, connected DotSets | ||
| 24 | # return ARRAYs of ConnectorSets, connected DotSets | ||
| 25 | sub get_sets { | ||
| 26 | my($class,$cd)=@_; | ||
| 27 | my $db=$cd->db; | ||
| 28 | $class->throw("Cannot get data: database is not connected") unless $db->is_connected; | ||
| 29 | $class->throw("Cannot get data: database does not exist") unless $db->exists; | ||
| 30 | my $dbh=$db->dbh; | ||
| 31 | my $sql=qq(SELECT connectorset.connectorset_id,connectorset.name,connectorset.file_name,connectorset.version,connectorset.ftp,connectorset.ftp_files,dotset.dotset_id,dotset.name,label.label_id,label.label | ||
| 32 | FROM connectorset,dotset,connectdotset,label | ||
| 33 | WHERE connectorset.connectorset_id=connectdotset.connectorset_id | ||
| 34 | AND dotset.dotset_id=connectdotset.dotset_id | ||
| 35 | AND label.label_id=connectdotset.label_id | ||
| 36 | ORDER BY connectorset.connectorset_id); | ||
| 37 | my $rows=$dbh->selectall_arrayref($sql) or $class->throw($dbh->errstr); | ||
| 38 | return undef unless @$rows; # no data. | ||
| 39 | my ($id2dotset,$connectorsets); | ||
| 40 | my $row=shift @$rows; | ||
| 41 | do { | ||
| 42 | my ($connectorset_id,$connectorset_name,$connectorset_filename,$version,$ftp,$ftp_files)=@$row; | ||
| 43 | my $label2dotset={}; | ||
| 44 | my $label2labelid={}; | ||
| 45 | do { | ||
| 46 | my($skip,$skip,$skip,$skip,$skip,$skip,$dotset_id,$dotset_name,$label_id,$label)=@$row; | ||
| 47 | my $dotset=$id2dotset->{$dotset_id} || | ||
| 48 | ($id2dotset->{$dotset_id}=new Bio::ConnectDots::DotSet | ||
| 49 | (-name=>$dotset_name,-db_id=>$dotset_id,-db=>$db)); | ||
| 50 | $label2dotset->{$label}=$dotset; | ||
| 51 | $label2labelid->{$label}=$label_id; | ||
| 52 | $row=shift @$rows; | ||
| 53 | } while ($row && $row->[0] == $connectorset_id); | ||
| 54 | # end of this connector | ||
| 55 | push(@$connectorsets, | ||
| 56 | new Bio::ConnectDots::ConnectorSet | ||
| 57 | (-name=>$connectorset_name,-cs_version=>$version,-ftp=>$ftp,-ftp_files=>$ftp_files,-file=>$connectorset_filename, | ||
| 58 | -db_id=>$connectorset_id,-db=>$db, | ||
| 59 | -dotsets=>$label2dotset,-label2labelid=>$label2labelid)); | ||
| 60 | } while ($row); | ||
| 61 | my($dotsets); | ||
| 62 | @$dotsets=values %$id2dotset; | ||
| 63 | ($connectorsets,$dotsets); | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | 1; |