KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > util > configuration > impl > OjbConfiguration


1 package org.apache.ojb.broker.util.configuration.impl;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.broker.ManageableCollection;
19 import org.apache.ojb.broker.PersistenceBroker;
20 import org.apache.ojb.broker.cache.ObjectCache;
21 import org.apache.ojb.broker.cache.ObjectCacheDefaultImpl;
22 import org.apache.ojb.broker.core.PBPoolConfiguration;
23 import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
24 import org.apache.ojb.broker.core.PersistenceBrokerImpl;
25 import org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl;
26 import org.apache.ojb.broker.core.proxy.IndirectionHandler;
27 import org.apache.ojb.broker.core.proxy.IndirectionHandlerJDKImpl;
28 import org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl;
29 import org.apache.ojb.broker.core.proxy.ProxyConfiguration;
30 import org.apache.ojb.broker.core.proxy.ProxyFactory;
31 import org.apache.ojb.broker.core.proxy.ProxyFactoryJDKImpl;
32 import org.apache.ojb.broker.core.proxy.SetProxyDefaultImpl;
33 import org.apache.ojb.broker.metadata.MetadataConfiguration;
34 import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
35 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectImpl;
36 import org.apache.ojb.broker.util.pooling.PoolConfiguration;
37 import org.apache.ojb.odmg.OdmgConfiguration;
38 import org.apache.ojb.odmg.collections.DListImpl;
39
40 /**
41  * This class contains the runtime configuration of the OJB
42  * system. This Configuration is read in only once at application startup.
43  * Changes to the OJB.properties file during execution are <b>not</b>
44  * reflected back into the application!
45  *
46  * @author Thomas Mahler
47  * @version $Id: OjbConfiguration.java,v 1.35.2.6 2005/12/21 22:28:15 tomdz Exp $
48  */

49 public class OjbConfiguration extends ConfigurationAbstractImpl
50                               implements OdmgConfiguration,
51                                          PersistenceBrokerConfiguration,
52                                          ProxyConfiguration,
53                                          PBPoolConfiguration,
54                                          MetadataConfiguration
55 {
56     /** Default filename of the OJB properties file */
57     public static final String JavaDoc OJB_PROPERTIES_FILE = "OJB.properties";
58     /** Default filename of the OJB repository metadata file */
59     public static final String JavaDoc OJB_METADATA_FILE = "repository.xml";
60
61     /** the repository file keeping the O/R Metadata*/
62     private String JavaDoc repositoryFilename;
63     private Class JavaDoc objectCacheClass;
64     private Class JavaDoc persistentFieldClass;
65     private Class JavaDoc persistenceBrokerClass;
66
67     // proxy related classes
68
private Class JavaDoc listProxyClass;
69     private Class JavaDoc setProxyClass;
70     private Class JavaDoc collectionProxyClass;
71     private Class JavaDoc indirectionHandlerClass;
72     private Class JavaDoc proxyFactoryClass;
73
74     // limit for number of values in SQL IN Statement
75
private int sqlInLimit;
76
77     // PB pooling configuration
78
private int maxActive;
79     private int maxIdle;
80     private long maxWait;
81     private long timeBetweenEvictionRunsMillis;
82     private long minEvictableIdleTimeMillis;
83     private byte whenExhaustedAction;
84
85     // ODMG configuration
86
private boolean useImplicitLocking;
87     private boolean lockAssociationAsWrites;
88     private Class JavaDoc oqlCollectionClass;
89
90     // Metadata configuration
91
private boolean useSerializedRepository;
92
93
94
95     public OjbConfiguration()
96     {
97         super();
98     }
99
100     public boolean useSerializedRepository()
101     {
102         return useSerializedRepository;
103     }
104
105     public boolean lockAssociationAsWrites()
106     {
107         return lockAssociationAsWrites;
108     }
109
110     public String JavaDoc getRepositoryFilename()
111     {
112         return repositoryFilename;
113     }
114
115     //*************************************************************
116
//PBPoolConfiguration methods
117
public int getMaxActive()
118     {
119         return maxActive;
120     }
121
122     public int getMaxIdle()
123     {
124         return maxIdle;
125     }
126
127     public long getMaxWaitMillis()
128     {
129         return maxWait;
130     }
131
132     public long getTimeBetweenEvictionRunsMilli()
133     {
134         return timeBetweenEvictionRunsMillis;
135     }
136
137     public long getMinEvictableIdleTimeMillis()
138     {
139         return minEvictableIdleTimeMillis;
140     }
141
142     public byte getWhenExhaustedAction()
143     {
144         return whenExhaustedAction;
145     }
146     //*************************************************************
147

148
149     //*************************************************************
150

151     public Class JavaDoc getObjectCacheClass()
152     {
153         return objectCacheClass;
154     }
155
156     public Class JavaDoc getOqlCollectionClass()
157     {
158         return oqlCollectionClass;
159     }
160
161     public Class JavaDoc getPersistentFieldClass()
162     {
163         return persistentFieldClass;
164     }
165
166     public Class JavaDoc getPersistenceBrokerClass()
167     {
168         return persistenceBrokerClass;
169     }
170
171     /**
172      * Returns the indirection handler implementation class.
173      *
174      * @return The indirection handler class
175      * @see org.apache.ojb.broker.core.proxy.IndirectionHandler
176      */

177     public Class JavaDoc getIndirectionHandlerClass()
178     {
179         return indirectionHandlerClass;
180     }
181     
182     /**
183      * Returns the proxy class used for that implement the {@link java.util.List} interface.
184      *
185      * @return The proxy class
186      * @see org.apache.ojb.broker.core.proxy.ProxyFactory#setListProxyClass(Class)
187      */

188     public Class JavaDoc getListProxyClass()
189     {
190         return listProxyClass;
191     }
192
193     /**
194      * Returns the proxy class used for that implement the {@link java.util.Set} interface.
195      *
196      * @return The proxy class
197      * @see org.apache.ojb.broker.core.proxy.ProxyFactory#setSetProxyClass(Class)
198      */

199     public Class JavaDoc getSetProxyClass()
200     {
201         return setProxyClass;
202     }
203
204     /**
205      * Returns the proxy class used for that implement the {@link java.util.Collection} interface.
206      *
207      * @return The proxy class
208      * @see org.apache.ojb.broker.core.proxy.ProxyFactory#setCollectionProxyClass(Class)
209      */

210     public Class JavaDoc getCollectionProxyClass()
211     {
212         return collectionProxyClass;
213     }
214     
215     
216     /**
217      * Returns the class that will be used as the proxy factory.
218      *
219      * @return The proxy factory class
220      */

221     public Class JavaDoc getProxyFactoryClass() {
222         return proxyFactoryClass;
223     }
224
225     /**
226      * Loads the configuration from file "OBJ.properties". If the system
227      * property "OJB.properties" is set, then the configuration in that file is
228      * loaded. Otherwise, the file "OJB.properties" is tried. If that is also
229      * unsuccessful, then the configuration is filled with default values.
230      */

231     protected void load()
232     {
233         // properties file may be set as a System property.
234
// if no property is set take default name.
235
String JavaDoc fn = System.getProperty(OJB_PROPERTIES_FILE, OJB_PROPERTIES_FILE);
236         setFilename(fn);
237         super.load();
238
239         // default repository & connection descriptor file
240
repositoryFilename = getString("repositoryFile", OJB_METADATA_FILE);
241
242         // object cache class
243
objectCacheClass = getClass("ObjectCacheClass", ObjectCacheDefaultImpl.class, ObjectCache.class);
244
245         // load PersistentField Class
246
persistentFieldClass =
247                 getClass("PersistentFieldClass", PersistentFieldDirectImpl.class, PersistentField.class);
248
249         // load PersistenceBroker Class
250
persistenceBrokerClass =
251                 getClass("PersistenceBrokerClass", PersistenceBrokerImpl.class, PersistenceBroker.class);
252
253         // load ListProxy Class
254
listProxyClass = getClass("ListProxyClass", ListProxyDefaultImpl.class);
255
256         // load SetProxy Class
257
setProxyClass = getClass("SetProxyClass", SetProxyDefaultImpl.class);
258
259         // load CollectionProxy Class
260
collectionProxyClass = getClass("CollectionProxyClass", CollectionProxyDefaultImpl.class);
261
262         // load IndirectionHandler Class
263
indirectionHandlerClass =
264             getClass("IndirectionHandlerClass", IndirectionHandlerJDKImpl.class, IndirectionHandler.class);
265         
266         // load ProxyFactory Class
267
proxyFactoryClass =
268             getClass("ProxyFactoryClass", ProxyFactoryJDKImpl.class, ProxyFactory.class);
269
270         // load configuration for ImplicitLocking parameter:
271
useImplicitLocking = getBoolean("ImplicitLocking", false);
272
273         // load configuration for LockAssociations parameter:
274
lockAssociationAsWrites = (getString("LockAssociations", "WRITE").equalsIgnoreCase("WRITE"));
275
276         // load OQL Collection Class
277
oqlCollectionClass = getClass("OqlCollectionClass", DListImpl.class, ManageableCollection.class);
278
279         // set the limit for IN-sql , -1 for no limits
280
sqlInLimit = getInteger("SqlInLimit", -1);
281
282         //load configuration for PB pool
283
maxActive = getInteger(PoolConfiguration.MAX_ACTIVE,
284                 PoolConfiguration.DEFAULT_MAX_ACTIVE);
285         maxIdle = getInteger(PoolConfiguration.MAX_IDLE,
286                 PoolConfiguration.DEFAULT_MAX_IDLE);
287         maxWait = getLong(PoolConfiguration.MAX_WAIT,
288                 PoolConfiguration.DEFAULT_MAX_WAIT);
289         timeBetweenEvictionRunsMillis = getLong(PoolConfiguration.TIME_BETWEEN_EVICTION_RUNS_MILLIS,
290                 PoolConfiguration.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
291         minEvictableIdleTimeMillis = getLong(PoolConfiguration.MIN_EVICTABLE_IDLE_TIME_MILLIS,
292                 PoolConfiguration.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
293         whenExhaustedAction = getByte(PoolConfiguration.WHEN_EXHAUSTED_ACTION,
294                 PoolConfiguration.DEFAULT_WHEN_EXHAUSTED_ACTION);
295
296         useSerializedRepository = getBoolean("useSerializedRepository", false);
297     }
298
299     /**
300      * Returns the SQLInLimit.
301      * @return int
302      */

303     public int getSqlInLimit()
304     {
305         return sqlInLimit;
306     }
307
308     /**
309      * Sets the persistentFieldClass.
310      * @param persistentFieldClass The persistentFieldClass to set
311      */

312     public void setPersistentFieldClass(Class JavaDoc persistentFieldClass)
313     {
314         this.persistentFieldClass = persistentFieldClass;
315     }
316
317     /**
318      * @see org.apache.ojb.odmg.OdmgConfiguration#useImplicitLocking()
319      */

320     public boolean useImplicitLocking()
321     {
322         return useImplicitLocking;
323     }
324
325     public void setUseImplicitLocking(boolean implicitLocking)
326     {
327         this.useImplicitLocking = implicitLocking;
328     }
329
330 }
331
Popular Tags