« blib/lib/blx/xsdsql/generator/sql/generic/handle/create_extra_tables.pm
↑ Summary
blib/lib/blx/xsdsql/xsd_parser/type/other.pm »
| 1 | package blx::xsdsql::xsd_parser::node::sequence; | ||
| 2 | |||
| 3 | use strict; # use strict is for PBP | ||
| 4 | use Filter::Include; | ||
| 5 | include blx::xsdsql::include; | ||
| 6 | #line 7 | ||
| 7 | use blx::xsdsql::ut::ut qw(nvl); | ||
| 8 | use blx::xsdsql::xsd_parser::type; | ||
| 9 | use base qw(blx::xsdsql::xsd_parser::node); | ||
| 10 | |||
| 11 | use constant { | ||
| 12 | DEFAULT_OCCURS_TABLE_PREFIX => 'm_' | ||
| 13 | }; | ||
| 14 | |||
| 15 | sub trigger_at_start_node { | ||
| 16 | my ($self,%params)=@_; | ||
| 17 | my $parent_table=$self->_get_parent_table; | ||
| 18 | my $path=$parent_table->get_path; | ||
| 19 | my ($maxoccurs,$minoccurs)=( | ||
| 20 | $self->_resolve_maxOccurs | ||
| 21 | ,$self->_resolve_minOccurs(CHOICE => $parent_table->get_attrs_value(qw(CHOICE))) | ||
| 22 | ); | ||
| 23 | if ($maxoccurs > 1) { | ||
| 24 | my $schema=$self->get_attrs_value(qw(STACK))->[1]; | ||
| 25 | my $table = $self->get_attrs_value(qw(TABLE_CLASS))->new( | ||
| 26 | NAME => DEFAULT_OCCURS_TABLE_PREFIX.$parent_table->get_attrs_value(qw(NAME)) | ||
| 27 | ,MAXOCCURS => $maxoccurs | ||
| 28 | ,DEBUG => $self->get_attrs_value(qw(DEBUG)) | ||
| 29 | ); | ||
| 30 | |||
| 31 | $schema->set_table_names($table); | ||
| 32 | |||
| 33 | $table->add_columns( | ||
| 34 | $schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(ID)) | ||
| 35 | ,$schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(SEQ)) | ||
| 36 | ); | ||
| 37 | $parent_table->add_child_tables($table); | ||
| 38 | my $isparent_choice=$parent_table->get_attrs_value(qw(CHOICE)); | ||
| 39 | |||
| 40 | my $column = $self->get_attrs_value(qw(COLUMN_CLASS))->new ( #hook the column to the parent table | ||
| 41 | NAME => $table->get_attrs_value(qw(NAME)) | ||
| 42 | ,TYPE => $schema->get_attrs_value(qw(ID_SQL_TYPE)) | ||
| 43 | ,MINOCCURS => 0 | ||
| 44 | ,MAXOCCURS => 1 | ||
| 45 | ,PATH_REFERENCE => $table->get_path | ||
| 46 | ,TABLE_REFERENCE => $table | ||
| 47 | ,CHOICE => $isparent_choice | ||
| 48 | ,ELEMENT_FORM => $self->_resolve_form | ||
| 49 | ,DEBUG => $self->get_attrs_value(qw(DEBUG)) | ||
| 50 | ); | ||
| 51 | if (defined $parent_table->get_xsd_seq) { #the table is a sequence or a choice | ||
| 52 | $column->set_attrs_value(XSD_SEQ => $parent_table->get_xsd_seq); | ||
| 53 | $parent_table->inc_xsd_seq unless $isparent_choice; | ||
| 54 | } | ||
| 55 | $parent_table->add_columns($column); | ||
| 56 | $self->set_attrs_value(TABLE => $table); | ||
| 57 | } | ||
| 58 | else { | ||
| 59 | $parent_table->set_attrs_value(XSD_SEQ => 0) unless defined $parent_table->get_xsd_seq; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | __END__ |