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