mpoeschl 2002/11/26 15:46:56
Modified: src/java/org/apache/torque/map ColumnMap.java
src/java/org/apache/torque/oid AutoIncrementIdGenerator.java
IDBroker.java IDGeneratorFactory.java
SequenceIdGenerator.java
src/java/org/apache/torque/pool ConnectionPool.java
ConnectionWaitTimeoutException.java
TorqueClassicDataSource.java
Log:
o javadocs
o checkstyle fixes
Revision Changes Path
1.6 +2 -3
jakarta-turbine-torque/src/java/org/apache/torque/map/ColumnMap.java
Index: ColumnMap.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/map/ColumnMap.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ColumnMap.java 13 Sep 2002 06:00:49 -0000 1.5
+++ ColumnMap.java 26 Nov 2002 23:46:56 -0000 1.6
@@ -177,8 +177,7 @@
*/
public void setForeignKey(String fullyQualifiedName)
{
- if (fullyQualifiedName != null &&
- fullyQualifiedName.length() > 0)
+ if (fullyQualifiedName != null && fullyQualifiedName.length() > 0)
{
relatedTableName = fullyQualifiedName.substring(
0, fullyQualifiedName.indexOf('.'));
1.5 +3 -3
jakarta-turbine-torque/src/java/org/apache/torque/oid/AutoIncrementIdGenerator.java
Index: AutoIncrementIdGenerator.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/AutoIncrementIdGenerator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AutoIncrementIdGenerator.java 7 May 2002 17:13:22 -0000 1.4
+++ AutoIncrementIdGenerator.java 26 Nov 2002 23:46:56 -0000 1.5
@@ -69,9 +69,9 @@
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
* @version $Id$
*/
-public class AutoIncrementIdGenerator
- implements IdGenerator
+public class AutoIncrementIdGenerator implements IdGenerator
{
+ /** the adapter that knows the correct sql syntax */
private DB dbAdapter;
/**
1.20 +55 -64
jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java
Index: IDBroker.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- IDBroker.java 8 Aug 2002 20:01:29 -0000 1.19
+++ IDBroker.java 26 Nov 2002 23:46:56 -0000 1.20
@@ -112,8 +112,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
* @version $Id$
*/
-public class IDBroker
- implements Runnable, IdGenerator
+public class IDBroker implements Runnable, IdGenerator
{
/**
* Name of the ID_TABLE = ID_TABLE
@@ -207,7 +206,7 @@
/**
* Category used for logging.
*/
- Category category =
+ private Category category =
Category.getInstance(IDBroker.class.getName());
/**
@@ -259,13 +258,13 @@
}
if (!transactionsSupported)
{
- category.warn
- ("IDBroker is being used with db '" + dbName +
- "', which does not support transactions. IDBroker " +
- "attempts to use transactions to limit the possibility of " +
- "duplicate key generation. Without transactions, " +
- "duplicate key generation is possible if multiple JVMs " +
- "are used or other means are used to write to the database.");
+ category.warn("IDBroker is being used with db '" + dbName
+ + "', which does not support transactions. IDBroker "
+ + "attempts to use transactions to limit the possibility "
+ + "of duplicate key generation. Without transactions, "
+ + "duplicate key generation is possible if multiple JVMs "
+ + "are used or other means are used to write to the "
+ + "database.");
}
}
@@ -287,7 +286,7 @@
* @exception Exception Database error.
*/
public int getIdAsInt(Connection connection, Object tableName)
- throws Exception
+ throws Exception
{
return getIdAsBigDecimal(connection, tableName).intValue();
}
@@ -415,7 +414,7 @@
{
if (tableName == null)
{
- throw new Exception ("getNextIds(): tableName == null");
+ throw new Exception("getNextIds(): tableName == null");
}
// A note about the synchronization: I (jmcnally) looked at
@@ -429,8 +428,7 @@
List availableIds = (List) ids.get(tableName);
- if ( availableIds == null ||
- availableIds.size() < numOfIdsToReturn )
+ if (availableIds == null || availableIds.size() < numOfIdsToReturn)
{
if (availableIds == null)
{
@@ -456,8 +454,8 @@
// {
for (int i = size - 1; i >= 0; i--)
{
- results[i] = (BigDecimal) availableIds.get(i);
- availableIds.remove(i);
+ results[i] = (BigDecimal) availableIds.get(i);
+ availableIds.remove(i);
}
// }
@@ -507,7 +505,6 @@
category.error("Release of connection failed.", e);
}
}
-
return exists;
}
@@ -541,7 +538,7 @@
+ "on table: " + tableName);
List availableIds = (List) ids.get(tableName);
int quantity = getQuantity(tableName, null).intValue();
- if ( quantity > availableIds.size() )
+ if (quantity > availableIds.size())
{
try
{
@@ -589,25 +586,24 @@
// Check if quantity changing is switched on.
// If prefetch is turned off, changing quantity does not make sense
if (!configuration.getBoolean(DB_IDBROKER_CLEVERQUANTITY, true)
- || !configuration.getBoolean(DB_IDBROKER_PREFETCH, true))
+ || !configuration.getBoolean(DB_IDBROKER_PREFETCH, true))
{
return;
}
// Get the last id request for this table.
- java.util.Date lastTime =
- (java.util.Date) lastQueryTime.get(tableName);
+ java.util.Date lastTime = (java.util.Date) lastQueryTime.get(tableName);
java.util.Date now = new java.util.Date();
- if ( lastTime != null)
+ if (lastTime != null)
{
long thenLong = lastTime.getTime();
long nowLong = now.getTime();
int timeLapse = (int) (nowLong - thenLong);
- if ( timeLapse < sleepPeriod && timeLapse > 0 )
+ if (timeLapse < sleepPeriod && timeLapse > 0)
{
- category.debug("Unscheduled retrieval of more ids for table: " +
- tableName);
+ category.debug("Unscheduled retrieval of more ids for table: "
+ + tableName);
// Increase quantity, so that hopefully this does not
// happen again.
float rate = getQuantity(tableName, null).floatValue()
@@ -672,7 +668,7 @@
// Update the row based on the quantity in the
// ID_TABLE.
BigDecimal newNextId = nextId.add(quantity);
- updateNextId(connection, tableName, newNextId.toString() );
+ updateNextId(connection, tableName, newNextId.toString());
Transaction.commit(connection);
}
@@ -683,10 +679,10 @@
}
List availableIds = (List) ids.get(tableName);
- if ( availableIds == null )
+ if (availableIds == null)
{
availableIds = new ArrayList();
- ids.put( tableName, availableIds );
+ ids.put(tableName, availableIds);
}
// Create the ids and store them in the list of available ids.
@@ -776,16 +772,15 @@
* @return A BigDecimal[].
* @exception Exception a generic exception.
*/
- private BigDecimal[] selectRow(Connection con,
- String tableName)
- throws Exception
+ private BigDecimal[] selectRow(Connection con, String tableName)
+ throws Exception
{
StringBuffer stmt = new StringBuffer();
- stmt.append( "SELECT " + NEXT_ID + ", " + QUANTITY)
- .append( " FROM " + ID_TABLE )
- .append( " WHERE TABLE_NAME = '" )
- .append( tableName )
- .append( '\'' );
+ stmt.append("SELECT " + NEXT_ID + ", " + QUANTITY)
+ .append(" FROM " + ID_TABLE)
+ .append(" WHERE TABLE_NAME = '")
+ .append(tableName)
+ .append('\'');
Statement statement = null;
@@ -793,7 +788,7 @@
try
{
statement = con.createStatement();
- ResultSet rs = statement.executeQuery( stmt.toString() );
+ ResultSet rs = statement.executeQuery(stmt.toString());
if (rs.next())
{
@@ -829,21 +824,19 @@
* @param id An int with the value to set for the id.
* @exception Exception Database error.
*/
- private void updateNextId(Connection con,
- String tableName,
- String id)
- throws Exception
+ private void updateNextId(Connection con, String tableName, String id)
+ throws Exception
{
- StringBuffer stmt =
- new StringBuffer(id.length() + tableName.length() + 50);
- stmt.append( "UPDATE " + ID_TABLE )
- .append( " SET NEXT_ID = " )
- .append( id )
- .append( " WHERE TABLE_NAME = '" )
- .append( tableName )
- .append( '\'' );
+ StringBuffer stmt = new StringBuffer(id.length()
+ + tableName.length() + 50);
+ stmt.append("UPDATE " + ID_TABLE)
+ .append(" SET NEXT_ID = ")
+ .append(id)
+ .append(" WHERE TABLE_NAME = '")
+ .append(tableName)
+ .append('\'');
Statement statement = null;
@@ -852,7 +845,7 @@
try
{
statement = con.createStatement();
- statement.executeUpdate( stmt.toString() );
+ statement.executeUpdate(stmt.toString());
}
finally
{
@@ -872,20 +865,18 @@
* @param quantity An int with the value of the quantity.
* @exception Exception Database error.
*/
- private void updateQuantity(Connection con,
- String tableName,
- BigDecimal quantity)
+ private void updateQuantity(Connection con, String tableName,
+ BigDecimal quantity)
throws Exception
{
- StringBuffer stmt =
- new StringBuffer(quantity.toString().length() + tableName.length()
- + 50);
- stmt.append( "UPDATE " + ID_TABLE )
- .append( " SET QUANTITY = " )
- .append( quantity )
- .append( " WHERE TABLE_NAME = '" )
- .append( tableName )
- .append( '\'' );
+ StringBuffer stmt = new StringBuffer(quantity.toString().length()
+ + tableName.length() + 50);
+ stmt.append("UPDATE " + ID_TABLE)
+ .append(" SET QUANTITY = ")
+ .append(quantity)
+ .append(" WHERE TABLE_NAME = '")
+ .append(tableName)
+ .append('\'');
Statement statement = null;
@@ -894,7 +885,7 @@
try
{
statement = con.createStatement();
- statement.executeUpdate( stmt.toString() );
+ statement.executeUpdate(stmt.toString());
}
finally
{
1.2 +3 -5
jakarta-turbine-torque/src/java/org/apache/torque/oid/IDGeneratorFactory.java
Index: IDGeneratorFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/IDGeneratorFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IDGeneratorFactory.java 13 Aug 2001 22:27:22 -0000 1.1
+++ IDGeneratorFactory.java 26 Nov 2002 23:46:56 -0000 1.2
@@ -82,10 +82,8 @@
* org.apache.torque.adapter.DB#getIDMethodType()} method.
* Returns <code>null</code> for unknown types.
*
- * @param dbAdapter The type of adapter to create an ID generator
- * for.
- * @return The appropriate ID generator (possibly
- * <code>null</code>).
+ * @param dbAdapter The type of adapter to create an ID generator for.
+ * @return The appropriate ID generator (possibly <code>null</code>).
*/
public static IdGenerator create(DB dbAdapter)
{
1.7 +7 -7
jakarta-turbine-torque/src/java/org/apache/torque/oid/SequenceIdGenerator.java
Index: SequenceIdGenerator.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/SequenceIdGenerator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SequenceIdGenerator.java 15 Aug 2002 01:21:16 -0000 1.6
+++ SequenceIdGenerator.java 26 Nov 2002 23:46:56 -0000 1.7
@@ -71,13 +71,13 @@
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
* @version $Id$
*/
-public class SequenceIdGenerator
- implements IdGenerator
+public class SequenceIdGenerator implements IdGenerator
{
-
/** The log. */
- private static Category category =
Category.getInstance(SequenceIdGenerator.class);
-
+ private static Category category = Category.getInstance(
+ SequenceIdGenerator.class);
+
+ /** the adapter that knows the correct sql syntax */
private DB dbAdapter;
/**
@@ -192,7 +192,7 @@
category.debug(idSql);
// Execute the query.
- QueryDataSet qds = new QueryDataSet( connection, idSql );
+ QueryDataSet qds = new QueryDataSet(connection, idSql);
Record rec;
try
{
1.14 +38 -38
jakarta-turbine-torque/src/java/org/apache/torque/pool/ConnectionPool.java
Index: ConnectionPool.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/pool/ConnectionPool.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ConnectionPool.java 7 Aug 2002 08:07:02 -0000 1.13
+++ ConnectionPool.java 26 Nov 2002 23:46:56 -0000 1.14
@@ -79,8 +79,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">John McNally</a>
* @version $Id$
*/
-class ConnectionPool
- implements ConnectionEventListener
+class ConnectionPool implements ConnectionEventListener
{
/**
* Pool containing database connections.
@@ -108,20 +107,17 @@
private String password;
/**
- * The current number of database connections that have been
- * created.
+ * The current number of database connections that have been created.
*/
private int totalConnections;
/**
- * The maximum number of database connections that can be
- * created.
+ * The maximum number of database connections that can be created.
*/
private int maxConnections;
/**
- * The amount of time in milliseconds that a connection will be
- * pooled.
+ * The amount of time in milliseconds that a connection will be pooled.
*/
private int expiryTime; // 1 hour
@@ -172,7 +168,7 @@
this.cpds = cpds;
this.username = username;
this.password = password;
- if ( maxConnections > 0 )
+ if (maxConnections > 0)
{
this.maxConnections = maxConnections;
}
@@ -180,7 +176,7 @@
{
this.maxConnections = 1;
}
- if ( expiryTime > 0 )
+ if (expiryTime > 0)
{
this.expiryTime = expiryTime * 1000;
}
@@ -188,7 +184,7 @@
{
this.expiryTime = 3600 * 1000; // one hour
}
- if ( connectionWaitTimeout > 0 )
+ if (connectionWaitTimeout > 0)
{
this.connectionWaitTimeout = connectionWaitTimeout * 1000;
}
@@ -225,13 +221,13 @@
getConnection(String username, String password)
throws SQLException
{
- if ( username != this.username || password != this.password )
+ if (username != this.username || password != this.password)
{
throw new SQLException("Username and password are invalid.");
}
PooledConnection pcon = null;
- if ( pool.empty() && totalConnections < maxConnections )
+ if (pool.empty() && totalConnections < maxConnections)
{
pcon = getNewConnection();
}
@@ -262,7 +258,7 @@
throws SQLException
{
PooledConnection pc = null;
- if ( username == null )
+ if (username == null)
{
pc = cpds.getPooledConnection();
}
@@ -274,8 +270,8 @@
// Age some connections so that there will not be a run on the db,
// when connections start expiring
long currentTime = System.currentTimeMillis();
- double ratio = (1.0 * totalConnections)/maxConnections;
- currentTime -= expiryTime*0.25*(1.0-ratio);
+ double ratio = (1.0 * totalConnections) / maxConnections;
+ currentTime -= expiryTime * 0.25 * (1.0 - ratio);
timeStamps.put(pc, new Long(currentTime));
totalConnections++;
return pc;
@@ -293,7 +289,7 @@
{
// We test waitCount > 0 to make sure no other threads are
// waiting for a connection.
- if ( waitCount > 0 || pool.empty() )
+ if (waitCount > 0 || pool.empty())
{
// The connection pool is empty and we cannot allocate any new
// connections. Wait the prescribed amount of time and see if
@@ -301,7 +297,7 @@
try
{
waitCount++;
- wait( connectionWaitTimeout );
+ wait(connectionWaitTimeout);
}
catch (InterruptedException ignored)
{
@@ -313,7 +309,7 @@
}
// Check for a returned connection.
- if ( pool.empty() )
+ if (pool.empty())
{
// If the pool is still empty here, we were not awoken by
// someone returning a connection.
@@ -333,13 +329,13 @@
private PooledConnection popConnection()
throws Exception
{
- while ( !pool.empty() )
+ while (!pool.empty())
{
PooledConnection con = (PooledConnection) pool.pop();
// It's really not safe to assume this connection is
// valid even though it's checked before being pooled.
- if ( isValid(con) )
+ if (isValid(con))
{
return con;
}
@@ -353,7 +349,7 @@
// guaranteed not to exceed the connection limit since we
// just killed off one or more invalid connections, and no
// one else can be accessing this cache right now.
- if ( pool.empty() )
+ if (pool.empty())
{
return getNewConnection();
}
@@ -374,13 +370,13 @@
* @param connection The connection to test.
* @return True if the connection is expired, false otherwise.
*/
- private boolean isExpired( PooledConnection connection )
+ private boolean isExpired(PooledConnection connection)
{
// Test the age of the connection (defined as current time
// minus connection birthday) against the connection pool
// expiration time.
- return ( expiryTime < (System.currentTimeMillis() -
- ((Long)timeStamps.get(connection)).longValue()) );
+ return (expiryTime < (System.currentTimeMillis() -
+ ((Long) timeStamps.get(connection)).longValue()));
}
/**
@@ -389,15 +385,15 @@
* @param connection The connection to test.
* @return True if the connection is valid, false otherwise.
*/
- private boolean isValid( PooledConnection connection )
+ private boolean isValid(PooledConnection connection)
{
- // all this code is commented out because
+ // all this code is commented out because
// connection.getConnection() is called when the connection
// is returned to the pool and it will open a new logical Connection
- // which does not get closed, then when it is called again
+ // which does not get closed, then when it is called again
// when a connection is requested it likely fails because a
// new Connection has been requested and the old one is still
- // open. need to either do it right or skip it. null check
+ // open. need to either do it right or skip it. null check
// was not working either.
//try
@@ -435,13 +431,13 @@
*/
void shutdown()
{
- if ( pool != null )
+ if (pool != null)
{
- while ( !pool.isEmpty() )
+ while (!pool.isEmpty())
{
try
{
- ((PooledConnection)pool.pop()).close();
+ ((PooledConnection) pool.pop()).close();
}
catch (SQLException ignore)
{
@@ -507,7 +503,7 @@
*/
public void connectionClosed(ConnectionEvent event)
{
- releaseConnection( (PooledConnection)event.getSource());
+ releaseConnection((PooledConnection) event.getSource());
}
/**
@@ -522,7 +518,7 @@
.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR");
//remove this from the listener list because we are no more
//interested in errors since we are about to close this connection
- ( (PooledConnection) event.getSource() )
+ ((PooledConnection) event.getSource())
.removeConnectionEventListener(this);
}
catch (Exception ignore)
@@ -532,7 +528,7 @@
try
{
- closePooledConnection( (PooledConnection)event.getSource() );
+ closePooledConnection((PooledConnection)event.getSource());
}
catch (Exception ignore)
{
@@ -548,7 +544,7 @@
*/
private synchronized void releaseConnection(PooledConnection pcon)
{
- if ( isValid(pcon) )
+ if (isValid(pcon))
{
pool.push(pcon);
notify();
@@ -559,6 +555,10 @@
}
}
+ /**
+ *
+ * @param pcon
+ */
private void closePooledConnection(PooledConnection pcon)
{
try
@@ -579,7 +579,7 @@
private void log(String s)
{
- if ( logWriter != null )
+ if (logWriter != null)
{
logWriter.println(s);
}
1.5 +2 -2
jakarta-turbine-torque/src/java/org/apache/torque/pool/ConnectionWaitTimeoutException.java
Index: ConnectionWaitTimeoutException.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/pool/ConnectionWaitTimeoutException.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConnectionWaitTimeoutException.java 7 Aug 2002 08:07:02 -0000 1.4
+++ ConnectionWaitTimeoutException.java 26 Nov 2002 23:46:56 -0000 1.5
@@ -68,7 +68,7 @@
*
* @param url The URL whose connection we were waiting for.
*/
- public ConnectionWaitTimeoutException( String url )
+ public ConnectionWaitTimeoutException(String url)
{
super("Timed out waiting for pooled connection from '" + url + '\'');
}
1.5 +73 -51
jakarta-turbine-torque/src/java/org/apache/torque/pool/TorqueClassicDataSource.java
Index: TorqueClassicDataSource.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/pool/TorqueClassicDataSource.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TorqueClassicDataSource.java 21 Aug 2002 01:51:21 -0000 1.4
+++ TorqueClassicDataSource.java 26 Nov 2002 23:46:56 -0000 1.5
@@ -190,7 +190,7 @@
*
* @param v Value to assign to expiryTime.
*/
- public void setMaxExpiryTime(int v)
+ public void setMaxExpiryTime(int v)
{
this.maxExpiryTime = v;
}
@@ -215,7 +215,7 @@
*
* @param v Value to assign to connectionWaitTimeout.
*/
- public void setConnectionWaitTimeout(int v)
+ public void setConnectionWaitTimeout(int v)
{
this.connectionWaitTimeout = v;
}
@@ -240,7 +240,7 @@
*
* @param v Value to assign to logInterval.
*/
- public void setLogInterval(int v)
+ public void setLogInterval(int v)
{
this.logInterval = v;
}
@@ -266,7 +266,7 @@
*
* @param v Value to assign to defaultAutoCommit.
*/
- public void setDefaultAutoCommit(boolean v)
+ public void setDefaultAutoCommit(boolean v)
{
this.defaultAutoCommit = v;
}
@@ -292,7 +292,7 @@
*
* @param v Value to assign to defaultReadOnly.
*/
- public void setDefaultReadOnly(boolean v)
+ public void setDefaultReadOnly(boolean v)
{
this.defaultReadOnly = v;
}
@@ -316,15 +316,15 @@
*
* @param v Value to assign to dataSourceName.
*/
- public void setDataSourceName(String v)
+ public void setDataSourceName(String v)
{
- if (getConnectionPoolDataSource() != null)
+ if (getConnectionPoolDataSource() != null)
{
throw new IllegalStateException("connectionPoolDataSource property"
- + " already has a value. Both dataSourceName and "
+ + " already has a value. Both dataSourceName and "
+ "connectionPoolDataSource properties cannot be set.");
}
-
+
this.dataSourceName = v;
}
@@ -348,7 +348,7 @@
*
* @param v Value to assign to description.
*/
- public void setDescription(String v)
+ public void setDescription(String v)
{
this.description = v;
}
@@ -359,6 +359,7 @@
* a jndi InitialContext. This InitialContext is used to locate the
* backend ConnectionPoolDataSource.
*
+ * @param key environment key
* @return value of jndiEnvironment.
*/
public String getJndiEnvironment(String key)
@@ -376,7 +377,8 @@
* a jndi InitialContext. This InitialContext is used to locate the
* backend ConnectionPoolDataSource.
*
- * @param v Value to assign to jndiEnvironment.
+ * @param key environment key
+ * @param value Value to assign to jndiEnvironment.
*/
public void setJndiEnvironment(String key, String value)
{
@@ -405,7 +407,7 @@
*
* @param v Value to assign to connectionPoolDataSource.
*/
- public void
+ public void
setConnectionPoolDataSource(ConnectionPoolDataSource v)
{
if (v == null)
@@ -413,10 +415,10 @@
throw new IllegalArgumentException(
"Null argument value is not allowed.");
}
- if (getDataSourceName() != null)
+ if (getDataSourceName() != null)
{
throw new IllegalStateException("dataSourceName property"
- + " already has a value. Both dataSourceName and "
+ + " already has a value. Both dataSourceName and "
+ "connectionPoolDataSource properties cannot be set.");
}
this.cpds = v;
@@ -425,31 +427,35 @@
dataSourceName = v.hashCode() + " internal cpds name " + cpdsCounter++;
}
-
/**
* Attempt to establish a database connection.
+ *
+ * @throws SQLException
*/
- public Connection getConnection()
- throws SQLException
+ public Connection getConnection() throws SQLException
{
return getConnection(null, null);
}
/**
* Attempt to establish a database connection.
+ *
+ * @param username
+ * @param password
+ * @throws SQLException
*/
synchronized public Connection getConnection(String username,
String password)
throws SQLException
{
String key = getKey(username);
- ConnectionPool pool = (ConnectionPool)pools.get(key);
- if ( pool == null )
+ ConnectionPool pool = (ConnectionPool) pools.get(key);
+ if (pool == null)
{
try
{
registerPool(username, password);
- pool = (ConnectionPool)pools.get(key);
+ pool = (ConnectionPool) pools.get(key);
}
catch (Exception e)
{
@@ -457,40 +463,50 @@
}
}
- Connection con =
- pool.getConnection(username, password).getConnection();
+ Connection con = pool.getConnection(username, password).getConnection();
con.setAutoCommit(defaultAutoCommit);
con.setReadOnly(defaultReadOnly);
return con;
}
+ /**
+ *
+ * @param suffix
+ * @return
+ */
private String getKey(String suffix)
{
String key = getDataSourceName();
if (key == null)
{
- throw new IllegalStateException("Attempted to use DataSource "
+ throw new IllegalStateException("Attempted to use DataSource "
+ "without a backend ConnectionPoolDataSource defined.");
}
-
- if ( suffix != null )
+
+ if (suffix != null)
{
key += suffix;
}
return key;
}
+ /**
+ *
+ * @param username
+ * @param password
+ * @throws javax.naming.NamingException
+ */
synchronized private void registerPool(String username, String password)
throws javax.naming.NamingException
{
String key = getKey(username);
- if ( !pools.containsKey(key) )
+ if (!pools.containsKey(key))
{
ConnectionPoolDataSource cpds = this.cpds;
- if ( cpds == null )
+ if (cpds == null)
{
Context ctx = null;
- if ( jndiEnvironment == null )
+ if (jndiEnvironment == null)
{
ctx = new InitialContext();
}
@@ -498,15 +514,15 @@
{
ctx = new InitialContext(jndiEnvironment);
}
- cpds = (ConnectionPoolDataSource)ctx.lookup(dataSourceName);
+ cpds = (ConnectionPoolDataSource) ctx.lookup(dataSourceName);
}
int maxConnections = getDefaultMaxConnections();
- if ( username != null )
+ if (username != null)
{
String userMaxCon =
- (String)getPerUserMaxConnections().get(username);
- if ( userMaxCon != null )
+ (String) getPerUserMaxConnections().get(username);
+ if (userMaxCon != null)
{
maxConnections = Integer.parseInt(userMaxCon);
}
@@ -564,8 +580,7 @@
/**
* <CODE>Referenceable</CODE> implementation.
*/
- public Reference getReference()
- throws NamingException
+ public Reference getReference() throws NamingException
{
String factory = getClass().getName();
@@ -584,7 +599,7 @@
byte[] serJndiEnv = null;
// BinaryRefAddr does not allow null byte[].
- if ( jndiEnvironment != null )
+ if (jndiEnvironment != null)
{
serJndiEnv = SerializationUtils.serialize(jndiEnvironment);
ref.add(new BinaryRefAddr("jndiEnvironment", serJndiEnv));
@@ -592,7 +607,7 @@
byte[] serPUMC = null;
// BinaryRefAddr does not allow null byte[].
- if ( getPerUserMaxConnections() != null )
+ if (getPerUserMaxConnections() != null)
{
serPUMC = SerializationUtils.serialize(getPerUserMaxConnections());
ref.add(new BinaryRefAddr("perUserMaxConnections", serPUMC));
@@ -601,42 +616,49 @@
return ref;
}
-
/**
* implements ObjectFactory to create an instance of this class
+ *
+ * @param refObj
+ * @param name
+ * @param context
+ * @param env
+ * @return
+ * @throws Exception
*/
public Object getObjectInstance(Object refObj, Name name,
Context context, Hashtable env)
throws Exception
{
- Reference ref = (Reference)refObj;
+ Reference ref = (Reference) refObj;
if (ref.getClassName().equals(getClass().getName()))
{
setDefaultMaxConnections(Integer.parseInt(
- (String)ref.get("defaultMaxConnections").getContent()));
+ (String) ref.get("defaultMaxConnections").getContent()));
setMaxExpiryTime(Integer.parseInt(
- (String)ref.get("maxExpiryTime").getContent()));
+ (String) ref.get("maxExpiryTime").getContent()));
setConnectionWaitTimeout(Integer.parseInt(
- (String)ref.get("connectionWaitTimeout").getContent()));
+ (String) ref.get("connectionWaitTimeout").getContent()));
setLogInterval(Integer.parseInt(
- (String)ref.get("logInterval").getContent()));
- setDataSourceName((String)ref.get("dataSourceName").getContent());
- setDescription((String)ref.get("description").getContent());
+ (String) ref.get("logInterval").getContent()));
+ setDataSourceName((String) ref.get("dataSourceName").getContent());
+ setDescription((String) ref.get("description").getContent());
RefAddr refAddr = ref.get("jndiEnvironment");
- if ( refAddr != null )
+ if (refAddr != null)
{
- byte[] serialized = (byte[])refAddr.getContent();
- jndiEnvironment =
(Properties)SerializationUtils.deserialize(serialized);
+ byte[] serialized = (byte[]) refAddr.getContent();
+ jndiEnvironment = (Properties)
+ SerializationUtils.deserialize(serialized);
}
refAddr = ref.get("perUserMaxConnections");
- if ( refAddr != null )
+ if (refAddr != null)
{
- byte[] serialized = (byte[])refAddr.getContent();
+ byte[] serialized = (byte[]) refAddr.getContent();
setPerUserMaxConnections(
- (Properties)SerializationUtils.deserialize(serialized) );
+ (Properties) SerializationUtils.deserialize(serialized));
}
return this;
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>