You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by to...@apache.org on 2004/11/14 10:34:27 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/core/factory Initializable.java ObjectCreator.java ObjectFactoryException.java ObjectFactory.java ObjectFactoryDefaultImpl.java
tomdz 2004/11/14 01:34:27
Modified: src/java/org/apache/ojb/broker/core/proxy
SetProxyDefaultImpl.java ListProxyDefaultImpl.java
VirtualProxy.java ProxyFactory.java
src/java/org/apache/ojb/broker/core
PersistenceBrokerImpl.java
PersistenceBrokerFactoryDefaultImpl.java
PersistenceBrokerFactoryIF.java
QueryReferenceBroker.java
PersistenceBrokerAbstractImpl.java
PersistenceBrokerFactorySyncImpl.java
DelegatingPersistenceBroker.java
PersistenceBrokerFactoryBaseImpl.java
PersistenceBrokerConfiguration.java PBPoolInfo.java
src/java/org/apache/ojb/broker/core/factory
ObjectFactoryException.java ObjectFactory.java
ObjectFactoryDefaultImpl.java
Added: src/java/org/apache/ojb/broker/core/proxy SetProxy.java
ListProxy.java
src/java/org/apache/ojb/broker/core/factory
Initializable.java ObjectCreator.java
Log:
Reworked the OJB core:
- replaced the factories/configuration concept with the ComponentContainer
- removal of most static calls within OJB
- removed the old "D" collection implementations and renamed the new ones
- moved StatementForClassIF handling to the PersistenceConfiguration
- moved RowReader caching from the ClassDescriptor to the PersistenceConfiguration
and other changes (see mail on the dev list for more details)
Revision Changes Path
1.3 +2 -2 db-ojb/src/java/org/apache/ojb/broker/core/proxy/SetProxyDefaultImpl.java
Index: SetProxyDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/SetProxyDefaultImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SetProxyDefaultImpl.java 25 Sep 2004 14:54:56 -0000 1.2
+++ SetProxyDefaultImpl.java 14 Nov 2004 09:34:27 -0000 1.3
@@ -30,7 +30,7 @@
* @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
* @version $Id$
*/
-public class SetProxyDefaultImpl extends CollectionProxyDefaultImpl implements Set
+public class SetProxyDefaultImpl extends CollectionProxyDefaultImpl implements SetProxy
{
private static final long serialVersionUID = 3227956140301449558L;
1.3 +2 -2 db-ojb/src/java/org/apache/ojb/broker/core/proxy/ListProxyDefaultImpl.java
Index: ListProxyDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/ListProxyDefaultImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ListProxyDefaultImpl.java 25 Sep 2004 14:54:56 -0000 1.2
+++ ListProxyDefaultImpl.java 14 Nov 2004 09:34:27 -0000 1.3
@@ -31,7 +31,7 @@
* @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
* @version $Id$
*/
-public class ListProxyDefaultImpl extends CollectionProxyDefaultImpl implements List
+public class ListProxyDefaultImpl extends CollectionProxyDefaultImpl implements ListProxy
{
private static final long serialVersionUID = 3314811873722031320L;
1.3 +5 -57 db-ojb/src/java/org/apache/ojb/broker/core/proxy/VirtualProxy.java
Index: VirtualProxy.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/VirtualProxy.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- VirtualProxy.java 11 Aug 2004 00:41:44 -0000 1.2
+++ VirtualProxy.java 14 Nov 2004 09:34:27 -0000 1.3
@@ -18,18 +18,8 @@
import org.apache.ojb.broker.Identity;
-import org.apache.ojb.broker.PBKey;
import org.apache.ojb.broker.PersistenceBrokerException;
-import java.lang.reflect.Constructor;
-//#ifdef JDK13
-import java.lang.reflect.InvocationHandler;
-//#else
-/*
-import com.develop.java.lang.reflect.InvocationHandler;
-*/
-//#endif
-
/**
* Proxy base class. can be used to implement lazy materialization techniques.
@@ -40,8 +30,8 @@
*/
public abstract class VirtualProxy implements java.io.Serializable
{
- static final long serialVersionUID = -3999451313262635171L; /**
- * reference to the IndirectionHandler that encapsulates the delegation mechanism */
+ static final long serialVersionUID = -3999451313262635171L;
+ /** Reference to the IndirectionHandler that encapsulates the delegation mechanism */
private IndirectionHandler indirectionHandler = null;
/**
@@ -51,25 +41,13 @@
{}
/**
- * Creates a VirtualProxy for the subject with the given identity.
- *
- * @param key The key of the PersistenceBroker
- * @param oid The identity of the subject
- */
- public VirtualProxy(PBKey key, Identity oid)
- {
- indirectionHandler = ProxyFactory.createIndirectionHandler(key, oid);
- }
-
- /**
* Create a VirtualProxy that uses the given invocation handler.
- * [tomdz] Why here the use of InvocationHandler ?
*
* @param handler The indirection handler of the proxy
*/
- public VirtualProxy(InvocationHandler handler)
+ public VirtualProxy(IndirectionHandler handler)
{
- indirectionHandler = (IndirectionHandler)handler;
+ indirectionHandler = handler;
}
/**
@@ -92,36 +70,6 @@
{
return indirectionHandler.alreadyMaterialized();
}
-
- /**
- * Creates VirtualProxy instances of a given proxy subclass and the real subject's identity.
- *
- * @param key The key of the PersistenceBroker
- * @param proxyClass The Proxy class
- * @param realSubjectsIdentity The identity of the subject
- * @return An instance of the proxy subclass
- * @throws PersistenceBrokerException If there is an error creating the proxy object
- */
- public static Object createProxy(PBKey key, Class proxyClass, Identity realSubjectsIdentity)
- {
- try
- {
- // the invocation handler manages all delegation stuff
- IndirectionHandler handler = ProxyFactory.createIndirectionHandler(key, realSubjectsIdentity);
-
- // the proxy simply provides the interface of the real subject
- // [tomdz] Perhaps we should define an interface that the proxy class should provide ?
- Constructor constructor = proxyClass.getDeclaredConstructor(new Class[]{ InvocationHandler.class });
- Object result = constructor.newInstance(new Object[]{ handler });
-
- return result;
- }
- catch (Exception ex)
- {
- throw new PersistenceBrokerException("Unable to create proxy using class:"+proxyClass.getName(), ex);
- }
- }
-
/**
* Returns the proxies real subject. The subject will be materialized if necessary.
1.2 +21 -48 db-ojb/src/java/org/apache/ojb/broker/core/proxy/ProxyFactory.java
Index: ProxyFactory.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/ProxyFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProxyFactory.java 9 Apr 2004 13:22:29 -0000 1.1
+++ ProxyFactory.java 14 Nov 2004 09:34:27 -0000 1.2
@@ -28,7 +28,6 @@
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.metadata.MetadataException;
import org.apache.ojb.broker.query.Query;
-import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
/**
* Factory class for creating instances of the indirection handler used by OJB's proxies, and
@@ -40,35 +39,21 @@
public class ProxyFactory
{
/** The class to be used for indirection handler instances */
- private static Constructor _indirectionHandlerConstructor;
+ private Constructor _indirectionHandlerConstructor;
/** The constructor used for creating list proxies */
- private static Constructor _listProxyConstructor;
+ private Constructor _listProxyConstructor;
/** The constructor used for creating set proxies */
- private static Constructor _setProxyConstructor;
+ private Constructor _setProxyConstructor;
/** The constructor used for creating collection proxies */
- private static Constructor _collectionProxyConstructor;
-
- /**
- * Returns the configuration object for proxies.
- *
- * @return The configuration object
- */
- private static ProxyConfiguration getProxyConfiguration()
- {
- return (ProxyConfiguration)OjbConfigurator.getInstance().getConfigurationFor(null);
- }
+ private Constructor _collectionProxyConstructor;
/**
* Returns the constructor of the indirection handler class.
*
* @return The constructor for indirection handlers
*/
- private static Constructor getIndirectionHandlerConstructor()
+ private Constructor getIndirectionHandlerConstructor()
{
- if (_indirectionHandlerConstructor == null)
- {
- setIndirectionHandlerClass(getProxyConfiguration().getIndirectionHandlerClass());
- }
return _indirectionHandlerConstructor;
}
@@ -77,7 +62,7 @@
*
* @return The class for indirection handlers
*/
- public static Class getIndirectionHandlerClass()
+ public Class getIndirectionHandlerClass()
{
return getIndirectionHandlerConstructor().getDeclaringClass();
}
@@ -87,7 +72,7 @@
*
* @param indirectionHandlerClass The class for indirection handlers
*/
- public static void setIndirectionHandlerClass(Class indirectionHandlerClass)
+ public void setIndirectionHandlerClass(Class indirectionHandlerClass)
{
if (indirectionHandlerClass == null)
{
@@ -121,7 +106,7 @@
* @param id The subject's ids
* @return The new instance
*/
- public static IndirectionHandler createIndirectionHandler(PBKey brokerKey, Identity id)
+ public IndirectionHandler createIndirectionHandler(PBKey brokerKey, Identity id)
{
Object args[] = { brokerKey, id };
@@ -152,7 +137,7 @@
* @param typeDesc The type of collection proxy
* @return The constructor
*/
- private static Constructor retrieveCollectionProxyConstructor(Class proxyClass, Class baseType, String typeDesc)
+ private Constructor retrieveCollectionProxyConstructor(Class proxyClass, Class baseType, String typeDesc)
{
if (proxyClass == null)
{
@@ -184,7 +169,7 @@
*
* @return The class used for list proxies
*/
- public static Class getListProxyClass()
+ public Class getListProxyClass()
{
return getListProxyConstructor().getDeclaringClass();
}
@@ -194,12 +179,8 @@
*
* @return The constructor for list proxies
*/
- private static Constructor getListProxyConstructor()
+ private Constructor getListProxyConstructor()
{
- if (_listProxyConstructor == null)
- {
- setListProxyClass(getProxyConfiguration().getListProxyClass());
- }
return _listProxyConstructor;
}
@@ -210,7 +191,7 @@
*
* @param listProxyClass The proxy class
*/
- public static void setListProxyClass(Class listProxyClass)
+ public void setListProxyClass(Class listProxyClass)
{
_listProxyConstructor = retrieveCollectionProxyConstructor(listProxyClass, List.class, "ListProxyClass");
}
@@ -220,7 +201,7 @@
*
* @return The class used for set proxies
*/
- public static Class getSetProxyClass()
+ public Class getSetProxyClass()
{
return getSetProxyConstructor().getDeclaringClass();
}
@@ -230,12 +211,8 @@
*
* @return The constructor for set proxies
*/
- private static Constructor getSetProxyConstructor()
+ private Constructor getSetProxyConstructor()
{
- if (_setProxyConstructor == null)
- {
- setSetProxyClass(getProxyConfiguration().getSetProxyClass());
- }
return _setProxyConstructor;
}
@@ -244,7 +221,7 @@
*
* @param setProxyClass The proxy class
*/
- public static void setSetProxyClass(Class setProxyClass)
+ public void setSetProxyClass(Class setProxyClass)
{
_setProxyConstructor = retrieveCollectionProxyConstructor(setProxyClass, Set.class, "SetProxyClass");
}
@@ -254,7 +231,7 @@
*
* @return The class used for collection proxies
*/
- public static Class getCollectionProxyClass()
+ public Class getCollectionProxyClass()
{
return getCollectionProxyConstructor().getDeclaringClass();
}
@@ -264,12 +241,8 @@
*
* @return The constructor for collection proxies
*/
- private static Constructor getCollectionProxyConstructor()
+ private Constructor getCollectionProxyConstructor()
{
- if (_collectionProxyConstructor == null)
- {
- setCollectionProxyClass(getProxyConfiguration().getCollectionProxyClass());
- }
return _collectionProxyConstructor;
}
@@ -278,7 +251,7 @@
*
* @param collectionProxyClass The proxy class
*/
- public static void setCollectionProxyClass(Class collectionProxyClass)
+ public void setCollectionProxyClass(Class collectionProxyClass)
{
_collectionProxyConstructor = retrieveCollectionProxyConstructor(collectionProxyClass, Collection.class, "CollectionProxyClass");
// we also require the class to be a subclass of ManageableCollection
@@ -296,7 +269,7 @@
* @param collectionClass The collection class
* @return The constructor of the proxy class
*/
- private static Constructor getCollectionProxyConstructor(Class collectionClass)
+ private Constructor getCollectionProxyConstructor(Class collectionClass)
{
if (List.class.isAssignableFrom(collectionClass))
{
@@ -320,7 +293,7 @@
* @param collectionClass The class to build the proxy for
* @return The collection proxy
*/
- public static ManageableCollection createCollectionProxy(PBKey brokerKey, Query query, Class collectionClass)
+ public ManageableCollection createCollectionProxy(PBKey brokerKey, Query query, Class collectionClass)
{
Object args[] = { brokerKey, collectionClass, query };
1.1 db-ojb/src/java/org/apache/ojb/broker/core/proxy/SetProxy.java
Index: SetProxy.java
===================================================================
package org.apache.ojb.broker.core.proxy;
import java.util.Set;
/**
* Interface which set proxies need to implement to be
* treated like collection proxies in ODMG.
* <p>
* Presently the collection proxy impl class can be plugged in and
* not implement this interface, but those implementations will
* *not* be treated as proxies by OJB
*
* @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
*/
public interface SetProxy extends CollectionProxy, Set
{
}
1.1 db-ojb/src/java/org/apache/ojb/broker/core/proxy/ListProxy.java
Index: ListProxy.java
===================================================================
package org.apache.ojb.broker.core.proxy;
import java.util.List;
/**
* Interface which list proxies need to implement to be
* treated like collection proxies in ODMG.
* <p>
* Presently the collection proxy impl class can be plugged in and
* not implement this interface, but those implementations will
* *not* be treated as proxies by OJB
*
* @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
*/
public interface ListProxy extends CollectionProxy, List
{
}
1.98 +166 -46 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Index: PersistenceBrokerImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -r1.97 -r1.98
--- PersistenceBrokerImpl.java 12 Nov 2004 00:15:59 -0000 1.97
+++ PersistenceBrokerImpl.java 14 Nov 2004 09:34:27 -0000 1.98
@@ -15,6 +15,8 @@
* limitations under the License.
*/
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -42,22 +44,31 @@
import org.apache.ojb.broker.accesslayer.OJBIterator;
import org.apache.ojb.broker.accesslayer.PagingIterator;
import org.apache.ojb.broker.accesslayer.PkEnumeration;
+import org.apache.ojb.broker.accesslayer.RowReader;
import org.apache.ojb.broker.accesslayer.RsIteratorFactory;
import org.apache.ojb.broker.accesslayer.RsIteratorFactoryFactory;
import org.apache.ojb.broker.accesslayer.StatementManagerIF;
import org.apache.ojb.broker.accesslayer.batch.BatchManager;
+import org.apache.ojb.broker.accesslayer.batch.BatchStrategy;
import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
import org.apache.ojb.broker.cache.LocalCache;
import org.apache.ojb.broker.cache.ObjectCache;
+import org.apache.ojb.broker.core.configuration.ComponentContainer;
import org.apache.ojb.broker.core.proxy.CollectionProxy;
+import org.apache.ojb.broker.core.proxy.IndirectionHandler;
+import org.apache.ojb.broker.core.proxy.ProxyFactory;
import org.apache.ojb.broker.core.proxy.ProxyHelper;
+import org.apache.ojb.broker.core.proxy.VirtualProxy;
+import org.apache.ojb.broker.metadata.BatchDescriptor;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
import org.apache.ojb.broker.metadata.DescriptorRepository;
import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
import org.apache.ojb.broker.metadata.MetadataManager;
import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryByCriteria;
@@ -71,7 +82,6 @@
import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.broker.util.sequence.SequenceManager;
import org.apache.ojb.broker.util.sequence.SequenceManagerException;
-import org.apache.ojb.broker.util.sequence.SequenceManagerFactory;
/**
* The PersistenceBrokerImpl is an implementation of the PersistenceBroker
@@ -92,10 +102,11 @@
private Logger logger = LoggerFactory.getLogger(PersistenceBrokerImpl.class);
protected PersistenceConfiguration persistenceConfiguration;
- protected PersistenceBrokerFactoryIF pbf;
protected BrokerHelper brokerHelper;
protected MtoNBroker mtoNBroker;
protected QueryReferenceBroker referencesBroker;
+ /** The proxy factory */
+ private ProxyFactory proxyFactory;
/**
* signs if this broker was closed
@@ -113,6 +124,9 @@
* m_DbAccess is used to do all Jdbc related work: connecting, executing...
*/
private BatchManager dbAccess;
+
+ /** Local container */
+ private ComponentContainer subContainer;
/**
* holds mapping information for all classes to be treated by PersistenceBroker
*/
@@ -163,52 +177,79 @@
*/
private Set deletedDuringTransaction = new HashSet();
+ /** The maximum number of prefetched objects */
+ private int sqlInLimit = 200;
+
/**
* Constructor used by {@link PersistenceBrokerFactoryIF} implementation.
*/
- public PersistenceBrokerImpl(PersistenceConfiguration persistenceConfiguration, PersistenceBrokerFactoryIF pbf)
+ public PersistenceBrokerImpl(ComponentContainer container, PersistenceConfiguration pc)
{
- this.persistenceConfiguration = persistenceConfiguration;
- this.pbf = pbf;
- Factories factories = persistenceConfiguration.getOjb().getFactories();
- /*
- be careful when changing initializing order
- */
+ persistenceConfiguration = pc;
+ subContainer = container.createChildContainer();
+
+ JdbcConnectionDescriptor jcd = pc.getJdbcConnectionDescriptor();
+ SequenceDescriptor seqDesc = jcd.getSequenceDescriptor();
+ BatchDescriptor batchDesc = jcd.getBatchDescriptor();
+
+ subContainer.setSingletonInstance(this);
+
+ // we check whether the sequence descriptor declares a different sequence manager
+ if ((seqDesc != null) && (seqDesc.getSequenceManagerClass() != null))
+ {
+ // if a seqMan was defined in repository, use that
+ Class seqManClass = seqDesc.getSequenceManagerClass();
+
+ subContainer.setImplementationClass(SequenceManager.class, seqManClass);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Jdbc-Connection-Descriptor '" + jcd.getJcdAlias() + "' use sequence manager: " + seqManClass);
+ }
+ }
+ if (batchDesc != null)
+ {
+ if (batchDesc.getBatchManager() != null)
+ {
+ subContainer.setImplementationClass(BatchManager.class, batchDesc.getBatchManager());
+ }
+ if (batchDesc.getBatchStrategy() != null)
+ {
+ subContainer.setImplementationClass(BatchStrategy.class, batchDesc.getBatchStrategy());
+ }
+ }
+
brokerHelper = new BrokerHelper(this);
- connectionManager = factories.getConnectionManagerFactory().createConnectionManager(this);
- sequenceManager = SequenceManagerFactory.getSequenceManager(this);
- dbAccess = factories.getBatchManagerFactory().createBatchManager(this);
- statementManager = factories.getStatementManagerFactory().createStatementManager(this);
- sqlGenerator = factories.getSqlGeneratorFactory().createSqlGenerator(connectionManager.getSupportedPlatform());
- mtoNBroker = new MtoNBroker(this);
- referencesBroker = new QueryReferenceBroker(this);
- identityFactory = factories.getIdentityFactoryFactory().createIdentityFactory(this);
- localCache = factories.getLocalCacheFactory().createLocalCache(this);
- }
+ dbAccess = (BatchManager)subContainer.getSingletonInstance(BatchManager.class);
+ dbAccess.setStrategy((BatchStrategy)subContainer.getInstance(BatchStrategy.class));
- public PersistenceBrokerFactoryIF ojbPersistenceBrokerFactory()
- {
- return this.pbf;
+ connectionManager = (ConnectionManagerIF)subContainer.getSingletonInstance(ConnectionManagerIF.class);
+ identityFactory = (IdentityFactory)subContainer.getSingletonInstance(IdentityFactory.class);
+ statementManager = (StatementManagerIF)subContainer.getSingletonInstance(StatementManagerIF.class);
+ sqlGenerator = (SqlGenerator)subContainer.getSingletonInstance(SqlGenerator.class);
+ mtoNBroker = new MtoNBroker(this);
+ referencesBroker = new QueryReferenceBroker(this);
+ localCache = (LocalCache)subContainer.getSingletonInstance(LocalCache.class);
+ proxyFactory = (ProxyFactory)subContainer.getSingletonInstance(ProxyFactory.class);
}
-
+
public LocalCache ojbLocalCache()
{
return this.localCache;
}
- public BatchManager ojbBatchManager()
+ public BatchManager getBatchManager()
{
return dbAccess;
}
public IdentityFactory serviceIdentity()
{
- return this.identityFactory;
+ return identityFactory;
}
public SqlGenerator serviceSqlGenerator()
{
- return this.sqlGenerator;
+ return sqlGenerator;
}
public StatementManagerIF serviceStatementManager()
@@ -218,7 +259,7 @@
public JdbcAccess serviceJdbcAccess()
{
- return dbAccess;
+ return getBatchManager();
}
public ConnectionManagerIF serviceConnectionManager()
@@ -228,12 +269,16 @@
public SequenceManager serviceSequenceManager()
{
- return this.sequenceManager;
+ if (sequenceManager == null)
+ {
+ sequenceManager = (SequenceManager)subContainer.getSingletonInstance(SequenceManager.class);
+ }
+ return sequenceManager;
}
public BrokerHelper serviceBrokerHelper()
{
- return this.brokerHelper;
+ return brokerHelper;
}
public ObjectCache serviceObjectCache()
@@ -243,9 +288,14 @@
public QueryReferenceBroker getReferenceBroker()
{
- return this.referencesBroker;
+ return referencesBroker;
}
+ public ProxyFactory getProxyFactory()
+ {
+ return proxyFactory;
+ }
+
public boolean isClosed()
{
return this.isClosed;
@@ -253,11 +303,31 @@
public void setClosed(boolean closed)
{
- if(closed == false)
+ if (closed == false)
{
refresh();
}
- this.isClosed = closed;
+ isClosed = closed;
+ }
+
+ /**
+ * Returns the maximum number of sql columns.
+ *
+ * @return The sql limit
+ */
+ public int getSqlInLimit()
+ {
+ return sqlInLimit;
+ }
+
+ /**
+ * Sets the maximum number of sql columns.
+ *
+ * @param sqlInLimit The new sql limit
+ */
+ public void setSqlInLimit(int sqlInLimit)
+ {
+ this.sqlInLimit = sqlInLimit;
}
/**
@@ -289,7 +359,6 @@
}
this.setClosed(true);
- this.pbf = null;
this.connectionManager = null;
this.dbAccess = null;
this.localCache = null;
@@ -305,7 +374,50 @@
public PersistenceConfiguration getConfiguration()
{
- return this.persistenceConfiguration;
+ return persistenceConfiguration;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.ojb.broker.PersistenceBrokerInternal#getRowReaderFor(org.apache.ojb.broker.metadata.ClassDescriptor)
+ */
+ public RowReader getRowReaderFor(ClassDescriptor classDesc)
+ {
+ return persistenceConfiguration.getRowReaderForClass(classDesc);
+ }
+
+ /**
+ * Creates a proxy instance.
+ *
+ * @param proxyClass The Proxy class
+ * @param realSubjectsIdentity The identity of the subject
+ * @return An instance of the proxy subclass
+ * @throws PersistenceBrokerException If there is an error creating the proxy object
+ */
+ public Object createProxy(Class proxyClass, Identity realSubjectsIdentity)
+ {
+ try
+ {
+ // the invocation handler manages all delegation stuff
+ IndirectionHandler handler = getProxyFactory().createIndirectionHandler(getPBKey(), realSubjectsIdentity);
+ Constructor constructor = null;
+
+ // the proxy simply provides the interface of the real subject
+ if (VirtualProxy.class.isAssignableFrom(proxyClass))
+ {
+ constructor = proxyClass.getDeclaredConstructor(new Class[]{ IndirectionHandler.class });
+ }
+ else
+ {
+ constructor = proxyClass.getDeclaredConstructor(new Class[]{ InvocationHandler.class });
+ }
+
+ return constructor.newInstance(new Object[]{ handler });
+ }
+ catch (Exception ex)
+ {
+ throw new PersistenceBrokerException("Unable to create proxy using class:"+proxyClass.getName(), ex);
+ }
}
/**
@@ -506,7 +618,7 @@
deleteCollections(obj, cld.getCollectionDescriptors());
}
// 2. delete object from directly mapped table
- dbAccess.executeDelete(cld, obj); // use obj not oid to delete, BRJ
+ getBatchManager().executeDelete(cld, obj); // use obj not oid to delete, BRJ
// 3. Add OID to the set of deleted objects
deletedDuringTransaction.add(oid);
@@ -542,7 +654,7 @@
if (query instanceof QueryBySQL)
{
String sql = ((QueryBySQL) query).getSql();
- this.dbAccess.executeUpdateSQL(sql, cld);
+ getBatchManager().executeUpdateSQL(sql, cld);
}
else
{
@@ -561,7 +673,7 @@
if (!cld.isInterface())
{
- this.dbAccess.executeDelete(query, cld);
+ getBatchManager().executeDelete(query, cld);
}
// if class is an extent, we have to delete all extent classes too
@@ -578,7 +690,7 @@
if (!extCld.getFullTableName().equals(lastUsedTable))
{
lastUsedTable = extCld.getFullTableName();
- this.dbAccess.executeDelete(query, extCld);
+ getBatchManager().executeDelete(query, extCld);
}
}
}
@@ -1236,7 +1348,7 @@
if (!cld.isInterface())
{
// 1. try to retrieve skalar fields from directly mapped table columns
- newObj = dbAccess.materializeObject(cld, oid);
+ newObj = getBatchManager().materializeObject(cld, oid);
}
// if we did not find the object yet AND if the cld represents an Extent,
@@ -1249,7 +1361,7 @@
{
ClassDescriptor extCld = (ClassDescriptor) extents.next();
- newObj = dbAccess.materializeObject(extCld, oid);
+ newObj = getBatchManager().materializeObject(extCld, oid);
if (newObj != null)
{
break;
@@ -1564,7 +1676,7 @@
fireBrokerEvent(BEFORE_UPDATE_EVENT);
BEFORE_UPDATE_EVENT.setTarget(null);
- dbAccess.executeUpdate(cld, fields, realObject);
+ getBatchManager().executeUpdate(cld, fields, realObject);
Identity oid = serviceIdentity().buildIdentity(cld, realObject);
ojbLocalCache().cache(oid, realObject);
@@ -1742,7 +1854,7 @@
// setreferenceFKs for auto_inc dbs - this can be ignored by hi low or any that do pre assignment
try
{
- sequenceManager.setReferenceFKs(obj, cld);
+ serviceSequenceManager().setReferenceFKs(obj, cld);
}
catch (SequenceManagerException e)
{
@@ -1771,11 +1883,11 @@
// if obj not present in db use INSERT
if (insert)
{
- dbAccess.executeInsert(cld, obj);
+ getBatchManager().executeInsert(cld, obj);
// Let SequenceManager update id if necessary, should only happen after an insert
try
{
- sequenceManager.afterStore(dbAccess, cld, obj);
+ sequenceManager.afterStore(getBatchManager(), cld, obj);
}
catch (SequenceManagerException e)
{
@@ -1787,7 +1899,7 @@
// else use UPDATE
else
{
- dbAccess.executeUpdate(cld, obj);
+ getBatchManager().executeUpdate(cld, obj);
}
// Create a new Identity based on the current set of primary key values.
Identity newOid = new Identity(obj, this, cld);
@@ -1981,6 +2093,14 @@
}
return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ojb.broker.PersistenceBrokerInternal#createCollection(java.lang.Class)
+ */
+ public ManageableCollection createCollection(Class collectionClass)
+ {
+ return (ManageableCollection)subContainer.getInstance(collectionClass);
}
/**
1.13 +6 -6 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactoryDefaultImpl.java
Index: PersistenceBrokerFactoryDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactoryDefaultImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- PersistenceBrokerFactoryDefaultImpl.java 11 Aug 2004 00:41:45 -0000 1.12
+++ PersistenceBrokerFactoryDefaultImpl.java 14 Nov 2004 09:34:27 -0000 1.13
@@ -30,6 +30,7 @@
import org.apache.ojb.broker.PersistenceConfiguration;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.broker.util.pooling.PoolConfiguration;
/**
* This is the default implementation of the {@link PersistenceBrokerFactoryIF}
@@ -62,15 +63,14 @@
{
private Logger log = LoggerFactory.getLogger(PersistenceBrokerFactoryDefaultImpl.class);
private GenericObjectPool brokerPool;
- private PBPoolInfo poolConfig;
+ private PoolConfiguration poolConfig;
- public PersistenceBrokerFactoryDefaultImpl(PersistenceConfiguration persistenceConfiguration)
+ public PersistenceBrokerFactoryDefaultImpl(PersistenceConfiguration persistenceConfiguration, PoolConfiguration poolConfig)
{
super(persistenceConfiguration);
- // get PB-pool configuration properties from OJB.properties
- poolConfig = new PBPoolInfo();
+ this.poolConfig = poolConfig;
// setup pool for PB instances
- brokerPool = this.createPool();
+ brokerPool = createPool();
log.info("Create PersistenceBroker instance pool for "
+ getConfiguration().getKey() + ", pool configuration was " + getPoolConfiguration());
}
1.6 +2 -3 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactoryIF.java
Index: PersistenceBrokerFactoryIF.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactoryIF.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PersistenceBrokerFactoryIF.java 11 Aug 2004 00:41:45 -0000 1.5
+++ PersistenceBrokerFactoryIF.java 14 Nov 2004 09:34:27 -0000 1.6
@@ -17,7 +17,6 @@
import org.apache.ojb.broker.PBFactoryException;
import org.apache.ojb.broker.PersistenceBroker;
-import org.apache.ojb.broker.util.configuration.Configurable;
/**
* Factory for {@link PersistenceBroker} instances.
@@ -26,7 +25,7 @@
* @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
* @version $Id$
*/
-public interface PersistenceBrokerFactoryIF extends Configurable
+public interface PersistenceBrokerFactoryIF
{
/**
* Return an {@link org.apache.ojb.broker.PersistenceBroker} instance.
1.23 +5 -19 db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
Index: QueryReferenceBroker.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- QueryReferenceBroker.java 12 Nov 2004 00:15:59 -0000 1.22
+++ QueryReferenceBroker.java 14 Nov 2004 09:34:27 -0000 1.23
@@ -35,9 +35,7 @@
import org.apache.ojb.broker.core.proxy.CollectionProxyListener;
import org.apache.ojb.broker.core.proxy.IndirectionHandler;
import org.apache.ojb.broker.core.proxy.MaterializationListener;
-import org.apache.ojb.broker.core.proxy.ProxyFactory;
import org.apache.ojb.broker.core.proxy.ProxyHelper;
-import org.apache.ojb.broker.core.proxy.VirtualProxy;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
@@ -108,7 +106,7 @@
try
{
- result = (ManageableCollection) collectionClass.newInstance();
+ result = pb.createCollection(collectionClass);
// now iterate over all elements and add them to the new collection
iter = pb.getIteratorFromQuery(query, cld);
@@ -168,18 +166,6 @@
classToPrefetch = saveClassToPrefetch;
}
}
- catch (InstantiationException ex)
- {
- log.error(ex);
- pb.ojbLocalCache().reset(false);
- throw new PersistenceBrokerException(ex);
- }
- catch (IllegalAccessException ex)
- {
- log.error(ex);
- pb.ojbLocalCache().reset(false);
- throw new PersistenceBrokerException(ex);
- }
catch(RuntimeException e)
{
// catch runtime exc. to guarantee clearing of internal buffer on failure
@@ -229,13 +215,13 @@
// BRJ: return empty Collection for null query
if (query == null)
{
- result = (ManageableCollection)collectionClass.newInstance();
+ result = pb.createCollection(collectionClass);
}
else
{
if (lazy)
{
- result = ProxyFactory.createCollectionProxy(pb.getPBKey(), query, collectionClass);
+ result = pb.getProxyFactory().createCollectionProxy(pb.getPBKey(), query, collectionClass);
}
else
{
@@ -551,7 +537,7 @@
{
try
{
- return VirtualProxy.createProxy(pb.getPBKey(), referencedProxy, id);
+ return pb.createProxy(referencedProxy, id);
}
catch (Exception e)
{
1.7 +3 -15 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java
Index: PersistenceBrokerAbstractImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PersistenceBrokerAbstractImpl.java 4 Apr 2004 23:53:33 -0000 1.6
+++ PersistenceBrokerAbstractImpl.java 14 Nov 2004 09:34:27 -0000 1.7
@@ -20,12 +20,10 @@
import org.apache.ojb.broker.PBListener;
import org.apache.ojb.broker.PBStateEvent;
import org.apache.ojb.broker.PBStateListener;
-import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerEvent;
import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
import org.apache.ojb.broker.util.logging.LoggerFactory;
-import org.apache.ojb.broker.util.configuration.Configuration;
-import org.apache.ojb.broker.util.configuration.ConfigurationException;
/**
* Abstract Implementation of the {@link org.apache.ojb.broker.PersistenceBroker}
@@ -40,7 +38,7 @@
* @author Armin Waibel
* @version $Id$
*/
-public abstract class PersistenceBrokerAbstractImpl implements PersistenceBroker
+public abstract class PersistenceBrokerAbstractImpl implements PersistenceBrokerInternal
{
private static final PBStateListener[] NO_STATE_LISTENERS = new PBStateListener[0];
private static final PBLifeCycleListener[] NO_LIFECYCLE_LISTENERS = new PBLifeCycleListener[0];
@@ -68,16 +66,6 @@
* instances.
*/
private PBLifeCycleListener[] temporaryLifeCycleListeners = NO_LIFECYCLE_LISTENERS;
-
- /**
- * Override if needed.
- *
- * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration pConfig) throws ConfigurationException
- {
- // noop
- }
/**
* @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener listener)
1.10 +6 -5 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java
Index: PersistenceBrokerFactorySyncImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PersistenceBrokerFactorySyncImpl.java 11 Aug 2004 00:41:45 -0000 1.9
+++ PersistenceBrokerFactorySyncImpl.java 14 Nov 2004 09:34:27 -0000 1.10
@@ -37,10 +37,11 @@
import org.apache.ojb.broker.TransactionNotInProgressException;
import org.apache.ojb.broker.PersistenceConfiguration;
import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
+import org.apache.ojb.broker.transaction.tm.TransactionManagerFactory;
import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
-import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryFactory;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.broker.util.pooling.PoolConfiguration;
/**
* Workaround for participate the PB-api in JTA {@link javax.transaction.Transaction transaction} by
@@ -65,12 +66,12 @@
private TransactionManager txMan;
private TxRegistry txRegistry;
- public PersistenceBrokerFactorySyncImpl(PersistenceConfiguration configuration)
+ public PersistenceBrokerFactorySyncImpl(PersistenceConfiguration configuration, PoolConfiguration poolConfig, TransactionManagerFactory factory)
{
- super(configuration);
+ super(configuration, poolConfig);
try
{
- txMan = TransactionManagerFactoryFactory.instance().getTransactionManager();
+ txMan = factory.getTransactionManager();
}
catch (TransactionManagerFactoryException e)
{
1.15 +46 -19 db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java
Index: DelegatingPersistenceBroker.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DelegatingPersistenceBroker.java 14 Sep 2004 16:16:35 -0000 1.14
+++ DelegatingPersistenceBroker.java 14 Nov 2004 09:34:27 -0000 1.15
@@ -7,6 +7,7 @@
import org.apache.ojb.broker.IdentityFactory;
import org.apache.ojb.broker.ManageableCollection;
import org.apache.ojb.broker.MtoNImplementor;
+import org.apache.ojb.broker.OJBRuntimeException;
import org.apache.ojb.broker.PBKey;
import org.apache.ojb.broker.PBLifeCycleEvent;
import org.apache.ojb.broker.PBListener;
@@ -15,6 +16,7 @@
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerEvent;
import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
import org.apache.ojb.broker.PersistenceConfiguration;
import org.apache.ojb.broker.TransactionAbortedException;
import org.apache.ojb.broker.TransactionInProgressException;
@@ -22,16 +24,17 @@
import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
import org.apache.ojb.broker.accesslayer.JdbcAccess;
import org.apache.ojb.broker.accesslayer.OJBIterator;
+import org.apache.ojb.broker.accesslayer.RowReader;
import org.apache.ojb.broker.accesslayer.StatementManagerIF;
+import org.apache.ojb.broker.accesslayer.batch.BatchManager;
import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
import org.apache.ojb.broker.cache.ObjectCache;
+import org.apache.ojb.broker.core.proxy.ProxyFactory;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.DescriptorRepository;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.util.BrokerHelper;
import org.apache.ojb.broker.util.ObjectModification;
-import org.apache.ojb.broker.util.configuration.Configuration;
-import org.apache.ojb.broker.util.configuration.ConfigurationException;
import org.apache.ojb.broker.util.sequence.SequenceManager;
/* Copyright 2003-2004 The Apache Software Foundation
@@ -48,24 +51,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-public class DelegatingPersistenceBroker implements PersistenceBroker, PBState
+public class DelegatingPersistenceBroker implements PersistenceBrokerInternal, PBState
{
- protected PersistenceBroker m_broker;
+ protected PersistenceBrokerInternal broker;
public DelegatingPersistenceBroker(PersistenceBroker broker)
{
- this.m_broker = broker;
+ setDelegate(broker);
}
/**
* All delegated method use this method to
* get the wrapped broker.
*/
- protected PersistenceBroker getBroker()
+ protected PersistenceBrokerInternal getBroker()
{
- if (m_broker != null)
+ if (broker != null)
{
- return m_broker;
+ return broker;
}
else
{
@@ -82,12 +85,16 @@
*/
public PersistenceBroker getDelegate()
{
- return this.m_broker;
+ return this.broker;
}
public void setDelegate(PersistenceBroker broker)
{
- this.m_broker = broker;
+ if ((broker != null) && !(broker instanceof PersistenceBrokerInternal))
+ {
+ throw new OJBRuntimeException("Cannot create instance of delegating persistence broker because the wrapped broker does not implement PersistenceBrokerInternal");
+ }
+ this.broker = (PersistenceBrokerInternal)broker;
}
/**
@@ -107,7 +114,7 @@
*/
public PersistenceBroker getInnermostDelegate()
{
- PersistenceBroker broker = this.m_broker;
+ PersistenceBroker broker = this.broker;
while (broker != null && broker instanceof DelegatingPersistenceBroker)
{
broker = ((DelegatingPersistenceBroker) broker).getDelegate();
@@ -119,14 +126,24 @@
return broker;
}
+ public RowReader getRowReaderFor(ClassDescriptor classDesc)
+ {
+ return getBroker().getRowReaderFor(classDesc);
+ }
+
+ public BatchManager getBatchManager()
+ {
+ return getBroker().getBatchManager();
+ }
+
public boolean isInTransaction() throws PersistenceBrokerException
{
- return m_broker != null ? getBroker().isInTransaction() : false;
+ return broker != null ? getBroker().isInTransaction() : false;
}
public boolean isClosed()
{
- return m_broker != null ? getBroker().isClosed() : true;
+ return broker != null ? getBroker().isClosed() : true;
}
public void setClosed(boolean closed)
@@ -212,7 +229,22 @@
return getBroker().getDescriptorRepository();
}
- public void removeAllListeners() throws PersistenceBrokerException
+ public ProxyFactory getProxyFactory()
+ {
+ return getBroker().getProxyFactory();
+ }
+
+ public Object createProxy(Class proxyClass, Identity realSubjectsIdentity)
+ {
+ return getBroker().createProxy(proxyClass, realSubjectsIdentity);
+ }
+
+ public ManageableCollection createCollection(Class collectionClass)
+ {
+ return getBroker().createCollection(collectionClass);
+ }
+
+ public void removeAllListeners() throws PersistenceBrokerException
{
getBroker().removeAllListeners();
}
@@ -347,11 +379,6 @@
public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
{
return getBroker().getCollectionByQuery(query);
- }
-
- public void configure(Configuration pConfig) throws ConfigurationException
- {
- getBroker().configure(pConfig);
}
public org.odbms.Query query()
1.5 +3 -30 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactoryBaseImpl.java
Index: PersistenceBrokerFactoryBaseImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactoryBaseImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PersistenceBrokerFactoryBaseImpl.java 11 Aug 2004 00:41:45 -0000 1.4
+++ PersistenceBrokerFactoryBaseImpl.java 14 Nov 2004 09:34:27 -0000 1.5
@@ -18,10 +18,6 @@
import org.apache.ojb.broker.PBFactoryException;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceConfiguration;
-import org.apache.ojb.broker.util.ClassHelper;
-import org.apache.ojb.broker.util.configuration.Configuration;
-import org.apache.ojb.broker.util.configuration.ConfigurationException;
-import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
@@ -37,7 +33,7 @@
*/
public class PersistenceBrokerFactoryBaseImpl implements PersistenceBrokerFactoryIF
{
- private static Logger log = LoggerFactory.getLogger(PersistenceBrokerFactoryBaseImpl.class);
+ private Logger log = LoggerFactory.getLogger(PersistenceBrokerFactoryBaseImpl.class);
private Class implementationClass;
private PersistenceConfiguration persistenceConfiguration;
@@ -45,7 +41,6 @@
public PersistenceBrokerFactoryBaseImpl(PersistenceConfiguration persistenceConfiguration)
{
this.persistenceConfiguration = persistenceConfiguration;
- configure(OjbConfigurator.getInstance().getConfigurationFor(null));
}
protected PersistenceConfiguration getConfiguration()
@@ -53,34 +48,12 @@
return persistenceConfiguration;
}
- /*
- * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration config) throws ConfigurationException
- {
- implementationClass = ((PersistenceBrokerConfiguration) config).getPersistenceBrokerClass();
- }
-
/**
* For internal use! This method creates real new PB instances
*/
protected PersistenceBroker newBrokerInstance() throws PBFactoryException
{
- PersistenceBroker instance = null;
- Class[] types = {PersistenceConfiguration.class, PersistenceBrokerFactoryIF.class};
- Object[] args = {persistenceConfiguration, this};
- try
- {
- instance = (PersistenceBroker) ClassHelper.newInstance(implementationClass, types, args);
- OjbConfigurator.getInstance().configure(instance);
- // instance = (PersistenceBroker) InterceptorFactory.getInstance().createInterceptorFor(instance);
- }
- catch (Exception e)
- {
- log.error("Creation of a new PB instance failed", e);
- throw new PBFactoryException("Creation of a new PB instance failed", e);
- }
- return instance;
+ return (PersistenceBroker)persistenceConfiguration.getComponentContainer().getInstance(PersistenceBroker.class);
}
public void releaseAllInstances()
1.6 +1 -5 db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java
Index: PersistenceBrokerConfiguration.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PersistenceBrokerConfiguration.java 20 Sep 2004 14:32:25 -0000 1.5
+++ PersistenceBrokerConfiguration.java 14 Nov 2004 09:34:27 -0000 1.6
@@ -33,9 +33,5 @@
public Class getPersistentFieldClass();
- public String getRepositoryFilename();
-
- public Class getPersistenceBrokerClass();
-
public int getSqlInLimit();
}
1.6 +5 -35 db-ojb/src/java/org/apache/ojb/broker/core/PBPoolInfo.java
Index: PBPoolInfo.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PBPoolInfo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PBPoolInfo.java 4 Apr 2004 23:53:33 -0000 1.5
+++ PBPoolInfo.java 14 Nov 2004 09:34:27 -0000 1.6
@@ -1,14 +1,5 @@
package org.apache.ojb.broker.core;
-import org.apache.ojb.broker.util.configuration.Configurable;
-import org.apache.ojb.broker.util.configuration.Configuration;
-import org.apache.ojb.broker.util.configuration.ConfigurationException;
-import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
-import org.apache.ojb.broker.util.logging.LoggerFactory;
-import org.apache.ojb.broker.util.pooling.PoolConfiguration;
-
-import java.util.Properties;
-
/* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-public class PBPoolInfo extends PoolConfiguration implements Configurable
+
+import org.apache.ojb.broker.util.pooling.PoolConfiguration;
+import java.util.Properties;
+
+public class PBPoolInfo extends PoolConfiguration
{
private static final long serialVersionUID = 3331426619896735439L;
@@ -31,39 +26,14 @@
{
super();
init();
- OjbConfigurator.getInstance().configure(this);
}
public PBPoolInfo(Properties properties)
{
super();
init();
- OjbConfigurator.getInstance().configure(this);
this.putAll(properties);
}
-
- /**
- * Read in the configuration properties.
- */
- public void configure(Configuration pConfig) throws ConfigurationException
- {
- if (pConfig instanceof PBPoolConfiguration)
- {
- PBPoolConfiguration conf = (PBPoolConfiguration) pConfig;
- this.setMaxActive(conf.getMaxActive());
- this.setMaxIdle(conf.getMaxIdle());
- this.setMaxWait(conf.getMaxWaitMillis());
- this.setMinEvictableIdleTimeMillis(conf.getMinEvictableIdleTimeMillis());
- this.setTimeBetweenEvictionRunsMillis(conf.getTimeBetweenEvictionRunsMilli());
- this.setWhenExhaustedAction(conf.getWhenExhaustedAction());
- }
- else
- {
- LoggerFactory.getDefaultLogger().error(this.getClass().getName() +
- " cannot read configuration properties, use default.");
- }
- }
-
/**
* Init default properties.
* We set {@link #setTestOnBorrow}, {@link #setTestOnReturn}, {@link #setTestWhileIdle}
1.2 +55 -8 db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactoryException.java
Index: ObjectFactoryException.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactoryException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ObjectFactoryException.java 26 Oct 2004 15:27:39 -0000 1.1
+++ ObjectFactoryException.java 14 Nov 2004 09:34:27 -0000 1.2
@@ -2,21 +2,68 @@
import org.apache.ojb.broker.PersistenceBrokerException;
-/**
- * @author leandro
+/* Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-public class ObjectFactoryException
- extends PersistenceBrokerException
+
+
+/**
+ * This exception is thrown by the {@link ObjectFactory}
+ * if an object could not be created.
+ *
+ * @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak<a>
+ */
+public class ObjectFactoryException extends PersistenceBrokerException
{
+ /**
+ * Creates a new exception object.
+ */
+ public ObjectFactoryException()
+ {
+ super();
+ }
+
+ /**
+ * Creates a new exception object.
+ *
+ * @param message The exception message
+ */
+ public ObjectFactoryException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Creates a new exception object.
+ *
+ * @param cause The original exception
+ */
+ public ObjectFactoryException(Throwable cause)
+ {
+ super(cause);
+ }
/**
- * @param string
- * @param e
+ * Creates a new exception object.
+ *
+ * @param message The message
+ * @param cause The original exception
*/
- public ObjectFactoryException(String msg, Throwable t)
+ public ObjectFactoryException(String message, Throwable cause)
{
- super(msg,t);
+ super(message, cause);
}
}
1.2 +37 -8 db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactory.java
Index: ObjectFactory.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ObjectFactory.java 26 Oct 2004 15:27:39 -0000 1.1
+++ ObjectFactory.java 14 Nov 2004 09:34:27 -0000 1.2
@@ -1,15 +1,44 @@
package org.apache.ojb.broker.core.factory;
-/**
- * @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
+/* Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * Interface for object factories. In contrast to {@link ObjectCreator} implementations,
+ * objects of this type are required to honor the settings in the clas descriptor, e.g.
+ * factory-class and factory-method settings. Also, it is possible to register
+ * object creators at an object factory to override the creation for specific classes.
+ *
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
*/
-public interface ObjectFactory
+public interface ObjectFactory extends ObjectCreator
{
- Object getInstanceOf(Class clazz)
- throws ObjectFactoryException;
-
- Object getInstanceOf(String className)
- throws ObjectFactoryException;
+ /**
+ * Registers the creator for the specified type.
+ *
+ * @param creator The creator for the type; <code>null</code> sets default creation
+ * @param type The type to register the creator for; must not be <code>null</code>
+ */
+ public void registerCreator(ObjectCreator creator, String type);
+ /**
+ * Registers the creator for the specified types.
+ *
+ * @param creator The creator for the type; <code>null</code> sets default creation
+ * @param types The types to register the creator for; must not be <code>null</code> or empty
+ */
+ public void registerCreator(ObjectCreator creator, String[] types);
}
1.2 +101 -4 db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactoryDefaultImpl.java
Index: ObjectFactoryDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactoryDefaultImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ObjectFactoryDefaultImpl.java 26 Oct 2004 15:27:39 -0000 1.1
+++ ObjectFactoryDefaultImpl.java 14 Nov 2004 09:34:27 -0000 1.2
@@ -1,11 +1,108 @@
package org.apache.ojb.broker.core.factory;
-/**
- * @author leandro
+/* Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+
+import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.util.ClassHelper;
+
+/**
+ * Default implementation for the object creation. It also honors the
+ * {@link Initializable} marker interface that identifies objects that want
+ * initialization after the creation.
+ *
+ * @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
*/
-public class ObjectFactoryDefaultImpl
- extends ObjectFactorySupport
+public class ObjectFactoryDefaultImpl implements ObjectFactory
{
+ /** The registered creators */
+ private HashMap creators = new HashMap();
+
+ /* (non-Javadoc)
+ * @see org.apache.ojb.broker.core.factory.ObjectFactory#registerCreator(org.apache.ojb.broker.core.factory.ObjectCreator, java.lang.String)
+ */
+ public void registerCreator(ObjectCreator creator, String type)
+ {
+ if (type == null)
+ {
+ throw new IllegalArgumentException("The type for which an creator is registered must not be null");
+ }
+ if (creator == null)
+ {
+ creators.remove(type);
+ }
+ else
+ {
+ creators.put(type, creator);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ojb.broker.core.factory.ObjectFactory#registerCreator(org.apache.ojb.broker.core.factory.ObjectCreator, java.lang.String[])
+ */
+ public void registerCreator(ObjectCreator creator, String[] types)
+ {
+ if ((types == null) || (types.length == 0))
+ {
+ throw new IllegalArgumentException("The types for which an creator is registered must not be empty");
+ }
+ for (int idx = 0; idx < types.length; idx++)
+ {
+ registerCreator(creator, types[idx]);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.ojb.broker.core.factory.ObjectCreator#newInstance(org.apache.ojb.broker.metadata.ClassDescriptor)
+ */
+ public Object newInstance(ClassDescriptor classDesc) throws ObjectFactoryException
+ {
+ try
+ {
+ ObjectCreator creator = (ObjectCreator)creators.get(classDesc.getClassNameOfObject());
+ Object obj = null;
+
+ if (creator != null)
+ {
+ obj = creator.newInstance(classDesc);
+ }
+ else
+ {
+ obj = ClassHelper.buildNewObjectInstance(classDesc);
+ }
+ if (obj instanceof Initializable)
+ {
+ ((Initializable)obj).initialize();
+ }
+ return obj;
+ }
+ catch (Throwable ex)
+ {
+ if (ex instanceof ObjectFactoryException)
+ {
+ throw (ObjectFactoryException)ex;
+ }
+ else
+ {
+ throw new ObjectFactoryException("An error occurred while creating an instance of "+classDesc.getClassNameOfObject(), ex);
+ }
+ }
+ }
}
1.1 db-ojb/src/java/org/apache/ojb/broker/core/factory/Initializable.java
Index: Initializable.java
===================================================================
package org.apache.ojb.broker.core.factory;
/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Marks objects that want to be initialized after creation.
*
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
* @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
*/
public interface Initializable
{
/**
* Initializes the object.
*
* @throws Exception If an error ocurred during initialization
*/
public void initialize() throws Exception;
}
1.1 db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectCreator.java
Index: ObjectCreator.java
===================================================================
package org.apache.ojb.broker.core.factory;
/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.ojb.broker.metadata.ClassDescriptor;
/**
* Interface for objects that can create other objects.
*
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
* @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
*/
public interface ObjectCreator
{
/**
* Creates a new instance of the type described by the given class descriptor.
*
* @param classDesc The class descriptor
* @return The new instance
* @throws ObjectFactoryException If no new instance could be created
*/
public Object newInstance(ClassDescriptor classDesc) throws ObjectFactoryException;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org