1 package de.fhdw.wtf.context.core;
2
3 import java.math.BigInteger;
4 import java.util.Collection;
5
6 import de.fhdw.wtf.persistence.facade.TypeManager;
7 import de.fhdw.wtf.persistence.meta.Link;
8 import de.fhdw.wtf.persistence.meta.MapLink;
9 import de.fhdw.wtf.persistence.meta.Object;
10 import de.fhdw.wtf.persistence.meta.UnidirectionalLink;
11 import de.fhdw.wtf.persistence.meta.UserObject;
12 import de.fhdw.wtf.persistence.utils.Tuple;
13
14 /**
15 * A Context represents the facade for interacting with the persistence layer. The Context is stored in a thread local
16 * variable to be accessible to all objects in the current thread. A Context is usually published to the thread by User
17 * Access.
18 *
19 */
20 public abstract class Context {
21
22 /**
23 * The per-transaction object cache.
24 */
25 private final IAnyTypeCache cache = new IAnyTypeCache();
26
27 /**
28 * Returns the object cache.
29 *
30 * @return The object cache.
31 */
32 public IAnyTypeCache getCache() {
33 return this.cache;
34 }
35
36 /**
37 * This method provides a Collection of User Object which have an association with a specified name and a given
38 * target value.
39 *
40 * @param associationName
41 * The name of the association on which the find will operate.
42 * @param value
43 * The String value of the association on which the find operates.
44 * @return A Collection of UserObjects which conform to the find query.
45 */
46 public abstract Collection<UserObject> find(String associationName, String value);
47
48 /**
49 * This method provides a Collection of User Object which have an association with a specified name and a given
50 * target value.
51 *
52 * @param associationName
53 * The name of the association on which the find will operate.
54 * @param value
55 * The Integer value of the association on which the find operates.
56 * @return A Collection of UserObjects which conform to the find query.
57 */
58 public abstract Collection<UserObject> find(String associationName, BigInteger value);
59
60 /**
61 * This method provides the owner and the UnidirectionalLink, which is an instance of an association with a given
62 * name and which has a specified UserObject as target.
63 *
64 * @param associationName
65 * The name of the association.
66 * @param object
67 * The target object of the association.
68 * @return Provides a Collection of Tuples of Links and UserObject which conform to the search query.
69 */
70 public abstract Collection<Tuple<UnidirectionalLink, UserObject>> inverseGet(String associationName,
71 UserObject object);
72
73 /**
74 * Provides a Collection of Tuples of Links and their target. The provided Links will have the provided object as an
75 * owner and are instances of an association with the provided name.
76 *
77 * @param object
78 * The owner of the Links.
79 * @param associationName
80 * The name of the association which is the type of the links.
81 * @return Provides a Collection of Links.
82 */
83 public abstract Collection<Tuple<UnidirectionalLink, Object>> get(UserObject object, String associationName);
84
85 /**
86 * Provides a Collection of Tuples of Keyed-Links and their target. The provided Links will have the provided object
87 * as an owner and are instances of an association with the provided name and key.
88 *
89 * @param object
90 * The owner of the Links.
91 * @param associationName
92 * The name of the association which is the type of the links. The target of this link represents a
93 * MutableMap.
94 * @param key
95 * The key to get the value for in the map.
96 * @return Provides a Collection of Links.
97 */
98 public abstract Collection<Tuple<MapLink, Object>> get(UserObject object, String associationName, String key);
99
100 /**
101 * Provides a Collection of Tuples of Keyed-Links and their target. The provided Links will have the provided object
102 * as an owner and are instances of an association with the provided name and key.
103 *
104 * @param object
105 * The owner of the Links.
106 * @param associationName
107 * The name of the association which is the type of the links. The target of this link represents a
108 * MutableMap.
109 * @param key
110 * The key to get the value for in the map.
111 * @return Provides a Collection of Links.
112 */
113 public abstract Collection<Tuple<MapLink, Object>> get(UserObject object, String associationName, BigInteger key);
114
115 /**
116 * Provides a Collection of Tuples of Keyed-Links and their target. The provided Links will have the provided object
117 * as an owner and are instances of an association with the provided name and key.
118 *
119 * @param object
120 * The owner of the Links.
121 * @param associationName
122 * The name of the association which is the type of the links. The target of this link represents a
123 * MutableMap.
124 * @param key
125 * The key to get the value for in the map.
126 * @return Provides a Collection of Links.
127 */
128 public abstract Collection<Tuple<MapLink, Object>> get(UserObject object, String associationName, UserObject key);
129
130 /**
131 * Provides an instance of a Type with a given name.
132 *
133 * @param typeName
134 * The name of the UserType.
135 * @return Provides a new User Object.
136 */
137 public abstract UserObject create(String typeName);
138
139 /**
140 * Creates a new UnidirectionalLink which has the provided object as owner and the provided String as target.
141 *
142 * @param object
143 * The owner of the newly created UnidirectionalLink.
144 * @param associationName
145 * The name of the association which is the Type of the created UnidirectionalLink.
146 * @param val
147 * The String Value which will be the target of the UnidirectionalLink.
148 * @return A newly created UnidirectionalLink object.
149 */
150 public abstract UnidirectionalLink set(UserObject object, String associationName, String val);
151
152 /**
153 * Creates a new UnidirectionalLink which has the provided object as owner and the provided Integer as target.
154 *
155 * @param object
156 * The owner of the newly created UnidirectionalLink.
157 * @param associationName
158 * The name of the association which is the Type of the created UnidirectionalLink.
159 * @param val
160 * The Integer Value which will be the target of the UnidirectionalLink.
161 * @return A newly created UnidirectionalLink object.
162 */
163 public abstract UnidirectionalLink set(UserObject object, String associationName, BigInteger val);
164
165 /**
166 * Creates a new UnidirectionalLink which has the provided object as owner and the provided User Object as target.
167 *
168 * @param object
169 * The owner of the newly created UnidirectionalLink.
170 * @param associationName
171 * The name of the association which is the Type of the created UnidirectionalLink.
172 * @param target
173 * The User Object which will be the target of the UnidirectionalLink.
174 * @return A newly created UnidirectionalLink object.
175 */
176 public abstract UnidirectionalLink set(UserObject object, String associationName, UserObject target);
177
178 /**
179 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
180 * The target is accessible via the provided key.
181 *
182 * @param owner
183 * The owner of the newly created UnidirectionalLink.
184 * @param associationName
185 * The name of the association which is the Type of the created UnidirectionalLink.
186 * @param target
187 * The object which will be the target of the UnidirectionalLink.
188 * @param key
189 * The key to access the target from the owner via the UnidirectionalLink.
190 * @return A newly created UnidirectionalLink object.
191 */
192 public abstract MapLink put(UserObject owner, String associationName, UserObject target, String key);
193
194 /**
195 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
196 * The target is accessible via the provided key.
197 *
198 * @param owner
199 * The owner of the newly created UnidirectionalLink.
200 * @param associationName
201 * The name of the association which is the Type of the created UnidirectionalLink.
202 * @param target
203 * The object which will be the target of the UnidirectionalLink.
204 * @param key
205 * The key to access the target from the owner via the UnidirectionalLink.
206 * @return A newly created UnidirectionalLink object.
207 */
208 public abstract MapLink put(UserObject owner, String associationName, BigInteger target, String key);
209
210 /**
211 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
212 * The target is accessible via the provided key.
213 *
214 * @param owner
215 * The owner of the newly created UnidirectionalLink.
216 * @param associationName
217 * The name of the association which is the Type of the created UnidirectionalLink.
218 * @param target
219 * The object which will be the target of the UnidirectionalLink.
220 * @param key
221 * The key to access the target from the owner via the UnidirectionalLink.
222 * @return A newly created UnidirectionalLink object.
223 */
224 public abstract MapLink put(UserObject owner, String associationName, String target, String key);
225
226 /**
227 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
228 * The target is accessible via the provided key.
229 *
230 * @param owner
231 * The owner of the newly created UnidirectionalLink.
232 * @param associationName
233 * The name of the association which is the Type of the created UnidirectionalLink.
234 * @param target
235 * The object which will be the target of the UnidirectionalLink.
236 * @param key
237 * The key to access the target from the owner via the UnidirectionalLink.
238 * @return A newly created UnidirectionalLink object.
239 */
240 public abstract MapLink put(UserObject owner, String associationName, UserObject target, BigInteger key);
241
242 /**
243 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
244 * The target is accessible via the provided key.
245 *
246 * @param owner
247 * The owner of the newly created UnidirectionalLink.
248 * @param associationName
249 * The name of the association which is the Type of the created UnidirectionalLink.
250 * @param target
251 * The object which will be the target of the UnidirectionalLink.
252 * @param key
253 * The key to access the target from the owner via the UnidirectionalLink.
254 * @return A newly created UnidirectionalLink object.
255 */
256 public abstract MapLink put(UserObject owner, String associationName, BigInteger target, BigInteger key);
257
258 /**
259 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
260 * The target is accessible via the provided key.
261 *
262 * @param owner
263 * The owner of the newly created UnidirectionalLink.
264 * @param associationName
265 * The name of the association which is the Type of the created UnidirectionalLink.
266 * @param target
267 * The object which will be the target of the UnidirectionalLink.
268 * @param key
269 * The key to access the target from the owner via the UnidirectionalLink.
270 * @return A newly created UnidirectionalLink object.
271 */
272 public abstract MapLink put(UserObject owner, String associationName, String target, BigInteger key);
273
274 /**
275 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
276 * The target is accessible via the provided key.
277 *
278 * @param owner
279 * The owner of the newly created UnidirectionalLink.
280 * @param associationName
281 * The name of the association which is the Type of the created UnidirectionalLink.
282 * @param target
283 * The object which will be the target of the UnidirectionalLink.
284 * @param key
285 * The key to access the target from the owner via the UnidirectionalLink.
286 * @return A newly created UnidirectionalLink object.
287 */
288 public abstract MapLink put(UserObject owner, String associationName, UserObject target, UserObject key);
289
290 /**
291 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
292 * The target is accessible via the provided key.
293 *
294 * @param owner
295 * The owner of the newly created UnidirectionalLink.
296 * @param associationName
297 * The name of the association which is the Type of the created UnidirectionalLink.
298 * @param target
299 * The object which will be the target of the UnidirectionalLink.
300 * @param key
301 * The key to access the target from the owner via the UnidirectionalLink.
302 * @return A newly created UnidirectionalLink object.
303 */
304 public abstract MapLink put(UserObject owner, String associationName, BigInteger target, UserObject key);
305
306 /**
307 * Creates a new UnidirectionalLink which has the provided object as owner and another provided object as target.
308 * The target is accessible via the provided key.
309 *
310 * @param owner
311 * The owner of the newly created UnidirectionalLink.
312 * @param associationName
313 * The name of the association which is the Type of the created UnidirectionalLink.
314 * @param target
315 * The object which will be the target of the UnidirectionalLink.
316 * @param key
317 * The key to access the target from the owner via the UnidirectionalLink.
318 * @return A newly created UnidirectionalLink object.
319 */
320 public abstract MapLink put(UserObject owner, String associationName, String target, UserObject key);
321
322 /**
323 * This method commits all changes. So they are accessible to all other transaction in the persistence layer It also
324 * closes the current transaction so it can not be used further.
325 */
326 public abstract void commit();
327
328 /**
329 * This method rolls back all changes of the current transaction. And also closes the actual transaction so it can
330 * not be used anymore.
331 */
332 public abstract void rollback();
333
334 /**
335 * This method will create a save Point in the persistence layer, so changes will be saved.
336 */
337 public abstract void savePoint();
338
339 /**
340 * This will roll back all changes did since the last save Point.
341 */
342 public abstract void rollbackToSavePoint();
343
344 /**
345 * This method removes a given UnidirectionalLink in the persistence Layer.
346 *
347 * @param toUnset
348 * The UnidirectionalLink, which will be removed.
349 */
350 public abstract void unset(Link toUnset);
351
352 /**
353 * Provides the Type Manager, which is used to query Type Information at Runtime.
354 *
355 * @return An instance of the Type Manager.
356 */
357 public abstract TypeManager getTypeManager();
358
359 /**
360 * Provides as Collection of User Objects, which contains all instance of a given type.
361 *
362 * @param typeName
363 * The name of a Type.
364 * @return A collection of UserObjects.
365 */
366 public abstract Collection<UserObject> getObjectsByType(String typeName);
367
368 /**
369 * Provides a User Object with the given Id. It also marks the object as read inside the database.
370 *
371 * @param object
372 * The Id of the Object.
373 * @return Provides a new User Object with given Id and type.
374 */
375 public abstract UserObject checkout(long object);
376
377 }