3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.23 2002/12/19 16:31:53 joko |
7 |
|
# +- renamed sub to 'rebuildDb' |
8 |
|
# |
9 |
|
# Revision 1.22 2002/12/18 22:28:16 jonen |
10 |
|
# + added extended logging at 'getObjectByGuid()' |
11 |
|
# |
12 |
|
# Revision 1.21 2002/12/16 22:20:49 jonen |
13 |
|
# + fixed bug at 'getObjectByGuid()' |
14 |
|
# |
15 |
|
# Revision 1.20 2002/12/16 20:49:17 jonen |
16 |
|
# + added sub 'getObjectByGuid()' |
17 |
|
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
18 |
|
# |
19 |
|
# Revision 1.19 2002/12/16 06:46:09 joko |
20 |
|
# + attempt to introduce a generic '_patchSchema' - cancelled! |
21 |
|
# |
22 |
|
# Revision 1.18 2002/12/13 21:48:07 joko |
23 |
|
# + fix to 'sub sendQuery' |
24 |
|
# |
25 |
|
# Revision 1.17 2002/12/12 02:51:09 joko |
26 |
|
# + cosmetics |
27 |
|
# |
28 |
|
# Revision 1.16 2002/12/11 06:54:10 joko |
29 |
|
# + fix: encapsulated object-loading inside an 'eval' |
30 |
|
# |
31 |
# Revision 1.15 2002/12/05 13:55:21 joko |
# Revision 1.15 2002/12/05 13:55:21 joko |
32 |
# + now utilizing 'object2hash' instead of 'var_deref' |
# + now utilizing 'object2hash' instead of 'var_deref' |
33 |
# + played around with having fresh-objects - no progress.... |
# + played around with having fresh-objects - no progress.... |
137 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
138 |
return 0; |
return 0; |
139 |
} |
} |
140 |
|
#$self->_patchSchema(); |
141 |
return 1; |
return 1; |
142 |
} |
} |
143 |
|
|
144 |
|
sub _patchSchema { |
145 |
|
my $self = shift; |
146 |
|
foreach (keys %{$schema_tangram->{classes}}) { |
147 |
|
next if $schema_tangram->{classes}->{$_}->{abstract}; |
148 |
|
#next if ($_ ne 'TsBankAccount'); |
149 |
|
#$_ ne 'AbstractAccount' && |
150 |
|
print "class: $_", "\n"; |
151 |
|
#print Dumper($schema_tangram->{classes}->{$_}); |
152 |
|
# create new string property named 'guid' |
153 |
|
my $tstring = Tangram::String->new(); |
154 |
|
$tstring->{name} = $tstring->{col} = 'guid'; |
155 |
|
# inject property into schema |
156 |
|
#$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring; |
157 |
|
print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}); |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
sub connect { |
sub connect { |
162 |
|
|
163 |
my $self = shift; |
my $self = shift; |
368 |
return $ok; |
return $ok; |
369 |
} |
} |
370 |
|
|
371 |
sub rebuildDbAndSchema { |
sub rebuildDb { |
372 |
my $self = shift; |
my $self = shift; |
373 |
$logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" ); |
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
374 |
my @results; |
my @results; |
375 |
|
|
376 |
# sum up results (bool (0/1)) in array |
# sum up results (bool (0/1)) in array |
466 |
|
|
467 |
sub createSet { |
sub createSet { |
468 |
my $self = shift; |
my $self = shift; |
469 |
|
#print "-" x 80, "\n"; |
470 |
|
#print Dumper(@_); |
471 |
my @objects = @_; |
my @objects = @_; |
472 |
my $rh = Set::Object->new(); |
my $rh = Set::Object->new(); |
473 |
foreach (@objects) { |
foreach (@objects) { |
474 |
#print Dumper($_); |
if (!isEmpty($_)) { |
475 |
$rh->insert($_) if !isEmpty($_); |
#print Dumper($_); |
476 |
|
$rh->insert($_); |
477 |
|
} |
478 |
} |
} |
479 |
#print Dumper($rh->members()); |
#print Dumper($rh->members()); |
480 |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
498 |
my $ident = $query->{criterias}->[0]->{val}; |
my $ident = $query->{criterias}->[0]->{val}; |
499 |
#print "load obj", "\n"; |
#print "load obj", "\n"; |
500 |
#return $self->createSet() if $ident == 5; |
#return $self->createSet() if $ident == 5; |
501 |
|
$self->{_COREHANDLE}->unload($ident); |
502 |
my $object = $self->{_COREHANDLE}->load($ident); |
my $object = $self->{_COREHANDLE}->load($ident); |
503 |
#print "get id", "\n"; |
#print "get id", "\n"; |
504 |
my $oid = $self->{_COREHANDLE}->id($object); |
my $oid = $self->{_COREHANDLE}->id($object); |
505 |
|
#print Dumper($object); |
506 |
|
#print "oid: $oid", "\n"; |
507 |
return $self->createSet($object); |
return $self->createSet($object); |
508 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
509 |
} |
} |
547 |
my $self = shift; |
my $self = shift; |
548 |
my $oid = shift; |
my $oid = shift; |
549 |
my $options = shift; |
my $options = shift; |
550 |
# TODO: create a deep_unload method |
|
551 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
552 |
# unload($oid) will only unload object, not deep object hashes |
# unload($oid) will only unload object, not deep object hashes |
553 |
$self->{_COREHANDLE}->unload() if($options->{destroy}); |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
554 |
|
|
555 |
# TODO: review this |
# TODO: review this |
556 |
#if (!$self->{COREHANDLE}) { return; } |
#if (!$self->{COREHANDLE}) { return; } |
557 |
return $self->{_COREHANDLE}->load($oid); |
|
558 |
|
# TODO: review this |
559 |
|
my $object = eval('$self->{_COREHANDLE}->load($oid);'); |
560 |
|
print $@, "\n" if $@; |
561 |
|
|
562 |
|
return $object if $object; |
563 |
|
} |
564 |
|
|
565 |
|
sub getObjectByGuid { |
566 |
|
my $self = shift; |
567 |
|
my $guid = shift; |
568 |
|
my $options = shift; |
569 |
|
|
570 |
|
# Guid and Classname is needed |
571 |
|
if(!$guid || !$options->{classname}) { |
572 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" ); |
573 |
|
return; |
574 |
|
} |
575 |
|
|
576 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
577 |
|
# unload($oid) will only unload object, not deep object hashes |
578 |
|
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
579 |
|
|
580 |
|
# search for object with given Classname and Guid |
581 |
|
my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname}); |
582 |
|
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
583 |
|
|
584 |
|
# we searched for global unique identifer of some object, |
585 |
|
# so I think we can trust there would be only one result |
586 |
|
if($result[0]) { |
587 |
|
return $result[0]; |
588 |
|
} else { |
589 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" ); |
590 |
|
return; |
591 |
|
} |
592 |
|
|
593 |
} |
} |
594 |
|
|
595 |
sub getObjectAsHash { |
sub getObjectAsHash { |
596 |
my $self = shift; |
my $self = shift; |
597 |
my $oid = shift; |
my $oid = shift; |
598 |
my $options = shift; |
my $options = shift; |
599 |
my $obj = $self->getObject($oid, $options); |
my $obj; |
600 |
|
|
601 |
|
if($options->{guid}) { |
602 |
|
$obj = $self->getObjectByGuid($oid, $options); |
603 |
|
} else { |
604 |
|
$obj = $self->getObject($oid, $options); |
605 |
|
} |
606 |
|
|
607 |
# build options (a callback to unload autovivified objects) for 'expand' |
# build options (a callback to unload autovivified objects) for 'expand' |
608 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |