3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.25 2003/01/19 02:30:05 joko |
7 |
|
# + fix: modified call to '_initSchema' |
8 |
|
# |
9 |
|
# Revision 1.24 2002/12/22 14:13:01 joko |
10 |
|
# + sub dropDb |
11 |
|
# |
12 |
|
# Revision 1.23 2002/12/19 16:31:53 joko |
13 |
|
# +- renamed sub to 'rebuildDb' |
14 |
|
# |
15 |
|
# Revision 1.22 2002/12/18 22:28:16 jonen |
16 |
|
# + added extended logging at 'getObjectByGuid()' |
17 |
|
# |
18 |
|
# Revision 1.21 2002/12/16 22:20:49 jonen |
19 |
|
# + fixed bug at 'getObjectByGuid()' |
20 |
|
# |
21 |
|
# Revision 1.20 2002/12/16 20:49:17 jonen |
22 |
|
# + added sub 'getObjectByGuid()' |
23 |
|
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
24 |
|
# |
25 |
|
# Revision 1.19 2002/12/16 06:46:09 joko |
26 |
|
# + attempt to introduce a generic '_patchSchema' - cancelled! |
27 |
|
# |
28 |
|
# Revision 1.18 2002/12/13 21:48:07 joko |
29 |
|
# + fix to 'sub sendQuery' |
30 |
|
# |
31 |
|
# Revision 1.17 2002/12/12 02:51:09 joko |
32 |
|
# + cosmetics |
33 |
|
# |
34 |
# Revision 1.16 2002/12/11 06:54:10 joko |
# Revision 1.16 2002/12/11 06:54:10 joko |
35 |
# + fix: encapsulated object-loading inside an 'eval' |
# + fix: encapsulated object-loading inside an 'eval' |
36 |
# |
# |
143 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
144 |
return 0; |
return 0; |
145 |
} |
} |
146 |
|
#$self->_patchSchema(); |
147 |
return 1; |
return 1; |
148 |
} |
} |
149 |
|
|
150 |
|
sub _patchSchema { |
151 |
|
my $self = shift; |
152 |
|
foreach (keys %{$schema_tangram->{classes}}) { |
153 |
|
next if $schema_tangram->{classes}->{$_}->{abstract}; |
154 |
|
#next if ($_ ne 'TsBankAccount'); |
155 |
|
#$_ ne 'AbstractAccount' && |
156 |
|
print "class: $_", "\n"; |
157 |
|
#print Dumper($schema_tangram->{classes}->{$_}); |
158 |
|
# create new string property named 'guid' |
159 |
|
my $tstring = Tangram::String->new(); |
160 |
|
$tstring->{name} = $tstring->{col} = 'guid'; |
161 |
|
# inject property into schema |
162 |
|
#$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring; |
163 |
|
print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}); |
164 |
|
} |
165 |
|
} |
166 |
|
|
167 |
sub connect { |
sub connect { |
168 |
|
|
169 |
my $self = shift; |
my $self = shift; |
170 |
|
|
171 |
my $dsn = shift; |
my $dsn = shift; |
172 |
|
|
173 |
|
#print Dumper($self); |
174 |
|
#exit; |
175 |
|
|
176 |
|
# TODO: re-enable |
177 |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
|
|
|
178 |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
179 |
|
|
180 |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
186 |
# return; |
# return; |
187 |
# } |
# } |
188 |
|
|
189 |
return unless $self->_initSchema(); |
#return unless $self->_initSchema(); |
190 |
|
$self->_initSchema(); |
191 |
|
|
192 |
# create the main tangram storage object |
# create the main tangram storage object |
193 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
379 |
return $ok; |
return $ok; |
380 |
} |
} |
381 |
|
|
382 |
sub rebuildDbAndSchema { |
sub rebuildDb { |
383 |
my $self = shift; |
my $self = shift; |
384 |
$logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" ); |
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
385 |
my @results; |
my @results; |
386 |
|
|
387 |
# sum up results (bool (0/1)) in array |
# sum up results (bool (0/1)) in array |
477 |
|
|
478 |
sub createSet { |
sub createSet { |
479 |
my $self = shift; |
my $self = shift; |
480 |
|
#print "-" x 80, "\n"; |
481 |
|
#print Dumper(@_); |
482 |
my @objects = @_; |
my @objects = @_; |
483 |
my $rh = Set::Object->new(); |
my $rh = Set::Object->new(); |
484 |
foreach (@objects) { |
foreach (@objects) { |
485 |
#print Dumper($_); |
if (!isEmpty($_)) { |
486 |
$rh->insert($_) if !isEmpty($_); |
#print Dumper($_); |
487 |
|
$rh->insert($_); |
488 |
|
} |
489 |
} |
} |
490 |
#print Dumper($rh->members()); |
#print Dumper($rh->members()); |
491 |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
509 |
my $ident = $query->{criterias}->[0]->{val}; |
my $ident = $query->{criterias}->[0]->{val}; |
510 |
#print "load obj", "\n"; |
#print "load obj", "\n"; |
511 |
#return $self->createSet() if $ident == 5; |
#return $self->createSet() if $ident == 5; |
512 |
|
$self->{_COREHANDLE}->unload($ident); |
513 |
my $object = $self->{_COREHANDLE}->load($ident); |
my $object = $self->{_COREHANDLE}->load($ident); |
514 |
#print "get id", "\n"; |
#print "get id", "\n"; |
515 |
my $oid = $self->{_COREHANDLE}->id($object); |
my $oid = $self->{_COREHANDLE}->id($object); |
516 |
|
#print Dumper($object); |
517 |
|
#print "oid: $oid", "\n"; |
518 |
return $self->createSet($object); |
return $self->createSet($object); |
519 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
520 |
} |
} |
561 |
|
|
562 |
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
563 |
# unload($oid) will only unload object, not deep object hashes |
# unload($oid) will only unload object, not deep object hashes |
564 |
$self->{_COREHANDLE}->unload() if($options->{destroy}); |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
565 |
|
|
566 |
# TODO: review this |
# TODO: review this |
567 |
#if (!$self->{COREHANDLE}) { return; } |
#if (!$self->{COREHANDLE}) { return; } |
573 |
return $object if $object; |
return $object if $object; |
574 |
} |
} |
575 |
|
|
576 |
|
sub getObjectByGuid { |
577 |
|
my $self = shift; |
578 |
|
my $guid = shift; |
579 |
|
my $options = shift; |
580 |
|
|
581 |
|
# Guid and Classname is needed |
582 |
|
if(!$guid || !$options->{classname}) { |
583 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" ); |
584 |
|
return; |
585 |
|
} |
586 |
|
|
587 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
588 |
|
# unload($oid) will only unload object, not deep object hashes |
589 |
|
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
590 |
|
|
591 |
|
# search for object with given Classname and Guid |
592 |
|
my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname}); |
593 |
|
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
594 |
|
|
595 |
|
# we searched for global unique identifer of some object, |
596 |
|
# so I think we can trust there would be only one result |
597 |
|
if($result[0]) { |
598 |
|
return $result[0]; |
599 |
|
} else { |
600 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" ); |
601 |
|
return; |
602 |
|
} |
603 |
|
|
604 |
|
} |
605 |
|
|
606 |
sub getObjectAsHash { |
sub getObjectAsHash { |
607 |
my $self = shift; |
my $self = shift; |
608 |
my $oid = shift; |
my $oid = shift; |
609 |
my $options = shift; |
my $options = shift; |
610 |
my $obj = $self->getObject($oid, $options); |
my $obj; |
611 |
|
|
612 |
|
if($options->{guid}) { |
613 |
|
$obj = $self->getObjectByGuid($oid, $options); |
614 |
|
} else { |
615 |
|
$obj = $self->getObject($oid, $options); |
616 |
|
} |
617 |
|
|
618 |
# build options (a callback to unload autovivified objects) for 'expand' |
# build options (a callback to unload autovivified objects) for 'expand' |
619 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |
656 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
657 |
} |
} |
658 |
|
|
659 |
|
sub dropDb { |
660 |
|
my $self = shift; |
661 |
|
my $storage = $self->_getSubLayerHandle(); |
662 |
|
return $storage->dropDb(); |
663 |
|
} |
664 |
|
|
665 |
1; |
1; |