3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.46 2004/05/06 12:54:34 jonen |
7 |
|
# + bugfix related to multiple select-'filter' |
8 |
|
# |
9 |
|
# Revision 1.45 2003/12/14 01:48:36 jonen |
10 |
|
# small HACK at _insertChildNode: some special Childnodes should not be created because existing objects have to be selected! |
11 |
|
# TODO: make this more generic, e.g. implement a special flag at Schema |
12 |
|
# |
13 |
|
# Revision 1.44 2003/12/04 01:01:50 joko |
14 |
|
# + sendQuery now returns result even on crud=UPDATE |
15 |
|
# |
16 |
|
# Revision 1.43 2003/07/02 11:07:12 jonen |
17 |
|
# re-activate filtering of results *after* results are fetched from tangram |
18 |
|
# (needed for e.g. UserManagment) |
19 |
|
# |
20 |
|
# Revision 1.42 2003/07/01 23:24:17 joko |
21 |
|
# now using package before using function |
22 |
|
# |
23 |
|
# Revision 1.41 2003/06/29 02:03:45 joko |
24 |
|
# fix:? initialize schema on startup |
25 |
|
# |
26 |
|
# Revision 1.40 2003/06/25 22:57:54 joko |
27 |
|
# major rework of "sub sendQuery / sub getListFiltered": now should be capable of "sorting" |
28 |
|
# |
29 |
|
# Revision 1.39 2003/06/06 11:40:40 jonen |
30 |
|
# fixed bug at 'getFilteredList' |
31 |
|
# |
32 |
|
# Revision 1.38 2003/05/13 16:38:38 joko |
33 |
|
# problems with "tied" on 5.6.1/win32 |
34 |
|
# |
35 |
|
# Revision 1.37 2003/05/10 17:37:39 jonen |
36 |
|
# corrected last commit |
37 |
|
# |
38 |
|
# Revision 1.36 2003/05/10 17:31:18 jonen |
39 |
|
# + added new functions related to 'create' item |
40 |
|
# - createNode() |
41 |
|
# # creates non-persistent 'deep dummy filled' object |
42 |
|
# - insertChildNode() |
43 |
|
# # inserts child node at given parent (child node haven't to exists, |
44 |
|
# createNode will be injected transparently) |
45 |
|
# |
46 |
|
# Revision 1.35 2003/04/19 16:09:48 jonen |
47 |
|
# + added operator dispatching (currently for getting ref-type) at 'getListFiltered' |
48 |
|
# |
49 |
|
# Revision 1.34 2003/04/11 01:18:53 joko |
50 |
|
# sendQuery: |
51 |
|
# + introduced crud action 'DELETE' |
52 |
|
# |
53 |
|
# Revision 1.33 2003/04/09 06:07:43 joko |
54 |
|
# revamped 'sub sendQuery' |
55 |
|
# |
56 |
|
# Revision 1.32 2003/04/08 22:52:22 joko |
57 |
|
# modified 'querySchema': better behaviour regarding filtering result |
58 |
|
# |
59 |
|
# Revision 1.31 2003/04/05 21:24:09 joko |
60 |
|
# modified 'sub getChildNodes': now contains code from 'querySchema' |
61 |
|
# |
62 |
# Revision 1.30 2003/03/27 15:31:14 joko |
# Revision 1.30 2003/03/27 15:31:14 joko |
63 |
# fixes to modules regarding new namespace(s) below Data::Mungle::* |
# fixes to modules regarding new namespace(s) below Data::Mungle::* |
64 |
# |
# |
183 |
|
|
184 |
use Data::Dumper; |
use Data::Dumper; |
185 |
use Tangram; |
use Tangram; |
186 |
|
use Class::Tangram; |
187 |
|
|
188 |
use DesignPattern::Object; |
use DesignPattern::Object; |
189 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
190 |
use Data::Mungle::Compare::Struct qw( isEmpty ); |
use Data::Mungle::Compare::Struct qw( isEmpty ); |
191 |
use Data::Mungle::Transform::Deep qw( expand ); |
use Data::Mungle::Transform::Deep qw( expand deep_copy merge_to ); |
192 |
|
|
193 |
# get logger instance |
# get logger instance |
194 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
195 |
|
|
196 |
|
#$Tangram::TRACE = *STDOUT; |
197 |
|
|
198 |
# this holds the complete instantiated schema from tangram |
# this holds the complete instantiated schema from tangram |
199 |
my $schema_tangram; |
my $schema_tangram; |
212 |
#if (!$schema_tangram) { |
#if (!$schema_tangram) { |
213 |
#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} } ); |
214 |
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
215 |
$schema_tangram = $obj->getSchema(); |
$schema_tangram = $obj->getSchema() if $obj; |
216 |
#} |
#} |
217 |
if (!$schema_tangram) { |
if (!$schema_tangram) { |
218 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{locator}->{schema}." ); |
219 |
return 0; |
return 0; |
220 |
} |
} |
221 |
#$self->_patchSchema(); |
#$self->_patchSchema(); |
261 |
# return; |
# return; |
262 |
# } |
# } |
263 |
|
|
264 |
#return unless $self->_initSchema(); |
return unless $self->_initSchema(); |
265 |
$self->_initSchema(); |
#$self->_initSchema(); |
266 |
|
|
267 |
# create the main tangram storage object |
# create the main tangram storage object |
268 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
289 |
sub getChildNodes { |
sub getChildNodes { |
290 |
|
|
291 |
my $self = shift; |
my $self = shift; |
292 |
my @nodes; |
my $mode = shift; |
293 |
|
my $filter = shift; |
294 |
|
|
295 |
|
$mode ||= 'core'; |
296 |
|
$filter ||= 'all'; |
297 |
|
|
298 |
|
$logger->debug( __PACKAGE__ . "->getChildNodes($mode)" ); |
299 |
|
|
300 |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
if ($mode eq 'core') { |
301 |
|
|
302 |
# create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE |
my @nodes; |
303 |
#my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} }); |
|
304 |
#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 |
305 |
|
#my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} }); |
306 |
# todo: should we retrieve information from the schema here |
#my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} ); |
307 |
# rather than poorly getting table names from underlying dbi? |
|
308 |
my $storage = $self->_getSubLayerHandle(); |
# todo: should we retrieve information from the schema here |
309 |
@nodes = @{$storage->getChildNodes()}; |
# rather than poorly getting table names from underlying dbi? |
310 |
#$storage->_configureCOREHANDLE(); |
my $storage = $self->_getSubLayerHandle(); |
311 |
#print "getchildnodes\n"; |
@nodes = @{$storage->getChildNodes()}; |
312 |
#print Dumper($self); |
#$storage->_configureCOREHANDLE(); |
313 |
#if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
#print "getchildnodes\n"; |
314 |
|
#print Dumper($self); |
315 |
|
#if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
316 |
|
|
317 |
|
# TODO: REVIEW |
318 |
|
#$storage->disconnect(); |
319 |
|
|
320 |
|
$self->{meta}->{childnodes} = \@nodes; |
321 |
|
|
322 |
|
return \@nodes; |
323 |
|
|
324 |
# TODO: REVIEW |
} elsif ($mode eq 'root') { |
325 |
#$storage->disconnect(); |
|
326 |
|
# FIXME: this will return *all* known classes to 'Class::Tangram', |
327 |
|
# which might not be what you expect since more than one instance |
328 |
|
# of Tangram may be in memory and Class::Tangram seems to |
329 |
|
# offer no methods to determine this or filter its result(s) according |
330 |
|
# to a specific database. |
331 |
|
my @object_names = Class::Tangram::known_classes(); |
332 |
|
my @concret_names; |
333 |
|
my $o_cnt; |
334 |
|
foreach (sort @object_names) { |
335 |
|
push @concret_names, $_ if (!Class::Tangram::class_is_abstract($_)); |
336 |
|
$o_cnt++; |
337 |
|
} |
338 |
|
|
339 |
|
if ($filter eq 'all') { |
340 |
|
return \@object_names; |
341 |
|
} elsif ($filter eq 'concrete') { |
342 |
|
return \@concret_names; |
343 |
|
} |
344 |
|
|
345 |
$self->{meta}->{childnodes} = \@nodes; |
} |
346 |
|
|
|
return \@nodes; |
|
347 |
|
|
348 |
} |
} |
349 |
|
|
|
|
|
350 |
sub testIntegrity { |
sub testIntegrity { |
351 |
|
|
352 |
my $self = shift; |
my $self = shift; |
524 |
# redirect to unfiltered mode |
# redirect to unfiltered mode |
525 |
#return $self->getListUnfiltered(@_); |
#return $self->getListUnfiltered(@_); |
526 |
|
|
527 |
my $nodename = shift; |
my $in = {}; |
528 |
my $filters = shift; |
$in->{nodename} = shift; |
529 |
|
$in->{filters} = shift; |
530 |
|
$in->{sorting} = shift; |
531 |
|
|
532 |
my @results; |
my @results; |
533 |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $in->{nodename} . "' )" ); |
534 |
|
|
535 |
#print Dumper($filters); |
#print "Filter_payload: " . Dumper($in->{filters}) . "\n"; |
536 |
|
|
537 |
|
# 1. "Remote Object Handle" - get set of objects from odbms by object name |
538 |
|
my $remote = $self->{_COREHANDLE}->remote($in->{nodename}); |
539 |
|
|
540 |
|
# 2. Transfer $in to $orm_query |
541 |
|
my $orm_query = {}; |
542 |
|
|
543 |
|
# 2.a. Filters |
544 |
my @tfilters; |
my @tfilters; |
545 |
|
my $orm_filter = undef; |
546 |
|
|
547 |
foreach my $filter (@$filters) { |
foreach my $filter (@{$in->{filters}}) { |
548 |
|
|
549 |
# get filter - TODO: for each filter |
# get filter - TODO: for each filter |
550 |
#my $filter = $filters->[0]; |
#my $filter = $filters->[0]; |
551 |
|
|
552 |
# build filter |
# 1. The parts of a filter source entry |
553 |
my $lexpr = $filter->{key}; |
my $lexpr = $filter->{key}; |
554 |
#my $op = $filter->{op}; |
#my $op = $filter->{op}; |
555 |
my $op = '='; |
my $op = '='; |
556 |
my $rexpr = $filter->{val}; |
my $rexpr = $filter->{val}; |
557 |
my $tight = 100; |
my $tight = 100; |
558 |
|
|
559 |
|
# 2. Build filter target entry |
560 |
|
|
561 |
# my $tfilter = Tangram::Filter->new( |
# Test 1 - didn't work out! |
562 |
# expr => "t1.$lexpr $op '$rexpr'", |
# my $tfilter = Tangram::Filter->new( |
563 |
# tight => $tight, |
# expr => "t1.$lexpr $op '$rexpr'", |
564 |
# objects => $objects, |
# tight => $tight, |
565 |
# ); |
# objects => $objects, |
566 |
|
# ); |
567 |
|
|
568 |
|
my $orm_filter_tmp = undef; |
569 |
|
# was: |
570 |
|
# TODO: is_op? |
571 |
|
# dispatch un-common operators if exists |
572 |
|
if ($filter->{op} eq "ref") { |
573 |
|
# do nothing, results will be filtered later cause 'tangram-filter' doesn't support 'ref' query |
574 |
|
#print "Filter->op eq 'ref'.\n"; |
575 |
|
#push @tfilters, 'ref($remote->{' . $filter->{key} . '})' . " eq '$filter->{val}'"; |
576 |
|
} else { |
577 |
|
# HACK: build eval-string (sorry) to get filtered list - please give advice here |
578 |
|
#push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'"; |
579 |
|
# better: calculate expression right here! |
580 |
|
#push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'"; |
581 |
|
|
582 |
|
#print "key: ", $filter->{key}, "\n"; |
583 |
|
|
584 |
|
my $left = $remote->{$filter->{key}}; |
585 |
|
#my $r = Tangram::Expr->new( 'string' => "'" . $filter->{val} . "'" ); |
586 |
|
my $right = $filter->{val}; |
587 |
|
my $op = $filter->{op}; |
588 |
|
$orm_filter_tmp = $left->$op($right); |
589 |
|
} |
590 |
|
|
591 |
|
if (!ref($orm_filter)) { |
592 |
|
$orm_filter = $orm_filter_tmp; |
593 |
|
} else { |
594 |
|
$orm_filter = $orm_filter->and($orm_filter_tmp); |
595 |
|
} |
596 |
|
|
597 |
|
} |
598 |
|
|
599 |
|
$orm_query->{filter} = $orm_filter; |
600 |
|
|
601 |
# HACK: build eval-string (sorry) to get filtered list - please give advice here |
# debug point: |
602 |
push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'"; |
#print "Filter: " . Dumper($orm_query->{filter}) . "\n"; |
603 |
|
|
604 |
|
# was: |
605 |
|
|
606 |
|
# 2.b. sorting [new as of 2003-06-17] |
607 |
|
if ($in->{sorting}) { |
608 |
|
my $sorting_rules = []; |
609 |
|
my $sorting_order = 'ASC'; |
610 |
|
foreach my $sorting_column (keys %{$in->{sorting}}) { |
611 |
|
$sorting_order = $in->{sorting}->{$sorting_column} if $in->{sorting}->{$sorting_column}; |
612 |
|
push @$sorting_rules, Tangram::Expr->new( 'string' => $sorting_column ); |
613 |
|
} |
614 |
|
$orm_query->{order} = $sorting_rules; |
615 |
|
if ($sorting_order eq 'DESC') { |
616 |
|
$orm_query->{desc} = 1; |
617 |
|
} |
618 |
} |
} |
619 |
|
|
|
my $tfilter = join(' & ', @tfilters); |
|
620 |
|
|
621 |
# get set of objects from odbms by object name |
# 3. build and issue query - return result as Tangram::Cursor |
|
my $remote = $self->{_COREHANDLE}->remote($nodename); |
|
622 |
|
|
623 |
# was: |
# coerce hash into array (This is valid in Perl) |
624 |
#@results = $self->{COREHANDLE}->select($object_set, $tfilter); |
my @orm_query_args = %$orm_query; |
625 |
|
# send query (arguments) to orm |
626 |
|
@results = $self->{_COREHANDLE}->select($remote, @orm_query_args); |
627 |
|
|
628 |
|
#my $cursor = $self->{_COREHANDLE}->cursor($remote, @orm_query_args); |
629 |
|
#return $cursor; |
630 |
|
#print Dumper(@results); |
631 |
|
|
632 |
# is: |
# is: |
633 |
# 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 |
634 |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
#my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . $sorting . ');'; |
635 |
|
#print "eval: $evalstring", "\n"; |
636 |
#print "eval: $evalstring", "\n"; |
# get filtered list/set |
637 |
|
#@results = eval($evalstring); |
638 |
# get filtered list/set |
#die $@ if $@; |
639 |
@results = eval($evalstring); |
|
640 |
die $@ if $@; |
# filter results - NEEDED for e.g. UserManagment !! |
641 |
|
if ($in->{filters}->[0]->{op} && ($in->{filters}->[0]->{op} eq "ref")) { |
642 |
|
#print "Filter->op eq 'ref'.\n"; |
643 |
|
my $att_name = $in->{filters}->[0]->{key}; |
644 |
|
my $att_val = $in->{filters}->[0]->{val}; |
645 |
|
my @filtered; |
646 |
|
foreach(@results) { |
647 |
|
if(ref($_->{$att_name}) eq $att_val) { |
648 |
|
push @filtered, $_; |
649 |
|
} |
650 |
|
} |
651 |
|
@results = @filtered; |
652 |
|
} |
653 |
|
|
654 |
|
#print "results: " . Dumper(\@results); |
655 |
|
|
656 |
return \@results; |
return \@results; |
657 |
} |
} |
681 |
return $result; |
return $result; |
682 |
} |
} |
683 |
|
|
684 |
|
sub createResult { |
685 |
|
my $self = shift; |
686 |
|
my $rh = shift; |
687 |
|
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
688 |
|
return $result; |
689 |
|
} |
690 |
|
|
691 |
sub sendQuery { |
sub sendQuery { |
692 |
my $self = shift; |
my $self = shift; |
693 |
my $query = shift; |
my $query = shift; |
|
#my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';"; |
|
|
#my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql); |
|
694 |
|
|
695 |
#print Dumper($query); |
#print Dumper($query); |
696 |
|
|
697 |
# HACK: special case: querying by id does not translate into a common tangram query |
# type = ITEM|LIST|TRANSPARENT |
698 |
# just load the object by given id(ent) |
my $type = ''; |
699 |
if ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq') { |
# mode = OID|SPECIAL |
700 |
#print "LOAD!!!", "\n"; |
my $mode = ''; |
701 |
#exit; |
my $ident = ''; |
702 |
#return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) ); |
my $crud = ''; |
703 |
my $ident = $query->{criterias}->[0]->{val}; |
|
704 |
#print "load obj", "\n"; |
|
705 |
#return $self->createSet() if $ident == 5; |
# dispatch type and mode |
706 |
$self->{_COREHANDLE}->unload($ident); |
|
707 |
my $object = $self->{_COREHANDLE}->load($ident); |
# defaults - 1 |
708 |
#print "get id", "\n"; |
if ($query->{options}) { |
709 |
my $oid = $self->{_COREHANDLE}->id($object); |
$crud = $query->{options}->{crud}; |
710 |
#print Dumper($object); |
$crud ||= $query->{options}->{action}; |
711 |
#print "oid: $oid", "\n"; |
} |
712 |
return $self->createSet($object); |
|
713 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
# defaults - 2 |
714 |
} |
$type ||= 'TRANSPARENT'; |
715 |
|
$crud ||= 'RETRIEVE'; |
716 |
my $list = $self->getListFiltered($query->{node}, $query->{criterias}); |
|
717 |
#return $self->createSet($object); |
if ($query->{options}->{OID}) { |
718 |
#return $self->createSet($list); |
$type = 'ITEM'; |
719 |
return $self->createSet(@$list); |
$mode = 'OID'; |
720 |
|
$ident = $query->{options}->{OID}; |
721 |
#die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
|
722 |
|
} elsif (my $guid = $query->{options}->{GUID}) { |
723 |
|
$type = 'TRANSPARENT'; |
724 |
|
$query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; |
725 |
|
|
726 |
|
# if operator is different (dispatcher for 'getListFiltered') |
727 |
|
} elsif (my $op = $query->{options}->{op}) { |
728 |
|
$type = 'TRANSPARENT'; |
729 |
|
$query->{criterias} = [ { key => $query->{options}->{meta_label}, op => $op, val => $query->{options}->{meta_value} } ]; |
730 |
|
|
731 |
|
} |
732 |
|
|
733 |
|
# HACK: special case: querying by id does not translate into a common tangram query |
734 |
|
# just load the object by given identifier (OID) named 'id' - this is required by Data::Transfer::Sync! |
735 |
|
if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) { |
736 |
|
$type = 'ITEM'; |
737 |
|
$mode = 'SPECIAL.SYNC'; |
738 |
|
$ident = $query->{criterias}->[0]->{val}; |
739 |
|
} |
740 |
|
|
741 |
|
|
742 |
|
# execute query |
743 |
|
my $result; |
744 |
|
|
745 |
|
if ($type eq 'ITEM' && $ident) { |
746 |
|
|
747 |
|
if ($mode eq 'OID') { |
748 |
|
# TODO: review this case! |
749 |
|
$result = $self->getObject($ident, $query->{options}); |
750 |
|
|
751 |
|
} elsif ($mode eq 'SPECIAL.SYNC') { |
752 |
|
|
753 |
|
# V1 - failed |
754 |
|
#return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) ); |
755 |
|
|
756 |
|
# hmm.... |
757 |
|
#return $self->createSet() if $ident == 5; |
758 |
|
|
759 |
|
# Unload single object before doing any further operations to |
760 |
|
# expect a "fresh" object from orm when performing the next calls. |
761 |
|
$self->{_COREHANDLE}->unload($ident); |
762 |
|
|
763 |
|
# Load object from orm. |
764 |
|
my $object = $self->{_COREHANDLE}->load($ident); |
765 |
|
|
766 |
|
# determine object identifier (OID) |
767 |
|
my $oid = $self->{_COREHANDLE}->id($object); |
768 |
|
|
769 |
|
# encapsulate into result/response container and return this one |
770 |
|
$result = $self->createSet($object); |
771 |
|
|
772 |
|
# debugging |
773 |
|
#$result = $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
774 |
|
|
775 |
|
} |
776 |
|
|
777 |
|
|
778 |
|
} elsif ($type eq 'TRANSPARENT') { |
779 |
|
|
780 |
|
if ($crud eq 'RETRIEVE') { |
781 |
|
|
782 |
|
my $list = $self->getListFiltered($query->{node}, $query->{criterias}, $query->{sorting}); |
783 |
|
#return $list; |
784 |
|
return $self->createResult($list); |
785 |
|
|
786 |
|
#return $self->createSet($object); |
787 |
|
#return $self->createSet($list); |
788 |
|
return $self->createSet(@$list); |
789 |
|
|
790 |
|
#die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
791 |
|
|
792 |
|
# try a generic tangram query here |
793 |
|
# TODO: try to place an oql on top of that (search.cpan.org!) |
794 |
|
my @crits; |
795 |
|
foreach (@{$query->{criterias}}) { |
796 |
|
my $op = ''; |
797 |
|
$op = '=' if lc $_->{op} eq 'eq'; |
798 |
|
push @crits, "$_->{key}$op'$_->{val}'"; |
799 |
|
} |
800 |
|
my $subnodes = {}; |
801 |
|
map { $subnodes->{$_}++ } @{$query->{subnodes}}; |
802 |
|
# HACK: this is hardcoded ;( expand possibilities! |
803 |
|
#my $crit = join(' AND ', @crits); |
804 |
|
#my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit); |
805 |
|
#return $self->sendCommand($sql); |
806 |
|
#my $h = $self->{COREHANDLE}->remote($query->{node}); |
807 |
|
#my $res = $self->{COREHANDLE}->select($h, $h->{); |
808 |
|
$result = $self->createCursor($query->{node}); |
809 |
|
|
810 |
|
} elsif ($crud eq 'UPDATE') { |
811 |
|
|
812 |
|
# Patch current query to be a loader (e.g. change action, remove payload) ... |
813 |
|
my $childquery = deep_copy($query); |
814 |
|
$childquery->{options}->{crud} = 'RETRIEVE'; |
815 |
|
delete $childquery->{payload}; |
816 |
|
|
817 |
|
# ... to use it to fetch a fresh object using ourselves (sendQuery). |
818 |
|
my $cursor = $self->sendQuery($childquery); |
819 |
|
my $status = $cursor->getStatus(); |
820 |
|
my $object = $cursor->getNextEntry(); |
821 |
|
|
822 |
|
# Merge values and apply value modifiers. |
823 |
|
my $options = { utf8 => 1, php => 1 }; |
824 |
|
merge_to($object, $query->{payload}, $options); |
825 |
|
|
826 |
|
#print Dumper($object); |
827 |
|
|
828 |
|
# Execute update operation at orm. |
829 |
|
$self->update($object); |
830 |
|
$result = $self->createResult([ $object ]); |
831 |
|
|
832 |
|
} elsif ($crud eq 'DELETE') { |
833 |
|
|
834 |
|
# Patch current query to be a loader (e.g. change action) ... |
835 |
|
my $childquery = deep_copy($query); |
836 |
|
$childquery->{options}->{crud} = 'RETRIEVE'; |
837 |
|
|
838 |
|
# ... to use it to fetch a fresh object using ourselves (sendQuery). |
839 |
|
my $cursor = $self->sendQuery($childquery); |
840 |
|
my $status = $cursor->getStatus(); |
841 |
|
my $object = $cursor->getNextEntry(); |
842 |
|
|
843 |
|
$self->erase($object); |
844 |
|
$self->unload($object); |
845 |
|
|
846 |
|
} elsif ($crud eq 'CREATE') { |
847 |
|
|
848 |
|
my $nodename = $query->{node}; |
849 |
|
my $newnode = $self->createNode($nodename); |
850 |
|
my $id = $self->{_COREHANDLE}->insert($newnode); |
851 |
|
|
852 |
|
print "Saved new node $nodename with GUID $newnode->{guid}, OID '$id': " . Dumper($newnode) . "\n"; |
853 |
|
|
854 |
|
return $newnode; |
855 |
|
|
856 |
|
} |
857 |
|
|
858 |
|
} |
859 |
|
|
860 |
|
return $result; |
861 |
|
|
|
# try a generic tangram query here |
|
|
# TODO: try to place an oql on top of that (search.cpan.org!) |
|
|
my @crits; |
|
|
foreach (@{$query->{criterias}}) { |
|
|
my $op = ''; |
|
|
$op = '=' if lc $_->{op} eq 'eq'; |
|
|
push @crits, "$_->{key}$op'$_->{val}'"; |
|
|
} |
|
|
my $subnodes = {}; |
|
|
map { $subnodes->{$_}++ } @{$query->{subnodes}}; |
|
|
# HACK: this is hardcoded ;( expand possibilities! |
|
|
#my $crit = join(' AND ', @crits); |
|
|
#my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit); |
|
|
#return $self->sendCommand($sql); |
|
|
#my $h = $self->{COREHANDLE}->remote($query->{node}); |
|
|
#my $res = $self->{COREHANDLE}->select($h, $h->{); |
|
|
return $self->createCursor($query->{node}); |
|
862 |
} |
} |
863 |
|
|
864 |
sub eraseAll { |
sub eraseAll { |
894 |
return $object if $object; |
return $object if $object; |
895 |
} |
} |
896 |
|
|
897 |
sub getObjectByGuid { |
sub getObjectByGuid_old { |
898 |
my $self = shift; |
my $self = shift; |
899 |
my $guid = shift; |
my $guid = shift; |
900 |
my $options = shift; |
my $options = shift; |
924 |
|
|
925 |
} |
} |
926 |
|
|
927 |
sub getObjectAsHash { |
sub getObjectAsHash_old { |
928 |
my $self = shift; |
my $self = shift; |
929 |
my $oid = shift; |
my $oid = shift; |
930 |
my $options = shift; |
my $options = shift; |
1007 |
$self->{dataStorageLayer}->disconnect(); |
$self->{dataStorageLayer}->disconnect(); |
1008 |
} |
} |
1009 |
|
|
1010 |
|
|
1011 |
|
sub createNode { |
1012 |
|
my $self = shift; |
1013 |
|
my $classname = shift; |
1014 |
|
|
1015 |
|
my $obj = $classname->new(); |
1016 |
|
|
1017 |
|
my $attr_options = Class::Tangram::attribute_options($classname); |
1018 |
|
#print "Attribute Options: " . Dumper($attr_options); |
1019 |
|
|
1020 |
|
my $attr_types = Class::Tangram::attribute_types($classname); |
1021 |
|
#print "Attribute Types: " . Dumper($attr_types); |
1022 |
|
|
1023 |
|
foreach(keys %{$attr_types}) { |
1024 |
|
if($attr_types->{$_} eq 'string') { |
1025 |
|
$obj->{$_} = ''; |
1026 |
|
} elsif($attr_types->{$_} eq 'int') { |
1027 |
|
$obj->{$_} = 0; |
1028 |
|
} elsif($attr_types->{$_} eq 'real') { |
1029 |
|
$obj->{$_} = 0; |
1030 |
|
} elsif($attr_types->{$_} eq 'rawdatetime') { |
1031 |
|
$obj->{$_} = '0000-00-00 00:00:00'; |
1032 |
|
} elsif($attr_types->{$_} eq 'ref') { |
1033 |
|
if($attr_options->{$_}->{class}) { |
1034 |
|
# HACK!!! |
1035 |
|
# STANDALONE Objects (objects which make sense to instanciat alone) should not created automaticly |
1036 |
|
# because they maybe exists and should only be SETTED not CREATED! |
1037 |
|
# TODO: Create a flag at the scheme for that reason! |
1038 |
|
# (e.g child_node => 1 for child-nodes only like e.g. UserData) |
1039 |
|
if($attr_options->{$_}->{class} eq 'NetPerson' || $attr_options->{$_}->{class} eq 'Event') { |
1040 |
|
#$obj->{$_} = undef(); |
1041 |
|
} else { |
1042 |
|
$obj->{$_} = $self->createNode($attr_options->{$_}->{class}); |
1043 |
|
} |
1044 |
|
} else { |
1045 |
|
#$obj->{$_} = undef(); |
1046 |
|
} |
1047 |
|
} elsif($attr_types->{$_} eq 'iarray') { |
1048 |
|
$obj->{$_} = [ ]; |
1049 |
|
} elsif($attr_types->{$_} eq 'hash') { |
1050 |
|
$obj->{$_} = { }; |
1051 |
|
} elsif($attr_types->{$_} eq 'flat_hash') { |
1052 |
|
$obj->{$_} = { }; |
1053 |
|
} |
1054 |
|
} |
1055 |
|
|
1056 |
|
#print "New Object: " . Dumper($obj); |
1057 |
|
|
1058 |
|
return $obj; |
1059 |
|
} |
1060 |
|
|
1061 |
|
|
1062 |
|
sub insertChildNode { |
1063 |
|
my $self = shift; |
1064 |
|
my $child_entry = shift; |
1065 |
|
my $query_args = shift; |
1066 |
|
|
1067 |
|
my $core = $self->{_COREHANDLE}; |
1068 |
|
my $nodename = $query_args->{nodename}; |
1069 |
|
|
1070 |
|
# get parent object |
1071 |
|
my $query = { |
1072 |
|
node => $query_args->{parent}->{nodename}, |
1073 |
|
options => { GUID => $query_args->{parent}->{guid}, }, |
1074 |
|
}; |
1075 |
|
my $cursor = $self->sendQuery($query); |
1076 |
|
my $parent = $cursor->getNextEntry(); |
1077 |
|
|
1078 |
|
# debug |
1079 |
|
#print "Parent_org: " . Dumper($parent); |
1080 |
|
|
1081 |
|
# Create child node object if isn't already done |
1082 |
|
# ($child_entry have to be the class name then...) |
1083 |
|
if(!ref($child_entry)) { |
1084 |
|
$child_entry = $self->createNode($child_entry); |
1085 |
|
# it could be insert 'manually' or will be insert 'transparent' if parent will be updated |
1086 |
|
#$core->insert($child_entry); |
1087 |
|
#print "Create child object [$nodename]: " . Dumper($child_entry); |
1088 |
|
} |
1089 |
|
|
1090 |
|
# get reference of tied node (seems, only on Linux node's are tied!!) |
1091 |
|
my $tied_node = tied $parent->{$nodename}; |
1092 |
|
|
1093 |
|
# insert/change child entry at parent |
1094 |
|
#print "reference: " . ref($parent->{$nodename}) . "\n"; |
1095 |
|
if(ref($parent->{$nodename}) eq 'ARRAY') { |
1096 |
|
# (seems, only on Linux node's are tied!!) |
1097 |
|
if($tied_node) { |
1098 |
|
# all tangram types are tied as 'SCALAR' with special 'FETCH', 'STORE' methods per type, |
1099 |
|
# so a 'PUSH' is not implemented (which could be then done transparently) |
1100 |
|
my $array = $tied_node->FETCH; |
1101 |
|
push @$array, $child_entry; |
1102 |
|
$tied_node->STORE($array); |
1103 |
|
# node will be normaly untied at 'STORE' |
1104 |
|
if(tied $parent->{$nodename}) { print "already tied !!\n"; } |
1105 |
|
else { undef $tied_node; } |
1106 |
|
} else { |
1107 |
|
push @{$parent->{$nodename}}, $child_entry; |
1108 |
|
} |
1109 |
|
} |
1110 |
|
elsif(ref($parent->{$nodename}) eq 'HASH') { |
1111 |
|
if(my $key = $query_args->{hash_key}) { |
1112 |
|
# (seems, only on Linux node's are tied!!) |
1113 |
|
if($tied_node) { |
1114 |
|
# same problem as with 'ARRAY': |
1115 |
|
# all tangram types are tied as 'SCALAR' with special 'FETCH', 'STORE' methods per type. |
1116 |
|
my $hash = $tied_node->FETCH; |
1117 |
|
$hash->{$key} = $child_entry; |
1118 |
|
$tied_node->STORE($hash); |
1119 |
|
# node will be normaly untied at 'STORE' |
1120 |
|
if(tied $parent->{$nodename}) { print "already tied !!\n"; } |
1121 |
|
else { undef $tied_node; } |
1122 |
|
} else { |
1123 |
|
$parent->{$nodename}->{$key} = $child_entry; |
1124 |
|
} |
1125 |
|
} else { |
1126 |
|
print "ERROR: No HASH KEY given, so not able to insert hash entry!"; |
1127 |
|
} |
1128 |
|
} |
1129 |
|
else { |
1130 |
|
$parent->{$nodename} = $child_entry; |
1131 |
|
} |
1132 |
|
|
1133 |
|
# debug |
1134 |
|
#print "Parent_new: " . Dumper($parent); |
1135 |
|
|
1136 |
|
# save parent |
1137 |
|
$core->update($parent); |
1138 |
|
|
1139 |
|
# debug |
1140 |
|
#print "Saved Parent: ". Dumper($parent); |
1141 |
|
|
1142 |
|
return $child_entry; |
1143 |
|
} |
1144 |
|
|
1145 |
|
|
1146 |
1; |
1; |
1147 |
__END__ |
__END__ |