KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > jdo > JDOObjectProvider


1 /*
2  * Created on Jul 29, 2005
3  */

4 package com.nightlabs.ipanema.jdo;
5
6 import java.util.Set JavaDoc;
7
8 import com.nightlabs.ipanema.jdo.cache.Cache;
9
10 /**
11  * @author Marco Schulze - marco at nightlabs dot de
12  */

13 public abstract class JDOObjectProvider
14 {
15     private Cache cache = Cache.sharedInstance();
16
17     public JDOObjectProvider()
18     {
19     }
20
21     /**
22      * Decide whether you want to use <tt>String[]</tt> or <tt>Set</tt>
23      * and then throw an <tt>UnsupportedOperationException</tt> in the
24      * other method.
25      */

26     protected Object JavaDoc retrieveJDOObject(
27             String JavaDoc scope, Object JavaDoc objectID, String JavaDoc[] fetchGroups)
28     throws Exception JavaDoc
29     {
30         throw new UnsupportedOperationException JavaDoc("method 'retrieveJDOObject(String scope, Object objectID, String[] fetchGroups)' not implemented!");
31     }
32
33     /**
34      * @see #retrieveJDOObject(String, Object, String[])
35      */

36     protected Object JavaDoc retrieveJDOObject(
37             String JavaDoc scope, Object JavaDoc objectID, Set JavaDoc fetchGroups)
38     throws Exception JavaDoc
39     {
40         throw new UnsupportedOperationException JavaDoc("method 'retrieveJDOObject(String scope, Object objectID, Set fetchGroups)' not implemented!");
41     }
42
43     protected synchronized Object JavaDoc getJDOObject(
44             String JavaDoc scope, Object JavaDoc objectID, Set JavaDoc fetchGroups)
45     {
46         try {
47             Object JavaDoc res = cache.get(scope, objectID, fetchGroups);
48             if (res == null) {
49                 res = retrieveJDOObject(scope, objectID, fetchGroups);
50                 cache.put(scope, objectID, fetchGroups);
51             }
52             return res;
53         } catch (Exception JavaDoc x) {
54             throw new RuntimeException JavaDoc(x);
55         }
56     }
57
58     protected synchronized Object JavaDoc getJDOObject(
59             String JavaDoc scope, Object JavaDoc objectID, String JavaDoc[] fetchGroups)
60     {
61         try {
62             Object JavaDoc res = cache.get(scope, objectID, fetchGroups);
63             if (res == null) {
64                 res = retrieveJDOObject(scope, objectID, fetchGroups);
65                 cache.put(scope, res, fetchGroups);
66             }
67             return res;
68         } catch (Exception JavaDoc x) {
69             throw new RuntimeException JavaDoc(x);
70         }
71     }
72
73 }
74
Popular Tags