KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > cache > DataStructCache


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  */

20 package org.enhydra.dods.cache;
21
22 import java.util.Map JavaDoc;
23 import org.enhydra.dods.cache.ConfigurationAdministration;
24 import com.lutris.appserver.server.sql.CoreDataStruct;
25 import org.enhydra.dods.exceptions.CacheObjectException;
26
27 /**
28  * This abstract class contains data and mechanisms needed for caching data
29  * objects (or DataStruct objects) by their OIDs and provides cache
30  * configuration and administration.
31  *
32  * @author Tanja Jovanovic
33  * @author Nenad Vico
34  * @author Zorica Suvajdzin
35  * @version 2.0 15.06.2003.
36  *
37  */

38 public abstract class DataStructCache extends ConfigurationAdministration {
39
40     /**
41      *
42      */

43     protected DataStructCache() {
44         Wrapper w = Wrapper.getInstance();
45
46         w.registerCache(this);
47     }
48
49     /**
50      * Creates DataStructCache instance.
51      *
52      * @return created data cache instance (for storing data (or DataStruct)
53      * objects.
54      */

55     public abstract DataStructCache newInstance() throws CacheObjectException;
56
57     /**
58      * Returns cache (data or DataStruct) content.
59      *
60      * @return Cache content as <code>Map</code> of data objects (or DataStruct
61      * objects).
62      */

63     public abstract Map JavaDoc getCacheContent();
64
65     /**
66      * Returns information if multi databases are supported.
67      *
68      * @return true if multi databases are used, otherwise false.
69      */

70     public abstract boolean isMulti();
71
72     /**
73      * Checks wheather cache reconfiguration needs to be done.
74      *
75      * @return true if cache reconfiguration needs to be done, otherwise false.
76      */

77     public abstract boolean toReconfigure();
78
79     /**
80      * Adds DataStruct object to the cache.
81      *
82      * @param newDS DataStruct object that will be added to the cache.
83      *
84      * @return Added DataStruct object.
85      */

86     public abstract CoreDataStruct addDataStruct(CoreDataStruct newDS);
87
88     /**
89      * Removes DataStruct object from the cache.
90      *
91      * @param data DataStruct object that will be removed from the cache.
92      *
93      * @return Removed DataStruct object, or <tt>null</tt> if there was no
94      * object removed from the cache.
95      */

96     public abstract CoreDataStruct removeDataStruct(CoreDataStruct data);
97
98     /**
99      * Removes DataStruct object from the cache.
100      *
101      * @param handle Cache handle of DataStruct object that will be removed from
102      * the cache. The form of cache handle is:
103      * "<database_name>.<String_presentation_of_oid>".
104      *
105      * @return Removed DataStruct object, or <tt>null</tt> if there was no
106      * object removed from the cache.
107      */

108     public abstract CoreDataStruct removeDataStruct(String JavaDoc handle);
109
110     /**
111      * Updates cached DataStruct object, or inserts it in the cache if it didn't
112      * exist in the cache.
113      *
114      * @param data DataStruct object that will be updated (or inserted if didn't
115      * exist in the cache).
116      *
117      * @return Updated or inserted DataStruct object.
118      */

119     public abstract CoreDataStruct updateDataStruct(CoreDataStruct data);
120
121     /**
122      * Deletes DataStruct object from the cache.
123      *
124      * @param data DataStruct object that will be deleted from the cache.
125      *
126      * @return Deleted DataStruct object, or <tt>null</tt> if there was no
127      * object deleted from the cache.
128      */

129     public abstract CoreDataStruct deleteDataStruct(CoreDataStruct data);
130
131     /**
132      * Returns DataStruct object whose String representation of OID is parameter
133      * handle.
134      *
135      * @param handle String representation of OID of DataStruct object that is
136      * being searched in the cache.
137      *
138      * @return DataStruct object whose String representation of OID is handle.
139      */

140     public abstract CoreDataStruct getDataStructByHandle(String JavaDoc handle);
141
142     /**
143      *
144      */

145     final synchronized void lock() {
146         locked = true;
147     }
148
149     /**
150      *
151      */

152     final synchronized void unlock() {
153         locked = false;
154     }
155
156     /**
157      *
158      */

159     protected final synchronized boolean isLocked() {
160         return locked;
161     }
162
163     /**
164      *
165      */

166     private boolean locked = false;
167 }
168
Popular Tags