3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.21 2002/12/16 22:20:49 jonen |
7 |
|
# + fixed bug at 'getObjectByGuid()' |
8 |
|
# |
9 |
|
# Revision 1.20 2002/12/16 20:49:17 jonen |
10 |
|
# + added sub 'getObjectByGuid()' |
11 |
|
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
12 |
|
# |
13 |
|
# Revision 1.19 2002/12/16 06:46:09 joko |
14 |
|
# + attempt to introduce a generic '_patchSchema' - cancelled! |
15 |
|
# |
16 |
# Revision 1.18 2002/12/13 21:48:07 joko |
# Revision 1.18 2002/12/13 21:48:07 joko |
17 |
# + fix to 'sub sendQuery' |
# + fix to 'sub sendQuery' |
18 |
# |
# |
131 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
132 |
return 0; |
return 0; |
133 |
} |
} |
134 |
|
#$self->_patchSchema(); |
135 |
return 1; |
return 1; |
136 |
} |
} |
137 |
|
|
138 |
|
sub _patchSchema { |
139 |
|
my $self = shift; |
140 |
|
foreach (keys %{$schema_tangram->{classes}}) { |
141 |
|
next if $schema_tangram->{classes}->{$_}->{abstract}; |
142 |
|
#next if ($_ ne 'TsBankAccount'); |
143 |
|
#$_ ne 'AbstractAccount' && |
144 |
|
print "class: $_", "\n"; |
145 |
|
#print Dumper($schema_tangram->{classes}->{$_}); |
146 |
|
# create new string property named 'guid' |
147 |
|
my $tstring = Tangram::String->new(); |
148 |
|
$tstring->{name} = $tstring->{col} = 'guid'; |
149 |
|
# inject property into schema |
150 |
|
#$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring; |
151 |
|
print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}); |
152 |
|
} |
153 |
|
} |
154 |
|
|
155 |
sub connect { |
sub connect { |
156 |
|
|
157 |
my $self = shift; |
my $self = shift; |
556 |
return $object if $object; |
return $object if $object; |
557 |
} |
} |
558 |
|
|
559 |
|
sub getObjectByGuid { |
560 |
|
my $self = shift; |
561 |
|
my $guid = shift; |
562 |
|
my $options = shift; |
563 |
|
|
564 |
|
# Guid and Classname is needed |
565 |
|
if(!$guid || !$options->{classname}) { |
566 |
|
return; |
567 |
|
} |
568 |
|
|
569 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
570 |
|
# unload($oid) will only unload object, not deep object hashes |
571 |
|
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
572 |
|
|
573 |
|
# search for object with given Classname and Guid |
574 |
|
my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname}); |
575 |
|
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
576 |
|
|
577 |
|
# we searched for global unique identifer of some object, |
578 |
|
# so it think we can trust there would be only one result |
579 |
|
if($result[0]) { |
580 |
|
return $result[0]; |
581 |
|
} else { |
582 |
|
return "No Object with Classname $options->{classname} and GUID $options->{guid} found!"; |
583 |
|
} |
584 |
|
|
585 |
|
} |
586 |
|
|
587 |
sub getObjectAsHash { |
sub getObjectAsHash { |
588 |
my $self = shift; |
my $self = shift; |
589 |
my $oid = shift; |
my $oid = shift; |
590 |
my $options = shift; |
my $options = shift; |
591 |
my $obj = $self->getObject($oid, $options); |
my $obj; |
592 |
|
|
593 |
|
if($options->{guid}) { |
594 |
|
$obj = $self->getObjectByGuid($oid, $options); |
595 |
|
} else { |
596 |
|
$obj = $self->getObject($oid, $options); |
597 |
|
} |
598 |
|
|
599 |
# build options (a callback to unload autovivified objects) for 'expand' |
# build options (a callback to unload autovivified objects) for 'expand' |
600 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |