/[eiffelstudio]/branches/eth/eve/Src/library/abel/libraries/ethz/src/abel/backends/ps_special_collection_handler.e
ViewVC logotype

Contents of /branches/eth/eve/Src/library/abel/libraries/ethz/src/abel/backends/ps_special_collection_handler.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 88969 - (show annotations)
Fri Jun 22 11:53:00 2012 UTC (7 years, 5 months ago) by romanschmocker
File size: 5147 byte(s)
Changed structure in the ABEL library repository - e.g. pre-built backends are now collected in their own cluster
1 note
2 description: "Colletion handler for SPECIAL for use in the relational memory backend."
3 author: "Roman Schmocker"
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 PS_SPECIAL_COLLECTION_HANDLER
9
10 inherit
11 PS_COLLECTION_HANDLER [SPECIAL [detachable ANY]]
12 redefine can_handle_type, do_disassemble end
13
14 create make
15
16 feature
17 can_handle_type (a_type: TYPE[detachable ANY]):BOOLEAN
18 -- Can `Current' handle the collection type `a_type'?
19 local
20 reflection: INTERNAL
21 do
22 create reflection
23 Result:= reflection.is_special_type (a_type.type_id)
24 fixme ("TODO: check this attached/detachable type problem here..")
25 end
26
27
28 feature -- Layout information
29
30
31 is_in_relational_storage_mode (a_collection: PS_COLLECTION_PART[SPECIAL[detachable ANY]]):BOOLEAN
32 -- Is `a_collection' stored in relational mode?
33 do
34 Result:= False
35 end
36
37 is_1_to_n_mapped (a_collection:PS_COLLECTION_PART[SPECIAL[detachable ANY]]): BOOLEAN
38 -- Is `a_collection' stored relationally in a 1:N mapping, meaning that the primary key of the parent is stored as a foreign key in the child's table?
39 do
40 Result:= False
41 end
42
43
44 feature -- Low-level operations
45
46 insert (a_collection: PS_COLLECTION_PART[SPECIAL[detachable ANY]])
47 local
48 current_collection: LINKED_LIST[INTEGER]
49 do
50 if collections.has (a_collection.object_id.object_identifier) then
51 current_collection:= attach (collections[a_collection.object_id.object_identifier])
52 else
53 create current_collection.make
54 collections.extend (current_collection, a_collection.object_id.object_identifier)
55 --print (a_collection.object_id.object_identifier)
56 end
57
58 -- fill the "foreign key table"
59 across a_collection.values as object_cursor loop
60 fixme ("handle basic types")
61 if attached{PS_COMPLEX_ATTRIBUTE_PART} object_cursor.item as obj then
62 current_collection.extend (obj.object_id.object_identifier)
63 elseif attached{PS_NULL_REFERENCE_PART} object_cursor.item as null_ref then
64 current_collection.extend (0)
65
66 end
67 end
68
69 -- add the 'count' variable
70
71 check attached{SPECIAL[detachable ANY]} a_collection.object_id.item as actual_collection then
72 collection_counts.extend (actual_collection.capacity, a_collection.object_id.object_identifier)
73 --print (actual_collection.capacity.out + "%N")
74 end
75
76 end
77
78
79 delete (a_collection: PS_COLLECTION_PART[SPECIAL[detachable ANY]])
80 do
81 collections.remove (a_collection.object_id.object_identifier)
82 collection_counts.remove (a_collection.object_id.object_identifier)
83
84 end
85
86
87 retrieve (parent_key, parent_type, child_type: INTEGER; parent_attr_name: STRING):
88 PS_PAIR [
89 LIST[INTEGER], -- The foreign keys in correct order
90 TUPLE ] -- Any additional information required to create the actual collection
91 local
92 count_tuple: TUPLE[INTEGER]
93 do
94 --print (parent_key.out + collection_counts[parent_key].out)
95 create count_tuple.default_create
96 count_tuple.put_integer (collection_counts[parent_key], 1)
97 create Result.make (attach (collections[parent_key]), count_tuple)
98 end
99
100 do_disassemble (collection:PS_COLLECTION_PART [SPECIAL[detachable ANY]]; disassemble_function:FUNCTION[ANY, TUPLE[ANY], PS_OBJECT_GRAPH_PART])
101 local
102 cursor:ITERATION_CURSOR[detachable ANY]
103 -- attached_item: ANY
104 do
105 precursor (collection, disassemble_function)
106 check attached{SPECIAL[detachable ANY]} collection.object_id.item as actual_collection then
107 check attached {PS_OBJECT_COLLECTION_PART[SPECIAL[detachable ANY]]} collection as part then
108 part.add_information ("count", actual_collection.capacity.out)
109 end
110 end
111 end
112
113
114 feature -- Object assembly
115
116 build_collection (type_id: PS_TYPE_METADATA; objects: LIST[detachable ANY]; additional_information: PS_RETRIEVED_OBJECT_COLLECTION):SPECIAL[detachable ANY]
117 -- Dynamic type id of the collection
118 local
119 reflection: INTERNAL
120 count, i:INTEGER
121 do
122 create reflection
123
124 -- fixme ("TODO: the following line:-)")
125 -- count:=10
126 count:= additional_information.get_information("count").to_integer
127 --print (additional_information.out + count.out)
128
129 if reflection.is_special_any_type (type_id.type.type_id) then
130 Result:= reflection.new_special_any_instance (type_id.type.type_id, count)
131 else
132 fixme ("TODO: all other basic types")
133 if type_id.actual_generic_parameter (1).type.out.is_equal ("BOOLEAN") then
134 create {SPECIAL[BOOLEAN]} Result.make_empty (count)
135 else
136 create {SPECIAL[INTEGER]} Result.make_empty (count)
137 end
138 end
139 --print (Result.count)
140
141 across objects as obj_cursor from i:=0 loop
142 Result.extend (obj_cursor.item)
143 i:=i+1
144 end
145
146 -- print (Result)
147 end
148
149 build_relational_collection (type_id: PS_TYPE_METADATA; objects: LIST[detachable ANY]):SPECIAL[detachable ANY]
150 do
151 fixme ("TODO")
152 create Result.make_empty (10)
153 end
154
155 feature {NONE}-- Implementation
156
157 collections: HASH_TABLE[LINKED_LIST[INTEGER],INTEGER]
158 -- Internal store of collection objects
159
160 collection_counts: HASH_TABLE[INTEGER, INTEGER]
161 -- The capacity of individual SPECIAL objects
162
163 make
164 do
165 create collections.make (100)
166 create collection_counts.make (100)
167 end
168
169 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23