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.35.2.6 2005/12/21 22:28:15 tomdz Exp $
048: */
049: public class OjbConfiguration extends ConfigurationAbstractImpl
050: implements OdmgConfiguration, PersistenceBrokerConfiguration,
051: ProxyConfiguration, PBPoolConfiguration, MetadataConfiguration {
052: /** Default filename of the OJB properties file */
053: public static final String OJB_PROPERTIES_FILE = "OJB.properties";
054: /** Default filename of the OJB repository metadata file */
055: public static final String OJB_METADATA_FILE = "repository.xml";
056:
057: /** the repository file keeping the O/R Metadata*/
058: private String repositoryFilename;
059: private Class objectCacheClass;
060: private Class persistentFieldClass;
061: private Class persistenceBrokerClass;
062:
063: // proxy related classes
064: private Class listProxyClass;
065: private Class setProxyClass;
066: private Class collectionProxyClass;
067: private Class indirectionHandlerClass;
068: private Class proxyFactoryClass;
069:
070: // limit for number of values in SQL IN Statement
071: private int sqlInLimit;
072:
073: // PB pooling configuration
074: private int maxActive;
075: private int maxIdle;
076: private long maxWait;
077: private long timeBetweenEvictionRunsMillis;
078: private long minEvictableIdleTimeMillis;
079: private byte whenExhaustedAction;
080:
081: // ODMG configuration
082: private boolean useImplicitLocking;
083: private boolean lockAssociationAsWrites;
084: private Class oqlCollectionClass;
085:
086: // Metadata configuration
087: private boolean useSerializedRepository;
088:
089: public OjbConfiguration() {
090: super ();
091: }
092:
093: public boolean useSerializedRepository() {
094: return useSerializedRepository;
095: }
096:
097: public boolean lockAssociationAsWrites() {
098: return lockAssociationAsWrites;
099: }
100:
101: public String getRepositoryFilename() {
102: return repositoryFilename;
103: }
104:
105: //*************************************************************
106: //PBPoolConfiguration methods
107: public int getMaxActive() {
108: return maxActive;
109: }
110:
111: public int getMaxIdle() {
112: return maxIdle;
113: }
114:
115: public long getMaxWaitMillis() {
116: return maxWait;
117: }
118:
119: public long getTimeBetweenEvictionRunsMilli() {
120: return timeBetweenEvictionRunsMillis;
121: }
122:
123: public long getMinEvictableIdleTimeMillis() {
124: return minEvictableIdleTimeMillis;
125: }
126:
127: public byte getWhenExhaustedAction() {
128: return whenExhaustedAction;
129: }
130:
131: //*************************************************************
132:
133: //*************************************************************
134:
135: public Class getObjectCacheClass() {
136: return objectCacheClass;
137: }
138:
139: public Class getOqlCollectionClass() {
140: return oqlCollectionClass;
141: }
142:
143: public Class getPersistentFieldClass() {
144: return persistentFieldClass;
145: }
146:
147: public Class getPersistenceBrokerClass() {
148: return persistenceBrokerClass;
149: }
150:
151: /**
152: * Returns the indirection handler implementation class.
153: *
154: * @return The indirection handler class
155: * @see org.apache.ojb.broker.core.proxy.IndirectionHandler
156: */
157: public Class getIndirectionHandlerClass() {
158: return indirectionHandlerClass;
159: }
160:
161: /**
162: * Returns the proxy class used for that implement the {@link java.util.List} interface.
163: *
164: * @return The proxy class
165: * @see org.apache.ojb.broker.core.proxy.ProxyFactory#setListProxyClass(Class)
166: */
167: public Class getListProxyClass() {
168: return listProxyClass;
169: }
170:
171: /**
172: * Returns the proxy class used for that implement the {@link java.util.Set} interface.
173: *
174: * @return The proxy class
175: * @see org.apache.ojb.broker.core.proxy.ProxyFactory#setSetProxyClass(Class)
176: */
177: public Class getSetProxyClass() {
178: return setProxyClass;
179: }
180:
181: /**
182: * Returns the proxy class used for that implement the {@link java.util.Collection} interface.
183: *
184: * @return The proxy class
185: * @see org.apache.ojb.broker.core.proxy.ProxyFactory#setCollectionProxyClass(Class)
186: */
187: public Class getCollectionProxyClass() {
188: return collectionProxyClass;
189: }
190:
191: /**
192: * Returns the class that will be used as the proxy factory.
193: *
194: * @return The proxy factory class
195: */
196: public Class getProxyFactoryClass() {
197: return proxyFactoryClass;
198: }
199:
200: /**
201: * Loads the configuration from file "OBJ.properties". If the system
202: * property "OJB.properties" is set, then the configuration in that file is
203: * loaded. Otherwise, the file "OJB.properties" is tried. If that is also
204: * unsuccessful, then the configuration is filled with default values.
205: */
206: protected void load() {
207: // properties file may be set as a System property.
208: // if no property is set take default name.
209: String fn = System.getProperty(OJB_PROPERTIES_FILE,
210: OJB_PROPERTIES_FILE);
211: setFilename(fn);
212: super .load();
213:
214: // default repository & connection descriptor file
215: repositoryFilename = getString("repositoryFile",
216: OJB_METADATA_FILE);
217:
218: // object cache class
219: objectCacheClass = getClass("ObjectCacheClass",
220: ObjectCacheDefaultImpl.class, ObjectCache.class);
221:
222: // load PersistentField Class
223: persistentFieldClass = getClass("PersistentFieldClass",
224: PersistentFieldDirectImpl.class, PersistentField.class);
225:
226: // load PersistenceBroker Class
227: persistenceBrokerClass = getClass("PersistenceBrokerClass",
228: PersistenceBrokerImpl.class, PersistenceBroker.class);
229:
230: // load ListProxy Class
231: listProxyClass = getClass("ListProxyClass",
232: ListProxyDefaultImpl.class);
233:
234: // load SetProxy Class
235: setProxyClass = getClass("SetProxyClass",
236: SetProxyDefaultImpl.class);
237:
238: // load CollectionProxy Class
239: collectionProxyClass = getClass("CollectionProxyClass",
240: CollectionProxyDefaultImpl.class);
241:
242: // load IndirectionHandler Class
243: indirectionHandlerClass = getClass("IndirectionHandlerClass",
244: IndirectionHandlerJDKImpl.class,
245: IndirectionHandler.class);
246:
247: // load ProxyFactory Class
248: proxyFactoryClass = getClass("ProxyFactoryClass",
249: ProxyFactoryJDKImpl.class, ProxyFactory.class);
250:
251: // load configuration for ImplicitLocking parameter:
252: useImplicitLocking = getBoolean("ImplicitLocking", false);
253:
254: // load configuration for LockAssociations parameter:
255: lockAssociationAsWrites = (getString("LockAssociations",
256: "WRITE").equalsIgnoreCase("WRITE"));
257:
258: // load OQL Collection Class
259: oqlCollectionClass = getClass("OqlCollectionClass",
260: DListImpl.class, ManageableCollection.class);
261:
262: // set the limit for IN-sql , -1 for no limits
263: sqlInLimit = getInteger("SqlInLimit", -1);
264:
265: //load configuration for PB pool
266: maxActive = getInteger(PoolConfiguration.MAX_ACTIVE,
267: PoolConfiguration.DEFAULT_MAX_ACTIVE);
268: maxIdle = getInteger(PoolConfiguration.MAX_IDLE,
269: PoolConfiguration.DEFAULT_MAX_IDLE);
270: maxWait = getLong(PoolConfiguration.MAX_WAIT,
271: PoolConfiguration.DEFAULT_MAX_WAIT);
272: timeBetweenEvictionRunsMillis = getLong(
273: PoolConfiguration.TIME_BETWEEN_EVICTION_RUNS_MILLIS,
274: PoolConfiguration.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
275: minEvictableIdleTimeMillis = getLong(
276: PoolConfiguration.MIN_EVICTABLE_IDLE_TIME_MILLIS,
277: PoolConfiguration.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
278: whenExhaustedAction = getByte(
279: PoolConfiguration.WHEN_EXHAUSTED_ACTION,
280: PoolConfiguration.DEFAULT_WHEN_EXHAUSTED_ACTION);
281:
282: useSerializedRepository = getBoolean("useSerializedRepository",
283: false);
284: }
285:
286: /**
287: * Returns the SQLInLimit.
288: * @return int
289: */
290: public int getSqlInLimit() {
291: return sqlInLimit;
292: }
293:
294: /**
295: * Sets the persistentFieldClass.
296: * @param persistentFieldClass The persistentFieldClass to set
297: */
298: public void setPersistentFieldClass(Class persistentFieldClass) {
299: this .persistentFieldClass = persistentFieldClass;
300: }
301:
302: /**
303: * @see org.apache.ojb.odmg.OdmgConfiguration#useImplicitLocking()
304: */
305: public boolean useImplicitLocking() {
306: return useImplicitLocking;
307: }
308:
309: public void setUseImplicitLocking(boolean implicitLocking) {
310: this.useImplicitLocking = implicitLocking;
311: }
312:
313: }
|