001 package org.apache.ojb.broker.util.configuration.impl;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import org.apache.ojb.broker.ManageableCollection;
019 import org.apache.ojb.broker.PersistenceBroker;
020 import org.apache.ojb.broker.cache.ObjectCache;
021 import org.apache.ojb.broker.cache.ObjectCacheDefaultImpl;
022 import org.apache.ojb.broker.core.PBPoolConfiguration;
023 import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
024 import org.apache.ojb.broker.core.PersistenceBrokerImpl;
025 import org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl;
026 import org.apache.ojb.broker.core.proxy.IndirectionHandler;
027 import org.apache.ojb.broker.core.proxy.IndirectionHandlerJDKImpl;
028 import org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl;
029 import org.apache.ojb.broker.core.proxy.ProxyConfiguration;
030 import org.apache.ojb.broker.core.proxy.ProxyFactory;
031 import org.apache.ojb.broker.core.proxy.ProxyFactoryJDKImpl;
032 import org.apache.ojb.broker.core.proxy.SetProxyDefaultImpl;
033 import org.apache.ojb.broker.metadata.MetadataConfiguration;
034 import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
035 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectImpl;
036 import org.apache.ojb.broker.util.pooling.PoolConfiguration;
037 import org.apache.ojb.odmg.OdmgConfiguration;
038 import org.apache.ojb.odmg.collections.DListImpl;
039
040 /**
041 * This class contains the runtime configuration of the OJB
042 * system. This Configuration is read in only once at application startup.
043 * Changes to the OJB.properties file during execution are <b>not</b>
044 * reflected back into the application!
045 *
046 * @author Thomas Mahler
047 * @version $Id: OjbConfiguration.java,v 1.1 2007-08-24 22:17:42 ewestfal Exp $
048 */
049 public class OjbConfiguration extends ConfigurationAbstractImpl
050 implements OdmgConfiguration,
051 PersistenceBrokerConfiguration,
052 ProxyConfiguration,
053 PBPoolConfiguration,
054 MetadataConfiguration
055 {
056 /** Default filename of the OJB properties file */
057 public static final String OJB_PROPERTIES_FILE = "OJB.properties";
058 /** Default filename of the OJB repository metadata file */
059 public static final String OJB_METADATA_FILE = "repository.xml";
060
061 /** the repository file keeping the O/R Metadata*/
062 private String repositoryFilename;
063 private Class objectCacheClass;
064 private Class persistentFieldClass;
065 private Class persistenceBrokerClass;
066
067 // proxy related classes
068 private Class listProxyClass;
069 private Class setProxyClass;
070 private Class collectionProxyClass;
071 private Class indirectionHandlerClass;
072 private Class proxyFactoryClass;
073
074 // limit for number of values in SQL IN Statement
075 private int sqlInLimit;
076
077 // PB pooling configuration
078 private int maxActive;
079 private int maxIdle;
080 private long maxWait;
081 private long timeBetweenEvictionRunsMillis;
082 private long minEvictableIdleTimeMillis;
083 private byte whenExhaustedAction;
084
085 // ODMG configuration
086 private boolean useImplicitLocking;
087 private boolean lockAssociationAsWrites;
088 private Class oqlCollectionClass;
089
090 // Metadata configuration
091 private boolean useSerializedRepository;
092
093
094
095 public OjbConfiguration()
096 {
097 super();
098 }
099
100 public boolean useSerializedRepository()
101 {
102 return useSerializedRepository;
103 }
104
105 public boolean lockAssociationAsWrites()
106 {
107 return lockAssociationAsWrites;
108 }
109
110 public String 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 getObjectCacheClass()
152 {
153 return objectCacheClass;
154 }
155
156 public Class getOqlCollectionClass()
157 {
158 return oqlCollectionClass;
159 }
160
161 public Class getPersistentFieldClass()
162 {
163 return persistentFieldClass;
164 }
165
166 public Class 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 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 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 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 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 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 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 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 }