| 3 |
# $Id$ |
# $Id$ |
| 4 |
# |
# |
| 5 |
# $Log$ |
# $Log$ |
| 6 |
|
# Revision 1.38 2003/05/13 16:38:38 joko |
| 7 |
|
# problems with "tied" on 5.6.1/win32 |
| 8 |
|
# |
| 9 |
|
# Revision 1.37 2003/05/10 17:37:39 jonen |
| 10 |
|
# corrected last commit |
| 11 |
|
# |
| 12 |
|
# Revision 1.36 2003/05/10 17:31:18 jonen |
| 13 |
|
# + added new functions related to 'create' item |
| 14 |
|
# - createNode() |
| 15 |
|
# # creates non-persistent 'deep dummy filled' object |
| 16 |
|
# - insertChildNode() |
| 17 |
|
# # inserts child node at given parent (child node haven't to exists, |
| 18 |
|
# createNode will be injected transparently) |
| 19 |
|
# |
| 20 |
# Revision 1.35 2003/04/19 16:09:48 jonen |
# Revision 1.35 2003/04/19 16:09:48 jonen |
| 21 |
# + added operator dispatching (currently for getting ref-type) at 'getListFiltered' |
# + added operator dispatching (currently for getting ref-type) at 'getListFiltered' |
| 22 |
# |
# |
| 728 |
|
|
| 729 |
$self->erase($object); |
$self->erase($object); |
| 730 |
|
|
| 731 |
|
} elsif ($crud eq 'CREATE') { |
| 732 |
|
|
| 733 |
|
my $nodename = $query->{node}; |
| 734 |
|
my $newnode = $self->createNode($nodename); |
| 735 |
|
my $id = $self->{_COREHANDLE}->insert($newnode); |
| 736 |
|
|
| 737 |
|
print "Saved new node $nodename with GUID $newnode->{guid}, OID '$id': " . Dumper($newnode) . "\n"; |
| 738 |
|
|
| 739 |
|
return $newnode; |
| 740 |
|
|
| 741 |
} |
} |
| 742 |
|
|
| 743 |
} |
} |
| 892 |
$self->{dataStorageLayer}->disconnect(); |
$self->{dataStorageLayer}->disconnect(); |
| 893 |
} |
} |
| 894 |
|
|
| 895 |
|
|
| 896 |
|
sub createNode { |
| 897 |
|
my $self = shift; |
| 898 |
|
my $classname = shift; |
| 899 |
|
|
| 900 |
|
my $obj = $classname->new(); |
| 901 |
|
|
| 902 |
|
my $attr_options = Class::Tangram::attribute_options($classname); |
| 903 |
|
#print "Attribute Options: " . Dumper($attr_options); |
| 904 |
|
|
| 905 |
|
my $attr_types = Class::Tangram::attribute_types($classname); |
| 906 |
|
#print "Attribute Types: " . Dumper($attr_types); |
| 907 |
|
|
| 908 |
|
foreach(keys %{$attr_types}) { |
| 909 |
|
if($attr_types->{$_} eq 'string') { |
| 910 |
|
$obj->{$_} = ''; |
| 911 |
|
} elsif($attr_types->{$_} eq 'int') { |
| 912 |
|
$obj->{$_} = 0; |
| 913 |
|
} elsif($attr_types->{$_} eq 'real') { |
| 914 |
|
$obj->{$_} = 0; |
| 915 |
|
} elsif($attr_types->{$_} eq 'rawdatetime') { |
| 916 |
|
$obj->{$_} = '0000-00-00 00:00:00'; |
| 917 |
|
} elsif($attr_types->{$_} eq 'ref') { |
| 918 |
|
if($attr_options->{$_}->{class}) { |
| 919 |
|
$obj->{$_} = $self->createNode($attr_options->{$_}->{class}); |
| 920 |
|
} else { |
| 921 |
|
#$obj->{$_} = undef(); |
| 922 |
|
} |
| 923 |
|
} elsif($attr_types->{$_} eq 'iarray') { |
| 924 |
|
$obj->{$_} = [ ]; |
| 925 |
|
} elsif($attr_types->{$_} eq 'hash') { |
| 926 |
|
$obj->{$_} = { }; |
| 927 |
|
} elsif($attr_types->{$_} eq 'flat_hash') { |
| 928 |
|
$obj->{$_} = { }; |
| 929 |
|
} |
| 930 |
|
} |
| 931 |
|
|
| 932 |
|
#print "New Object: " . Dumper($obj); |
| 933 |
|
|
| 934 |
|
return $obj; |
| 935 |
|
} |
| 936 |
|
|
| 937 |
|
|
| 938 |
|
sub insertChildNode { |
| 939 |
|
my $self = shift; |
| 940 |
|
my $child_entry = shift; |
| 941 |
|
my $query_args = shift; |
| 942 |
|
|
| 943 |
|
my $core = $self->{_COREHANDLE}; |
| 944 |
|
my $nodename = $query_args->{nodename}; |
| 945 |
|
|
| 946 |
|
# get parent object |
| 947 |
|
my $query = { |
| 948 |
|
node => $query_args->{parent}->{nodename}, |
| 949 |
|
options => { GUID => $query_args->{parent}->{guid}, }, |
| 950 |
|
}; |
| 951 |
|
my $cursor = $self->sendQuery($query); |
| 952 |
|
my $parent = $cursor->getNextEntry(); |
| 953 |
|
|
| 954 |
|
# debug |
| 955 |
|
#print "Parent_org: " . Dumper($parent); |
| 956 |
|
|
| 957 |
|
# Create child node object if isn't already done |
| 958 |
|
# ($child_entry have to be the class name then...) |
| 959 |
|
if(!ref($child_entry)) { |
| 960 |
|
$child_entry = $self->createNode($child_entry); |
| 961 |
|
# it could be insert 'manually' or will be insert 'transparent' if parent will be updated |
| 962 |
|
#$core->insert($child_entry); |
| 963 |
|
#print "Create child object [$nodename]: " . Dumper($child_entry); |
| 964 |
|
} |
| 965 |
|
|
| 966 |
|
# get reference of tied node (seems, only on Linux node's are tied!!) |
| 967 |
|
my $tied_node = tied $parent->{$nodename}; |
| 968 |
|
|
| 969 |
|
# insert/change child entry at parent |
| 970 |
|
#print "reference: " . ref($parent->{$nodename}) . "\n"; |
| 971 |
|
if(ref($parent->{$nodename}) eq 'ARRAY') { |
| 972 |
|
# (seems, only on Linux node's are tied!!) |
| 973 |
|
if($tied_node) { |
| 974 |
|
# all tangram types are tied as 'SCALAR' with special 'FETCH', 'STORE' methods per type, |
| 975 |
|
# so a 'PUSH' is not implemented (which could be then done transparently) |
| 976 |
|
my $array = $tied_node->FETCH; |
| 977 |
|
push @$array, $child_entry; |
| 978 |
|
$tied_node->STORE($array); |
| 979 |
|
# node will be normaly untied at 'STORE' |
| 980 |
|
if(tied $parent->{$nodename}) { print "already tied !!\n"; } |
| 981 |
|
else { undef $tied_node; } |
| 982 |
|
} else { |
| 983 |
|
push @{$parent->{$nodename}}, $child_entry; |
| 984 |
|
} |
| 985 |
|
} |
| 986 |
|
elsif(ref($parent->{$nodename}) eq 'HASH') { |
| 987 |
|
if(my $key = $query_args->{hash_key}) { |
| 988 |
|
# (seems, only on Linux node's are tied!!) |
| 989 |
|
if($tied_node) { |
| 990 |
|
# same problem as with 'ARRAY': |
| 991 |
|
# all tangram types are tied as 'SCALAR' with special 'FETCH', 'STORE' methods per type. |
| 992 |
|
my $hash = $tied_node->FETCH; |
| 993 |
|
$hash->{$key} = $child_entry; |
| 994 |
|
$tied_node->STORE($hash); |
| 995 |
|
# node will be normaly untied at 'STORE' |
| 996 |
|
if(tied $parent->{$nodename}) { print "already tied !!\n"; } |
| 997 |
|
else { undef $tied_node; } |
| 998 |
|
} else { |
| 999 |
|
$parent->{$nodename}->{$key} = $child_entry; |
| 1000 |
|
} |
| 1001 |
|
} else { |
| 1002 |
|
print "ERROR: No HASH KEY given, so not able to insert hash entry!"; |
| 1003 |
|
} |
| 1004 |
|
} |
| 1005 |
|
else { |
| 1006 |
|
$parent->{$nodename} = $child_entry; |
| 1007 |
|
} |
| 1008 |
|
|
| 1009 |
|
# debug |
| 1010 |
|
#print "Parent_new: " . Dumper($parent); |
| 1011 |
|
|
| 1012 |
|
# save parent |
| 1013 |
|
$core->update($parent); |
| 1014 |
|
|
| 1015 |
|
# debug |
| 1016 |
|
#print "Saved Parent: ". Dumper($parent); |
| 1017 |
|
|
| 1018 |
|
return $child_entry; |
| 1019 |
|
} |
| 1020 |
|
|
| 1021 |
|
|
| 1022 |
1; |
1; |
| 1023 |
__END__ |
__END__ |