blib/lib/blx/xsdsql/xsd_parser/node/group.pm untested

filter: Statementstmt 0.0% 0 / 84 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 113 CC 9 SCAR 29.6
CC
9
Cov
0%
trigger_at_start_node
42.0
adj_redefine_from_schema
20.0
factory_type
2.0
CRAP 19.3
1 package blx::xsdsql::xsd_parser::node::group;
2 use strict; # use strict is for PBP
3 use Filter::Include;
4 include blx::xsdsql::include;
5 #line 6
6 use blx::xsdsql::ut::ut qw(nvl);
7 use blx::xsdsql::schema_repository::sql::generic::table qw(:overload);
8 use blx::xsdsql::xsd_parser::type;
9 use blx::xsdsql::xsd_parser::type::group;
10 use base qw(blx::xsdsql::xsd_parser::node);
11  
12  
13 sub adj_redefine_from_schema {
14 my ($self,%params)=@_;
15 my $child_schema=$self->get_attrs_value(qw(REDEFINE_FROM_SCHEMA));
16 affirm { defined $child_schema } "redefine_from_schema not set";
17 my $name=$self->get_attrs_value(qw(name));
18 affirm { defined $name } "not name defined for this group type";
19 my $types=$child_schema->get_attrs_value(qw(TYPE_NODE_NAMES));
20 affirm { defined $types } "not TYPE_NODE_NAMES in child schema";
21 my $t=$types->{$name};
22 affirm { defined $t } "$name: no such type with this name";
23 my $dest_table=$self->get_attrs_value(qw(TABLE));
24 affirm { defined $dest_table } "no such TABLE in self";
25 my $source_table=$t->get_attrs_value(qw(TABLE));
26 affirm { defined $source_table } "no such TABLE in type";
27 my $fl=0;
28 my @new_cols=();
29 for my $col($dest_table->reset_columns) {
30 if ($col->get_attrs_value(qw(NAME)) eq $name) {
31 $fl=1;
32 for my $col($source_table->get_columns) {
33 next if $col->is_pk;
34 next if $col->is_sys_attributes;
35 push @new_cols,$col->shallow_clone->set_attrs_value(ELEMENT_FORM => 'Q') # qualified because is external ref ;
36 }
37 }
38 else {
39 push @new_cols,$col;
40 }
41 }
42 affirm { $fl } "$name: no such column with this name in table ".$dest_table->get_sql_name;
43 $dest_table->add_columns(@new_cols);
44 $self->set_attrs_value(REDEFINE_FROM_SCHEMA => undef);
45 return $self;
46 }
47  
48 sub trigger_at_start_node {
49 my ($self,%params)=@_;
50 my $parent_table=$self->_get_parent_table;
51 my $schema=$self->get_attrs_value(qw(STACK))->[1];
52 $self->set_attrs_value(REDEFINE_FROM_SCHEMA => $schema->get_attrs_value(qw(REDEFINE_FROM_SCHEMA)));
53 if (defined (my $ref=$self->get_attrs_value(qw(ref)))) {
54 my $isparent_choice=$parent_table->get_attrs_value(qw(CHOICE));
55 my ($maxoccurs,$minoccurs) = ($self->_resolve_maxOccurs,$self->_resolve_minOccurs(CHOICE => $isparent_choice));
56 my $name=nvl($self->get_attrs_value(qw(name)),$ref);
57 my $ty_obj=defined $schema->get_attrs_value(qw(REDEFINE_FROM_SCHEMA))
58 ? undef
59 : blx::xsdsql::xsd_parser::type::factory(
60 $ref
61 ,SCHEMA => $schema
62 ,DEBUG => $self->get_attrs_value(qw(DEBUG))
63 );
64
65 my $column = $self->get_attrs_value(qw(COLUMN_CLASS))->new(
66 PATH => $self->_construct_path(undef,%params,PARENT => undef)
67 ,NAME => $name
68 ,TYPE => $ty_obj
69 ,MINOCCURS => $minoccurs
70 ,MAXOCCURS => $maxoccurs
71 ,GROUP_REF => 1
72 ,CHOICE => $isparent_choice
73 # ,ELEMENT_FORM => $self->_resolve_form
74 ,ELEMENT_FORM => 'Q'
75 ,DEBUG => $self->get_attrs_value(qw(DEBUG))
76
77 );
78 if (defined $parent_table->get_xsd_seq) { #the table is a sequence or choice
79 $column->set_attrs_value(XSD_SEQ => $parent_table->get_xsd_seq);
80 $parent_table->inc_xsd_seq unless $isparent_choice; #the columns of a choice have the same xsd_seq
81 }
82 $parent_table->add_columns({ ACCEPT_DUPLICATE_PATH => 1},$column);
83 $self->set_attrs_value(TABLE => $parent_table);
84 }
85 elsif (defined (my $name=$self->get_attrs_value(qw(name)))) {
86 my $table = $self->get_attrs_value(qw(TABLE_CLASS))->new (
87 PATH => $self->_construct_path($name,PARENT => undef)
88 ,NAME => $name
89 ,XSD_TYPE => XSD_TYPE_GROUP
90 ,XSD_SEQ => 1
91 ,DEBUG => $self->get_attrs_value(qw(DEBUG))
92 );
93 $schema->set_table_names($table);
94 $table->add_columns(
95 $schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(ID))
96 ,$schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(SEQ))
97 );
98 $self->set_attrs_value(TABLE => $table);
99 $schema->add_types($self);
100 }
101 else {
102 croak "group without name or ref is not supported\n";
103 }
104 return $self;
105 }
106  
107 sub factory_type {
108 my ($self,$t,$types,%params)=@_;
109 return blx::xsdsql::xsd_parser::type::group->new(NAME => $t,SCHEMA => $t->get_attrs_value(qw(STACK))->[1],DEBUG => $self->get_attrs_value(qw(DEBUG)));
110 }
111  
112 1;
113  
114  
115 __END__