Author: markt
Date: Tue Aug 2 00:20:09 2011
New Revision: 1152981
URL: http://svn.apache.org/viewvc?rev=1152981&view=rev
Log:
Generics
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java?rev=1152981&r1=1152980&r2=1152981&view=diff
==============================================================================
---
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
(original)
+++
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
Tue Aug 2 00:20:09 2011
@@ -1014,7 +1014,7 @@ public class BasicDataSource implements
*
* @since 1.3
*/
- protected volatile List connectionInitSqls;
+ protected volatile List<String> connectionInitSqls;
/**
* Returns the list of SQL statements executed when a physical connection
@@ -1024,10 +1024,10 @@ public class BasicDataSource implements
* @return initialization SQL statements
* @since 1.3
*/
- public Collection getConnectionInitSqls() {
- Collection result = connectionInitSqls;
+ public Collection<String> getConnectionInitSqls() {
+ Collection<String> result = connectionInitSqls;
if (result == null) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
return result;
}
@@ -1044,20 +1044,17 @@ public class BasicDataSource implements
* @param connectionInitSqls Collection of SQL statements to execute
* on connection creation
*/
- public void setConnectionInitSqls(Collection connectionInitSqls) {
+ public void setConnectionInitSqls(Collection<String> connectionInitSqls) {
if ((connectionInitSqls != null) && (connectionInitSqls.size() > 0)) {
- ArrayList newVal = null;
- for (Iterator iterator = connectionInitSqls.iterator();
+ ArrayList<String> newVal = null;
+ for (Iterator<String> iterator = connectionInitSqls.iterator();
iterator.hasNext();) {
- Object o = iterator.next();
- if (o != null) {
- String s = o.toString();
- if (s.trim().length() > 0) {
- if (newVal == null) {
- newVal = new ArrayList();
- }
- newVal.add(s);
+ String s = iterator.next();
+ if (s != null && s.trim().length() > 0) {
+ if (newVal == null) {
+ newVal = new ArrayList<String>();
}
+ newVal.add(s);
}
}
this.connectionInitSqls = newVal;
@@ -1799,17 +1796,6 @@ public class BasicDataSource implements
}
}
- /**
- * Not used currently
- */
- private void restart() {
- try {
- close();
- } catch (SQLException e) {
- log("Could not restart DataSource, cause: " + e.getMessage());
- }
- }
-
protected void log(String message) {
if (logWriter != null) {
logWriter.println(message);
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java?rev=1152981&r1=1152980&r2=1152981&view=diff
==============================================================================
---
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
(original)
+++
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
Tue Aug 2 00:20:09 2011
@@ -19,6 +19,8 @@ package org.apache.commons.dbcp2;
import java.io.ByteArrayInputStream;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
@@ -137,7 +139,7 @@ public class BasicDataSourceFactory impl
*/
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable environment)
+ @SuppressWarnings("rawtypes") Hashtable environment)
throws Exception {
// We only know how to deal with <code>javax.naming.Reference</code>s
@@ -353,13 +355,20 @@ public class BasicDataSourceFactory impl
value = properties.getProperty(PROP_CONNECTIONINITSQLS);
if (value != null) {
StringTokenizer tokenizer = new StringTokenizer(value, ";");
- dataSource.setConnectionInitSqls(Collections.list(tokenizer));
+ // Have to jump through these hoops as StringTokenizer implements
+ // Enumeration<Object> rather than Enumeration<String>
+ Collection<String> tokens =
+ new ArrayList<String>(tokenizer.countTokens());
+ while (tokenizer.hasMoreTokens()) {
+ tokens.add(tokenizer.nextToken());
+ }
+ dataSource.setConnectionInitSqls(tokens);
}
value = properties.getProperty(PROP_CONNECTIONPROPERTIES);
if (value != null) {
Properties p = getProperties(value);
- Enumeration e = p.propertyNames();
+ Enumeration<?> e = p.propertyNames();
while (e.hasMoreElements()) {
String propertyName = (String) e.nextElement();
dataSource.addConnectionProperty(propertyName,
p.getProperty(propertyName));