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 ar...@apache.org on 2003/01/09 18:08:46 UTC
cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/util BrokerHelper.java
arminw 2003/01/09 09:08:45
Modified: src/java/org/apache/ojb/broker/singlevm
DelegatingPersistenceBroker.java
PersistenceBrokerImpl.java
src/java/org/apache/ojb/broker/ta
PersistenceBrokerFactoryDefaultImpl.java
PersistenceBrokerFactoryIF.java
src/java/org/apache/ojb/broker/util/configuration/impl
OjbConfiguration.java
src/java/org/apache/ojb/broker/util/pooling
PoolConfiguration.java
src/java/org/apache/ojb/broker/util BrokerHelper.java
Log:
- move the whole sequence-manager
properties stuff from the OJB.properties to
the repository
- move the 'useAutoCommit' and
'ignoreAutocommitExceptions' properties from OJB.properties
to jdbc-connection-descriptor
- remove the 'maxConnectionsInPool'
property from OJB.properties
- rename DescriptorRepository#getExtentClass
to #getTopLevelClass, deprecate PB#getExtentClass
and add PB#getTopLevelClass
Revision Changes Path
1.6 +5 -0 jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/DelegatingPersistenceBroker.java
Index: DelegatingPersistenceBroker.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/DelegatingPersistenceBroker.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DelegatingPersistenceBroker.java 28 Dec 2002 12:56:31 -0000 1.5
+++ DelegatingPersistenceBroker.java 9 Jan 2003 17:08:44 -0000 1.6
@@ -216,6 +216,11 @@
return broker.getExtentClass(clazz);
}
+ public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
+ {
+ return broker.getTopLevelClass(clazz);
+ }
+
public boolean hasClassDescriptor(Class clazz)
{
return broker.hasClassDescriptor(clazz);
1.108 +31 -17 jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
Index: PersistenceBrokerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- PersistenceBrokerImpl.java 5 Jan 2003 17:18:08 -0000 1.107
+++ PersistenceBrokerImpl.java 9 Jan 2003 17:08:44 -0000 1.108
@@ -188,13 +188,13 @@
refresh();
this.pbf = pbf;
this.pbKey = key;
+ brokerHelper = new BrokerHelper(this);
connectionManager = new ConnectionManager(this);
- dbAccess = new JdbcAccess(this);
sequenceManager = SequenceManagerFactory.getSequenceManager(this);
+ dbAccess = new JdbcAccess(this);
statementManager = new StatementManager(this);
sqlGenerator = SqlGeneratorFactory.getInstance().createSqlGenerator(
connectionManager.getSupportedPlatform());
- brokerHelper = new BrokerHelper(this);
}
@@ -1152,7 +1152,7 @@
{
Class referencedClass = rds.getItemClass();
// ensure that top-level extents are used for Identities
- referencedClass = descriptorRepository.getExtentClass(referencedClass);
+ referencedClass = descriptorRepository.getTopLevelClass(referencedClass);
Object[] pkVals = rds.getForeignKeyValues(obj, cld);
Identity id;
Class referencedProxy;
@@ -1984,10 +1984,10 @@
* (autoincrement or locking) or if it does contain a
* valid non-null value.
*/
- if (! (fieldDescriptors[i].isAutoIncrement()
- || fieldDescriptors[i].isLocking()
+ if (! (fieldDescriptors[i].isAutoIncrement()
+ || fieldDescriptors[i].isLocking()
|| assertValidPkValue(pkValues[i]) ))
- {
+ {
return false;
}
}
@@ -2017,8 +2017,8 @@
{
return false;
}
- }
- return true;
+ }
+ return true;
}
@@ -2162,7 +2162,7 @@
CollectionDescriptor inverseCod = null;
CollectionDescriptor icod;
Class itemClass = cld.getClassOfObject();
- Class baseClass = getExtentClass(itemClass);
+ Class baseClass = getTopLevelClass(itemClass);
Criteria criteria = new Criteria();
QueryByCriteria query;
@@ -2247,10 +2247,24 @@
* @throws PersistenceBrokerException if clazz is not persistence capable,
* i.e. if clazz is not defined in the DescriptorRepository.
* @param clazz the class to lookup the Extent for
+ * @deprecated use {@link #getTopLevelClass}
*/
public Class getExtentClass(Class clazz) throws PersistenceBrokerException
{
- return descriptorRepository.getExtentClass(clazz);
+ //return descriptorRepository.getExtentClass(clazz);
+ return getTopLevelClass(clazz);
+ }
+
+ public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
+ {
+ try
+ {
+ return descriptorRepository.getTopLevelClass(clazz);
+ }
+ catch (ClassNotPersistenceCapableException e)
+ {
+ throw new PersistenceBrokerException(e);
+ }
}
/**
@@ -2302,7 +2316,7 @@
{
reportCrit = query.getCriteria().copy(false, false, false);
}
-
+
// BRJ: add a column for each pkField, make it distinct if query is distinct
// tbd check if it really works for multiple keys ?
for (int i = 0; i < pkFields.length; i++)
@@ -2316,7 +2330,7 @@
columns[i] = "count(" + pkFields[i].getAttributeName() + ")";
}
}
-
+
// BRJ: we have to preserve indirection table !
if (query instanceof MtoNQuery)
{
@@ -2512,18 +2526,18 @@
// ************************************************************************
// inner class
// ************************************************************************
-
+
/**
* This is a helper class to model a Key of an Object
*/
private final class Key
{
- Object[] m_key;
+ final Object[] m_key;
- Key(Object[] aKey)
+ Key(final Object[] aKey)
{
m_key = new Object[aKey.length];
-
+
for (int i = 0; i < aKey.length; i++)
{
// BRJ:
1.30 +19 -3 jakarta-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryDefaultImpl.java
Index: PersistenceBrokerFactoryDefaultImpl.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryDefaultImpl.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- PersistenceBrokerFactoryDefaultImpl.java 28 Dec 2002 12:55:46 -0000 1.29
+++ PersistenceBrokerFactoryDefaultImpl.java 9 Jan 2003 17:08:45 -0000 1.30
@@ -115,12 +115,19 @@
setDefaultKey(buildDefaultKey());
}
+ /**
+ * @see org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF#setDefaultKey
+ */
public void setDefaultKey(PBKey key)
{
- log.info("Set default PBKey: "+key);
+
this.defaultPBKey = key;
+ log.info("Set default PBKey: "+key);
}
+ /**
+ * @see org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF#getDefaultKey()
+ */
public PBKey getDefaultKey()
{
return this.defaultPBKey;
@@ -231,19 +238,28 @@
return broker;
}
-
+ /**
+ * @see org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF#createPersistenceBroker(
+ * String jcdAlias, String user, String password)
+ */
public PersistenceBroker createPersistenceBroker(String jcdAlias, String user, String password)
throws PBFactoryException
{
return this.createPersistenceBroker(new PBKey(jcdAlias, user, password));
}
+ /**
+ * @see org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF#defaultPersistenceBroker
+ */
public PersistenceBroker defaultPersistenceBroker(String user, String password) throws PBFactoryException
{
return this.createPersistenceBroker(
new PBKey(getDefaultKey().getAlias(), user, password));
}
+ /**
+ * @see org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF#createPersistenceBroker(PBKey key)
+ */
public PersistenceBroker defaultPersistenceBroker() throws PBFactoryException
{
return this.createPersistenceBroker(getDefaultKey());
1.12 +3 -3 jakarta-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryIF.java
Index: PersistenceBrokerFactoryIF.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryIF.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- PersistenceBrokerFactoryIF.java 27 Dec 2002 23:06:56 -0000 1.11
+++ PersistenceBrokerFactoryIF.java 9 Jan 2003 17:08:45 -0000 1.12
@@ -98,8 +98,8 @@
throws PBFactoryException;
/**
- * Return a default broker instance, specified in configuration
- * or set using {@link #setDefaultKey}.
+ * Return a default broker instance.
+ * @deprecated use one of the other methods to obtain an instance.
*/
public PersistenceBroker defaultPersistenceBroker(String user, String password) throws PBFactoryException;
1.19 +6 -84 jakarta-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java
Index: OjbConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- OjbConfiguration.java 24 Dec 2002 13:28:58 -0000 1.18
+++ OjbConfiguration.java 9 Jan 2003 17:08:45 -0000 1.19
@@ -55,17 +55,14 @@
*/
import org.apache.ojb.broker.ManageableCollection;
-import org.apache.ojb.broker.PBKey;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.accesslayer.ConnectionFactory;
-import org.apache.ojb.broker.accesslayer.ConnectionFactoryConfiguration;
import org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl;
import org.apache.ojb.broker.cache.ObjectCache;
import org.apache.ojb.broker.cache.ObjectCacheDefaultImpl;
+import org.apache.ojb.broker.metadata.MetadataConfiguration;
import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl;
-import org.apache.ojb.broker.metadata.MetadataConfiguration;
-import org.apache.ojb.broker.platforms.PlatformConfiguration;
import org.apache.ojb.broker.server.BrokerPool;
import org.apache.ojb.broker.server.PersistenceBrokerServer;
import org.apache.ojb.broker.singlevm.PersistenceBrokerConfiguration;
@@ -75,9 +72,6 @@
import org.apache.ojb.broker.util.logging.LoggingConfiguration;
import org.apache.ojb.broker.util.logging.PoorMansLoggerImpl;
import org.apache.ojb.broker.util.pooling.PoolConfiguration;
-import org.apache.ojb.broker.util.sequence.SequenceConfiguration;
-import org.apache.ojb.broker.util.sequence.SequenceManager;
-import org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl;
import org.apache.ojb.odmg.OdmgConfiguration;
import org.apache.ojb.odmg.collections.DListImpl;
import org.apache.ojb.odmg.locking.AbstractLockStrategy;
@@ -99,9 +93,11 @@
public class OjbConfiguration
extends ConfigurationAbstractImpl
implements LoggingConfiguration, OdmgConfiguration, LockingConfiguration,
- PersistenceBrokerConfiguration, SequenceConfiguration, PlatformConfiguration,
- PBPoolConfiguration, ConnectionFactoryConfiguration, MetadataConfiguration
+ PersistenceBrokerConfiguration,
+ PBPoolConfiguration, MetadataConfiguration
{
+ private static final String NULL = "null";
+
/** use Server or local broker*/
private boolean serverUsed;
/** the repository file keeping the O/R Metadata*/
@@ -116,11 +112,6 @@
// limit for number of values in SQL IN Statement
private int sqlInLimit;
- // sequence manager
- private int sequenceManagerGrabSize;
- private Class sequenceManagerClass;
- private boolean sequenceManagerGlobalId;
- private String sequenceManagerRepository;
// PB pooling configuration
private int maxActive;
private int maxIdle;
@@ -128,10 +119,6 @@
private long timeBetweenEvictionRunsMillis;
private long minEvictableIdleTimeMillis;
private byte whenExhaustedAction;
- // Connection pooling configuration
- private int con_maxActive;
- private boolean ignoreAutocommitExceptions;
- private int useAutoCommit;
// ODMG configuration
private boolean useImplicitLocking;
@@ -184,24 +171,6 @@
return this.getString(loggerName + ".LogLevel", "INFO");
}
-
- //*************************************************************
- //Connection pooling configuration methods
- public int getConMaxActive()
- {
- return con_maxActive;
- }
-
- public boolean ignoreAutocommitExceptions()
- {
- return ignoreAutocommitExceptions;
- }
-
- public int useAutoCommit()
- {
- return useAutoCommit;
- }
-
//*************************************************************
//PBPoolConfiguration methods
public int getMaxActive()
@@ -235,34 +204,6 @@
}
//*************************************************************
- //*************************************************************
- // Sequence manager
-
- public Class getSequenceManagerClass()
- {
- return sequenceManagerClass;
- }
-
- /**
- * Return PBKey for separate sequence generation.
- * @return PBKey or null
- */
- public PBKey getSeparatePBKey()
- {
- return sequenceManagerRepository.equalsIgnoreCase(NULL) ? null : new PBKey(sequenceManagerRepository);
- }
-
- private static final String NULL = "null";
-
- public boolean getSequenceManagerGlobalId()
- {
- return sequenceManagerGlobalId;
- }
-
- public int getSequenceManagerGrabSize()
- {
- return sequenceManagerGrabSize;
- }
//*************************************************************
@@ -322,17 +263,6 @@
repositoryFilename = getString("repositoryFile", "repository.xml");
servers = getStrings("BrokerServers", "localhost:2001");
- // load SeqManager class
- sequenceManagerClass =
- getClass("SequenceManagerClass", SequenceManagerHighLowImpl.class, SequenceManager.class);
-
- // load SeqManager Grab size value
- sequenceManagerGrabSize = getInteger("SequenceManagerGrabSize", 10);
-
- sequenceManagerGlobalId = getBoolean("SequenceManagerGlobalIDs", false);
-
- sequenceManagerRepository = getString("SequenceManagerRepository", NULL);
-
// load ObjectCache Class
objectCacheClass = getClass("ObjectCacheClass", ObjectCacheDefaultImpl.class, ObjectCache.class);
@@ -377,11 +307,6 @@
// load OQL Collection Class
oqlCollectionClass = getClass("OqlCollectionClass", DListImpl.class, ManageableCollection.class);
- // load the platform configuration for autocommit exceptions
- ignoreAutocommitExceptions = super.getBoolean("ignoreAutoCommitExceptions", false);
-
- useAutoCommit = getInteger("useAutoCommit", 1);
-
// set the limit for IN-sql , -1 for no limits
sqlInLimit = getInteger("SqlInLimit", -1);
@@ -398,9 +323,6 @@
PoolConfiguration.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
whenExhaustedAction = getByte(PoolConfiguration.WHEN_EXHAUSTED_ACTION,
PoolConfiguration.DEFAULT_WHEN_EXHAUSTED_ACTION);
-
- //load configuration for connection pools
- con_maxActive = getInteger("maxConnectionsInPool", 10);
useSerializedRepository = getBoolean("useSerializedRepository", false);
}
1.3 +68 -13 jakarta-ojb/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java
Index: PoolConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/pooling/PoolConfiguration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PoolConfiguration.java 24 Dec 2002 13:24:29 -0000 1.2
+++ PoolConfiguration.java 9 Jan 2003 17:08:45 -0000 1.3
@@ -60,6 +60,7 @@
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.dbcp.AbandonedConfig;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import java.io.Serializable;
@@ -76,7 +77,9 @@
public class PoolConfiguration extends Properties implements Serializable //, Configurable
{
public static final String EMPTY = "";
-
+ //*****************************************************
+ // constants
+ //*****************************************************
public static final String MAX_ACTIVE = "maxActive";
public static final String MAX_IDLE = "maxIdle";
public static final String MAX_WAIT = "maxWait";
@@ -86,19 +89,29 @@
public static final String TEST_WHILE_IDLE = "testWhileIdle";
public static final String TIME_BETWEEN_EVICTION_RUNS_MILLIS = "timeBetweenEvictionRunsMillis";
public static final String NUM_TESTS_PER_EVICTION_RUN = "numTestsPerEvictionRun";
- public static final String MIN_EVICTABLE_IDLE_TIME_MILLIS = "minEvictableIdleIimeMillis";
+ public static final String MIN_EVICTABLE_IDLE_TIME_MILLIS = "minEvictableIdleTimeMillis";
+ public static final String LOG_ABANDONED = "logAbandoned";
+ public static final String REMOVE_ABANDONED = "removeAbandoned";
+ public static final String REMOVE_ABANDONED_TIMEOUT = "removeAbandonedTimeout";
public static final String VALIDATION_QUERY = "validationQuery";
- public static int DEFAULT_MAX_ACTIVE = 15;
- public static int DEFAULT_MAX_IDLE = -1;
- public static long DEFAULT_MAX_WAIT = 5000;
- public static byte DEFAULT_WHEN_EXHAUSTED_ACTION = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
- public static boolean DEFAULT_TEST_ON_BORROW = true;
- public static boolean DEFAULT_TEST_ON_RETURN = true;
- public static boolean DEFAULT_TEST_WHILE_IDLE = true;
- public static long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
- public static int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 10;
- public static long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000 * 60 * 10;
+
+ //*****************************************************
+ // used default values
+ //*****************************************************
+ public static final int DEFAULT_MAX_ACTIVE = 21;
+ public static final int DEFAULT_MAX_IDLE = -1;
+ public static final long DEFAULT_MAX_WAIT = 5000;
+ public static final byte DEFAULT_WHEN_EXHAUSTED_ACTION = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
+ public static final boolean DEFAULT_TEST_ON_BORROW = true;
+ public static final boolean DEFAULT_TEST_ON_RETURN = false;
+ public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
+ public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
+ public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 10;
+ public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000 * 60 * 10;
+ public static final boolean DEFAULT_LOG_ABANDONED = false;
+ public static final boolean DEFAULT_REMOVE_ABANDONED = false;
+ public static final int DEFAULT_REMOVE_ABANDONED_TIMEOUT = 300;
public PoolConfiguration()
{
@@ -112,6 +125,9 @@
this.setMinEvictableIdleTimeMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
this.setTimeBetweenEvictionRunsMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
this.setNumTestsPerEvictionRun(DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
+ this.setLogAbandoned(DEFAULT_LOG_ABANDONED);
+ this.setRemoveAbandoned(DEFAULT_REMOVE_ABANDONED);
+ this.setRemoveAbandonedTimeout(DEFAULT_REMOVE_ABANDONED_TIMEOUT);
}
public PoolConfiguration(Properties properties)
@@ -162,6 +178,45 @@
conf.timeBetweenEvictionRunsMillis = getTimeBetweenEvictionRunsMillis();
conf.whenExhaustedAction = getWhenExhaustedAction();
return conf;
+ }
+
+ public AbandonedConfig getAbandonedConfig()
+ {
+ AbandonedConfig conf = new AbandonedConfig();
+ conf.setLogAbandoned(isLogAbandoned());
+ conf.setRemoveAbandoned(isRemoveAbandoned());
+ conf.setRemoveAbandonedTimeout(getRemoveAbandonedTimeout());
+ return conf;
+ }
+
+ public boolean isLogAbandoned()
+ {
+ return new Boolean(getProperty(LOG_ABANDONED)).booleanValue();
+ }
+
+ public void setLogAbandoned(boolean logAbandoned)
+ {
+ this.setProperty(LOG_ABANDONED, EMPTY + logAbandoned);
+ }
+
+ public boolean isRemoveAbandoned()
+ {
+ return new Boolean(getProperty(REMOVE_ABANDONED)).booleanValue();
+ }
+
+ public void setRemoveAbandoned(boolean removeAbandoned)
+ {
+ this.setProperty(REMOVE_ABANDONED, EMPTY + removeAbandoned);
+ }
+
+ public int getRemoveAbandonedTimeout()
+ {
+ return new Integer(getProperty(REMOVE_ABANDONED_TIMEOUT)).intValue();
+ }
+
+ public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
+ {
+ this.setProperty(REMOVE_ABANDONED_TIMEOUT, EMPTY + removeAbandonedTimeout);
}
public String getValidationQuery()
1.5 +15 -2 jakarta-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
Index: BrokerHelper.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BrokerHelper.java 24 Dec 2002 13:25:26 -0000 1.4
+++ BrokerHelper.java 9 Jan 2003 17:08:45 -0000 1.5
@@ -92,10 +92,15 @@
* splits up the name string and extract db url,
* user name and password and build a new PBKey
* instance - the token '#' is used to separate
- * the substrings
+ * the substrings.
+ * @throws
*/
public static PBKey extractAllTokens(String name)
{
+ if (name == null)
+ {
+ throw new PersistenceBrokerException("Could not extract PBKey, given argument is 'null'");
+ }
String user = null;
String passwd = null;
StringTokenizer tok = new StringTokenizer(name, REPOSITORY_NAME_SEPARATOR);
@@ -103,10 +108,18 @@
if (tok.hasMoreTokens())
{
user = tok.nextToken();
+ if(user != null && user.trim().equals(""))
+ {
+ user = null;
+ }
}
if (tok.hasMoreTokens())
{
passwd = tok.nextToken();
+ }
+ if(user != null && passwd == null)
+ {
+ passwd = "";
}
PBKey key = new PBKey(dbName, user, passwd);
return key;