diff --git a/jOOQ/src/main/java/org/jooq/Configuration.java b/jOOQ/src/main/java/org/jooq/Configuration.java
index ddd8aa8c10..a280843bf4 100644
--- a/jOOQ/src/main/java/org/jooq/Configuration.java
+++ b/jOOQ/src/main/java/org/jooq/Configuration.java
@@ -39,6 +39,8 @@ import java.io.Serializable;
import java.sql.Connection;
import java.util.Map;
+import javax.sql.DataSource;
+
import org.jooq.conf.Settings;
/**
@@ -53,6 +55,16 @@ public interface Configuration extends Serializable {
*/
SQLDialect getDialect();
+ /**
+ * Retrieve the configured data source
+ */
+ DataSource getDataSource();
+
+ /**
+ * Set the configured data source
+ */
+ void setDataSource(DataSource datasource);
+
/**
* Retrieve the configured connection
*/
diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractConfiguration.java b/jOOQ/src/main/java/org/jooq/impl/AbstractConfiguration.java
index 30f70f2772..c812e2ac41 100644
--- a/jOOQ/src/main/java/org/jooq/impl/AbstractConfiguration.java
+++ b/jOOQ/src/main/java/org/jooq/impl/AbstractConfiguration.java
@@ -38,6 +38,8 @@ package org.jooq.impl;
import java.sql.Connection;
import java.util.Map;
+import javax.sql.DataSource;
+
import org.jooq.Configuration;
import org.jooq.SQLDialect;
import org.jooq.conf.Settings;
@@ -66,6 +68,16 @@ abstract class AbstractConfiguration implements Configuration {
return configuration.getDialect();
}
+ @Override
+ public final DataSource getDataSource() {
+ return configuration.getDataSource();
+ }
+
+ @Override
+ public final void setDataSource(DataSource datasource) {
+ configuration.setDataSource(datasource);
+ }
+
@Override
public final Connection getConnection() {
return configuration.getConnection();
diff --git a/jOOQ/src/main/java/org/jooq/impl/DataSourceConnection.java b/jOOQ/src/main/java/org/jooq/impl/DataSourceConnection.java
new file mode 100644
index 0000000000..a6851a18f9
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/DataSourceConnection.java
@@ -0,0 +1,373 @@
+/**
+ * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
+ * All rights reserved.
+ *
+ * This software is licensed to you under the Apache License, Version 2.0
+ * (the "License"); You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * . Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * . Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * . Neither the name "jOOQ" nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.jooq.impl;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+
+import org.jooq.conf.Settings;
+import org.jooq.exception.DataAccessException;
+
+/**
+ * A {@link DataSource}-enabled connection.
+ *
+ * This is a wrapper for both a {@link DataSource} and/or a {@link Connection}.
+ * This wrapper abstracts closing a JDBC connection when it is obtained from a
+ * data source by closing it when the {@link Statement},
+ * {@link PreparedStatement}, or {@link CallableStatement} is closed.
+ *
+ * @author Lukas Eder
+ */
+class DataSourceConnection implements Connection {
+
+ private final DataSource datasource;
+ private final Settings settings;
+
+ private Connection connection;
+
+ DataSourceConnection(DataSource datasource, Connection connection, Settings settings) {
+ this.datasource = datasource;
+ this.connection = connection;
+ this.settings = settings;
+ }
+
+ final Connection getDelegate() {
+ if (connection == null) {
+ try {
+ connection = new ConnectionProxy(datasource.getConnection(), settings);
+ }
+ catch (SQLException e) {
+ throw new DataAccessException("Error when fetching Connection from DataSource", e);
+ }
+ }
+
+ return connection;
+ }
+
+ final DataSource getDataSource() {
+ return datasource;
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Closing the connection
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final void close() throws SQLException {
+ getDelegate().close();
+
+ if (datasource != null) {
+ connection = null;
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Creation of Statements
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final Statement createStatement() throws SQLException {
+ return new DataSourceStatement(this, getDelegate().createStatement());
+ }
+
+ @Override
+ public final Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
+ return new DataSourceStatement(this, getDelegate().createStatement(resultSetType, resultSetConcurrency));
+ }
+
+ @Override
+ public final Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return new DataSourceStatement(this, getDelegate().createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Creation of PreparedStatements
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final PreparedStatement prepareStatement(String sql) throws SQLException {
+ return new DataSourcePreparedStatement(this, getDelegate().prepareStatement(sql));
+ }
+
+ @Override
+ public final PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
+ return new DataSourcePreparedStatement(this, getDelegate().prepareStatement(sql, autoGeneratedKeys));
+ }
+
+ @Override
+ public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ return new DataSourcePreparedStatement(this, getDelegate().prepareStatement(sql, resultSetType, resultSetConcurrency));
+ }
+
+ @Override
+ public final PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return new DataSourcePreparedStatement(this, getDelegate().prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+ }
+
+ @Override
+ public final PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
+ return new DataSourcePreparedStatement(this, getDelegate().prepareStatement(sql, columnIndexes));
+ }
+
+ @Override
+ public final PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
+ return new DataSourcePreparedStatement(this, getDelegate().prepareStatement(sql, columnNames));
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Creation of CallableStatements
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final CallableStatement prepareCall(String sql) throws SQLException {
+ return new DataSourcePreparedCall(this, getDelegate().prepareCall(sql));
+ }
+
+ @Override
+ public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+ return new DataSourcePreparedCall(this, getDelegate().prepareCall(sql, resultSetType, resultSetConcurrency));
+ }
+
+ @Override
+ public final CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return new DataSourcePreparedCall(this, getDelegate().prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Other methods
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final T unwrap(Class iface) throws SQLException {
+ return getDelegate().unwrap(iface);
+ }
+
+ @Override
+ public final boolean isWrapperFor(Class> iface) throws SQLException {
+ return getDelegate().isWrapperFor(iface);
+ }
+
+ @Override
+ public final String nativeSQL(String sql) throws SQLException {
+ return getDelegate().nativeSQL(sql);
+ }
+
+ @Override
+ public final void setAutoCommit(boolean autoCommit) throws SQLException {
+ getDelegate().setAutoCommit(autoCommit);
+ }
+
+ @Override
+ public final boolean getAutoCommit() throws SQLException {
+ return getDelegate().getAutoCommit();
+ }
+
+ @Override
+ public final void commit() throws SQLException {
+ getDelegate().commit();
+ }
+
+ @Override
+ public final void rollback() throws SQLException {
+ getDelegate().rollback();
+ }
+
+ @Override
+ public final boolean isClosed() throws SQLException {
+ return getDelegate().isClosed();
+ }
+
+ @Override
+ public final DatabaseMetaData getMetaData() throws SQLException {
+ return getDelegate().getMetaData();
+ }
+
+ @Override
+ public final void setReadOnly(boolean readOnly) throws SQLException {
+ getDelegate().setReadOnly(readOnly);
+ }
+
+ @Override
+ public final boolean isReadOnly() throws SQLException {
+ return getDelegate().isReadOnly();
+ }
+
+ @Override
+ public final void setCatalog(String catalog) throws SQLException {
+ getDelegate().setCatalog(catalog);
+ }
+
+ @Override
+ public final String getCatalog() throws SQLException {
+ return getDelegate().getCatalog();
+ }
+
+ @Override
+ public final void setTransactionIsolation(int level) throws SQLException {
+ getDelegate().setTransactionIsolation(level);
+ }
+
+ @Override
+ public final int getTransactionIsolation() throws SQLException {
+ return getDelegate().getTransactionIsolation();
+ }
+
+ @Override
+ public final SQLWarning getWarnings() throws SQLException {
+ return getDelegate().getWarnings();
+ }
+
+ @Override
+ public final void clearWarnings() throws SQLException {
+ getDelegate().clearWarnings();
+ }
+
+ @Override
+ public final Map> getTypeMap() throws SQLException {
+ return getDelegate().getTypeMap();
+ }
+
+ @Override
+ public final void setTypeMap(Map> map) throws SQLException {
+ getDelegate().setTypeMap(map);
+ }
+
+ @Override
+ public final void setHoldability(int holdability) throws SQLException {
+ getDelegate().setHoldability(holdability);
+ }
+
+ @Override
+ public final int getHoldability() throws SQLException {
+ return getDelegate().getHoldability();
+ }
+
+ @Override
+ public final Savepoint setSavepoint() throws SQLException {
+ return getDelegate().setSavepoint();
+ }
+
+ @Override
+ public final Savepoint setSavepoint(String name) throws SQLException {
+ return getDelegate().setSavepoint(name);
+ }
+
+ @Override
+ public final void rollback(Savepoint savepoint) throws SQLException {
+ getDelegate().rollback(savepoint);
+ }
+
+ @Override
+ public final void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ getDelegate().releaseSavepoint(savepoint);
+ }
+
+ @Override
+ public final Clob createClob() throws SQLException {
+ return getDelegate().createClob();
+ }
+
+ @Override
+ public final Blob createBlob() throws SQLException {
+ return getDelegate().createBlob();
+ }
+
+ @Override
+ public final NClob createNClob() throws SQLException {
+ return getDelegate().createNClob();
+ }
+
+ @Override
+ public final SQLXML createSQLXML() throws SQLException {
+ return getDelegate().createSQLXML();
+ }
+
+ @Override
+ public final boolean isValid(int timeout) throws SQLException {
+ return getDelegate().isValid(timeout);
+ }
+
+ @Override
+ public final void setClientInfo(String name, String value) throws SQLClientInfoException {
+ getDelegate().setClientInfo(name, value);
+ }
+
+ @Override
+ public final void setClientInfo(Properties properties) throws SQLClientInfoException {
+ getDelegate().setClientInfo(properties);
+ }
+
+ @Override
+ public final String getClientInfo(String name) throws SQLException {
+ return getDelegate().getClientInfo(name);
+ }
+
+ @Override
+ public final Properties getClientInfo() throws SQLException {
+ return getDelegate().getClientInfo();
+ }
+
+ @Override
+ public final Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+ return getDelegate().createArrayOf(typeName, elements);
+ }
+
+ @Override
+ public final Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+ return getDelegate().createStruct(typeName, attributes);
+ }
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DataSourcePreparedCall.java b/jOOQ/src/main/java/org/jooq/impl/DataSourcePreparedCall.java
new file mode 100644
index 0000000000..457d66cc84
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/DataSourcePreparedCall.java
@@ -0,0 +1,638 @@
+/**
+ * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
+ * All rights reserved.
+ *
+ * This software is licensed to you under the Apache License, Version 2.0
+ * (the "License"); You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * . Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * . Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * . Neither the name "jOOQ" nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.jooq.impl;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+/**
+ * A {@link DataSource}-enabled statement.
+ *
+ * @author Lukas Eder
+ * @see DataSourceConnection
+ */
+class DataSourcePreparedCall extends DataSourcePreparedStatement implements CallableStatement {
+
+ DataSourcePreparedCall(DataSourceConnection connection, CallableStatement statement) {
+ super(connection, statement);
+ }
+
+ /**
+ * Subclasses may override this method
+ */
+ @Override
+ CallableStatement getDelegate() {
+ return (CallableStatement) super.getDelegate();
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Other methods
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
+ getDelegate().registerOutParameter(parameterIndex, sqlType);
+ }
+
+ @Override
+ public final void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
+ getDelegate().registerOutParameter(parameterIndex, sqlType, scale);
+ }
+
+ @Override
+ public final boolean wasNull() throws SQLException {
+ return getDelegate().wasNull();
+ }
+
+ @Override
+ public final String getString(int parameterIndex) throws SQLException {
+ return getDelegate().getString(parameterIndex);
+ }
+
+ @Override
+ public final boolean getBoolean(int parameterIndex) throws SQLException {
+ return getDelegate().getBoolean(parameterIndex);
+ }
+
+ @Override
+ public final byte getByte(int parameterIndex) throws SQLException {
+ return getDelegate().getByte(parameterIndex);
+ }
+
+ @Override
+ public final short getShort(int parameterIndex) throws SQLException {
+ return getDelegate().getShort(parameterIndex);
+ }
+
+ @Override
+ public final int getInt(int parameterIndex) throws SQLException {
+ return getDelegate().getInt(parameterIndex);
+ }
+
+ @Override
+ public final long getLong(int parameterIndex) throws SQLException {
+ return getDelegate().getLong(parameterIndex);
+ }
+
+ @Override
+ public final float getFloat(int parameterIndex) throws SQLException {
+ return getDelegate().getFloat(parameterIndex);
+ }
+
+ @Override
+ public final double getDouble(int parameterIndex) throws SQLException {
+ return getDelegate().getDouble(parameterIndex);
+ }
+
+ @Override
+ @Deprecated
+ public final BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
+ return getDelegate().getBigDecimal(parameterIndex, scale);
+ }
+
+ @Override
+ public final byte[] getBytes(int parameterIndex) throws SQLException {
+ return getDelegate().getBytes(parameterIndex);
+ }
+
+ @Override
+ public final Date getDate(int parameterIndex) throws SQLException {
+ return getDelegate().getDate(parameterIndex);
+ }
+
+ @Override
+ public final Time getTime(int parameterIndex) throws SQLException {
+ return getDelegate().getTime(parameterIndex);
+ }
+
+ @Override
+ public final Timestamp getTimestamp(int parameterIndex) throws SQLException {
+ return getDelegate().getTimestamp(parameterIndex);
+ }
+
+ @Override
+ public final Object getObject(int parameterIndex) throws SQLException {
+ return getDelegate().getObject(parameterIndex);
+ }
+
+ @Override
+ public final BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
+ return getDelegate().getBigDecimal(parameterIndex);
+ }
+
+ @Override
+ public final Object getObject(int parameterIndex, Map> map) throws SQLException {
+ return getDelegate().getObject(parameterIndex, map);
+ }
+
+ @Override
+ public final Ref getRef(int parameterIndex) throws SQLException {
+ return getDelegate().getRef(parameterIndex);
+ }
+
+ @Override
+ public final Blob getBlob(int parameterIndex) throws SQLException {
+ return getDelegate().getBlob(parameterIndex);
+ }
+
+ @Override
+ public final Clob getClob(int parameterIndex) throws SQLException {
+ return getDelegate().getClob(parameterIndex);
+ }
+
+ @Override
+ public final Array getArray(int parameterIndex) throws SQLException {
+ return getDelegate().getArray(parameterIndex);
+ }
+
+ @Override
+ public final Date getDate(int parameterIndex, Calendar cal) throws SQLException {
+ return getDelegate().getDate(parameterIndex, cal);
+ }
+
+ @Override
+ public final Time getTime(int parameterIndex, Calendar cal) throws SQLException {
+ return getDelegate().getTime(parameterIndex, cal);
+ }
+
+ @Override
+ public final Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
+ return getDelegate().getTimestamp(parameterIndex, cal);
+ }
+
+ @Override
+ public final void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
+ getDelegate().registerOutParameter(parameterIndex, sqlType, typeName);
+ }
+
+ @Override
+ public final void registerOutParameter(String parameterName, int sqlType) throws SQLException {
+ getDelegate().registerOutParameter(parameterName, sqlType);
+ }
+
+ @Override
+ public final void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
+ getDelegate().registerOutParameter(parameterName, sqlType, scale);
+ }
+
+ @Override
+ public final void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
+ getDelegate().registerOutParameter(parameterName, sqlType, typeName);
+ }
+
+ @Override
+ public final URL getURL(int parameterIndex) throws SQLException {
+ return getDelegate().getURL(parameterIndex);
+ }
+
+ @Override
+ public final void setURL(String parameterName, URL val) throws SQLException {
+ getDelegate().setURL(parameterName, val);
+ }
+
+ @Override
+ public final void setNull(String parameterName, int sqlType) throws SQLException {
+ getDelegate().setNull(parameterName, sqlType);
+ }
+
+ @Override
+ public final void setBoolean(String parameterName, boolean x) throws SQLException {
+ getDelegate().setBoolean(parameterName, x);
+ }
+
+ @Override
+ public final void setByte(String parameterName, byte x) throws SQLException {
+ getDelegate().setByte(parameterName, x);
+ }
+
+ @Override
+ public final void setShort(String parameterName, short x) throws SQLException {
+ getDelegate().setShort(parameterName, x);
+ }
+
+ @Override
+ public final void setInt(String parameterName, int x) throws SQLException {
+ getDelegate().setInt(parameterName, x);
+ }
+
+ @Override
+ public final void setLong(String parameterName, long x) throws SQLException {
+ getDelegate().setLong(parameterName, x);
+ }
+
+ @Override
+ public final void setFloat(String parameterName, float x) throws SQLException {
+ getDelegate().setFloat(parameterName, x);
+ }
+
+ @Override
+ public final void setDouble(String parameterName, double x) throws SQLException {
+ getDelegate().setDouble(parameterName, x);
+ }
+
+ @Override
+ public final void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
+ getDelegate().setBigDecimal(parameterName, x);
+ }
+
+ @Override
+ public final void setString(String parameterName, String x) throws SQLException {
+ getDelegate().setString(parameterName, x);
+ }
+
+ @Override
+ public final void setBytes(String parameterName, byte[] x) throws SQLException {
+ getDelegate().setBytes(parameterName, x);
+ }
+
+ @Override
+ public final void setDate(String parameterName, Date x) throws SQLException {
+ getDelegate().setDate(parameterName, x);
+ }
+
+ @Override
+ public final void setTime(String parameterName, Time x) throws SQLException {
+ getDelegate().setTime(parameterName, x);
+ }
+
+ @Override
+ public final void setTimestamp(String parameterName, Timestamp x) throws SQLException {
+ getDelegate().setTimestamp(parameterName, x);
+ }
+
+ @Override
+ public final void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
+ getDelegate().setAsciiStream(parameterName, x, length);
+ }
+
+ @Override
+ public final void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
+ getDelegate().setBinaryStream(parameterName, x, length);
+ }
+
+ @Override
+ public final void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
+ getDelegate().setObject(parameterName, x, targetSqlType, scale);
+ }
+
+ @Override
+ public final void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
+ getDelegate().setObject(parameterName, x, targetSqlType);
+ }
+
+ @Override
+ public final void setObject(String parameterName, Object x) throws SQLException {
+ getDelegate().setObject(parameterName, x);
+ }
+
+ @Override
+ public final void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
+ getDelegate().setCharacterStream(parameterName, reader, length);
+ }
+
+ @Override
+ public final void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
+ getDelegate().setDate(parameterName, x, cal);
+ }
+
+ @Override
+ public final void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
+ getDelegate().setTime(parameterName, x, cal);
+ }
+
+ @Override
+ public final void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
+ getDelegate().setTimestamp(parameterName, x, cal);
+ }
+
+ @Override
+ public final void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
+ getDelegate().setNull(parameterName, sqlType, typeName);
+ }
+
+ @Override
+ public final String getString(String parameterName) throws SQLException {
+ return getDelegate().getString(parameterName);
+ }
+
+ @Override
+ public final boolean getBoolean(String parameterName) throws SQLException {
+ return getDelegate().getBoolean(parameterName);
+ }
+
+ @Override
+ public final byte getByte(String parameterName) throws SQLException {
+ return getDelegate().getByte(parameterName);
+ }
+
+ @Override
+ public final short getShort(String parameterName) throws SQLException {
+ return getDelegate().getShort(parameterName);
+ }
+
+ @Override
+ public final int getInt(String parameterName) throws SQLException {
+ return getDelegate().getInt(parameterName);
+ }
+
+ @Override
+ public final long getLong(String parameterName) throws SQLException {
+ return getDelegate().getLong(parameterName);
+ }
+
+ @Override
+ public final float getFloat(String parameterName) throws SQLException {
+ return getDelegate().getFloat(parameterName);
+ }
+
+ @Override
+ public final double getDouble(String parameterName) throws SQLException {
+ return getDelegate().getDouble(parameterName);
+ }
+
+ @Override
+ public final byte[] getBytes(String parameterName) throws SQLException {
+ return getDelegate().getBytes(parameterName);
+ }
+
+ @Override
+ public final Date getDate(String parameterName) throws SQLException {
+ return getDelegate().getDate(parameterName);
+ }
+
+ @Override
+ public final Time getTime(String parameterName) throws SQLException {
+ return getDelegate().getTime(parameterName);
+ }
+
+ @Override
+ public final Timestamp getTimestamp(String parameterName) throws SQLException {
+ return getDelegate().getTimestamp(parameterName);
+ }
+
+ @Override
+ public final Object getObject(String parameterName) throws SQLException {
+ return getDelegate().getObject(parameterName);
+ }
+
+ @Override
+ public final BigDecimal getBigDecimal(String parameterName) throws SQLException {
+ return getDelegate().getBigDecimal(parameterName);
+ }
+
+ @Override
+ public final Object getObject(String parameterName, Map> map) throws SQLException {
+ return getDelegate().getObject(parameterName, map);
+ }
+
+ @Override
+ public final Ref getRef(String parameterName) throws SQLException {
+ return getDelegate().getRef(parameterName);
+ }
+
+ @Override
+ public final Blob getBlob(String parameterName) throws SQLException {
+ return getDelegate().getBlob(parameterName);
+ }
+
+ @Override
+ public final Clob getClob(String parameterName) throws SQLException {
+ return getDelegate().getClob(parameterName);
+ }
+
+ @Override
+ public final Array getArray(String parameterName) throws SQLException {
+ return getDelegate().getArray(parameterName);
+ }
+
+ @Override
+ public final Date getDate(String parameterName, Calendar cal) throws SQLException {
+ return getDelegate().getDate(parameterName, cal);
+ }
+
+ @Override
+ public final Time getTime(String parameterName, Calendar cal) throws SQLException {
+ return getDelegate().getTime(parameterName, cal);
+ }
+
+ @Override
+ public final Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
+ return getDelegate().getTimestamp(parameterName, cal);
+ }
+
+ @Override
+ public final URL getURL(String parameterName) throws SQLException {
+ return getDelegate().getURL(parameterName);
+ }
+
+ @Override
+ public final RowId getRowId(int parameterIndex) throws SQLException {
+ return getDelegate().getRowId(parameterIndex);
+ }
+
+ @Override
+ public final RowId getRowId(String parameterName) throws SQLException {
+ return getDelegate().getRowId(parameterName);
+ }
+
+ @Override
+ public final void setRowId(String parameterName, RowId x) throws SQLException {
+ getDelegate().setRowId(parameterName, x);
+ }
+
+ @Override
+ public final void setNString(String parameterName, String value) throws SQLException {
+ getDelegate().setNString(parameterName, value);
+ }
+
+ @Override
+ public final void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
+ getDelegate().setNCharacterStream(parameterName, value, length);
+ }
+
+ @Override
+ public final void setNClob(String parameterName, NClob value) throws SQLException {
+ getDelegate().setNClob(parameterName, value);
+ }
+
+ @Override
+ public final void setClob(String parameterName, Reader reader, long length) throws SQLException {
+ getDelegate().setClob(parameterName, reader, length);
+ }
+
+ @Override
+ public final void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
+ getDelegate().setBlob(parameterName, inputStream, length);
+ }
+
+ @Override
+ public final void setNClob(String parameterName, Reader reader, long length) throws SQLException {
+ getDelegate().setNClob(parameterName, reader, length);
+ }
+
+ @Override
+ public final NClob getNClob(int parameterIndex) throws SQLException {
+ return getDelegate().getNClob(parameterIndex);
+ }
+
+ @Override
+ public final NClob getNClob(String parameterName) throws SQLException {
+ return getDelegate().getNClob(parameterName);
+ }
+
+ @Override
+ public final void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
+ getDelegate().setSQLXML(parameterName, xmlObject);
+ }
+
+ @Override
+ public final SQLXML getSQLXML(int parameterIndex) throws SQLException {
+ return getDelegate().getSQLXML(parameterIndex);
+ }
+
+ @Override
+ public final SQLXML getSQLXML(String parameterName) throws SQLException {
+ return getDelegate().getSQLXML(parameterName);
+ }
+
+ @Override
+ public final String getNString(int parameterIndex) throws SQLException {
+ return getDelegate().getNString(parameterIndex);
+ }
+
+ @Override
+ public final String getNString(String parameterName) throws SQLException {
+ return getDelegate().getNString(parameterName);
+ }
+
+ @Override
+ public final Reader getNCharacterStream(int parameterIndex) throws SQLException {
+ return getDelegate().getNCharacterStream(parameterIndex);
+ }
+
+ @Override
+ public final Reader getNCharacterStream(String parameterName) throws SQLException {
+ return getDelegate().getNCharacterStream(parameterName);
+ }
+
+ @Override
+ public final Reader getCharacterStream(int parameterIndex) throws SQLException {
+ return getDelegate().getCharacterStream(parameterIndex);
+ }
+
+ @Override
+ public final Reader getCharacterStream(String parameterName) throws SQLException {
+ return getDelegate().getCharacterStream(parameterName);
+ }
+
+ @Override
+ public final void setBlob(String parameterName, Blob x) throws SQLException {
+ getDelegate().setBlob(parameterName, x);
+ }
+
+ @Override
+ public final void setClob(String parameterName, Clob x) throws SQLException {
+ getDelegate().setClob(parameterName, x);
+ }
+
+ @Override
+ public final void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
+ getDelegate().setAsciiStream(parameterName, x, length);
+ }
+
+ @Override
+ public final void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
+ getDelegate().setBinaryStream(parameterName, x, length);
+ }
+
+ @Override
+ public final void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
+ getDelegate().setCharacterStream(parameterName, reader, length);
+ }
+
+ @Override
+ public final void setAsciiStream(String parameterName, InputStream x) throws SQLException {
+ getDelegate().setAsciiStream(parameterName, x);
+ }
+
+ @Override
+ public final void setBinaryStream(String parameterName, InputStream x) throws SQLException {
+ getDelegate().setBinaryStream(parameterName, x);
+ }
+
+ @Override
+ public final void setCharacterStream(String parameterName, Reader reader) throws SQLException {
+ getDelegate().setCharacterStream(parameterName, reader);
+ }
+
+ @Override
+ public final void setNCharacterStream(String parameterName, Reader value) throws SQLException {
+ getDelegate().setNCharacterStream(parameterName, value);
+ }
+
+ @Override
+ public final void setClob(String parameterName, Reader reader) throws SQLException {
+ getDelegate().setClob(parameterName, reader);
+ }
+
+ @Override
+ public final void setBlob(String parameterName, InputStream inputStream) throws SQLException {
+ getDelegate().setBlob(parameterName, inputStream);
+ }
+
+ @Override
+ public final void setNClob(String parameterName, Reader reader) throws SQLException {
+ getDelegate().setNClob(parameterName, reader);
+ }
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DataSourcePreparedStatement.java b/jOOQ/src/main/java/org/jooq/impl/DataSourcePreparedStatement.java
new file mode 100644
index 0000000000..3e206e52c9
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/DataSourcePreparedStatement.java
@@ -0,0 +1,364 @@
+/**
+ * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
+ * All rights reserved.
+ *
+ * This software is licensed to you under the Apache License, Version 2.0
+ * (the "License"); You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * . Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * . Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * . Neither the name "jOOQ" nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.jooq.impl;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.ParameterMetaData;
+import java.sql.PreparedStatement;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+
+import javax.sql.DataSource;
+
+/**
+ * A {@link DataSource}-enabled statement.
+ *
+ * @author Lukas Eder
+ * @see DataSourceConnection
+ */
+class DataSourcePreparedStatement extends DataSourceStatement implements PreparedStatement {
+
+ DataSourcePreparedStatement(DataSourceConnection connection, PreparedStatement statement) {
+ super(connection, statement);
+ }
+
+ /**
+ * Subclasses may override this method
+ */
+ @Override
+ PreparedStatement getDelegate() {
+ return (PreparedStatement) super.getDelegate();
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Executing the statement
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final boolean execute() throws SQLException {
+ return getDelegate().execute();
+ }
+
+ @Override
+ public final ResultSet executeQuery() throws SQLException {
+ return getDelegate().executeQuery();
+ }
+
+ @Override
+ public final int executeUpdate() throws SQLException {
+ return getDelegate().executeUpdate();
+ }
+
+ @Override
+ public final void setArray(int parameterIndex, Array x) throws SQLException {
+ getDelegate().setArray(parameterIndex, x);
+ }
+
+ @Override
+ public final void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
+ getDelegate().setAsciiStream(parameterIndex, x);
+ }
+
+ @Override
+ public final void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getDelegate().setAsciiStream(parameterIndex, x, length);
+ }
+
+ @Override
+ public final void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
+ getDelegate().setAsciiStream(parameterIndex, x, length);
+ }
+
+ @Override
+ public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
+ getDelegate().setBigDecimal(parameterIndex, x);
+ }
+
+ @Override
+ public final void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
+ getDelegate().setBinaryStream(parameterIndex, x);
+ }
+
+ @Override
+ public final void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getDelegate().setBinaryStream(parameterIndex, x, length);
+ }
+
+ @Override
+ public final void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
+ getDelegate().setBinaryStream(parameterIndex, x, length);
+ }
+
+ @Override
+ public final void setBlob(int parameterIndex, Blob x) throws SQLException {
+ getDelegate().setBlob(parameterIndex, x);
+ }
+
+ @Override
+ public final void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
+ getDelegate().setBlob(parameterIndex, inputStream);
+ }
+
+ @Override
+ public final void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
+ getDelegate().setBlob(parameterIndex, inputStream, length);
+ }
+
+ @Override
+ public final void setBoolean(int parameterIndex, boolean x) throws SQLException {
+ getDelegate().setBoolean(parameterIndex, x);
+ }
+
+ @Override
+ public final void setByte(int parameterIndex, byte x) throws SQLException {
+ getDelegate().setByte(parameterIndex, x);
+ }
+
+ @Override
+ public final void setBytes(int parameterIndex, byte[] x) throws SQLException {
+ getDelegate().setBytes(parameterIndex, x);
+ }
+
+ @Override
+ public final void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
+ getDelegate().setCharacterStream(parameterIndex, reader);
+ }
+
+ @Override
+ public final void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
+ getDelegate().setCharacterStream(parameterIndex, reader, length);
+ }
+
+ @Override
+ public final void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
+ getDelegate().setCharacterStream(parameterIndex, reader, length);
+ }
+
+ @Override
+ public final void setClob(int parameterIndex, Clob x) throws SQLException {
+ getDelegate().setClob(parameterIndex, x);
+ }
+
+ @Override
+ public final void setClob(int parameterIndex, Reader reader) throws SQLException {
+ getDelegate().setClob(parameterIndex, reader);
+ }
+
+ @Override
+ public final void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
+ getDelegate().setClob(parameterIndex, reader, length);
+ }
+
+ @Override
+ public final void setDate(int parameterIndex, Date x) throws SQLException {
+ getDelegate().setDate(parameterIndex, x);
+ }
+
+ @Override
+ public final void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+ getDelegate().setDate(parameterIndex, x, cal);
+ }
+
+ @Override
+ public final void setDouble(int parameterIndex, double x) throws SQLException {
+ getDelegate().setDouble(parameterIndex, x);
+ }
+
+ @Override
+ public final void setFloat(int parameterIndex, float x) throws SQLException {
+ getDelegate().setFloat(parameterIndex, x);
+ }
+
+ @Override
+ public final void setInt(int parameterIndex, int x) throws SQLException {
+ getDelegate().setInt(parameterIndex, x);
+ }
+
+ @Override
+ public final void setLong(int parameterIndex, long x) throws SQLException {
+ getDelegate().setLong(parameterIndex, x);
+ }
+
+ @Override
+ public final void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
+ getDelegate().setNCharacterStream(parameterIndex, value);
+ }
+
+ @Override
+ public final void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
+ getDelegate().setNCharacterStream(parameterIndex, value, length);
+ }
+
+ @Override
+ public final void setNClob(int parameterIndex, NClob value) throws SQLException {
+ getDelegate().setNClob(parameterIndex, value);
+ }
+
+ @Override
+ public final void setNClob(int parameterIndex, Reader reader) throws SQLException {
+ getDelegate().setNClob(parameterIndex, reader);
+ }
+
+ @Override
+ public final void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
+ getDelegate().setNClob(parameterIndex, reader, length);
+ }
+
+ @Override
+ public final void setNString(int parameterIndex, String value) throws SQLException {
+ getDelegate().setNString(parameterIndex, value);
+ }
+
+ @Override
+ public final void setNull(int parameterIndex, int sqlType) throws SQLException {
+ getDelegate().setNull(parameterIndex, sqlType);
+ }
+
+ @Override
+ public final void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
+ getDelegate().setNull(parameterIndex, sqlType, typeName);
+ }
+
+ @Override
+ public final void setObject(int parameterIndex, Object x) throws SQLException {
+ getDelegate().setObject(parameterIndex, x);
+ }
+
+ @Override
+ public final void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
+ getDelegate().setObject(parameterIndex, x, targetSqlType);
+ }
+
+ @Override
+ public final void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
+ getDelegate().setObject(parameterIndex, x, targetSqlType, scaleOrLength);
+ }
+
+ @Override
+ public final void setRef(int parameterIndex, Ref x) throws SQLException {
+ getDelegate().setRef(parameterIndex, x);
+ }
+
+ @Override
+ public final void setRowId(int parameterIndex, RowId x) throws SQLException {
+ getDelegate().setRowId(parameterIndex, x);
+ }
+
+ @Override
+ public final void setShort(int parameterIndex, short x) throws SQLException {
+ getDelegate().setShort(parameterIndex, x);
+ }
+
+ @Override
+ public final void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
+ getDelegate().setSQLXML(parameterIndex, xmlObject);
+ }
+
+ @Override
+ public final void setString(int parameterIndex, String x) throws SQLException {
+ getDelegate().setString(parameterIndex, x);
+ }
+
+ @Override
+ public final void setTime(int parameterIndex, Time x) throws SQLException {
+ getDelegate().setTime(parameterIndex, x);
+ }
+
+ @Override
+ public final void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+ getDelegate().setTime(parameterIndex, x, cal);
+ }
+
+ @Override
+ public final void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
+ getDelegate().setTimestamp(parameterIndex, x);
+ }
+
+ @Override
+ public final void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
+ getDelegate().setTimestamp(parameterIndex, x, cal);
+ }
+
+ @Override
+ @Deprecated
+ public final void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getDelegate().setUnicodeStream(parameterIndex, x, length);
+ }
+
+ @Override
+ public final void setURL(int parameterIndex, URL x) throws SQLException {
+ getDelegate().setURL(parameterIndex, x);
+ }
+
+ @Override
+ public final void clearParameters() throws SQLException {
+ getDelegate().clearParameters();
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Other methods
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final void addBatch() throws SQLException {
+ getDelegate().addBatch();
+ }
+
+ @Override
+ public final ResultSetMetaData getMetaData() throws SQLException {
+ return getDelegate().getMetaData();
+ }
+
+ @Override
+ public final ParameterMetaData getParameterMetaData() throws SQLException {
+ return getDelegate().getParameterMetaData();
+ }
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DataSourceStatement.java b/jOOQ/src/main/java/org/jooq/impl/DataSourceStatement.java
new file mode 100644
index 0000000000..fb42341d10
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/DataSourceStatement.java
@@ -0,0 +1,297 @@
+/**
+ * Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
+ * All rights reserved.
+ *
+ * This software is licensed to you under the Apache License, Version 2.0
+ * (the "License"); You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * . Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * . Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * . Neither the name "jOOQ" nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.jooq.impl;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+import javax.sql.DataSource;
+
+/**
+ * A {@link DataSource}-enabled statement.
+ *
+ * @author Lukas Eder
+ * @see DataSourceConnection
+ */
+class DataSourceStatement implements Statement {
+
+ private final DataSourceConnection connection;
+ private final Statement statement;
+
+ DataSourceStatement(DataSourceConnection connection, Statement statement) {
+ this.connection = connection;
+ this.statement = statement;
+ }
+
+ /**
+ * Subclasses may override this method
+ */
+ Statement getDelegate() {
+ return statement;
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Closing the Statement
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final void close() throws SQLException {
+ try {
+ getDelegate().close();
+ }
+ finally {
+ if (connection.getDataSource() != null) {
+ connection.close();
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Executing the statement
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final boolean execute(String sql) throws SQLException {
+ return getDelegate().execute(sql);
+ }
+
+ @Override
+ public final boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ return getDelegate().execute(sql, autoGeneratedKeys);
+ }
+
+ @Override
+ public final boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ return getDelegate().execute(sql, columnIndexes);
+ }
+
+ @Override
+ public final boolean execute(String sql, String[] columnNames) throws SQLException {
+ return getDelegate().execute(sql, columnNames);
+ }
+
+ @Override
+ public final int[] executeBatch() throws SQLException {
+ return getDelegate().executeBatch();
+ }
+
+ @Override
+ public final ResultSet executeQuery(String sql) throws SQLException {
+ return getDelegate().executeQuery(sql);
+ }
+
+ @Override
+ public final int executeUpdate(String sql) throws SQLException {
+ return getDelegate().executeUpdate(sql);
+ }
+
+ @Override
+ public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ return getDelegate().executeUpdate(sql, autoGeneratedKeys);
+ }
+
+ @Override
+ public final int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ return getDelegate().executeUpdate(sql, columnIndexes);
+ }
+
+ @Override
+ public final int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ return getDelegate().executeUpdate(sql, columnNames);
+ }
+
+ // ------------------------------------------------------------------------
+ // XXX Other methods
+ // ------------------------------------------------------------------------
+
+ @Override
+ public final T unwrap(Class iface) throws SQLException {
+ return getDelegate().unwrap(iface);
+ }
+
+ @Override
+ public final boolean isWrapperFor(Class> iface) throws SQLException {
+ return getDelegate().isWrapperFor(iface);
+ }
+
+ @Override
+ public final int getMaxFieldSize() throws SQLException {
+ return getDelegate().getMaxFieldSize();
+ }
+
+ @Override
+ public final void setMaxFieldSize(int max) throws SQLException {
+ getDelegate().setMaxFieldSize(max);
+ }
+
+ @Override
+ public final int getMaxRows() throws SQLException {
+ return getDelegate().getMaxRows();
+ }
+
+ @Override
+ public final void setMaxRows(int max) throws SQLException {
+ getDelegate().setMaxRows(max);
+ }
+
+ @Override
+ public final void setEscapeProcessing(boolean enable) throws SQLException {
+ getDelegate().setEscapeProcessing(enable);
+ }
+
+ @Override
+ public final int getQueryTimeout() throws SQLException {
+ return getDelegate().getQueryTimeout();
+ }
+
+ @Override
+ public final void setQueryTimeout(int seconds) throws SQLException {
+ getDelegate().setQueryTimeout(seconds);
+ }
+
+ @Override
+ public final void cancel() throws SQLException {
+ getDelegate().cancel();
+ }
+
+ @Override
+ public final SQLWarning getWarnings() throws SQLException {
+ return getDelegate().getWarnings();
+ }
+
+ @Override
+ public final void clearWarnings() throws SQLException {
+ getDelegate().clearWarnings();
+ }
+
+ @Override
+ public final void setCursorName(String name) throws SQLException {
+ getDelegate().setCursorName(name);
+ }
+
+ @Override
+ public final ResultSet getResultSet() throws SQLException {
+ return getDelegate().getResultSet();
+ }
+
+ @Override
+ public final int getUpdateCount() throws SQLException {
+ return getDelegate().getUpdateCount();
+ }
+
+ @Override
+ public final boolean getMoreResults() throws SQLException {
+ return getDelegate().getMoreResults();
+ }
+
+ @Override
+ public final void setFetchDirection(int direction) throws SQLException {
+ getDelegate().setFetchDirection(direction);
+ }
+
+ @Override
+ public final int getFetchDirection() throws SQLException {
+ return getDelegate().getFetchDirection();
+ }
+
+ @Override
+ public final void setFetchSize(int rows) throws SQLException {
+ getDelegate().setFetchSize(rows);
+ }
+
+ @Override
+ public final int getFetchSize() throws SQLException {
+ return getDelegate().getFetchSize();
+ }
+
+ @Override
+ public final int getResultSetConcurrency() throws SQLException {
+ return getDelegate().getResultSetConcurrency();
+ }
+
+ @Override
+ public final int getResultSetType() throws SQLException {
+ return getDelegate().getResultSetType();
+ }
+
+ @Override
+ public final void addBatch(String sql) throws SQLException {
+ getDelegate().addBatch(sql);
+ }
+
+ @Override
+ public final void clearBatch() throws SQLException {
+ getDelegate().clearBatch();
+ }
+
+ @Override
+ public final Connection getConnection() throws SQLException {
+ return getDelegate().getConnection();
+ }
+
+ @Override
+ public final boolean getMoreResults(int current) throws SQLException {
+ return getDelegate().getMoreResults(current);
+ }
+
+ @Override
+ public final ResultSet getGeneratedKeys() throws SQLException {
+ return getDelegate().getGeneratedKeys();
+ }
+
+ @Override
+ public final int getResultSetHoldability() throws SQLException {
+ return getDelegate().getResultSetHoldability();
+ }
+
+ @Override
+ public final boolean isClosed() throws SQLException {
+ return getDelegate().isClosed();
+ }
+
+ @Override
+ public final void setPoolable(boolean poolable) throws SQLException {
+ getDelegate().setPoolable(poolable);
+ }
+
+ @Override
+ public final boolean isPoolable() throws SQLException {
+ return getDelegate().isPoolable();
+ }
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java
index 13db6f84c6..641550bfeb 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBindContext.java
@@ -40,7 +40,7 @@ import static org.jooq.SQLDialect.POSTGRES;
import static org.jooq.SQLDialect.SQLITE;
import static org.jooq.SQLDialect.SQLSERVER;
import static org.jooq.SQLDialect.SYBASE;
-import static org.jooq.util.postgres.PGIntervalConverter.toPGInterval;
+import static org.jooq.util.postgres.PostgresUtils.toPGInterval;
import java.math.BigDecimal;
import java.math.BigInteger;
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java b/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java
index 4614cacc4a..e5e82dc0ea 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultConfiguration.java
@@ -39,6 +39,8 @@ import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
+import javax.sql.DataSource;
+
import org.jooq.Configuration;
import org.jooq.SQLDialect;
import org.jooq.conf.Settings;
@@ -63,6 +65,14 @@ final class DefaultConfiguration implements Configuration {
return SQLDialect.SQL99;
}
+ @Override
+ public final DataSource getDataSource() {
+ return null;
+ }
+
+ @Override
+ public void setDataSource(DataSource datasource) {}
+
@Override
public final Connection getConnection() {
return null;
diff --git a/jOOQ/src/main/java/org/jooq/impl/Factory.java b/jOOQ/src/main/java/org/jooq/impl/Factory.java
index 41c0b61546..0000db4c16 100644
--- a/jOOQ/src/main/java/org/jooq/impl/Factory.java
+++ b/jOOQ/src/main/java/org/jooq/impl/Factory.java
@@ -73,6 +73,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.sql.DataSource;
import javax.xml.bind.JAXB;
import org.jooq.AggregateFunction;
@@ -175,6 +176,7 @@ public class Factory implements FactoryOperations {
private static final Factory[] DEFAULT_INSTANCES = new Factory[SQLDialect.values().length];
private transient Connection connection;
+ private transient DataSource datasource;
private final SQLDialect dialect;
@SuppressWarnings("deprecation")
@@ -187,31 +189,42 @@ public class Factory implements FactoryOperations {
// -------------------------------------------------------------------------
/**
- * Create a factory with a connection and a dialect configured
+ * Create a factory with a connection and a dialect configured.
*
* @param connection The connection to use with objects created from this
* factory
* @param dialect The dialect to use with objects created from this factory
*/
public Factory(Connection connection, SQLDialect dialect) {
- this(connection, dialect, null, null, null);
+ this(null, connection, dialect, null, null, null);
}
/**
- * Create a factory with a dialect configured
+ * Create a factory with a data source and a dialect configured.
+ *
+ * @param datasource The data source to use with objects created from this
+ * factory
+ * @param dialect The dialect to use with objects created from this factory
+ */
+ public Factory(DataSource datasource, SQLDialect dialect) {
+ this(datasource, null, dialect, null, null, null);
+ }
+
+ /**
+ * Create a factory with a dialect configured.
*
- * Without a connection, this factory cannot execute queries. Use it to
- * render SQL only.
+ * Without a connection or data source, this factory cannot execute queries.
+ * Use it to render SQL only.
*
* @param dialect The dialect to use with objects created from this factory
*/
public Factory(SQLDialect dialect) {
- this(null, dialect, null, null, null);
+ this(null, null, dialect, null, null, null);
}
/**
* Create a factory with a connection, a dialect and a schema mapping
- * configured
+ * configured.
*
* @param connection The connection to use with objects created from this
* factory
@@ -223,11 +236,11 @@ public class Factory implements FactoryOperations {
*/
@Deprecated
public Factory(Connection connection, SQLDialect dialect, org.jooq.SchemaMapping mapping) {
- this(connection, dialect, null, null, null);
+ this(null, connection, dialect, null, null, null);
}
/**
- * Create a factory with a connection, a dialect and settings configured
+ * Create a factory with a connection, a dialect and settings configured.
*
* @param connection The connection to use with objects created from this
* factory
@@ -237,14 +250,28 @@ public class Factory implements FactoryOperations {
*/
@SuppressWarnings("deprecation")
public Factory(Connection connection, SQLDialect dialect, Settings settings) {
- this(connection, dialect, settings, new org.jooq.SchemaMapping(settings), null);
+ this(null, connection, dialect, settings, new org.jooq.SchemaMapping(settings), null);
+ }
+
+ /**
+ * Create a factory with a data source, a dialect and settings configured.
+ *
+ * @param datasource The data source to use with objects created from this
+ * factory
+ * @param dialect The dialect to use with objects created from this factory
+ * @param settings The runtime settings to apply to objects created from
+ * this factory
+ */
+ @SuppressWarnings("deprecation")
+ public Factory(DataSource datasource, SQLDialect dialect, Settings settings) {
+ this(datasource, null, dialect, settings, new org.jooq.SchemaMapping(settings), null);
}
/**
* Create a factory with a dialect and settings configured
*
- * Without a connection, this factory cannot execute queries. Use it to
- * render SQL only.
+ * Without a connection or data source, this factory cannot execute queries.
+ * Use it to render SQL only.
*
* @param dialect The dialect to use with objects created from this factory
* @param settings The runtime settings to apply to objects created from
@@ -252,15 +279,16 @@ public class Factory implements FactoryOperations {
*/
@SuppressWarnings("deprecation")
public Factory(SQLDialect dialect, Settings settings) {
- this(null, dialect, settings, new org.jooq.SchemaMapping(settings), null);
+ this(null, null, dialect, settings, new org.jooq.SchemaMapping(settings), null);
}
/**
* Do the instanciation
*/
@SuppressWarnings("deprecation")
- private Factory(Connection connection, SQLDialect dialect, Settings settings, org.jooq.SchemaMapping mapping, Map data) {
+ private Factory(DataSource datasource, Connection connection, SQLDialect dialect, Settings settings, org.jooq.SchemaMapping mapping, Map data) {
this.connection = connection;
+ this.datasource = datasource;
this.dialect = dialect;
this.settings = settings != null ? settings : SettingsTools.defaultSettings();
this.mapping = mapping != null ? mapping : new org.jooq.SchemaMapping(this.settings);
@@ -279,19 +307,51 @@ public class Factory implements FactoryOperations {
return dialect;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final DataSource getDataSource() {
+ return datasource;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setDataSource(DataSource datasource) {
+ this.datasource = datasource;
+ }
+
/**
* {@inheritDoc}
*/
@Override
public final Connection getConnection() {
- if (connection == null) {
+
+ // SQL-builder only Factory
+ if (connection == null && datasource == null) {
return null;
}
+
+ // [#1424] DataSource-enabled Factory with no Connection yet
+ else if (connection == null && datasource != null) {
+ return new DataSourceConnection(datasource, null, settings);
+ }
+
+ // Factory clone
+ else if (connection.getClass() == DataSourceConnection.class) {
+ return connection;
+ }
+
+ // Factory clone
else if (connection.getClass() == ConnectionProxy.class) {
return connection;
}
+
+ // [#1424] Connection-based Factory
else {
- return new ConnectionProxy(connection, settings);
+ return new DataSourceConnection(null, new ConnectionProxy(connection, settings), settings);
}
}
@@ -5642,7 +5702,7 @@ public class Factory implements FactoryOperations {
static {
for (SQLDialect dialect : SQLDialect.values()) {
- Factory.DEFAULT_INSTANCES[dialect.ordinal()] = new Factory(null, dialect);
+ Factory.DEFAULT_INSTANCES[dialect.ordinal()] = new Factory(dialect);
}
}
@@ -5670,6 +5730,7 @@ public class Factory implements FactoryOperations {
}
else {
return new Factory(
+ configuration.getDataSource(),
configuration.getConnection(),
configuration.getDialect(),
configuration.getSettings(),
diff --git a/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java b/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java
index 27947c024b..80b41e56fa 100644
--- a/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java
+++ b/jOOQ/src/main/java/org/jooq/impl/FactoryProxy.java
@@ -98,10 +98,15 @@ import org.jooq.exception.DataAccessException;
* Spring. Note that this implementation of a FactoryProxy might be
* re-designed in jOOQ 3.0. Please consider this functionality as being
* EXPERIMENTAL
- *
+ *
* @author Sergey Epik
* @author Lukas Eder
+ * @deprecated - Use the newly {@link DataSource}-enabled {@link Factory}
+ * constructors instead, e.g.
+ * {@link Factory#Factory(DataSource, SQLDialect)} or
+ * {@link Factory#Factory(DataSource, SQLDialect, Settings)}
*/
+@Deprecated
public final class FactoryProxy implements FactoryOperations {
/**
@@ -129,6 +134,7 @@ public final class FactoryProxy implements FactoryOperations {
this.dataSource = dataSource;
}
+ @Override
public final DataSource getDataSource() {
return this.dataSource;
}
diff --git a/jOOQ/src/main/java/org/jooq/impl/Util.java b/jOOQ/src/main/java/org/jooq/impl/Util.java
index d8bec3cda1..b3cc244b8d 100644
--- a/jOOQ/src/main/java/org/jooq/impl/Util.java
+++ b/jOOQ/src/main/java/org/jooq/impl/Util.java
@@ -587,6 +587,10 @@ final class Util {
// If the connection is wrapped by jOOQ, extract the underlying
// connection
+ if (connection.getClass() == DataSourceConnection.class) {
+ connection = ((DataSourceConnection) connection).getDelegate();
+ }
+
if (connection.getClass() == ConnectionProxy.class) {
connection = ((ConnectionProxy) connection).getDelegate();
}