1 |
package ERDB; |
package ERDB; |
2 |
|
|
3 |
use strict; |
use strict; |
|
use Carp; |
|
4 |
use Tracer; |
use Tracer; |
5 |
use DBKernel; |
use DBrtns; |
6 |
use Data::Dumper; |
use Data::Dumper; |
7 |
use XML::Simple; |
use XML::Simple; |
8 |
use DBQuery; |
use DBQuery; |
9 |
use DBObject; |
use DBObject; |
10 |
use Stats; |
use Stats; |
11 |
use Time::HiRes qw(gettimeofday); |
use Time::HiRes qw(gettimeofday); |
12 |
|
use FIG; |
13 |
|
|
14 |
=head1 Entity-Relationship Database Package |
=head1 Entity-Relationship Database Package |
15 |
|
|
33 |
relation that contains two fields-- the feature ID (C<id>) and the alias name (C<alias>). |
relation that contains two fields-- the feature ID (C<id>) and the alias name (C<alias>). |
34 |
The B<FEATURE> entity also contains an optional virulence number. This is implemented |
The B<FEATURE> entity also contains an optional virulence number. This is implemented |
35 |
as a separate relation C<FeatureVirulence> which contains an ID (C<id>) and a virulence number |
as a separate relation C<FeatureVirulence> which contains an ID (C<id>) and a virulence number |
36 |
(C<virulence>). If the virulence of a feature I<ABC> is known to be 6, there will be one row in the |
(C<virulence>). If the virulence of a feature I<ABC> is known to be 6, there will be one row in |
37 |
C<FeatureVirulence> relation possessing the value I<ABC> as its ID and 6 as its virulence number. |
the C<FeatureVirulence> relation possessing the value I<ABC> as its ID and 6 as its virulence |
38 |
If the virulence of I<ABC> is not known, there will not be any rows for it in C<FeatureVirulence>. |
number. If the virulence of I<ABC> is not known, there will not be any rows for it in |
39 |
|
C<FeatureVirulence>. |
40 |
|
|
41 |
Entities are connected by binary relationships implemented using single relations possessing the |
Entities are connected by binary relationships implemented using single relations possessing the |
42 |
same name as the relationship itself and that has an I<arity> of 1-to-1 (C<11>), 1-to-many (C<1M>), |
same name as the relationship itself and that has an I<arity> of 1-to-1 (C<11>), 1-to-many (C<1M>), |
71 |
is described in the L</GenerateEntity> and L</GenerateConnection> methods, though it is not yet |
is described in the L</GenerateEntity> and L</GenerateConnection> methods, though it is not yet |
72 |
fully implemented. |
fully implemented. |
73 |
|
|
74 |
|
=head2 XML Database Description |
75 |
|
|
76 |
|
=head3 Data Types |
77 |
|
|
78 |
|
The ERDB system supports the following data types. Note that there are numerous string |
79 |
|
types depending on the maximum length. Some database packages limit the total number of |
80 |
|
characters you have in an index key; to insure the database works in all environments, |
81 |
|
the type of string should be the shortest one possible that supports all the known values. |
82 |
|
|
83 |
|
=over 4 |
84 |
|
|
85 |
|
=item char |
86 |
|
|
87 |
|
single ASCII character |
88 |
|
|
89 |
|
=item int |
90 |
|
|
91 |
|
32-bit signed integer |
92 |
|
|
93 |
|
=item date |
94 |
|
|
95 |
|
64-bit unsigned integer, representing a PERL date/time value |
96 |
|
|
97 |
|
=item text |
98 |
|
|
99 |
|
long string; Text fields cannot be used in indexes or sorting and do not support the |
100 |
|
normal syntax of filter clauses, but can be up to a billion character in length |
101 |
|
|
102 |
|
=item float |
103 |
|
|
104 |
|
double-precision floating-point number |
105 |
|
|
106 |
|
=item boolean |
107 |
|
|
108 |
|
single-bit numeric value; The value is stored as a 16-bit signed integer (for |
109 |
|
compatability with certain database packages), but the only values supported are |
110 |
|
0 and 1. |
111 |
|
|
112 |
|
=item key-string |
113 |
|
|
114 |
|
variable-length string, maximum 40 characters |
115 |
|
|
116 |
|
=item name-string |
117 |
|
|
118 |
|
variable-length string, maximum 80 characters |
119 |
|
|
120 |
|
=item medium-string |
121 |
|
|
122 |
|
variable-length string, maximum 160 characters |
123 |
|
|
124 |
|
=item string |
125 |
|
|
126 |
|
variable-length string, maximum 255 characters |
127 |
|
|
128 |
|
=back |
129 |
|
|
130 |
|
=head3 Global Tags |
131 |
|
|
132 |
|
The entire database definition must be inside a B<Database> tag. The display name of |
133 |
|
the database is given by the text associated with the B<Title> tag. The display name |
134 |
|
is only used in the automated documentation. It has no other effect. The entities and |
135 |
|
relationships are listed inside the B<Entities> and B<Relationships> tags, |
136 |
|
respectively. None of these tags have attributes. |
137 |
|
|
138 |
|
<Database> |
139 |
|
<Title>... display title here...</Title> |
140 |
|
<Entities> |
141 |
|
... entity definitions here ... |
142 |
|
</Entities> |
143 |
|
<Relationships> |
144 |
|
... relationship definitions here... |
145 |
|
</Relationships> |
146 |
|
</Database> |
147 |
|
|
148 |
|
Entities, relationships, indexes, and fields all allow a text tag called B<Notes>. |
149 |
|
The text inside the B<Notes> tag contains comments that will appear when the database |
150 |
|
documentation is generated. Within a B<Notes> tag, you may use C<[i]> and C<[/i]> for |
151 |
|
italics, C<[b]> and C<[/b]> for bold, and C<[p]> for a new paragraph. |
152 |
|
|
153 |
|
=head3 Fields |
154 |
|
|
155 |
|
Both entities and relationships have fields described by B<Field> tags. A B<Field> |
156 |
|
tag can have B<Notes> associated with it. The complete set of B<Field> tags for an |
157 |
|
object mus be inside B<Fields> tags. |
158 |
|
|
159 |
|
<Entity ... > |
160 |
|
<Fields> |
161 |
|
... Field tags ... |
162 |
|
</Fields> |
163 |
|
</Entity> |
164 |
|
|
165 |
|
The attributes for the B<Field> tag are as follows. |
166 |
|
|
167 |
|
=over 4 |
168 |
|
|
169 |
|
=item name |
170 |
|
|
171 |
|
Name of the field. The field name should contain only letters, digits, and hyphens (C<->), |
172 |
|
and the first character should be a letter. Most underlying databases are case-insensitive |
173 |
|
with the respect to field names, so a best practice is to use lower-case letters only. |
174 |
|
|
175 |
|
=item type |
176 |
|
|
177 |
|
Data type of the field. The legal data types are given above. |
178 |
|
|
179 |
|
=item relation |
180 |
|
|
181 |
|
Name of the relation containing the field. This should only be specified for entity |
182 |
|
fields. The ERDB system does not support optional fields or multi-occurring fields |
183 |
|
in the primary relation of an entity. Instead, they are put into secondary relations. |
184 |
|
So, for example, in the C<Genome> entity, the C<group-name> field indicates a special |
185 |
|
grouping used to select a subset of the genomes. A given genome may not be in any |
186 |
|
groups or may be in multiple groups. Therefore, C<group-name> specifies a relation |
187 |
|
value. The relation name specified must be a valid table name. By convention, it is |
188 |
|
usually the entity name followed by a qualifying word (e.g. C<GenomeGroup>). In an |
189 |
|
entity, the fields without a relation attribute are said to belong to the |
190 |
|
I<primary relation>. This relation has the same name as the entity itself. |
191 |
|
|
192 |
|
=back |
193 |
|
|
194 |
|
=head3 Indexes |
195 |
|
|
196 |
|
An entity can have multiple alternate indexes associated with it. The fields must |
197 |
|
be from the primary relation. The alternate indexes assist in ordering results |
198 |
|
from a query. A relationship can have up to two indexes-- a I<to-index> and a |
199 |
|
I<from-index>. These order the results when crossing the relationship. For |
200 |
|
example, in the relationship C<HasContig> from C<Genome> to C<Contig>, the |
201 |
|
from-index would order the contigs of a ganome, and the to-index would order |
202 |
|
the genomes of a contig. A relationship's index must specify only fields in |
203 |
|
the relationship. |
204 |
|
|
205 |
|
The indexes for an entity must be listed inside the B<Indexes> tag. The from-index |
206 |
|
of a relationship is specified using the B<FromIndex> tag; the to-index is specified |
207 |
|
using the B<ToIndex> tag. |
208 |
|
|
209 |
|
Each index can contain a B<Notes> tag. In addition, it will have an B<IndexFields> |
210 |
|
tag containing the B<IndexField> tags. These specify, in order, the fields used in |
211 |
|
the index. The attributes of an B<IndexField> tag are as follows. |
212 |
|
|
213 |
|
=over 4 |
214 |
|
|
215 |
|
=item name |
216 |
|
|
217 |
|
Name of the field. |
218 |
|
|
219 |
|
=item order |
220 |
|
|
221 |
|
Sort order of the field-- C<ascending> or C<descending>. |
222 |
|
|
223 |
|
=back |
224 |
|
|
225 |
|
The B<Index>, B<FromIndex>, and B<ToIndex> tags themselves have no attributes. |
226 |
|
|
227 |
|
=head3 Object and Field Names |
228 |
|
|
229 |
|
By convention entity and relationship names use capital casing (e.g. C<Genome> or |
230 |
|
C<HasRegionsIn>. Most underlying databases, however, are aggressively case-insensitive |
231 |
|
with respect to relation names, converting them internally to all-upper case or |
232 |
|
all-lower case. |
233 |
|
|
234 |
|
If syntax or parsing errors occur when you try to load or use an ERDB database, the |
235 |
|
most likely reason is that one of your objects has an SQL reserved word as its name. |
236 |
|
The list of SQL reserved words keeps increasing; however, most are unlikely to show |
237 |
|
up as a noun or declarative verb phrase. The exceptions are C<Group>, C<User>, |
238 |
|
C<Table>, C<Index>, C<Object>, C<Date>, C<Number>, C<Update>, C<Time>, C<Percent>, |
239 |
|
C<Memo>, C<Order>, and C<Sum>. This problem can crop up in field names as well. |
240 |
|
|
241 |
|
Every entity has a field called C<id> that acts as its primary key. Every relationship |
242 |
|
has fields called C<from-link> and C<to-link> that contain copies of the relevant |
243 |
|
entity IDs. These are essentially ERDB's reserved words, and should not be used |
244 |
|
for user-defined field names. |
245 |
|
|
246 |
|
=head3 Entities |
247 |
|
|
248 |
|
An entity is described by the B<Entity> tag. The entity can contain B<Notes>, an |
249 |
|
B<Indexes> tag containing one or more secondary indexes, and a B<Fields> tag |
250 |
|
containing one or more fields. The attributes of the B<Entity> tag are as follows. |
251 |
|
|
252 |
|
=over 4 |
253 |
|
|
254 |
|
=item name |
255 |
|
|
256 |
|
Name of the entity. The entity name, by convention, uses capital casing (e.g. C<Genome> |
257 |
|
or C<GroupBlock>) and should be a noun or noun phrase. |
258 |
|
|
259 |
|
=item keyType |
260 |
|
|
261 |
|
Data type of the primary key. The primary key is always named C<id>. |
262 |
|
|
263 |
|
=back |
264 |
|
|
265 |
|
=head3 Relationships |
266 |
|
|
267 |
|
A relationship is described by the C<Relationship> tag. Within a relationship, |
268 |
|
there can be a C<Notes> tag, a C<Fields> tag containing the intersection data |
269 |
|
fields, a C<FromIndex> tag containing the from-index, and a C<ToIndex> tag containing |
270 |
|
the to-index. |
271 |
|
|
272 |
|
The C<Relationship> tag has the following attributes. |
273 |
|
|
274 |
|
=over 4 |
275 |
|
|
276 |
|
=item name |
277 |
|
|
278 |
|
Name of the relationship. The relationship name, by convention, uses capital casing |
279 |
|
(e.g. C<ContainsRegionIn> or C<HasContig>), and should be a declarative verb |
280 |
|
phrase, designed to fit between the from-entity and the to-entity (e.g. |
281 |
|
Block C<ContainsRegionIn> Genome). |
282 |
|
|
283 |
|
=item from |
284 |
|
|
285 |
|
Name of the entity from which the relationship starts. |
286 |
|
|
287 |
|
=item to |
288 |
|
|
289 |
|
Name of the entity to which the relationship proceeds. |
290 |
|
|
291 |
|
=item arity |
292 |
|
|
293 |
|
Relationship type: C<1M> for one-to-many and C<MM> for many-to-many. |
294 |
|
|
295 |
|
=back |
296 |
|
|
297 |
=cut |
=cut |
298 |
|
|
299 |
# GLOBALS |
# GLOBALS |
301 |
# Table of information about our datatypes. "sqlType" is the corresponding SQL datatype string. |
# Table of information about our datatypes. "sqlType" is the corresponding SQL datatype string. |
302 |
# "maxLen" is the maximum permissible length of the incoming string data used to populate a field |
# "maxLen" is the maximum permissible length of the incoming string data used to populate a field |
303 |
# of the specified type. "dataGen" is PERL string that will be evaluated if no test data generation |
# of the specified type. "dataGen" is PERL string that will be evaluated if no test data generation |
304 |
#string is specified in the field definition. |
# string is specified in the field definition. "avgLen" is the average byte length for estimating |
305 |
my %TypeTable = ( char => { sqlType => 'CHAR(1)', maxLen => 1, dataGen => "StringGen('A')" }, |
# record sizes. |
306 |
int => { sqlType => 'INTEGER', maxLen => 20, dataGen => "IntGen(0, 99999999)" }, |
my %TypeTable = ( char => { sqlType => 'CHAR(1)', maxLen => 1, avgLen => 1, dataGen => "StringGen('A')" }, |
307 |
string => { sqlType => 'VARCHAR(255)', maxLen => 255, dataGen => "StringGen(IntGen(10,250))" }, |
int => { sqlType => 'INTEGER', maxLen => 20, avgLen => 4, dataGen => "IntGen(0, 99999999)" }, |
308 |
text => { sqlType => 'TEXT', maxLen => 1000000000, dataGen => "StringGen(IntGen(80,1000))" }, |
string => { sqlType => 'VARCHAR(255)', maxLen => 255, avgLen => 100, dataGen => "StringGen(IntGen(10,250))" }, |
309 |
date => { sqlType => 'BIGINT', maxLen => 80, dataGen => "DateGen(-7, 7, IntGen(0,1400))" }, |
text => { sqlType => 'TEXT', maxLen => 1000000000, avgLen => 500, dataGen => "StringGen(IntGen(80,1000))" }, |
310 |
float => { sqlType => 'DOUBLE PRECISION', maxLen => 40, dataGen => "FloatGen(0.0, 100.0)" }, |
date => { sqlType => 'BIGINT', maxLen => 80, avgLen => 8, dataGen => "DateGen(-7, 7, IntGen(0,1400))" }, |
311 |
boolean => { sqlType => 'SMALLINT', maxLen => 1, dataGen => "IntGen(0, 1)" }, |
float => { sqlType => 'DOUBLE PRECISION', maxLen => 40, avgLen => 8, dataGen => "FloatGen(0.0, 100.0)" }, |
312 |
|
boolean => { sqlType => 'SMALLINT', maxLen => 1, avgLen => 2, dataGen => "IntGen(0, 1)" }, |
313 |
'key-string' => |
'key-string' => |
314 |
{ sqlType => 'VARCHAR(40)', maxLen => 40, dataGen => "StringGen(IntGen(10,40))" }, |
{ sqlType => 'VARCHAR(40)', maxLen => 40, avgLen => 10, dataGen => "StringGen(IntGen(10,40))" }, |
315 |
'name-string' => |
'name-string' => |
316 |
{ sqlType => 'VARCHAR(80)', maxLen => 80, dataGen => "StringGen(IntGen(10,80))" }, |
{ sqlType => 'VARCHAR(80)', maxLen => 80, avgLen => 40, dataGen => "StringGen(IntGen(10,80))" }, |
317 |
'medium-string' => |
'medium-string' => |
318 |
{ sqlType => 'VARCHAR(160)', maxLen => 160, dataGen => "StringGen(IntGen(10,160))" }, |
{ sqlType => 'VARCHAR(160)', maxLen => 160, avgLen => 40, dataGen => "StringGen(IntGen(10,160))" }, |
319 |
); |
); |
320 |
|
|
321 |
# Table translating arities into natural language. |
# Table translating arities into natural language. |
365 |
_metaData => $metaData |
_metaData => $metaData |
366 |
}; |
}; |
367 |
# Bless and return it. |
# Bless and return it. |
368 |
bless $self; |
bless $self, $class; |
369 |
return $self; |
return $self; |
370 |
} |
} |
371 |
|
|
372 |
=head3 ShowMetaData |
=head3 ShowMetaData |
373 |
|
|
374 |
C<< $database->ShowMetaData($fileName); >> |
C<< $erdb->ShowMetaData($fileName); >> |
375 |
|
|
376 |
This method outputs a description of the database. This description can be used to help users create |
This method outputs a description of the database. This description can be used to help users create |
377 |
the data to be loaded into the relations. |
the data to be loaded into the relations. |
503 |
print HTMLOUT _OpenTable("Join Table", "Source", "Target", "Join Condition"); |
print HTMLOUT _OpenTable("Join Table", "Source", "Target", "Join Condition"); |
504 |
# Loop through the joins. |
# Loop through the joins. |
505 |
my $joinTable = $metadata->{Joins}; |
my $joinTable = $metadata->{Joins}; |
506 |
for my $joinKey (sort keys %{$joinTable}) { |
my @joinKeys = keys %{$joinTable}; |
507 |
|
for my $joinKey (sort @joinKeys) { |
508 |
# Separate out the source, the target, and the join clause. |
# Separate out the source, the target, and the join clause. |
509 |
$joinKey =~ m!([^/]*)/(.*)$!; |
$joinKey =~ m!^([^/]+)/(.+)$!; |
510 |
my ($source, $target, $clause) = ($self->ComputeObjectSentence($1), |
my ($sourceRelation, $targetRelation) = ($1, $2); |
511 |
$self->ComputeObjectSentence($2), |
Trace("Join with key $joinKey is from $sourceRelation to $targetRelation.") if T(4); |
512 |
$joinTable->{$joinKey}); |
my $source = $self->ComputeObjectSentence($sourceRelation); |
513 |
|
my $target = $self->ComputeObjectSentence($targetRelation); |
514 |
|
my $clause = $joinTable->{$joinKey}; |
515 |
# Display them in a table row. |
# Display them in a table row. |
516 |
print HTMLOUT "<tr><td>$source</td><td>$target</td><td>$clause</td></tr>\n"; |
print HTMLOUT "<tr><td>$source</td><td>$target</td><td>$clause</td></tr>\n"; |
517 |
} |
} |
526 |
|
|
527 |
=head3 DumpMetaData |
=head3 DumpMetaData |
528 |
|
|
529 |
C<< $database->DumpMetaData(); >> |
C<< $erdb->DumpMetaData(); >> |
530 |
|
|
531 |
Return a dump of the metadata structure. |
Return a dump of the metadata structure. |
532 |
|
|
541 |
|
|
542 |
=head3 CreateTables |
=head3 CreateTables |
543 |
|
|
544 |
C<< $datanase->CreateTables(); >> |
C<< $erdb->CreateTables(); >> |
545 |
|
|
546 |
This method creates the tables for the database from the metadata structure loaded by the |
This method creates the tables for the database from the metadata structure loaded by the |
547 |
constructor. It is expected this function will only be used on rare occasions, when the |
constructor. It is expected this function will only be used on rare occasions, when the |
553 |
sub CreateTables { |
sub CreateTables { |
554 |
# Get the parameters. |
# Get the parameters. |
555 |
my ($self) = @_; |
my ($self) = @_; |
556 |
my $metadata = $self->{_metaData}; |
# Get the relation names. |
557 |
my $dbh = $self->{_dbh}; |
my @relNames = $self->GetTableNames(); |
558 |
# Loop through the entities. |
# Loop through the relations. |
559 |
while (my ($entityName, $entityData) = each %{$metadata->{Entities}}) { |
for my $relationName (@relNames) { |
|
# Tell the user what we're doing. |
|
|
Trace("Creating relations for entity $entityName.") if T(1); |
|
|
# Loop through the entity's relations. |
|
|
for my $relationName (keys %{$entityData->{Relations}}) { |
|
560 |
# Create a table for this relation. |
# Create a table for this relation. |
561 |
$self->CreateTable($relationName); |
$self->CreateTable($relationName); |
562 |
Trace("Relation $relationName created.") if T(1); |
Trace("Relation $relationName created.") if T(2); |
|
} |
|
|
} |
|
|
# Loop through the relationships. |
|
|
my $relationshipTable = $metadata->{Relationships}; |
|
|
for my $relationshipName (keys %{$metadata->{Relationships}}) { |
|
|
# Create a table for this relationship. |
|
|
Trace("Creating relationship $relationshipName.") if T(1); |
|
|
$self->CreateTable($relationshipName); |
|
563 |
} |
} |
564 |
} |
} |
565 |
|
|
566 |
=head3 CreateTable |
=head3 CreateTable |
567 |
|
|
568 |
C<< $database->CreateTable($tableName, $indexFlag); >> |
C<< $erdb->CreateTable($tableName, $indexFlag, $estimatedRows); >> |
569 |
|
|
570 |
Create the table for a relation and optionally create its indexes. |
Create the table for a relation and optionally create its indexes. |
571 |
|
|
575 |
|
|
576 |
Name of the relation (which will also be the table name). |
Name of the relation (which will also be the table name). |
577 |
|
|
578 |
=item $indexFlag |
=item indexFlag |
579 |
|
|
580 |
TRUE if the indexes for the relation should be created, else FALSE. If FALSE, |
TRUE if the indexes for the relation should be created, else FALSE. If FALSE, |
581 |
L</CreateIndexes> must be called later to bring the indexes into existence. |
L</CreateIndexes> must be called later to bring the indexes into existence. |
582 |
|
|
583 |
|
=item estimatedRows (optional) |
584 |
|
|
585 |
|
If specified, the estimated maximum number of rows for the relation. This |
586 |
|
information allows the creation of tables using storage engines that are |
587 |
|
faster but require size estimates, such as MyISAM. |
588 |
|
|
589 |
=back |
=back |
590 |
|
|
591 |
=cut |
=cut |
592 |
|
|
593 |
sub CreateTable { |
sub CreateTable { |
594 |
# Get the parameters. |
# Get the parameters. |
595 |
my ($self, $relationName, $indexFlag) = @_; |
my ($self, $relationName, $indexFlag, $estimatedRows) = @_; |
596 |
# Get the database handle. |
# Get the database handle. |
597 |
my $dbh = $self->{_dbh}; |
my $dbh = $self->{_dbh}; |
598 |
# Get the relation data and determine whether or not the relation is primary. |
# Get the relation data and determine whether or not the relation is primary. |
616 |
# Insure the table is not already there. |
# Insure the table is not already there. |
617 |
$dbh->drop_table(tbl => $relationName); |
$dbh->drop_table(tbl => $relationName); |
618 |
Trace("Table $relationName dropped.") if T(2); |
Trace("Table $relationName dropped.") if T(2); |
619 |
|
# If there are estimated rows, create an estimate so we can take advantage of |
620 |
|
# faster DB technologies. |
621 |
|
my $estimation = undef; |
622 |
|
if ($estimatedRows) { |
623 |
|
$estimation = [$self->EstimateRowSize($relationName), $estimatedRows]; |
624 |
|
} |
625 |
# Create the table. |
# Create the table. |
626 |
Trace("Creating table $relationName: $fieldThing") if T(2); |
Trace("Creating table $relationName: $fieldThing") if T(2); |
627 |
$dbh->create_table(tbl => $relationName, flds => $fieldThing); |
$dbh->create_table(tbl => $relationName, flds => $fieldThing, estimates => $estimation); |
628 |
Trace("Relation $relationName created in database.") if T(2); |
Trace("Relation $relationName created in database.") if T(2); |
629 |
# If we want to build the indexes, we do it here. |
# If we want to build the indexes, we do it here. |
630 |
if ($indexFlag) { |
if ($indexFlag) { |
634 |
|
|
635 |
=head3 CreateIndex |
=head3 CreateIndex |
636 |
|
|
637 |
C<< $database->CreateIndex($relationName); >> |
C<< $erdb->CreateIndex($relationName); >> |
638 |
|
|
639 |
Create the indexes for a relation. If a table is being loaded from a large source file (as |
Create the indexes for a relation. If a table is being loaded from a large source file (as |
640 |
is the case in L</LoadTable>), it is best to create the indexes after the load. If that is |
is the case in L</LoadTable>), it is sometimes best to create the indexes after the load. |
641 |
the case, then L</CreateTable> should be called with the index flag set to FALSE, and this |
If that is the case, then L</CreateTable> should be called with the index flag set to |
642 |
method used after the load to create the indexes for the table. |
FALSE, and this method used after the load to create the indexes for the table. |
643 |
|
|
644 |
=cut |
=cut |
645 |
|
|
651 |
# Get the database handle. |
# Get the database handle. |
652 |
my $dbh = $self->{_dbh}; |
my $dbh = $self->{_dbh}; |
653 |
# Now we need to create this relation's indexes. We do this by looping through its index table. |
# Now we need to create this relation's indexes. We do this by looping through its index table. |
654 |
while (my ($indexName, $indexData) = each %{$relationData->{Indexes}}) { |
my $indexHash = $relationData->{Indexes}; |
655 |
|
for my $indexName (keys %{$indexHash}) { |
656 |
|
my $indexData = $indexHash->{$indexName}; |
657 |
# Get the index's field list. |
# Get the index's field list. |
658 |
my @fieldList = _FixNames(@{$indexData->{IndexFields}}); |
my @fieldList = _FixNames(@{$indexData->{IndexFields}}); |
659 |
my $flds = join(', ', @fieldList); |
my $flds = join(', ', @fieldList); |
660 |
# Get the index's uniqueness flag. |
# Get the index's uniqueness flag. |
661 |
my $unique = (exists $indexData->{Unique} ? $indexData->{Unique} : 'false'); |
my $unique = (exists $indexData->{Unique} ? $indexData->{Unique} : 'false'); |
662 |
# Create the index. |
# Create the index. |
663 |
$dbh->create_index(idx => $indexName, tbl => $relationName, flds => $flds, unique => $unique); |
my $rv = $dbh->create_index(idx => $indexName, tbl => $relationName, |
664 |
|
flds => $flds, unique => $unique); |
665 |
|
if ($rv) { |
666 |
Trace("Index created: $indexName for $relationName ($flds)") if T(1); |
Trace("Index created: $indexName for $relationName ($flds)") if T(1); |
667 |
|
} else { |
668 |
|
Confess("Error creating index $indexName for $relationName using ($flds): " . $dbh->error_message()); |
669 |
|
} |
670 |
} |
} |
671 |
} |
} |
672 |
|
|
673 |
=head3 LoadTables |
=head3 LoadTables |
674 |
|
|
675 |
C<< my $stats = $database->LoadTables($directoryName, $rebuild); >> |
C<< my $stats = $erdb->LoadTables($directoryName, $rebuild); >> |
676 |
|
|
677 |
This method will load the database tables from a directory. The tables must already have been created |
This method will load the database tables from a directory. The tables must already have been created |
678 |
in the database. (This can be done by calling L</CreateTables>.) The caller passes in a directory name; |
in the database. (This can be done by calling L</CreateTables>.) The caller passes in a directory name; |
715 |
$directoryName =~ s!/\\$!!; |
$directoryName =~ s!/\\$!!; |
716 |
# Declare the return variable. |
# Declare the return variable. |
717 |
my $retVal = Stats->new(); |
my $retVal = Stats->new(); |
718 |
# Get the metadata structure. |
# Get the relation names. |
719 |
my $metaData = $self->{_metaData}; |
my @relNames = $self->GetTableNames(); |
720 |
# Loop through the entities. |
for my $relationName (@relNames) { |
|
for my $entity (values %{$metaData->{Entities}}) { |
|
|
# Loop through the entity's relations. |
|
|
for my $relationName (keys %{$entity->{Relations}}) { |
|
721 |
# Try to load this relation. |
# Try to load this relation. |
722 |
my $result = $self->_LoadRelation($directoryName, $relationName, $rebuild); |
my $result = $self->_LoadRelation($directoryName, $relationName, $rebuild); |
723 |
# Accumulate the statistics. |
# Accumulate the statistics. |
724 |
$retVal->Accumulate($result); |
$retVal->Accumulate($result); |
725 |
} |
} |
|
} |
|
|
# Loop through the relationships. |
|
|
for my $relationshipName (keys %{$metaData->{Relationships}}) { |
|
|
# Try to load this relationship's relation. |
|
|
my $result = $self->_LoadRelation($directoryName, $relationshipName, $rebuild); |
|
|
# Accumulate the statistics. |
|
|
$retVal->Accumulate($result); |
|
|
} |
|
726 |
# Add the duration of the load to the statistical object. |
# Add the duration of the load to the statistical object. |
727 |
$retVal->Add('duration', gettimeofday - $startTime); |
$retVal->Add('duration', gettimeofday - $startTime); |
728 |
# Return the accumulated statistics. |
# Return the accumulated statistics. |
729 |
return $retVal; |
return $retVal; |
730 |
} |
} |
731 |
|
|
732 |
|
|
733 |
=head3 GetTableNames |
=head3 GetTableNames |
734 |
|
|
735 |
C<< my @names = $database->GetTableNames; >> |
C<< my @names = $erdb->GetTableNames; >> |
736 |
|
|
737 |
Return a list of the relations required to implement this database. |
Return a list of the relations required to implement this database. |
738 |
|
|
749 |
|
|
750 |
=head3 GetEntityTypes |
=head3 GetEntityTypes |
751 |
|
|
752 |
C<< my @names = $database->GetEntityTypes; >> |
C<< my @names = $erdb->GetEntityTypes; >> |
753 |
|
|
754 |
Return a list of the entity type names. |
Return a list of the entity type names. |
755 |
|
|
764 |
return sort keys %{$entityList}; |
return sort keys %{$entityList}; |
765 |
} |
} |
766 |
|
|
767 |
|
=head3 IsEntity |
768 |
|
|
769 |
|
C<< my $flag = $erdb->IsEntity($entityName); >> |
770 |
|
|
771 |
|
Return TRUE if the parameter is an entity name, else FALSE. |
772 |
|
|
773 |
|
=over 4 |
774 |
|
|
775 |
|
=item entityName |
776 |
|
|
777 |
|
Object name to be tested. |
778 |
|
|
779 |
|
=item RETURN |
780 |
|
|
781 |
|
Returns TRUE if the specified string is an entity name, else FALSE. |
782 |
|
|
783 |
|
=back |
784 |
|
|
785 |
|
=cut |
786 |
|
|
787 |
|
sub IsEntity { |
788 |
|
# Get the parameters. |
789 |
|
my ($self, $entityName) = @_; |
790 |
|
# Test to see if it's an entity. |
791 |
|
return exists $self->{_metaData}->{Entities}->{$entityName}; |
792 |
|
} |
793 |
|
|
794 |
=head3 Get |
=head3 Get |
795 |
|
|
796 |
C<< my $query = $database->Get(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >> |
C<< my $query = $erdb->Get(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >> |
797 |
|
|
798 |
This method returns a query object for entities of a specified type using a specified filter. |
This method returns a query object for entities of a specified type using a specified filter. |
799 |
The filter is a standard WHERE/ORDER BY clause with question marks as parameter markers and each |
The filter is a standard WHERE/ORDER BY clause with question marks as parameter markers and each |
801 |
following call requests all B<Genome> objects for the genus specified in the variable |
following call requests all B<Genome> objects for the genus specified in the variable |
802 |
$genus. |
$genus. |
803 |
|
|
804 |
C<< $query = $sprout->Get(['Genome'], "Genome(genus) = ?", $genus); >> |
C<< $query = $erdb->Get(['Genome'], "Genome(genus) = ?", $genus); >> |
805 |
|
|
806 |
The WHERE clause contains a single question mark, so there is a single additional |
The WHERE clause contains a single question mark, so there is a single additional |
807 |
parameter representing the parameter value. It would also be possible to code |
parameter representing the parameter value. It would also be possible to code |
808 |
|
|
809 |
C<< $query = $sprout->Get(['Genome'], "Genome(genus) = \'$genus\'"); >> |
C<< $query = $erdb->Get(['Genome'], "Genome(genus) = \'$genus\'"); >> |
810 |
|
|
811 |
however, this version of the call would generate a syntax error if there were any quote |
however, this version of the call would generate a syntax error if there were any quote |
812 |
characters inside the variable C<$genus>. |
characters inside the variable C<$genus>. |
818 |
It is possible to specify multiple entity and relationship names in order to retrieve more than |
It is possible to specify multiple entity and relationship names in order to retrieve more than |
819 |
one object's data at the same time, which allows highly complex joined queries. For example, |
one object's data at the same time, which allows highly complex joined queries. For example, |
820 |
|
|
821 |
C<< $query = $sprout->Get(['Genome', 'ComesFrom', 'Source'], "Genome(genus) = ?", $genus); >> |
C<< $query = $erdb->Get(['Genome', 'ComesFrom', 'Source'], "Genome(genus) = ?", $genus); >> |
822 |
|
|
823 |
If multiple names are specified, then the query processor will automatically determine a |
If multiple names are specified, then the query processor will automatically determine a |
824 |
join path between the entities and relationships. The algorithm used is very simplistic. |
join path between the entities and relationships. The algorithm used is very simplistic. |
877 |
my $dbh = $self->{_dbh}; |
my $dbh = $self->{_dbh}; |
878 |
my $command = "SELECT DISTINCT " . join('.*, ', @{$objectNames}) . ".* FROM " . |
my $command = "SELECT DISTINCT " . join('.*, ', @{$objectNames}) . ".* FROM " . |
879 |
join(', ', @{$objectNames}); |
join(', ', @{$objectNames}); |
880 |
|
Trace("SQL = $command") if T(SQL => 4); |
881 |
# Check for a filter clause. |
# Check for a filter clause. |
882 |
if ($filterClause) { |
if ($filterClause) { |
883 |
# Here we have one, so we convert its field names and add it to the query. First, |
# Here we have one, so we convert its field names and add it to the query. First, |
982 |
$command .= " ORDER BY $orderClause"; |
$command .= " ORDER BY $orderClause"; |
983 |
} |
} |
984 |
} |
} |
985 |
Trace("SQL query: $command") if T(2); |
Trace("SQL query: $command") if T(3); |
986 |
Trace("PARMS: '" . (join "', '", @params) . "'") if (T(3) && (@params > 0)); |
Trace("PARMS: '" . (join "', '", @params) . "'") if (T(4) && (@params > 0)); |
987 |
my $sth = $dbh->prepare_command($command); |
my $sth = $dbh->prepare_command($command); |
988 |
# Execute it with the parameters bound in. |
# Execute it with the parameters bound in. |
989 |
$sth->execute(@params) || Confess("SELECT error" . $sth->errstr()); |
$sth->execute(@params) || Confess("SELECT error" . $sth->errstr()); |
992 |
return $retVal; |
return $retVal; |
993 |
} |
} |
994 |
|
|
995 |
|
=head3 GetList |
996 |
|
|
997 |
|
C<< my @dbObjects = $erdb->GetList(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >> |
998 |
|
|
999 |
|
Return a list of object descriptors for the specified objects as determined by the |
1000 |
|
specified filter clause. |
1001 |
|
|
1002 |
|
This method is essentially the same as L</Get> except it returns a list of objects rather |
1003 |
|
than a query object that can be used to get the results one record at a time. |
1004 |
|
|
1005 |
|
=over 4 |
1006 |
|
|
1007 |
|
=item objectNames |
1008 |
|
|
1009 |
|
List containing the names of the entity and relationship objects to be retrieved. |
1010 |
|
|
1011 |
|
=item filterClause |
1012 |
|
|
1013 |
|
WHERE clause (without the WHERE) to be used to filter and sort the query. The WHERE clause can |
1014 |
|
be parameterized with parameter markers (C<?>). Each field used in the WHERE clause must be |
1015 |
|
specified in the standard form B<I<objectName>(I<fieldName>)>. Any parameters specified |
1016 |
|
in the filter clause should be added to the parameter list as additional parameters. The |
1017 |
|
fields in a filter clause can come from primary entity relations, relationship relations, |
1018 |
|
or secondary entity relations; however, all of the entities and relationships involved must |
1019 |
|
be included in the list of object names. |
1020 |
|
|
1021 |
|
The filter clause can also specify a sort order. To do this, simply follow the filter string |
1022 |
|
with an ORDER BY clause. For example, the following filter string gets all genomes for a |
1023 |
|
particular genus and sorts them by species name. |
1024 |
|
|
1025 |
|
C<< "Genome(genus) = ? ORDER BY Genome(species)" >> |
1026 |
|
|
1027 |
|
The rules for field references in a sort order are the same as those for field references in the |
1028 |
|
filter clause in general; however, odd things may happen if a sort field is from a secondary |
1029 |
|
relation. |
1030 |
|
|
1031 |
|
=item param1, param2, ..., paramN |
1032 |
|
|
1033 |
|
Parameter values to be substituted into the filter clause. |
1034 |
|
|
1035 |
|
=item RETURN |
1036 |
|
|
1037 |
|
Returns a list of B<DBObject>s that satisfy the query conditions. |
1038 |
|
|
1039 |
|
=back |
1040 |
|
|
1041 |
|
=cut |
1042 |
|
#: Return Type @% |
1043 |
|
sub GetList { |
1044 |
|
# Get the parameters. |
1045 |
|
my ($self, $objectNames, $filterClause, @params) = @_; |
1046 |
|
# Declare the return variable. |
1047 |
|
my @retVal = (); |
1048 |
|
# Perform the query. |
1049 |
|
my $query = $self->Get($objectNames, $filterClause, @params); |
1050 |
|
# Loop through the results. |
1051 |
|
while (my $object = $query->Fetch) { |
1052 |
|
push @retVal, $object; |
1053 |
|
} |
1054 |
|
# Return the result. |
1055 |
|
return @retVal; |
1056 |
|
} |
1057 |
|
|
1058 |
=head3 ComputeObjectSentence |
=head3 ComputeObjectSentence |
1059 |
|
|
1060 |
C<< my $sentence = $database->ComputeObjectSentence($objectName); >> |
C<< my $sentence = $erdb->ComputeObjectSentence($objectName); >> |
1061 |
|
|
1062 |
Check an object name, and if it is a relationship convert it to a relationship sentence. |
Check an object name, and if it is a relationship convert it to a relationship sentence. |
1063 |
|
|
1092 |
|
|
1093 |
=head3 DumpRelations |
=head3 DumpRelations |
1094 |
|
|
1095 |
C<< $database->DumpRelations($outputDirectory); >> |
C<< $erdb->DumpRelations($outputDirectory); >> |
1096 |
|
|
1097 |
Write the contents of all the relations to tab-delimited files in the specified directory. |
Write the contents of all the relations to tab-delimited files in the specified directory. |
1098 |
Each file will have the same name as the relation dumped, with an extension of DTX. |
Each file will have the same name as the relation dumped, with an extension of DTX. |
1113 |
# Now we need to run through all the relations. First, we loop through the entities. |
# Now we need to run through all the relations. First, we loop through the entities. |
1114 |
my $metaData = $self->{_metaData}; |
my $metaData = $self->{_metaData}; |
1115 |
my $entities = $metaData->{Entities}; |
my $entities = $metaData->{Entities}; |
1116 |
while (my ($entityName, $entityStructure) = each %{$entities}) { |
for my $entityName (keys %{$entities}) { |
1117 |
|
my $entityStructure = $entities->{$entityName}; |
1118 |
# Get the entity's relations. |
# Get the entity's relations. |
1119 |
my $relationList = $entityStructure->{Relations}; |
my $relationList = $entityStructure->{Relations}; |
1120 |
# Loop through the relations, dumping them. |
# Loop through the relations, dumping them. |
1121 |
while (my ($relationName, $relation) = each %{$relationList}) { |
for my $relationName (keys %{$relationList}) { |
1122 |
|
my $relation = $relationList->{$relationName}; |
1123 |
$self->_DumpRelation($outputDirectory, $relationName, $relation); |
$self->_DumpRelation($outputDirectory, $relationName, $relation); |
1124 |
} |
} |
1125 |
} |
} |
1126 |
# Next, we loop through the relationships. |
# Next, we loop through the relationships. |
1127 |
my $relationships = $metaData->{Relationships}; |
my $relationships = $metaData->{Relationships}; |
1128 |
while (my ($relationshipName, $relationshipStructure) = each %{$relationships}) { |
for my $relationshipName (keys %{$relationships}) { |
1129 |
|
my $relationshipStructure = $relationships->{$relationshipName}; |
1130 |
# Dump this relationship's relation. |
# Dump this relationship's relation. |
1131 |
$self->_DumpRelation($outputDirectory, $relationshipName, $relationshipStructure->{Relations}->{$relationshipName}); |
$self->_DumpRelation($outputDirectory, $relationshipName, $relationshipStructure->{Relations}->{$relationshipName}); |
1132 |
} |
} |
1134 |
|
|
1135 |
=head3 InsertObject |
=head3 InsertObject |
1136 |
|
|
1137 |
C<< my $ok = $database->InsertObject($objectType, \%fieldHash); >> |
C<< my $ok = $erdb->InsertObject($objectType, \%fieldHash); >> |
1138 |
|
|
1139 |
Insert an object into the database. The object is defined by a type name and then a hash |
Insert an object into the database. The object is defined by a type name and then a hash |
1140 |
of field names to values. Field values in the primary relation are represented by scalars. |
of field names to values. Field values in the primary relation are represented by scalars. |
1143 |
example, the following line inserts an inactive PEG feature named C<fig|188.1.peg.1> with aliases |
example, the following line inserts an inactive PEG feature named C<fig|188.1.peg.1> with aliases |
1144 |
C<ZP_00210270.1> and C<gi|46206278>. |
C<ZP_00210270.1> and C<gi|46206278>. |
1145 |
|
|
1146 |
C<< $database->InsertObject('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >> |
C<< $erdb->InsertObject('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >> |
1147 |
|
|
1148 |
The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and |
The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and |
1149 |
property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>. |
property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>. |
1150 |
|
|
1151 |
C<< $database->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >> |
C<< $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >> |
1152 |
|
|
1153 |
=over 4 |
=over 4 |
1154 |
|
|
1180 |
# Loop through the relations. We'll build insert statements for each one. If a relation is |
# Loop through the relations. We'll build insert statements for each one. If a relation is |
1181 |
# secondary, we may end up generating multiple insert statements. If an error occurs, we |
# secondary, we may end up generating multiple insert statements. If an error occurs, we |
1182 |
# stop the loop. |
# stop the loop. |
1183 |
while ($retVal && (my ($relationName, $relationDefinition) = each %{$relationTable})) { |
my @relationList = keys %{$relationTable}; |
1184 |
|
for (my $i = 0; $retVal && $i <= $#relationList; $i++) { |
1185 |
|
my $relationName = $relationList[$i]; |
1186 |
|
my $relationDefinition = $relationTable->{$relationName}; |
1187 |
# Get the relation's fields. For each field we will collect a value in the corresponding |
# Get the relation's fields. For each field we will collect a value in the corresponding |
1188 |
# position of the @valueList array. If one of the fields is missing, we will add it to the |
# position of the @valueList array. If one of the fields is missing, we will add it to the |
1189 |
# @missing list. |
# @missing list. |
1273 |
|
|
1274 |
=head3 LoadTable |
=head3 LoadTable |
1275 |
|
|
1276 |
C<< my %results = $database->LoadTable($fileName, $relationName, $truncateFlag); >> |
C<< my %results = $erdb->LoadTable($fileName, $relationName, $truncateFlag); >> |
1277 |
|
|
1278 |
Load data from a tab-delimited file into a specified table, optionally re-creating the table first. |
Load data from a tab-delimited file into a specified table, optionally re-creating the table |
1279 |
|
first. |
1280 |
|
|
1281 |
=over 4 |
=over 4 |
1282 |
|
|
1294 |
|
|
1295 |
=item RETURN |
=item RETURN |
1296 |
|
|
1297 |
Returns a statistical object containing the number of records read and a list of the error messages. |
Returns a statistical object containing the number of records read and a list of |
1298 |
|
the error messages. |
1299 |
|
|
1300 |
=back |
=back |
1301 |
|
|
1306 |
# Create the statistical return object. |
# Create the statistical return object. |
1307 |
my $retVal = _GetLoadStats(); |
my $retVal = _GetLoadStats(); |
1308 |
# Trace the fact of the load. |
# Trace the fact of the load. |
1309 |
Trace("Loading table $relationName from $fileName") if T(1); |
Trace("Loading table $relationName from $fileName") if T(2); |
1310 |
# Get the database handle. |
# Get the database handle. |
1311 |
my $dbh = $self->{_dbh}; |
my $dbh = $self->{_dbh}; |
1312 |
|
# Get the input file size. |
1313 |
|
my $fileSize = -s $fileName; |
1314 |
# Get the relation data. |
# Get the relation data. |
1315 |
my $relation = $self->_FindRelation($relationName); |
my $relation = $self->_FindRelation($relationName); |
1316 |
# Check the truncation flag. |
# Check the truncation flag. |
1317 |
if ($truncateFlag) { |
if ($truncateFlag) { |
1318 |
Trace("Creating table $relationName") if T(1); |
Trace("Creating table $relationName") if T(2); |
1319 |
|
# Compute the row count estimate. We take the size of the load file, |
1320 |
|
# divide it by the estimated row size, and then multiply by 1.5 to |
1321 |
|
# leave extra room. We postulate a minimum row count of 1000 to |
1322 |
|
# prevent problems with incoming empty load files. |
1323 |
|
my $rowSize = $self->EstimateRowSize($relationName); |
1324 |
|
my $estimate = FIG::max($fileSize * 1.5 / $rowSize, 1000); |
1325 |
# Re-create the table without its index. |
# Re-create the table without its index. |
1326 |
$self->CreateTable($relationName, 0); |
$self->CreateTable($relationName, 0, $estimate); |
1327 |
|
# If this is a pre-index DBMS, create the index here. |
1328 |
|
if ($dbh->{_preIndex}) { |
1329 |
|
eval { |
1330 |
|
$self->CreateIndex($relationName); |
1331 |
|
}; |
1332 |
|
if ($@) { |
1333 |
|
$retVal->AddMessage($@); |
1334 |
|
} |
1335 |
|
} |
1336 |
} |
} |
|
# Determine whether or not this is a primary relation. Primary relations have an extra |
|
|
# field indicating whether or not a given object is new or was loaded from the flat files. |
|
|
my $primary = $self->_IsPrimary($relationName); |
|
|
# Get the number of fields in this relation. |
|
|
my @fieldList = @{$relation->{Fields}}; |
|
|
my $fieldCount = @fieldList; |
|
|
# Record the number of expected fields. |
|
|
my $expectedFields = $fieldCount + ($primary ? 1 : 0); |
|
|
# Start a database transaction. |
|
|
$dbh->begin_tran; |
|
|
# Open the relation file. We need to create a cleaned-up copy before loading. |
|
|
open TABLEIN, '<', $fileName; |
|
|
my $tempName = "$fileName.tbl"; |
|
|
open TABLEOUT, '>', $tempName; |
|
|
# Loop through the file. |
|
|
while (<TABLEIN>) { |
|
|
# Chop off the new-line character. |
|
|
my $record = $_; |
|
|
chomp $record; |
|
|
# Only proceed if the record is non-blank. |
|
|
if ($record) { |
|
|
# Escape all the backslashes found in the line. |
|
|
$record =~ s/\\/\\\\/g; |
|
|
# Eliminate any trailing tabs. |
|
|
chop $record while substr($record, -1) eq "\t"; |
|
|
# If this is a primary relation, add a 0 for the new-record flag (indicating that |
|
|
# this record is not new, but part of the original load). |
|
|
if ($primary) { |
|
|
$record .= "\t0"; |
|
|
} |
|
|
# Write the record. |
|
|
print TABLEOUT "$record\n"; |
|
|
# Count the record read. |
|
|
my $count = $retVal->Add('records'); |
|
|
my $len = length $record; |
|
|
Trace("Record $count written with $len characters.") if T(4); |
|
|
} |
|
|
} |
|
|
# Close the files. |
|
|
close TABLEIN; |
|
|
close TABLEOUT; |
|
|
Trace("Temporary file $tempName created.") if T(4); |
|
1337 |
# Load the table. |
# Load the table. |
1338 |
my $rv; |
my $rv; |
1339 |
eval { |
eval { |
1340 |
$rv = $dbh->load_table(file => $tempName, tbl => $relationName); |
$rv = $dbh->load_table(file => $fileName, tbl => $relationName); |
1341 |
}; |
}; |
1342 |
if (!defined $rv) { |
if (!defined $rv) { |
1343 |
$retVal->AddMessage($@) if ($@); |
$retVal->AddMessage($@) if ($@); |
1344 |
$retVal->AddMessage("Table load failed for $relationName using $tempName."); |
$retVal->AddMessage("Table load failed for $relationName using $fileName."); |
1345 |
Trace("Table load failed for $relationName.") if T(1); |
Trace("Table load failed for $relationName.") if T(1); |
1346 |
} else { |
} else { |
1347 |
# Here we successfully loaded the table. Trace the number of records loaded. |
# Here we successfully loaded the table. |
1348 |
Trace("$retVal->{records} records read for $relationName.") if T(1); |
$retVal->Add("tables"); |
1349 |
|
my $size = -s $fileName; |
1350 |
|
Trace("$size bytes loaded into $relationName.") if T(2); |
1351 |
# If we're rebuilding, we need to create the table indexes. |
# If we're rebuilding, we need to create the table indexes. |
1352 |
if ($truncateFlag) { |
if ($truncateFlag && ! $dbh->{_preIndex}) { |
1353 |
eval { |
eval { |
1354 |
$self->CreateIndex($relationName); |
$self->CreateIndex($relationName); |
1355 |
}; |
}; |
1358 |
} |
} |
1359 |
} |
} |
1360 |
} |
} |
1361 |
# Commit the database changes. |
# Analyze the table to improve performance. |
1362 |
$dbh->commit_tran; |
$dbh->vacuum_it($relationName); |
|
# Delete the temporary file. |
|
|
unlink $tempName; |
|
1363 |
# Return the statistics. |
# Return the statistics. |
1364 |
return $retVal; |
return $retVal; |
1365 |
} |
} |
1366 |
|
|
1367 |
=head3 GenerateEntity |
=head3 GenerateEntity |
1368 |
|
|
1369 |
C<< my $fieldHash = $database->GenerateEntity($id, $type, \%values); >> |
C<< my $fieldHash = $erdb->GenerateEntity($id, $type, \%values); >> |
1370 |
|
|
1371 |
Generate the data for a new entity instance. This method creates a field hash suitable for |
Generate the data for a new entity instance. This method creates a field hash suitable for |
1372 |
passing as a parameter to L</InsertObject>. The ID is specified by the callr, but the rest |
passing as a parameter to L</InsertObject>. The ID is specified by the callr, but the rest |
1422 |
return $this; |
return $this; |
1423 |
} |
} |
1424 |
|
|
1425 |
|
=head3 GetEntity |
1426 |
|
|
1427 |
|
C<< my $entityObject = $erdb->GetEntity($entityType, $ID); >> |
1428 |
|
|
1429 |
|
Return an object describing the entity instance with a specified ID. |
1430 |
|
|
1431 |
|
=over 4 |
1432 |
|
|
1433 |
|
=item entityType |
1434 |
|
|
1435 |
|
Entity type name. |
1436 |
|
|
1437 |
|
=item ID |
1438 |
|
|
1439 |
|
ID of the desired entity. |
1440 |
|
|
1441 |
|
=item RETURN |
1442 |
|
|
1443 |
|
Returns a B<DBObject> representing the desired entity instance, or an undefined value if no |
1444 |
|
instance is found with the specified key. |
1445 |
|
|
1446 |
|
=back |
1447 |
|
|
1448 |
|
=cut |
1449 |
|
|
1450 |
|
sub GetEntity { |
1451 |
|
# Get the parameters. |
1452 |
|
my ($self, $entityType, $ID) = @_; |
1453 |
|
# Create a query. |
1454 |
|
my $query = $self->Get([$entityType], "$entityType(id) = ?", $ID); |
1455 |
|
# Get the first (and only) object. |
1456 |
|
my $retVal = $query->Fetch(); |
1457 |
|
# Return the result. |
1458 |
|
return $retVal; |
1459 |
|
} |
1460 |
|
|
1461 |
|
=head3 GetEntityValues |
1462 |
|
|
1463 |
|
C<< my @values = $erdb->GetEntityValues($entityType, $ID, \@fields); >> |
1464 |
|
|
1465 |
|
Return a list of values from a specified entity instance. |
1466 |
|
|
1467 |
|
=over 4 |
1468 |
|
|
1469 |
|
=item entityType |
1470 |
|
|
1471 |
|
Entity type name. |
1472 |
|
|
1473 |
|
=item ID |
1474 |
|
|
1475 |
|
ID of the desired entity. |
1476 |
|
|
1477 |
|
=item fields |
1478 |
|
|
1479 |
|
List of field names, each of the form I<objectName>C<(>I<fieldName>C<)>. |
1480 |
|
|
1481 |
|
=item RETURN |
1482 |
|
|
1483 |
|
Returns a flattened list of the values of the specified fields for the specified entity. |
1484 |
|
|
1485 |
|
=back |
1486 |
|
|
1487 |
|
=cut |
1488 |
|
|
1489 |
|
sub GetEntityValues { |
1490 |
|
# Get the parameters. |
1491 |
|
my ($self, $entityType, $ID, $fields) = @_; |
1492 |
|
# Get the specified entity. |
1493 |
|
my $entity = $self->GetEntity($entityType, $ID); |
1494 |
|
# Declare the return list. |
1495 |
|
my @retVal = (); |
1496 |
|
# If we found the entity, push the values into the return list. |
1497 |
|
if ($entity) { |
1498 |
|
push @retVal, $entity->Values($fields); |
1499 |
|
} |
1500 |
|
# Return the result. |
1501 |
|
return @retVal; |
1502 |
|
} |
1503 |
|
|
1504 |
|
=head3 GetAll |
1505 |
|
|
1506 |
|
C<< my @list = $erdb->GetAll(\@objectNames, $filterClause, \@parameters, \@fields, $count); >> |
1507 |
|
|
1508 |
|
Return a list of values taken from the objects returned by a query. The first three |
1509 |
|
parameters correspond to the parameters of the L</Get> method. The final parameter is |
1510 |
|
a list of the fields desired from each record found by the query. The field name |
1511 |
|
syntax is the standard syntax used for fields in the B<ERDB> system-- |
1512 |
|
B<I<objectName>(I<fieldName>)>-- where I<objectName> is the name of the relevant entity |
1513 |
|
or relationship and I<fieldName> is the name of the field. |
1514 |
|
|
1515 |
|
The list returned will be a list of lists. Each element of the list will contain |
1516 |
|
the values returned for the fields specified in the fourth parameter. If one of the |
1517 |
|
fields specified returns multiple values, they are flattened in with the rest. For |
1518 |
|
example, the following call will return a list of the features in a particular |
1519 |
|
spreadsheet cell, and each feature will be represented by a list containing the |
1520 |
|
feature ID followed by all of its aliases. |
1521 |
|
|
1522 |
|
C<< $query = $erdb->Get(['ContainsFeature', 'Feature'], "ContainsFeature(from-link) = ?", [$ssCellID], ['Feature(id)', 'Feature(alias)']); >> |
1523 |
|
|
1524 |
|
=over 4 |
1525 |
|
|
1526 |
|
=item objectNames |
1527 |
|
|
1528 |
|
List containing the names of the entity and relationship objects to be retrieved. |
1529 |
|
|
1530 |
|
=item filterClause |
1531 |
|
|
1532 |
|
WHERE/ORDER BY clause (without the WHERE) to be used to filter and sort the query. The WHERE clause can |
1533 |
|
be parameterized with parameter markers (C<?>). Each field used must be specified in the standard form |
1534 |
|
B<I<objectName>(I<fieldName>)>. Any parameters specified in the filter clause should be added to the |
1535 |
|
parameter list as additional parameters. The fields in a filter clause can come from primary |
1536 |
|
entity relations, relationship relations, or secondary entity relations; however, all of the |
1537 |
|
entities and relationships involved must be included in the list of object names. |
1538 |
|
|
1539 |
|
=item parameterList |
1540 |
|
|
1541 |
|
List of the parameters to be substituted in for the parameters marks in the filter clause. |
1542 |
|
|
1543 |
|
=item fields |
1544 |
|
|
1545 |
|
List of the fields to be returned in each element of the list returned. |
1546 |
|
|
1547 |
|
=item count |
1548 |
|
|
1549 |
|
Maximum number of records to return. If omitted or 0, all available records will be returned. |
1550 |
|
|
1551 |
|
=item RETURN |
1552 |
|
|
1553 |
|
Returns a list of list references. Each element of the return list contains the values for the |
1554 |
|
fields specified in the B<fields> parameter. |
1555 |
|
|
1556 |
|
=back |
1557 |
|
|
1558 |
|
=cut |
1559 |
|
#: Return Type @@; |
1560 |
|
sub GetAll { |
1561 |
|
# Get the parameters. |
1562 |
|
my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_; |
1563 |
|
# Translate the parameters from a list reference to a list. If the parameter |
1564 |
|
# list is a scalar we convert it into a singleton list. |
1565 |
|
my @parmList = (); |
1566 |
|
if (ref $parameterList eq "ARRAY") { |
1567 |
|
@parmList = @{$parameterList}; |
1568 |
|
} else { |
1569 |
|
push @parmList, $parameterList; |
1570 |
|
} |
1571 |
|
# Create the query. |
1572 |
|
my $query = $self->Get($objectNames, $filterClause, @parmList); |
1573 |
|
# Set up a counter of the number of records read. |
1574 |
|
my $fetched = 0; |
1575 |
|
# Insure the counter has a value. |
1576 |
|
if (!defined $count) { |
1577 |
|
$count = 0; |
1578 |
|
} |
1579 |
|
# Loop through the records returned, extracting the fields. Note that if the |
1580 |
|
# counter is non-zero, we stop when the number of records read hits the count. |
1581 |
|
my @retVal = (); |
1582 |
|
while (($count == 0 || $fetched < $count) && (my $row = $query->Fetch())) { |
1583 |
|
my @rowData = $row->Values($fields); |
1584 |
|
push @retVal, \@rowData; |
1585 |
|
$fetched++; |
1586 |
|
} |
1587 |
|
# Return the resulting list. |
1588 |
|
return @retVal; |
1589 |
|
} |
1590 |
|
|
1591 |
|
=head3 EstimateRowSize |
1592 |
|
|
1593 |
|
C<< my $rowSize = $erdb->EstimateRowSize($relName); >> |
1594 |
|
|
1595 |
|
Estimate the row size of the specified relation. The estimated row size is computed by adding |
1596 |
|
up the average length for each data type. |
1597 |
|
|
1598 |
|
=over 4 |
1599 |
|
|
1600 |
|
=item relName |
1601 |
|
|
1602 |
|
Name of the relation whose estimated row size is desired. |
1603 |
|
|
1604 |
|
=item RETURN |
1605 |
|
|
1606 |
|
Returns an estimate of the row size for the specified relation. |
1607 |
|
|
1608 |
|
=back |
1609 |
|
|
1610 |
|
=cut |
1611 |
|
#: Return Type $; |
1612 |
|
sub EstimateRowSize { |
1613 |
|
# Get the parameters. |
1614 |
|
my ($self, $relName) = @_; |
1615 |
|
# Declare the return variable. |
1616 |
|
my $retVal = 0; |
1617 |
|
# Find the relation descriptor. |
1618 |
|
my $relation = $self->_FindRelation($relName); |
1619 |
|
# Get the list of fields. |
1620 |
|
for my $fieldData (@{$relation->{Fields}}) { |
1621 |
|
# Get the field type and add its length. |
1622 |
|
my $fieldLen = $TypeTable{$fieldData->{type}}->{avgLen}; |
1623 |
|
$retVal += $fieldLen; |
1624 |
|
} |
1625 |
|
# Return the result. |
1626 |
|
return $retVal; |
1627 |
|
} |
1628 |
|
|
1629 |
=head2 Internal Utility Methods |
=head2 Internal Utility Methods |
1630 |
|
|
2001 |
sub _LoadMetaData { |
sub _LoadMetaData { |
2002 |
# Get the parameters. |
# Get the parameters. |
2003 |
my ($filename) = @_; |
my ($filename) = @_; |
2004 |
|
Trace("Reading Sprout DBD from $filename.") if T(2); |
2005 |
# Slurp the XML file into a variable. Extensive use of options is used to insure we |
# Slurp the XML file into a variable. Extensive use of options is used to insure we |
2006 |
# get the exact structure we want. |
# get the exact structure we want. |
2007 |
my $metadata = XML::Simple::XMLin($filename, |
my $metadata = XML::Simple::XMLin($filename, |
2026 |
my %masterRelationTable = (); |
my %masterRelationTable = (); |
2027 |
# Loop through the entities. |
# Loop through the entities. |
2028 |
my $entityList = $metadata->{Entities}; |
my $entityList = $metadata->{Entities}; |
2029 |
while (my ($entityName, $entityStructure) = each %{$entityList}) { |
for my $entityName (keys %{$entityList}) { |
2030 |
|
my $entityStructure = $entityList->{$entityName}; |
2031 |
# |
# |
2032 |
# The first step is to run creating all the entity's default values. For C<Field> elements, |
# The first step is to create all the entity's default values. For C<Field> elements, |
2033 |
# the relation name must be added where it is not specified. For relationships, |
# the relation name must be added where it is not specified. For relationships, |
2034 |
# the B<from-link> and B<to-link> fields must be inserted, and for entities an B<id> |
# the B<from-link> and B<to-link> fields must be inserted, and for entities an B<id> |
2035 |
# field must be added to each relation. Finally, each field will have a C<PrettySort> attribute |
# field must be added to each relation. Finally, each field will have a C<PrettySort> attribute |
2075 |
# to a list of fields. First, we need the ID field itself. |
# to a list of fields. First, we need the ID field itself. |
2076 |
my $idField = $fieldList->{id}; |
my $idField = $fieldList->{id}; |
2077 |
# Loop through the relations. |
# Loop through the relations. |
2078 |
while (my ($relationName, $relation) = each %{$relationTable}) { |
for my $relationName (keys %{$relationTable}) { |
2079 |
|
my $relation = $relationTable->{$relationName}; |
2080 |
# Get the relation's field list. |
# Get the relation's field list. |
2081 |
my $relationFieldList = $relation->{Fields}; |
my $relationFieldList = $relation->{Fields}; |
2082 |
# Add the ID field to it. If the field's already there, it will not make any |
# Add the ID field to it. If the field's already there, it will not make any |
2126 |
# The next step is to insure that each relation has at least one index that begins with the ID field. |
# The next step is to insure that each relation has at least one index that begins with the ID field. |
2127 |
# After that, we convert each relation's index list to an index table. We first need to loop through |
# After that, we convert each relation's index list to an index table. We first need to loop through |
2128 |
# the relations. |
# the relations. |
2129 |
while (my ($relationName, $relation) = each %{$relationTable}) { |
for my $relationName (keys %{$relationTable}) { |
2130 |
|
my $relation = $relationTable->{$relationName}; |
2131 |
# Get the relation's index list. |
# Get the relation's index list. |
2132 |
my $indexList = $relation->{Indexes}; |
my $indexList = $relation->{Indexes}; |
2133 |
# Insure this relation has an ID index. |
# Insure this relation has an ID index. |
2158 |
# Loop through the relationships. Relationships actually turn out to be much simpler than entities. |
# Loop through the relationships. Relationships actually turn out to be much simpler than entities. |
2159 |
# For one thing, there is only a single constituent relation. |
# For one thing, there is only a single constituent relation. |
2160 |
my $relationshipList = $metadata->{Relationships}; |
my $relationshipList = $metadata->{Relationships}; |
2161 |
while (my ($relationshipName, $relationshipStructure) = each %{$relationshipList}) { |
for my $relationshipName (keys %{$relationshipList}) { |
2162 |
|
my $relationshipStructure = $relationshipList->{$relationshipName}; |
2163 |
# Fix up this relationship. |
# Fix up this relationship. |
2164 |
_FixupFields($relationshipStructure, $relationshipName, 2, 3); |
_FixupFields($relationshipStructure, $relationshipName, 2, 3); |
2165 |
# Format a description for the FROM field. |
# Format a description for the FROM field. |
2208 |
my @fromList = (); |
my @fromList = (); |
2209 |
my @toList = (); |
my @toList = (); |
2210 |
my @bothList = (); |
my @bothList = (); |
2211 |
while (my ($relationshipName, $relationship) = each %{$relationshipList}) { |
Trace("Join table build for $entityName.") if T(metadata => 4); |
2212 |
|
for my $relationshipName (keys %{$relationshipList}) { |
2213 |
|
my $relationship = $relationshipList->{$relationshipName}; |
2214 |
# Determine if this relationship has our entity in one of its link fields. |
# Determine if this relationship has our entity in one of its link fields. |
2215 |
if ($relationship->{from} eq $entityName) { |
my $fromEntity = $relationship->{from}; |
2216 |
if ($relationship->{to} eq $entityName) { |
my $toEntity = $relationship->{to}; |
2217 |
|
Trace("Join check for relationship $relationshipName from $fromEntity to $toEntity.") if T(4); |
2218 |
|
if ($fromEntity eq $entityName) { |
2219 |
|
if ($toEntity eq $entityName) { |
2220 |
# Here the relationship is recursive. |
# Here the relationship is recursive. |
2221 |
push @bothList, $relationshipName; |
push @bothList, $relationshipName; |
2222 |
|
Trace("Relationship $relationshipName put in both-list.") if T(metadata => 4); |
2223 |
} else { |
} else { |
2224 |
# Here the relationship comes from the entity. |
# Here the relationship comes from the entity. |
2225 |
push @fromList, $relationshipName; |
push @fromList, $relationshipName; |
2226 |
|
Trace("Relationship $relationshipName put in from-list.") if T(metadata => 4); |
2227 |
} |
} |
2228 |
} elsif ($relationship->{to} eq $entityName) { |
} elsif ($toEntity eq $entityName) { |
2229 |
# Here the relationship goes to the entity. |
# Here the relationship goes to the entity. |
2230 |
push @toList, $relationshipName; |
push @toList, $relationshipName; |
2231 |
|
Trace("Relationship $relationshipName put in to-list.") if T(metadata => 4); |
2232 |
} |
} |
2233 |
} |
} |
2234 |
# Create the nonrecursive joins. Note that we build two hashes for running |
# Create the nonrecursive joins. Note that we build two hashes for running |
2237 |
# hash table at the same time. |
# hash table at the same time. |
2238 |
my %directRelationships = ( from => \@fromList, to => \@toList ); |
my %directRelationships = ( from => \@fromList, to => \@toList ); |
2239 |
my %otherRelationships = ( from => \@fromList, to => \@toList ); |
my %otherRelationships = ( from => \@fromList, to => \@toList ); |
2240 |
while (my ($linkType, $relationships) = each %directRelationships) { |
for my $linkType (keys %directRelationships) { |
2241 |
|
my $relationships = $directRelationships{$linkType}; |
2242 |
# Loop through all the relationships. |
# Loop through all the relationships. |
2243 |
for my $relationshipName (@{$relationships}) { |
for my $relationshipName (@{$relationships}) { |
2244 |
# Create joins between the entity and this relationship. |
# Create joins between the entity and this relationship. |
2245 |
my $linkField = "$relationshipName.${linkType}_link"; |
my $linkField = "$relationshipName.${linkType}_link"; |
2246 |
my $joinClause = "$entityName.id = $linkField"; |
my $joinClause = "$entityName.id = $linkField"; |
2247 |
|
Trace("Entity join clause is $joinClause for $entityName and $relationshipName.") if T(metadata => 4); |
2248 |
$joinTable{"$entityName/$relationshipName"} = $joinClause; |
$joinTable{"$entityName/$relationshipName"} = $joinClause; |
2249 |
$joinTable{"$relationshipName/$entityName"} = $joinClause; |
$joinTable{"$relationshipName/$entityName"} = $joinClause; |
2250 |
# Create joins between this relationship and the other relationships. |
# Create joins between this relationship and the other relationships. |
2251 |
while (my ($otherType, $otherships) = each %otherRelationships) { |
for my $otherType (keys %otherRelationships) { |
2252 |
|
my $otherships = $otherRelationships{$otherType}; |
2253 |
for my $otherName (@{$otherships}) { |
for my $otherName (@{$otherships}) { |
2254 |
# Get the key for this join. |
# Get the key for this join. |
2255 |
my $joinKey = "$otherName/$relationshipName"; |
my $joinKey = "$otherName/$relationshipName"; |
2259 |
# path is ambiguous. We delete the join from the join |
# path is ambiguous. We delete the join from the join |
2260 |
# table to prevent it from being used. |
# table to prevent it from being used. |
2261 |
delete $joinTable{$joinKey}; |
delete $joinTable{$joinKey}; |
2262 |
|
Trace("Deleting ambiguous join $joinKey.") if T(4); |
2263 |
} elsif ($otherName ne $relationshipName) { |
} elsif ($otherName ne $relationshipName) { |
2264 |
# Here we have a valid join. Note that joins between a |
# Here we have a valid join. Note that joins between a |
2265 |
# relationship and itself are prohibited. |
# relationship and itself are prohibited. |
2266 |
$joinTable{$joinKey} = "$otherName.${otherType}_link = $linkField"; |
my $relJoinClause = "$otherName.${otherType}_link = $linkField"; |
2267 |
|
$joinTable{$joinKey} = $relJoinClause; |
2268 |
|
Trace("Relationship join clause is $relJoinClause for $joinKey.") if T(metadata => 4); |
2269 |
} |
} |
2270 |
} |
} |
2271 |
} |
} |
2274 |
# relationship can only be ambiguous with another recursive relationship, |
# relationship can only be ambiguous with another recursive relationship, |
2275 |
# and the incoming relationship from the outer loop is never recursive. |
# and the incoming relationship from the outer loop is never recursive. |
2276 |
for my $otherName (@bothList) { |
for my $otherName (@bothList) { |
2277 |
|
Trace("Setting up relationship joins to recursive relationship $otherName with $relationshipName.") if T(metadata => 4); |
2278 |
# Join from the left. |
# Join from the left. |
2279 |
$joinTable{"$relationshipName/$otherName"} = |
$joinTable{"$relationshipName/$otherName"} = |
2280 |
"$linkField = $otherName.from_link"; |
"$linkField = $otherName.from_link"; |
2289 |
# rise to situations where we can't create the path we want; however, it is always |
# rise to situations where we can't create the path we want; however, it is always |
2290 |
# possible to get the same effect using multiple queries. |
# possible to get the same effect using multiple queries. |
2291 |
for my $relationshipName (@bothList) { |
for my $relationshipName (@bothList) { |
2292 |
|
Trace("Setting up entity joins to recursive relationship $relationshipName with $entityName.") if T(metadata => 4); |
2293 |
# Join to the entity from each direction. |
# Join to the entity from each direction. |
2294 |
$joinTable{"$entityName/$relationshipName"} = |
$joinTable{"$entityName/$relationshipName"} = |
2295 |
"$entityName.id = $relationshipName.from_link"; |
"$entityName.id = $relationshipName.from_link"; |
2340 |
# index descriptor does not exist, it will be created automatically so we can add |
# index descriptor does not exist, it will be created automatically so we can add |
2341 |
# the field to it. |
# the field to it. |
2342 |
unshift @{$newIndex->{IndexFields}}, $firstField; |
unshift @{$newIndex->{IndexFields}}, $firstField; |
2343 |
|
# If this is a one-to-many relationship, the "To" index is unique. |
2344 |
|
if ($relationshipStructure->{arity} eq "1M" && $indexKey eq "To") { |
2345 |
|
$newIndex->{Unique} = 'true'; |
2346 |
|
} |
2347 |
# Add the index to the relation. |
# Add the index to the relation. |
2348 |
_AddIndex("idx$relationshipName$indexKey", $relationStructure, $newIndex); |
_AddIndex("idx$relationshipName$indexKey", $relationStructure, $newIndex); |
2349 |
} |
} |
2433 |
$structure->{Fields} = { }; |
$structure->{Fields} = { }; |
2434 |
} else { |
} else { |
2435 |
# Here we have a field list. Loop through its fields. |
# Here we have a field list. Loop through its fields. |
2436 |
while (my ($fieldName, $fieldData) = each %{$structure->{Fields}}) { |
my $fieldStructures = $structure->{Fields}; |
2437 |
|
for my $fieldName (keys %{$fieldStructures}) { |
2438 |
|
Trace("Processing field $fieldName of $defaultRelationName.") if T(4); |
2439 |
|
my $fieldData = $fieldStructures->{$fieldName}; |
2440 |
# Get the field type. |
# Get the field type. |
2441 |
my $type = $fieldData->{type}; |
my $type = $fieldData->{type}; |
2442 |
# Plug in a relation name if it is needed. |
# Plug in a relation name if it is needed. |