Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement JDK 7 Connection/DataSource methods

  • Loading branch information...
commit 43e8026e89a724cf49e7608993613b351356a845 1 parent b764bae
@aaime aaime authored
View
14 modules/library/jdbc/src/main/java/org/geotools/data/jdbc/datasource/AbstractManageableDataSource.java
@@ -19,6 +19,8 @@
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.logging.Logger;
import javax.sql.DataSource;
@@ -71,7 +73,13 @@ public boolean isWrapperFor(Class c) throws SQLException {
return false;
}
- public Object unwrap(Class arg0) throws SQLException {
- throw new SQLException("This implementation cannot unwrap anything");
- }
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new SQLException("This implementation cannot unwrap anything");
+ }
+
+ @Override
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
}
View
48 modules/library/jdbc/src/main/java/org/geotools/jdbc/LifecycleConnection.java
@@ -16,6 +16,7 @@
*/
package org.geotools.jdbc;
+import java.lang.reflect.Method;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
@@ -34,6 +35,11 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.Executor;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.geotools.util.logging.Logging;
/**
* Calls the {@link ConnectionLifecycleListener#onBorrow(Connection)} method on construction and
@@ -44,6 +50,8 @@
* @author Andrea Aime - GeoSolutions
*/
class LifecycleConnection implements Connection {
+
+ static final Logger LOGGER = Logging.getLogger(LifecycleConnection.class);
Connection delegate;
@@ -278,6 +286,44 @@ public Struct createStruct(String typeName, Object[] attributes) throws SQLExcep
return delegate.createStruct(typeName, attributes);
}
-
+ @Override
+ public void setSchema(String schema) throws SQLException {
+ invokeMethodQuietly("setSchema", new Class[] {String.class}, new Object[] {schema}, null);
+ }
+
+ @Override
+ public String getSchema() throws SQLException {
+ return (String) invokeMethodQuietly("getSchema", null, null, null);
+ }
+
+ @Override
+ public void abort(Executor executor) throws SQLException {
+ invokeMethodQuietly("abort", new Class[] {Executor.class}, new Object[] {executor}, null);
+ }
+
+ @Override
+ public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
+ invokeMethodQuietly("setNetworkTimeout", new Class[] {Executor.class, int.class}, new Object[] {executor, milliseconds}, null);
+ }
+
+ @Override
+ public int getNetworkTimeout() throws SQLException {
+ return (Integer) invokeMethodQuietly("getNetworkTimeout", null, null, 0);
+ }
+
+ private Object invokeMethodQuietly(String methodName, Class[] paramTypes, Object[] params, Object defaultValue) {
+ try {
+ if(paramTypes == null) {
+ Method method = delegate.getClass().getDeclaredMethod(methodName);
+ return method.invoke(delegate);
+ } else {
+ Method method = delegate.getClass().getDeclaredMethod(methodName, paramTypes);
+ return method.invoke(delegate, params);
+ }
+ } catch (Exception e) {
+ LOGGER.log(Level.FINER, "Failed to invoke delegate method", e);
+ return defaultValue;
+ }
+ }
}
View
7 .../library/referencing/src/main/java/org/geotools/referencing/factory/epsg/SingleConnectionDataSource.java
@@ -19,6 +19,8 @@
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.logging.Logger;
import javax.sql.DataSource;
@@ -69,4 +71,9 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new SQLException("Not wrapping an object implementing "+ iface.getClass().getName() );
}
+ @Override
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ throw new SQLFeatureNotSupportedException();
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.