3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.14 2002/12/05 09:40:30 jonen |
7 |
|
# + added option->{destroy} at getObject for unloading all instance |
8 |
|
# |
9 |
|
# Revision 1.13 2002/12/05 07:59:04 joko |
10 |
|
# + now using Tie::SecureHash as a base for the COREHANDLE |
11 |
|
# + former public COREHANDLE becomes private _COREHANDLE now |
12 |
|
# + sub getCOREHANDLE |
13 |
|
# |
14 |
|
# Revision 1.12 2002/12/04 11:34:49 joko |
15 |
|
# - $schema_tangram doesn't have to be in class? |
16 |
|
# |
17 |
|
# Revision 1.11 2002/12/04 08:54:08 jonen |
18 |
|
# + untested bugfix: undef($object) after transform to hash at getObjectAsHash |
19 |
|
# |
20 |
|
# Revision 1.10 2002/12/03 15:53:23 joko |
21 |
|
# + small bugfix regarding object hierarchy |
22 |
|
# |
23 |
|
# Revision 1.9 2002/12/03 05:29:40 joko |
24 |
|
# + sub getObject |
25 |
|
# + sub getObjectAsHash |
26 |
|
# |
27 |
# Revision 1.8 2002/12/01 22:25:51 joko |
# Revision 1.8 2002/12/01 22:25:51 joko |
28 |
# + now utilizing metadata from storage locator when connecting to DBI in "raw"-mode |
# + now utilizing metadata from storage locator when connecting to DBI in "raw"-mode |
29 |
# |
# |
70 |
use strict; |
use strict; |
71 |
use warnings; |
use warnings; |
72 |
|
|
73 |
|
use base ("Data::Storage::Handler"); |
74 |
use base ("Data::Storage::Handler::Abstract"); |
use base ("Data::Storage::Handler::Abstract"); |
75 |
|
|
76 |
use Tangram; |
use Tangram; |
78 |
use libp qw( getNewPerlObjectByPkgName ); |
use libp qw( getNewPerlObjectByPkgName ); |
79 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
80 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
81 |
|
use Data::Transform::Deep qw( var_deref ); |
82 |
|
use Data::Transform::Encode qw( var2utf8 ); |
83 |
|
|
84 |
|
|
85 |
# get logger instance |
# get logger instance |
86 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
87 |
|
|
88 |
|
|
89 |
|
# this holds the complete instantiated schema from tangram |
90 |
|
my $schema_tangram; |
91 |
|
|
92 |
sub getMetaInfo { |
sub getMetaInfo { |
93 |
my $self = shift; |
my $self = shift; |
94 |
$logger->debug( __PACKAGE__ . "->getMetaInfo()" ); |
$logger->debug( __PACKAGE__ . "->getMetaInfo()" ); |
100 |
sub _initSchema { |
sub _initSchema { |
101 |
my $self = shift; |
my $self = shift; |
102 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
103 |
#if (!$self->{schema_tangram}) { |
#if (!$schema_tangram) { |
104 |
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} } ); |
105 |
$self->{schema_tangram} = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
106 |
#} |
#} |
107 |
if (!$self->{schema_tangram}) { |
if (!$schema_tangram) { |
108 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
109 |
return 0; |
return 0; |
110 |
} |
} |
133 |
|
|
134 |
# create the main tangram storage object |
# create the main tangram storage object |
135 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
136 |
$self->{COREHANDLE} = Tangram::Relational->connect( $self->{schema_tangram}, $dsn ); |
$self->{_COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn ); |
137 |
|
|
138 |
|
#print "connect", "\n"; |
139 |
|
#my $core = $self->{_COREHANDLE}; |
140 |
|
#print Dumper($core); |
141 |
|
|
142 |
# some attempts for configuring the wrapped underlying dbi..... |
# some attempts for configuring the wrapped underlying dbi..... |
143 |
#$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage(); |
#$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage(); |
243 |
foreach my $key (keys %{$self->{dbi}}) { |
foreach my $key (keys %{$self->{dbi}}) { |
244 |
my $val = $self->{dbi}->{$key}; |
my $val = $self->{dbi}->{$key}; |
245 |
print "entry: $key; $val", "\n"; |
print "entry: $key; $val", "\n"; |
246 |
$self->{COREHANDLE}->{db}->{$key} = $val; |
$self->{_COREHANDLE}->{db}->{$key} = $val; |
247 |
} |
} |
248 |
#print Dumper($self->{COREHANDLE}->{db}); |
#print Dumper($self->{COREHANDLE}->{db}); |
249 |
} |
} |
259 |
|
|
260 |
# apply configured modifications |
# apply configured modifications |
261 |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
262 |
$self->{COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file}); |
$self->{_COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file}); |
263 |
} |
} |
264 |
if (exists $self->{dbi}->{RaiseError}) { |
if (exists $self->{dbi}->{RaiseError}) { |
265 |
$self->{COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError}; |
$self->{_COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError}; |
266 |
} |
} |
267 |
if (exists $self->{dbi}->{PrintError}) { |
if (exists $self->{dbi}->{PrintError}) { |
268 |
$self->{COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError}; |
$self->{_COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError}; |
269 |
} |
} |
270 |
if (exists $self->{dbi}->{HandleError}) { |
if (exists $self->{dbi}->{HandleError}) { |
271 |
$self->{COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError}; |
$self->{_COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError}; |
272 |
} |
} |
273 |
|
|
274 |
} |
} |
284 |
my $ok; |
my $ok; |
285 |
if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) { |
if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) { |
286 |
return unless $self->_initSchema(); |
return unless $self->_initSchema(); |
287 |
$ok = Tangram::Relational->deploy($self->{schema_tangram}, $dbh ); |
$ok = Tangram::Relational->deploy($schema_tangram, $dbh ); |
288 |
$dbh->disconnect(); |
$dbh->disconnect(); |
289 |
} |
} |
290 |
return $ok; |
return $ok; |
305 |
#use Data::Dumper; print Dumper($self); |
#use Data::Dumper; print Dumper($self); |
306 |
$self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11"); |
$self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11"); |
307 |
|
|
308 |
$ok = Tangram::Relational->retreat($self->{schema_tangram}, $dbh ); |
$ok = Tangram::Relational->retreat($schema_tangram, $dbh ); |
309 |
|
|
310 |
# 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... |
311 |
# - ... Tangram::Relational->retreat doesn't seem to return a valid status |
# - ... Tangram::Relational->retreat doesn't seem to return a valid status |
347 |
my @results; |
my @results; |
348 |
$logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" ); |
$logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" ); |
349 |
# get set of objects from odbms by object name |
# get set of objects from odbms by object name |
350 |
my $object_set = $self->{COREHANDLE}->remote($nodename); |
my $object_set = $self->{_COREHANDLE}->remote($nodename); |
351 |
@results = $self->{COREHANDLE}->select($object_set); |
@results = $self->{_COREHANDLE}->select($object_set); |
352 |
return \@results; |
return \@results; |
353 |
} |
} |
354 |
|
|
393 |
my $tfilter = join(' & ', @tfilters); |
my $tfilter = join(' & ', @tfilters); |
394 |
|
|
395 |
# get set of objects from odbms by object name |
# get set of objects from odbms by object name |
396 |
my $remote = $self->{COREHANDLE}->remote($nodename); |
my $remote = $self->{_COREHANDLE}->remote($nodename); |
397 |
|
|
398 |
# was: |
# was: |
399 |
#@results = $self->{COREHANDLE}->select($object_set, $tfilter); |
#@results = $self->{COREHANDLE}->select($object_set, $tfilter); |
400 |
|
|
401 |
# is: |
# is: |
402 |
# 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 |
403 |
my $evalstring = 'return $self->{COREHANDLE}->select($remote, ' . $tfilter . ');'; |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
404 |
|
|
405 |
# get filtered list/set |
# get filtered list/set |
406 |
@results = eval($evalstring); |
@results = eval($evalstring); |
412 |
sub createCursor { |
sub createCursor { |
413 |
my $self = shift; |
my $self = shift; |
414 |
my $node = shift; |
my $node = shift; |
415 |
my $cmdHandle = $self->{COREHANDLE}->cursor($node); |
my $cmdHandle = $self->{_COREHANDLE}->cursor($node); |
416 |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle ); |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle ); |
417 |
return $result; |
return $result; |
418 |
} |
} |
447 |
my $ident = $query->{criterias}->[0]->{val}; |
my $ident = $query->{criterias}->[0]->{val}; |
448 |
#print "load obj", "\n"; |
#print "load obj", "\n"; |
449 |
#return $self->createSet() if $ident == 5; |
#return $self->createSet() if $ident == 5; |
450 |
my $object = $self->{COREHANDLE}->load($ident); |
my $object = $self->{_COREHANDLE}->load($ident); |
451 |
#print "get id", "\n"; |
#print "get id", "\n"; |
452 |
my $oid = $self->{COREHANDLE}->id($object); |
my $oid = $self->{_COREHANDLE}->id($object); |
453 |
return $self->createSet($object); |
return $self->createSet($object); |
454 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
455 |
} |
} |
478 |
sub eraseAll { |
sub eraseAll { |
479 |
my $self = shift; |
my $self = shift; |
480 |
my $classname = shift; |
my $classname = shift; |
481 |
my $remote = $self->{storage}->remote($classname); |
my $remote = $self->{_COREHANDLE}->remote($classname); |
482 |
my @objs = $self->{storage}->select($remote); |
my @objs = $self->{_COREHANDLE}->select($remote); |
483 |
$self->{COREHANDLE}->erase(@objs); |
$self->{_COREHANDLE}->erase(@objs); |
484 |
} |
} |
485 |
|
|
486 |
sub createDb { |
sub createDb { |
489 |
return $storage->createDb(); |
return $storage->createDb(); |
490 |
} |
} |
491 |
|
|
492 |
|
sub getObject { |
493 |
|
my $self = shift; |
494 |
|
my $oid = shift; |
495 |
|
my $options = shift; |
496 |
|
# TODO: create a deep_unload method |
497 |
|
# unload($oid) will only unload object, not deep object hashes |
498 |
|
$self->{_COREHANDLE}->unload() if($options->{destroy}); |
499 |
|
# TODO: review this |
500 |
|
#if (!$self->{COREHANDLE}) { return; } |
501 |
|
return $self->{_COREHANDLE}->load($oid); |
502 |
|
} |
503 |
|
|
504 |
|
sub getObjectAsHash { |
505 |
|
my $self = shift; |
506 |
|
my $oid = shift; |
507 |
|
my $options = shift; |
508 |
|
my $obj = $self->getObject($oid, $options); |
509 |
|
my $deref = var_deref($obj); |
510 |
|
var2utf8($deref) if ($options->{utf8}); |
511 |
|
#$obj->clear_refs; |
512 |
|
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
513 |
|
#$obj->DESTROY; |
514 |
|
#undef($obj) if($options->{destroy}); |
515 |
|
return $deref; |
516 |
|
} |
517 |
|
|
518 |
|
sub getSchema { |
519 |
|
return $schema_tangram; |
520 |
|
} |
521 |
|
|
522 |
|
sub getCOREHANDLE { |
523 |
|
my $self = shift; |
524 |
|
return $self->{_COREHANDLE}; |
525 |
|
} |
526 |
|
|
527 |
1; |
1; |