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