« blib/lib/blx/xsdsql/xsd_parser/node.pm
↑ Summary
blib/lib/blx/xsdsql/schema_repository/stowage.pm »
| 1 | package blx::xsdsql::schema_repository::xml; | ||
| 2 | |||
| 3 | use strict; # use strict is for PBP | ||
| 4 | use Filter::Include; | ||
| 5 | include blx::xsdsql::include; | ||
| 6 | #line 7 | ||
| 7 | use Storable; | ||
| 8 | |||
| 9 | use base qw(blx::xsdsql::schema_repository::base); | ||
| 10 | |||
| 11 | |||
| 12 | sub new { | ||
| 13 | my ($class,%params)=@_; | ||
| 14 | return $class->SUPER::_new(%params); | ||
| 15 | } | ||
| 16 | |||
| 17 | sub store_xml { | ||
| 18 | my ($self,$xml,%params)=@_; | ||
| 19 | affirm { defined $params{CATALOG_NAME} } 'param CATALOG_NAME not set'; | ||
| 20 | my $id=$xml->read(%params); | ||
| 21 | return unless defined $id; | ||
| 22 | if (defined (my $na=$params{XML_NAME})) { | ||
| 23 | my $table=$self->{_EXTRA_TABLES}->get_extra_table(qw(XML_CATALOG)); | ||
| 24 | my $n=$self->{_BINDING}->insert_row_from_generic( | ||
| 25 | $table | ||
| 26 | ,[$id,$params{CATALOG_NAME},$na] | ||
| 27 | ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__} | ||
| 28 | ); | ||
| 29 | $self->{_BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); | ||
| 30 | affirm { defined $n && $n == 1 } "the rows insert is not 1"; | ||
| 31 | } | ||
| 32 | else { | ||
| 33 | my $table=$self->{_EXTRA_TABLES}->get_extra_table(qw(XML_ID)); | ||
| 34 | my $n=$self->{_BINDING}->insert_row_from_generic( | ||
| 35 | $table | ||
| 36 | ,[$id,$params{CATALOG_NAME}] | ||
| 37 | ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__} | ||
| 38 | ); | ||
| 39 | $self->{_BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); | ||
| 40 | affirm { defined $n && $n == 1 } "the rows insert is not 1"; | ||
| 41 | } | ||
| 42 | return $id; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub put_xml { | ||
| 46 | my ($self,$xml,%params)=@_; | ||
| 47 | affirm {defined $params{ID} } 'param ID not set'; | ||
| 48 | my $r=$xml->write(%params,DELETE_ROWS => $params{DELETE},ROOT_ID => $params{ID}); | ||
| 49 | return unless defined $r; | ||
| 50 | if ($params{DELETE}) { | ||
| 51 | for my $k(qw( XML_CATALOG XML_ID)) { | ||
| 52 | my $table=$self->{_EXTRA_TABLES}->get_extra_table($k); | ||
| 53 | my $n=$self->{_BINDING}->delete_rows_from_generic( | ||
| 54 | $table | ||
| 55 | ,[ | ||
| 56 | {COL => '$ID',VALUE => $params{ID}} | ||
| 57 | ], | ||
| 58 | ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__} | ||
| 59 | ); | ||
| 60 | $self->{_BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | return $params{ID}; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub get_xml_names { | ||
| 67 | my ($self,%params)=@_; | ||
| 68 | my $table=$self->{_EXTRA_TABLES}->get_extra_table(qw(XML_CATALOG)); | ||
| 69 | my @where=(); | ||
| 70 | push @where,{ COL => 'catalog_name',VALUE => $params{CATALOG_NAME} } if defined $params{CATALOG_NAME}; | ||
| 71 | push @where,{ COL => 'xml_name',VALUE => $params{XML_NAME} } if defined $params{XML_NAME}; | ||
| 72 | |||
| 73 | my $prep=$self->{_BINDING}->generic_query_rows( | ||
| 74 | $table | ||
| 75 | ,WHERE => \@where | ||
| 76 | ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__} | ||
| 77 | ) | ||
| 78 | ; | ||
| 79 | my @rows=(); | ||
| 80 | while(my $r=$prep->fetchrow_arrayref) { | ||
| 81 | push @rows,Storable::dclone($r); | ||
| 82 | } | ||
| 83 | $self->{_BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); | ||
| 84 | return wantarray ? @rows : \@rows; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub get_xml_ids { | ||
| 88 | my ($self,%params)=@_; | ||
| 89 | my $table=$self->{_EXTRA_TABLES}->get_extra_table(qw(XML_ID)); | ||
| 90 | my @where=(); | ||
| 91 | push @where,{ COL => 'catalog_name',VALUE => $params{CATALOG_NAME} } if defined $params{CATALOG_NAME}; | ||
| 92 | push @where,{ COL => '$ID',VALUE => $params{ID} } if defined $params{ID}; | ||
| 93 | |||
| 94 | my $prep=$self->{_BINDING}->generic_query_rows( | ||
| 95 | $table | ||
| 96 | ,WHERE => \@where | ||
| 97 | ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__} | ||
| 98 | ) | ||
| 99 | ; | ||
| 100 | my @rows=(); | ||
| 101 | while(my $r=$prep->fetchrow_arrayref) { | ||
| 102 | push @rows,Storable::dclone($r); | ||
| 103 | } | ||
| 104 | $self->{_BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); | ||
| 105 | return wantarray ? @rows : \@rows; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub get_xml_stored { | ||
| 109 | my ($self,%params)=@_; | ||
| 110 | my %rows=(); | ||
| 111 | unless (defined $params{XML_NAME}) { | ||
| 112 | my @where=(); | ||
| 113 | push @where,{ COL => '$ID',VALUE => $params{ID} } if defined $params{ID}; | ||
| 114 | push @where,{ COL => 'catalog_name',VALUE => $params{CATALOG_NAME} } if defined $params{CATALOG_NAME}; | ||
| 115 | my $table=$self->{_EXTRA_TABLES}->get_extra_table(qw(XML_ID)); | ||
| 116 | my $prep=$self->{_BINDING}->generic_query_rows( | ||
| 117 | $table | ||
| 118 | ,WHERE => \@where | ||
| 119 | ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__} | ||
| 120 | ) | ||
| 121 | ; | ||
| 122 | while(my $r=$prep->fetchrow_arrayref) { | ||
| 123 | my $clone=Storable::dclone($r); | ||
| 124 | $clone->[2]=undef; # set the name to undef | ||
| 125 | $rows{$r->[0]}=$clone; | ||
| 126 | } | ||
| 127 | $self->{_BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); | ||
| 128 | } | ||
| 129 | { | ||
| 130 | my $table=$self->{_EXTRA_TABLES}->get_extra_table(qw(XML_CATALOG)); | ||
| 131 | my @where=(); | ||
| 132 | push @where,{ COL => '$ID',VALUE => $params{ID} } if defined $params{ID}; | ||
| 133 | push @where,{ COL => 'catalog_name',VALUE => $params{CATALOG_NAME} } if defined $params{CATALOG_NAME}; | ||
| 134 | push @where,{ COL => 'xml_name',VALUE => $params{XML_NAME} } if defined $params{XML_NAME}; | ||
| 135 | |||
| 136 | my $prep=$self->{_BINDING}->generic_query_rows( | ||
| 137 | $table | ||
| 138 | ,WHERE => \@where | ||
| 139 | ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__} | ||
| 140 | ) | ||
| 141 | ; | ||
| 142 | while(my $r=$prep->fetchrow_arrayref) { | ||
| 143 | $rows{$r->[0]}=Storable::dclone($r); | ||
| 144 | } | ||
| 145 | $self->{_BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); | ||
| 146 | } | ||
| 147 | my @rows=(); | ||
| 148 | for my $k(sort { $a <=> $b } keys %rows) { #numeric sort | ||
| 149 | push @rows,$rows{$k}; | ||
| 150 | } | ||
| 151 | return wantarray ? @rows : \@rows; | ||
| 152 | } | ||
| 153 | |||
| 154 | 1; | ||
| 155 | |||
| 156 | __END__ |