3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.29 2003/02/21 01:47:18 joko |
7 |
|
# purged old code |
8 |
|
# minor cosmetics |
9 |
|
# |
10 |
|
# Revision 1.28 2003/02/20 20:20:26 joko |
11 |
|
# tried to get auto-disconnect working again - failed with that |
12 |
|
# |
13 |
|
# Revision 1.27 2003/01/31 06:30:59 joko |
14 |
|
# + enabled 'sendQuery' |
15 |
|
# |
16 |
|
# Revision 1.26 2003/01/30 22:29:47 joko |
17 |
|
# + fixed module usage (removed dependency on 'libp.pm') |
18 |
|
# |
19 |
|
# Revision 1.25 2003/01/19 02:30:05 joko |
20 |
|
# + fix: modified call to '_initSchema' |
21 |
|
# |
22 |
|
# Revision 1.24 2002/12/22 14:13:01 joko |
23 |
|
# + sub dropDb |
24 |
|
# |
25 |
|
# Revision 1.23 2002/12/19 16:31:53 joko |
26 |
|
# +- renamed sub to 'rebuildDb' |
27 |
|
# |
28 |
|
# Revision 1.22 2002/12/18 22:28:16 jonen |
29 |
|
# + added extended logging at 'getObjectByGuid()' |
30 |
|
# |
31 |
|
# Revision 1.21 2002/12/16 22:20:49 jonen |
32 |
|
# + fixed bug at 'getObjectByGuid()' |
33 |
|
# |
34 |
# Revision 1.20 2002/12/16 20:49:17 jonen |
# Revision 1.20 2002/12/16 20:49:17 jonen |
35 |
# + added sub 'getObjectByGuid()' |
# + added sub 'getObjectByGuid()' |
36 |
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
48 |
# + fix: encapsulated object-loading inside an 'eval' |
# + fix: encapsulated object-loading inside an 'eval' |
49 |
# |
# |
50 |
# Revision 1.15 2002/12/05 13:55:21 joko |
# Revision 1.15 2002/12/05 13:55:21 joko |
51 |
# + now utilizing 'object2hash' instead of 'var_deref' |
# + now utilizing 'expand' instead of 'var_deref' |
52 |
# + played around with having fresh-objects - no progress.... |
# + played around with having fresh-objects - no progress.... |
53 |
# |
# |
54 |
# Revision 1.14 2002/12/05 09:40:30 jonen |
# Revision 1.14 2002/12/05 09:40:30 jonen |
121 |
use base ("Data::Storage::Handler"); |
use base ("Data::Storage::Handler"); |
122 |
use base ("Data::Storage::Handler::Abstract"); |
use base ("Data::Storage::Handler::Abstract"); |
123 |
|
|
124 |
use Tangram; |
|
125 |
use Data::Dumper; |
use Data::Dumper; |
126 |
use libp qw( getNewPerlObjectByPkgName ); |
use Tangram; |
127 |
|
|
128 |
|
use DesignPattern::Object; |
129 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
130 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
131 |
use Data::Transform::Deep qw( object2hash ); |
use Data::Transform::Deep qw( expand ); |
|
use Data::Transform::Encode qw( var2utf8 ); |
|
|
|
|
132 |
|
|
133 |
# get logger instance |
# get logger instance |
134 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
149 |
my $self = shift; |
my $self = shift; |
150 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
151 |
#if (!$schema_tangram) { |
#if (!$schema_tangram) { |
152 |
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} } ); |
153 |
|
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
154 |
$schema_tangram = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
155 |
#} |
#} |
156 |
if (!$schema_tangram) { |
if (!$schema_tangram) { |
183 |
my $self = shift; |
my $self = shift; |
184 |
|
|
185 |
my $dsn = shift; |
my $dsn = shift; |
186 |
|
|
187 |
|
#print Dumper($self); |
188 |
|
#exit; |
189 |
|
|
190 |
|
# TODO: re-enable |
191 |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
|
|
|
192 |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
193 |
|
|
194 |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
200 |
# return; |
# return; |
201 |
# } |
# } |
202 |
|
|
203 |
return unless $self->_initSchema(); |
#return unless $self->_initSchema(); |
204 |
|
$self->_initSchema(); |
205 |
|
|
206 |
# create the main tangram storage object |
# create the main tangram storage object |
207 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
328 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
329 |
|
|
330 |
#my $subLayer = $self->_getSubLayerHandle(); |
#my $subLayer = $self->_getSubLayerHandle(); |
331 |
|
#print Dumper($self); |
332 |
|
#exit; |
333 |
|
|
334 |
# apply configured modifications |
# apply configured modifications |
335 |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
395 |
return $ok; |
return $ok; |
396 |
} |
} |
397 |
|
|
398 |
sub rebuildDbAndSchema { |
sub rebuildDb { |
399 |
my $self = shift; |
my $self = shift; |
400 |
$logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" ); |
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
401 |
my @results; |
my @results; |
402 |
|
|
403 |
# sum up results (bool (0/1)) in array |
# sum up results (bool (0/1)) in array |
437 |
my @results; |
my @results; |
438 |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
439 |
|
|
440 |
#print Dumper($filters); |
#print Dumper($filters); |
441 |
|
|
442 |
my @tfilters; |
my @tfilters; |
443 |
|
|
476 |
# 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 |
477 |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
478 |
|
|
479 |
|
#print "eval: $evalstring", "\n"; |
480 |
|
|
481 |
# get filtered list/set |
# get filtered list/set |
482 |
@results = eval($evalstring); |
@results = eval($evalstring); |
483 |
die $@ if $@; |
die $@ if $@; |
537 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
538 |
} |
} |
539 |
|
|
540 |
die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
my $list = $self->getListFiltered($query->{node}, $query->{criterias}); |
541 |
|
#return $self->createSet($object); |
542 |
|
#return $self->createSet($list); |
543 |
|
return $self->createSet(@$list); |
544 |
|
|
545 |
|
#die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
546 |
|
|
547 |
|
|
|
# TODO: do a common tangram query here |
|
548 |
|
|
549 |
|
|
550 |
|
# try a generic tangram query here |
551 |
|
# TODO: try to place an oql on top of that (search.cpan.org!) |
552 |
my @crits; |
my @crits; |
553 |
foreach (@{$query->{criterias}}) { |
foreach (@{$query->{criterias}}) { |
554 |
my $op = ''; |
my $op = ''; |
606 |
|
|
607 |
# Guid and Classname is needed |
# Guid and Classname is needed |
608 |
if(!$guid || !$options->{classname}) { |
if(!$guid || !$options->{classname}) { |
609 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" ); |
610 |
return; |
return; |
611 |
} |
} |
612 |
|
|
615 |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
616 |
|
|
617 |
# search for object with given Classname and Guid |
# search for object with given Classname and Guid |
618 |
my $obj_tmp = $self->{_COREHANDLE}->remote($classname); |
my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname}); |
619 |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
620 |
|
|
621 |
# we searched for global unique identifer of some object, |
# we searched for global unique identifer of some object, |
622 |
# so it think we can trust there would be only one result |
# so I think we can trust there would be only one result |
623 |
if($result[0]) { |
if($result[0]) { |
624 |
return $result[0]; |
return $result[0]; |
625 |
} else { |
} else { |
626 |
return "No Object with Classname $classname and GUID $options->{guid} found!"; |
$logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" ); |
627 |
|
return; |
628 |
} |
} |
629 |
|
|
630 |
} |
} |
644 |
# build options (a callback to unload autovivified objects) for 'expand' |
# build options (a callback to unload autovivified objects) for 'expand' |
645 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |
646 |
my $cb; # = sub {}; |
my $cb; # = sub {}; |
647 |
|
|
648 |
|
# deactivated way to get rid of used instances, if requested |
649 |
=pod |
=pod |
650 |
if ($options->{destroy}) { |
if ($options->{destroy}) { |
651 |
$options->{cb}->{destroy} = sub { |
$options->{cb}->{destroy} = sub { |
652 |
print "================ DESTROY", "\n"; |
print "================ DESTROY", "\n"; |
653 |
my $object = shift; |
my $object = shift; |
654 |
#print Dumper($object); |
#print Dumper($object); |
655 |
$self->{_COREHANDLE}->unload($object); |
$self->{_COREHANDLE}->unload($object); |
656 |
#undef($object); |
#undef($object); |
657 |
}; |
}; |
658 |
} |
} |
659 |
=cut |
=cut |
660 |
|
|
661 |
my $hash = object2hash($obj, $options); |
my $hash = expand($obj, $options); |
662 |
#$options->{cb}->{destroy}->($obj); |
|
663 |
#$self->{_COREHANDLE}->unload($obj); |
# old (unsuccessful) attempts to get rid of used instances, if requested |
664 |
|
|
665 |
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
# V1: |
666 |
# now done in object2hash |
#$options->{cb}->{destroy}->($obj); |
667 |
#var2utf8($hash) if ($options->{utf8}); |
#$self->{_COREHANDLE}->unload($obj); |
668 |
|
|
669 |
# old (wrong) attempts to get rid of used instances, if requested |
# V2: |
670 |
#$obj->clear_refs; |
#$obj->clear_refs; |
671 |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
672 |
#$obj->DESTROY; |
#$obj->DESTROY; |
684 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
685 |
} |
} |
686 |
|
|
687 |
|
sub dropDb { |
688 |
|
my $self = shift; |
689 |
|
my $storage = $self->_getSubLayerHandle(); |
690 |
|
return $storage->dropDb(); |
691 |
|
} |
692 |
|
|
693 |
|
sub testAvailability { |
694 |
|
my $self = shift; |
695 |
|
my $storage = $self->_getSubLayerHandle(); |
696 |
|
return $storage->testAvailability(); |
697 |
|
} |
698 |
|
|
699 |
|
sub disconnect2 { |
700 |
|
my $self = shift; |
701 |
|
my $storage = $self->_getSubLayerHandle(); |
702 |
|
print "DISC!", "\n"; |
703 |
|
|
704 |
|
my $storage_ll = $storage->{_COREHANDLE}; |
705 |
|
$storage_ll->disconnect(); |
706 |
|
|
707 |
|
print Dumper($storage); |
708 |
|
exit; |
709 |
|
|
710 |
|
#$self->{_COREHANDLE} |
711 |
|
#$storage->disconnect(); |
712 |
|
$self->{dataStorageLayer}->disconnect(); |
713 |
|
} |
714 |
|
|
715 |
1; |
1; |
716 |
|
__END__ |