3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.32 2003/04/08 22:52:22 joko |
7 |
|
# modified 'querySchema': better behaviour regarding filtering result |
8 |
|
# |
9 |
|
# Revision 1.31 2003/04/05 21:24:09 joko |
10 |
|
# modified 'sub getChildNodes': now contains code from 'querySchema' |
11 |
|
# |
12 |
|
# Revision 1.30 2003/03/27 15:31:14 joko |
13 |
|
# fixes to modules regarding new namespace(s) below Data::Mungle::* |
14 |
|
# |
15 |
|
# Revision 1.29 2003/02/21 01:47:18 joko |
16 |
|
# purged old code |
17 |
|
# minor cosmetics |
18 |
|
# |
19 |
|
# Revision 1.28 2003/02/20 20:20:26 joko |
20 |
|
# tried to get auto-disconnect working again - failed with that |
21 |
|
# |
22 |
|
# Revision 1.27 2003/01/31 06:30:59 joko |
23 |
|
# + enabled 'sendQuery' |
24 |
|
# |
25 |
|
# Revision 1.26 2003/01/30 22:29:47 joko |
26 |
|
# + fixed module usage (removed dependency on 'libp.pm') |
27 |
|
# |
28 |
|
# Revision 1.25 2003/01/19 02:30:05 joko |
29 |
|
# + fix: modified call to '_initSchema' |
30 |
|
# |
31 |
|
# Revision 1.24 2002/12/22 14:13:01 joko |
32 |
|
# + sub dropDb |
33 |
|
# |
34 |
# Revision 1.23 2002/12/19 16:31:53 joko |
# Revision 1.23 2002/12/19 16:31:53 joko |
35 |
# +- renamed sub to 'rebuildDb' |
# +- renamed sub to 'rebuildDb' |
36 |
# |
# |
57 |
# + fix: encapsulated object-loading inside an 'eval' |
# + fix: encapsulated object-loading inside an 'eval' |
58 |
# |
# |
59 |
# Revision 1.15 2002/12/05 13:55:21 joko |
# Revision 1.15 2002/12/05 13:55:21 joko |
60 |
# + now utilizing 'object2hash' instead of 'var_deref' |
# + now utilizing 'expand' instead of 'var_deref' |
61 |
# + played around with having fresh-objects - no progress.... |
# + played around with having fresh-objects - no progress.... |
62 |
# |
# |
63 |
# Revision 1.14 2002/12/05 09:40:30 jonen |
# Revision 1.14 2002/12/05 09:40:30 jonen |
130 |
use base ("Data::Storage::Handler"); |
use base ("Data::Storage::Handler"); |
131 |
use base ("Data::Storage::Handler::Abstract"); |
use base ("Data::Storage::Handler::Abstract"); |
132 |
|
|
133 |
use Tangram; |
|
134 |
use Data::Dumper; |
use Data::Dumper; |
135 |
use libp qw( getNewPerlObjectByPkgName ); |
use Tangram; |
|
use Data::Storage::Result::Tangram; |
|
|
use Data::Compare::Struct qw( isEmpty ); |
|
|
use Data::Transform::Deep qw( object2hash ); |
|
|
use Data::Transform::Encode qw( var2utf8 ); |
|
136 |
|
|
137 |
|
use DesignPattern::Object; |
138 |
|
use Data::Storage::Result::Tangram; |
139 |
|
use Data::Mungle::Compare::Struct qw( isEmpty ); |
140 |
|
use Data::Mungle::Transform::Deep qw( expand ); |
141 |
|
|
142 |
# get logger instance |
# get logger instance |
143 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
158 |
my $self = shift; |
my $self = shift; |
159 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
160 |
#if (!$schema_tangram) { |
#if (!$schema_tangram) { |
161 |
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} } ); |
162 |
|
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
163 |
$schema_tangram = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
164 |
#} |
#} |
165 |
if (!$schema_tangram) { |
if (!$schema_tangram) { |
192 |
my $self = shift; |
my $self = shift; |
193 |
|
|
194 |
my $dsn = shift; |
my $dsn = shift; |
195 |
|
|
196 |
|
#print Dumper($self); |
197 |
|
#exit; |
198 |
|
|
199 |
|
# TODO: re-enable |
200 |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
|
|
|
201 |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
202 |
|
|
203 |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
209 |
# return; |
# return; |
210 |
# } |
# } |
211 |
|
|
212 |
return unless $self->_initSchema(); |
#return unless $self->_initSchema(); |
213 |
|
$self->_initSchema(); |
214 |
|
|
215 |
# create the main tangram storage object |
# create the main tangram storage object |
216 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
237 |
sub getChildNodes { |
sub getChildNodes { |
238 |
|
|
239 |
my $self = shift; |
my $self = shift; |
240 |
my @nodes; |
my $mode = shift; |
241 |
|
my $filter = shift; |
242 |
|
|
243 |
|
$mode ||= 'core'; |
244 |
|
$filter ||= 'all'; |
245 |
|
|
246 |
|
$logger->debug( __PACKAGE__ . "->getChildNodes($mode)" ); |
247 |
|
|
248 |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
if ($mode eq 'core') { |
249 |
|
|
250 |
# create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE |
my @nodes; |
251 |
#my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} }); |
|
252 |
#my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} ); |
# create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE |
253 |
|
#my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} }); |
254 |
# todo: should we retrieve information from the schema here |
#my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} ); |
255 |
# rather than poorly getting table names from underlying dbi? |
|
256 |
my $storage = $self->_getSubLayerHandle(); |
# todo: should we retrieve information from the schema here |
257 |
@nodes = @{$storage->getChildNodes()}; |
# rather than poorly getting table names from underlying dbi? |
258 |
#$storage->_configureCOREHANDLE(); |
my $storage = $self->_getSubLayerHandle(); |
259 |
#print "getchildnodes\n"; |
@nodes = @{$storage->getChildNodes()}; |
260 |
#print Dumper($self); |
#$storage->_configureCOREHANDLE(); |
261 |
#if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
#print "getchildnodes\n"; |
262 |
|
#print Dumper($self); |
263 |
|
#if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
264 |
|
|
265 |
|
# TODO: REVIEW |
266 |
|
#$storage->disconnect(); |
267 |
|
|
268 |
|
$self->{meta}->{childnodes} = \@nodes; |
269 |
|
|
270 |
|
return \@nodes; |
271 |
|
|
272 |
# TODO: REVIEW |
} elsif ($mode eq 'root') { |
273 |
#$storage->disconnect(); |
|
274 |
|
# FIXME: this will return *all* known classes to 'Class::Tangram', |
275 |
|
# which might not be what you expect since more than one instance |
276 |
|
# of Tangram may be in memory and Class::Tangram seems to |
277 |
|
# offer no methods to determine this or filter its result(s) according |
278 |
|
# to a specific database. |
279 |
|
my @object_names = Class::Tangram::known_classes(); |
280 |
|
my @concret_names; |
281 |
|
my $o_cnt; |
282 |
|
foreach (sort @object_names) { |
283 |
|
push @concret_names, $_ if (!Class::Tangram::class_is_abstract($_)); |
284 |
|
$o_cnt++; |
285 |
|
} |
286 |
|
|
287 |
|
if ($filter eq 'all') { |
288 |
|
return \@object_names; |
289 |
|
} elsif ($filter eq 'concrete') { |
290 |
|
return \@concret_names; |
291 |
|
} |
292 |
|
|
293 |
$self->{meta}->{childnodes} = \@nodes; |
} |
294 |
|
|
|
return \@nodes; |
|
295 |
|
|
296 |
} |
} |
297 |
|
|
|
|
|
298 |
sub testIntegrity { |
sub testIntegrity { |
299 |
|
|
300 |
my $self = shift; |
my $self = shift; |
368 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
369 |
|
|
370 |
#my $subLayer = $self->_getSubLayerHandle(); |
#my $subLayer = $self->_getSubLayerHandle(); |
371 |
|
#print Dumper($self); |
372 |
|
#exit; |
373 |
|
|
374 |
# apply configured modifications |
# apply configured modifications |
375 |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
477 |
my @results; |
my @results; |
478 |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
479 |
|
|
480 |
#print Dumper($filters); |
#print Dumper($filters); |
481 |
|
|
482 |
my @tfilters; |
my @tfilters; |
483 |
|
|
516 |
# 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 |
517 |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
518 |
|
|
519 |
|
#print "eval: $evalstring", "\n"; |
520 |
|
|
521 |
# get filtered list/set |
# get filtered list/set |
522 |
@results = eval($evalstring); |
@results = eval($evalstring); |
523 |
die $@ if $@; |
die $@ if $@; |
560 |
|
|
561 |
# HACK: special case: querying by id does not translate into a common tangram query |
# HACK: special case: querying by id does not translate into a common tangram query |
562 |
# just load the object by given id(ent) |
# just load the object by given id(ent) |
563 |
if ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq') { |
if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) { |
564 |
#print "LOAD!!!", "\n"; |
#print "LOAD!!!", "\n"; |
565 |
#exit; |
#exit; |
566 |
#return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) ); |
#return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) ); |
577 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
578 |
} |
} |
579 |
|
|
580 |
die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
my $list = $self->getListFiltered($query->{node}, $query->{criterias}); |
581 |
|
#return $self->createSet($object); |
582 |
|
#return $self->createSet($list); |
583 |
|
return $self->createSet(@$list); |
584 |
|
|
585 |
|
#die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
586 |
|
|
|
# TODO: do a common tangram query here |
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
# try a generic tangram query here |
591 |
|
# TODO: try to place an oql on top of that (search.cpan.org!) |
592 |
my @crits; |
my @crits; |
593 |
foreach (@{$query->{criterias}}) { |
foreach (@{$query->{criterias}}) { |
594 |
my $op = ''; |
my $op = ''; |
684 |
# build options (a callback to unload autovivified objects) for 'expand' |
# build options (a callback to unload autovivified objects) for 'expand' |
685 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |
686 |
my $cb; # = sub {}; |
my $cb; # = sub {}; |
687 |
|
|
688 |
|
# deactivated way to get rid of used instances, if requested |
689 |
=pod |
=pod |
690 |
if ($options->{destroy}) { |
if ($options->{destroy}) { |
691 |
$options->{cb}->{destroy} = sub { |
$options->{cb}->{destroy} = sub { |
692 |
print "================ DESTROY", "\n"; |
print "================ DESTROY", "\n"; |
693 |
my $object = shift; |
my $object = shift; |
694 |
#print Dumper($object); |
#print Dumper($object); |
695 |
$self->{_COREHANDLE}->unload($object); |
$self->{_COREHANDLE}->unload($object); |
696 |
#undef($object); |
#undef($object); |
697 |
}; |
}; |
698 |
} |
} |
699 |
=cut |
=cut |
700 |
|
|
701 |
my $hash = object2hash($obj, $options); |
my $hash = expand($obj, $options); |
702 |
#$options->{cb}->{destroy}->($obj); |
|
703 |
#$self->{_COREHANDLE}->unload($obj); |
# old (unsuccessful) attempts to get rid of used instances, if requested |
704 |
|
|
705 |
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
# V1: |
706 |
# now done in object2hash |
#$options->{cb}->{destroy}->($obj); |
707 |
#var2utf8($hash) if ($options->{utf8}); |
#$self->{_COREHANDLE}->unload($obj); |
708 |
|
|
709 |
# old (wrong) attempts to get rid of used instances, if requested |
# V2: |
710 |
#$obj->clear_refs; |
#$obj->clear_refs; |
711 |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
712 |
#$obj->DESTROY; |
#$obj->DESTROY; |
724 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
725 |
} |
} |
726 |
|
|
727 |
|
sub dropDb { |
728 |
|
my $self = shift; |
729 |
|
my $storage = $self->_getSubLayerHandle(); |
730 |
|
return $storage->dropDb(); |
731 |
|
} |
732 |
|
|
733 |
|
sub testAvailability { |
734 |
|
my $self = shift; |
735 |
|
my $storage = $self->_getSubLayerHandle(); |
736 |
|
return $storage->testAvailability(); |
737 |
|
} |
738 |
|
|
739 |
|
sub disconnect2 { |
740 |
|
my $self = shift; |
741 |
|
my $storage = $self->_getSubLayerHandle(); |
742 |
|
print "DISC!", "\n"; |
743 |
|
|
744 |
|
my $storage_ll = $storage->{_COREHANDLE}; |
745 |
|
$storage_ll->disconnect(); |
746 |
|
|
747 |
|
print Dumper($storage); |
748 |
|
exit; |
749 |
|
|
750 |
|
#$self->{_COREHANDLE} |
751 |
|
#$storage->disconnect(); |
752 |
|
$self->{dataStorageLayer}->disconnect(); |
753 |
|
} |
754 |
|
|
755 |
1; |
1; |
756 |
|
__END__ |