[#1544] Remove Attachable interface from QueryPart hierarchy

This commit is contained in:
Lukas Eder 2012-07-27 18:43:39 +02:00
parent a9c2e61c66
commit edcdb41adc
3 changed files with 33 additions and 8 deletions

View File

@ -123,9 +123,6 @@ abstract class AbstractQuery extends AbstractQueryPart implements Query {
throw new DetachedException("Cannot execute query. No Connection configured");
}
// Ensure that all depending Attachables are attached
attach(configuration);
int result = 0;
try {
listener.renderStart(ctx);

View File

@ -49,6 +49,7 @@ import java.sql.Clob;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLOutput;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
@ -76,10 +77,22 @@ class DefaultBindContext extends AbstractBindContext {
/**
* Generated UID
*/
private static final long serialVersionUID = -5457385919209241505L;
private static final JooqLogger log = JooqLogger.getLogger(DefaultBindContext.class);
private static final long serialVersionUID = -5457385919209241505L;
private static final JooqLogger log = JooqLogger.getLogger(DefaultBindContext.class);
private final PreparedStatement stmt;
/**
* The localConfiguration is used to communicate a Configuration to an
* {@link ArrayRecord}, in case that ArrayRecord is serialised to a
* {@link SQLOutput} object.
* <p>
* This is probably the only solution to circumvent this bad JDBC design.
* See also <a
* href="http://stackoverflow.com/q/11439543/521799">http://stackoverflow
* .com/q/11439543/521799</a>
*/
static ThreadLocal<Configuration> localConfiguration = new ThreadLocal<Configuration>();
private final PreparedStatement stmt;
DefaultBindContext(Configuration configuration, PreparedStatement stmt) {
super(configuration);
@ -311,7 +324,15 @@ class DefaultBindContext extends AbstractBindContext {
bindValue(primaryKey, primaryKey.getClass());
}
else {
stmt.setObject(nextIndex(), value);
try {
// [#1544] Set the local configuration, in case an array needs
// to be serialised to SQLOutput
localConfiguration.set(this);
stmt.setObject(nextIndex(), value);
}
finally {
localConfiguration.remove();
}
}
return this;

View File

@ -39,6 +39,7 @@ package org.jooq.impl;
import static org.jooq.SQLDialect.CUBRID;
import static org.jooq.SQLDialect.POSTGRES;
import static org.jooq.impl.Factory.getNewFactory;
import static org.jooq.impl.Util.getDriverConnection;
import static org.jooq.tools.reflect.Reflect.on;
import java.math.BigDecimal;
@ -47,6 +48,7 @@ import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -346,7 +348,12 @@ public final class FieldTypeHelper {
stream.writeString(value.toString());
}
else if (ArrayRecord.class.isAssignableFrom(type)) {
stream.writeArray(((ArrayRecord<?>) value).createArray());
// [#1544] We can safely assume that localConfiguration has been
// set on DefaultBindContext, prior to serialising arrays to SQLOut
Connection connection = getDriverConnection(DefaultBindContext.localConfiguration.get());
ArrayRecord<?> arrayRecord = (ArrayRecord<?>) value;
stream.writeArray(on(connection).call("createARRAY", arrayRecord.getName(), arrayRecord.get()).<Array>get());
}
else if (EnumType.class.isAssignableFrom(type)) {
stream.writeString(((EnumType) value).getLiteral());