3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.15 2002/12/05 13:55:21 joko |
7 |
|
# + now utilizing 'object2hash' instead of 'var_deref' |
8 |
|
# + played around with having fresh-objects - no progress.... |
9 |
|
# |
10 |
|
# Revision 1.14 2002/12/05 09:40:30 jonen |
11 |
|
# + added option->{destroy} at getObject for unloading all instance |
12 |
|
# |
13 |
|
# Revision 1.13 2002/12/05 07:59:04 joko |
14 |
|
# + now using Tie::SecureHash as a base for the COREHANDLE |
15 |
|
# + former public COREHANDLE becomes private _COREHANDLE now |
16 |
|
# + sub getCOREHANDLE |
17 |
|
# |
18 |
|
# Revision 1.12 2002/12/04 11:34:49 joko |
19 |
|
# - $schema_tangram doesn't have to be in class? |
20 |
|
# |
21 |
|
# Revision 1.11 2002/12/04 08:54:08 jonen |
22 |
|
# + untested bugfix: undef($object) after transform to hash at getObjectAsHash |
23 |
|
# |
24 |
# Revision 1.10 2002/12/03 15:53:23 joko |
# Revision 1.10 2002/12/03 15:53:23 joko |
25 |
# + small bugfix regarding object hierarchy |
# + small bugfix regarding object hierarchy |
26 |
# |
# |
74 |
use strict; |
use strict; |
75 |
use warnings; |
use warnings; |
76 |
|
|
77 |
|
use base ("Data::Storage::Handler"); |
78 |
use base ("Data::Storage::Handler::Abstract"); |
use base ("Data::Storage::Handler::Abstract"); |
79 |
|
|
80 |
use Tangram; |
use Tangram; |
82 |
use libp qw( getNewPerlObjectByPkgName ); |
use libp qw( getNewPerlObjectByPkgName ); |
83 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
84 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
85 |
use Data::Transform::Deep qw( var_deref ); |
use Data::Transform::Deep qw( object2hash ); |
86 |
use Data::Transform::Encode qw( var2utf8 ); |
use Data::Transform::Encode qw( var2utf8 ); |
87 |
|
|
88 |
|
|
90 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
91 |
|
|
92 |
|
|
93 |
|
# this holds the complete instantiated schema from tangram |
94 |
|
my $schema_tangram; |
95 |
|
|
96 |
sub getMetaInfo { |
sub getMetaInfo { |
97 |
my $self = shift; |
my $self = shift; |
98 |
$logger->debug( __PACKAGE__ . "->getMetaInfo()" ); |
$logger->debug( __PACKAGE__ . "->getMetaInfo()" ); |
104 |
sub _initSchema { |
sub _initSchema { |
105 |
my $self = shift; |
my $self = shift; |
106 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
107 |
#if (!$self->{schema_tangram}) { |
#if (!$schema_tangram) { |
108 |
my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } ); |
my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } ); |
109 |
$self->{schema_tangram} = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
110 |
#} |
#} |
111 |
if (!$self->{schema_tangram}) { |
if (!$schema_tangram) { |
112 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
113 |
return 0; |
return 0; |
114 |
} |
} |
137 |
|
|
138 |
# create the main tangram storage object |
# create the main tangram storage object |
139 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
140 |
$self->{COREHANDLE} = Tangram::Relational->connect( $self->{schema_tangram}, $dsn ); |
$self->{_COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn ); |
141 |
|
|
142 |
|
#print "connect", "\n"; |
143 |
|
#my $core = $self->{_COREHANDLE}; |
144 |
|
#print Dumper($core); |
145 |
|
|
146 |
# some attempts for configuring the wrapped underlying dbi..... |
# some attempts for configuring the wrapped underlying dbi..... |
147 |
#$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage(); |
#$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage(); |
247 |
foreach my $key (keys %{$self->{dbi}}) { |
foreach my $key (keys %{$self->{dbi}}) { |
248 |
my $val = $self->{dbi}->{$key}; |
my $val = $self->{dbi}->{$key}; |
249 |
print "entry: $key; $val", "\n"; |
print "entry: $key; $val", "\n"; |
250 |
$self->{COREHANDLE}->{db}->{$key} = $val; |
$self->{_COREHANDLE}->{db}->{$key} = $val; |
251 |
} |
} |
252 |
#print Dumper($self->{COREHANDLE}->{db}); |
#print Dumper($self->{COREHANDLE}->{db}); |
253 |
} |
} |
263 |
|
|
264 |
# apply configured modifications |
# apply configured modifications |
265 |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
266 |
$self->{COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file}); |
$self->{_COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file}); |
267 |
} |
} |
268 |
if (exists $self->{dbi}->{RaiseError}) { |
if (exists $self->{dbi}->{RaiseError}) { |
269 |
$self->{COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError}; |
$self->{_COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError}; |
270 |
} |
} |
271 |
if (exists $self->{dbi}->{PrintError}) { |
if (exists $self->{dbi}->{PrintError}) { |
272 |
$self->{COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError}; |
$self->{_COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError}; |
273 |
} |
} |
274 |
if (exists $self->{dbi}->{HandleError}) { |
if (exists $self->{dbi}->{HandleError}) { |
275 |
$self->{COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError}; |
$self->{_COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError}; |
276 |
} |
} |
277 |
|
|
278 |
} |
} |
288 |
my $ok; |
my $ok; |
289 |
if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) { |
if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) { |
290 |
return unless $self->_initSchema(); |
return unless $self->_initSchema(); |
291 |
$ok = Tangram::Relational->deploy($self->{schema_tangram}, $dbh ); |
$ok = Tangram::Relational->deploy($schema_tangram, $dbh ); |
292 |
$dbh->disconnect(); |
$dbh->disconnect(); |
293 |
} |
} |
294 |
return $ok; |
return $ok; |
309 |
#use Data::Dumper; print Dumper($self); |
#use Data::Dumper; print Dumper($self); |
310 |
$self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11"); |
$self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11"); |
311 |
|
|
312 |
$ok = Tangram::Relational->retreat($self->{schema_tangram}, $dbh ); |
$ok = Tangram::Relational->retreat($schema_tangram, $dbh ); |
313 |
|
|
314 |
# answer "$ok=2" means "maybe" for now - we have to patch this to a constant here because... |
# answer "$ok=2" means "maybe" for now - we have to patch this to a constant here because... |
315 |
# - ... Tangram::Relational->retreat doesn't seem to return a valid status |
# - ... Tangram::Relational->retreat doesn't seem to return a valid status |
351 |
my @results; |
my @results; |
352 |
$logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" ); |
$logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" ); |
353 |
# get set of objects from odbms by object name |
# get set of objects from odbms by object name |
354 |
my $object_set = $self->{COREHANDLE}->remote($nodename); |
my $object_set = $self->{_COREHANDLE}->remote($nodename); |
355 |
@results = $self->{COREHANDLE}->select($object_set); |
@results = $self->{_COREHANDLE}->select($object_set); |
356 |
return \@results; |
return \@results; |
357 |
} |
} |
358 |
|
|
397 |
my $tfilter = join(' & ', @tfilters); |
my $tfilter = join(' & ', @tfilters); |
398 |
|
|
399 |
# get set of objects from odbms by object name |
# get set of objects from odbms by object name |
400 |
my $remote = $self->{COREHANDLE}->remote($nodename); |
my $remote = $self->{_COREHANDLE}->remote($nodename); |
401 |
|
|
402 |
# was: |
# was: |
403 |
#@results = $self->{COREHANDLE}->select($object_set, $tfilter); |
#@results = $self->{COREHANDLE}->select($object_set, $tfilter); |
404 |
|
|
405 |
# is: |
# is: |
406 |
# HACK: build eval-string (sorry) to get filtered list - please give advice here |
# HACK: build eval-string (sorry) to get filtered list - please give advice here |
407 |
my $evalstring = 'return $self->{COREHANDLE}->select($remote, ' . $tfilter . ');'; |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
408 |
|
|
409 |
# get filtered list/set |
# get filtered list/set |
410 |
@results = eval($evalstring); |
@results = eval($evalstring); |
416 |
sub createCursor { |
sub createCursor { |
417 |
my $self = shift; |
my $self = shift; |
418 |
my $node = shift; |
my $node = shift; |
419 |
my $cmdHandle = $self->{COREHANDLE}->cursor($node); |
my $cmdHandle = $self->{_COREHANDLE}->cursor($node); |
420 |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle ); |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle ); |
421 |
return $result; |
return $result; |
422 |
} |
} |
451 |
my $ident = $query->{criterias}->[0]->{val}; |
my $ident = $query->{criterias}->[0]->{val}; |
452 |
#print "load obj", "\n"; |
#print "load obj", "\n"; |
453 |
#return $self->createSet() if $ident == 5; |
#return $self->createSet() if $ident == 5; |
454 |
my $object = $self->{COREHANDLE}->load($ident); |
my $object = $self->{_COREHANDLE}->load($ident); |
455 |
#print "get id", "\n"; |
#print "get id", "\n"; |
456 |
my $oid = $self->{COREHANDLE}->id($object); |
my $oid = $self->{_COREHANDLE}->id($object); |
457 |
return $self->createSet($object); |
return $self->createSet($object); |
458 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
459 |
} |
} |
482 |
sub eraseAll { |
sub eraseAll { |
483 |
my $self = shift; |
my $self = shift; |
484 |
my $classname = shift; |
my $classname = shift; |
485 |
my $remote = $self->{COREHANDLE}->remote($classname); |
my $remote = $self->{_COREHANDLE}->remote($classname); |
486 |
my @objs = $self->{COREHANDLE}->select($remote); |
my @objs = $self->{_COREHANDLE}->select($remote); |
487 |
$self->{COREHANDLE}->erase(@objs); |
$self->{_COREHANDLE}->erase(@objs); |
488 |
} |
} |
489 |
|
|
490 |
sub createDb { |
sub createDb { |
496 |
sub getObject { |
sub getObject { |
497 |
my $self = shift; |
my $self = shift; |
498 |
my $oid = shift; |
my $oid = shift; |
499 |
|
my $options = shift; |
500 |
|
# TODO: create a deep_unload method |
501 |
|
# unload($oid) will only unload object, not deep object hashes |
502 |
|
$self->{_COREHANDLE}->unload() if($options->{destroy}); |
503 |
# TODO: review this |
# TODO: review this |
504 |
#if (!$self->{COREHANDLE}) { return; } |
#if (!$self->{COREHANDLE}) { return; } |
505 |
return $self->{COREHANDLE}->load($oid); |
return $self->{_COREHANDLE}->load($oid); |
506 |
} |
} |
507 |
|
|
508 |
sub getObjectAsHash { |
sub getObjectAsHash { |
509 |
my $self = shift; |
my $self = shift; |
510 |
my $oid = shift; |
my $oid = shift; |
511 |
my $options = shift; |
my $options = shift; |
512 |
my $obj = $self->getObject($oid); |
my $obj = $self->getObject($oid, $options); |
513 |
my $deref = var_deref($obj); |
|
514 |
var2utf8($deref) if ($options->{utf8}); |
# build options (a callback to unload autovivified objects) for 'expand' |
515 |
return $deref; |
# TODO: use $logger to write to debug here! |
516 |
|
my $cb; # = sub {}; |
517 |
|
=pod |
518 |
|
if ($options->{destroy}) { |
519 |
|
$options->{cb}->{destroy} = sub { |
520 |
|
print "================ DESTROY", "\n"; |
521 |
|
my $object = shift; |
522 |
|
#print Dumper($object); |
523 |
|
$self->{_COREHANDLE}->unload($object); |
524 |
|
#undef($object); |
525 |
|
}; |
526 |
|
} |
527 |
|
=cut |
528 |
|
|
529 |
|
my $hash = object2hash($obj, $options); |
530 |
|
#$options->{cb}->{destroy}->($obj); |
531 |
|
#$self->{_COREHANDLE}->unload($obj); |
532 |
|
|
533 |
|
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
534 |
|
# now done in object2hash |
535 |
|
#var2utf8($hash) if ($options->{utf8}); |
536 |
|
|
537 |
|
# old (wrong) attempts to get rid of used instances, if requested |
538 |
|
#$obj->clear_refs; |
539 |
|
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
540 |
|
#$obj->DESTROY; |
541 |
|
#undef($obj) if($options->{destroy}); |
542 |
|
|
543 |
|
return $hash; |
544 |
|
} |
545 |
|
|
546 |
|
sub getSchema { |
547 |
|
return $schema_tangram; |
548 |
|
} |
549 |
|
|
550 |
|
sub getCOREHANDLE { |
551 |
|
my $self = shift; |
552 |
|
return $self->{_COREHANDLE}; |
553 |
} |
} |
554 |
|
|
555 |
1; |
1; |