[#1693] Cannot bind UDT values from other schemata to stored procedures

This commit is contained in:
Lukas Eder 2012-08-10 16:16:58 +02:00
parent 28d4f9a064
commit b48db4a690
4 changed files with 35 additions and 6 deletions

View File

@ -99,6 +99,7 @@ import org.jooq.TableField;
import org.jooq.UDTRecord;
import org.jooq.UpdatableTable;
import org.jooq.conf.Settings;
import org.jooq.impl.Factory;
import org.jooq.test._.converters.Boolean_10;
import org.jooq.test._.converters.Boolean_TF_LC;
import org.jooq.test._.converters.Boolean_TF_UC;
@ -134,6 +135,7 @@ import org.jooq.test.oracle.generatedclasses.test.udt.UInvalidTable;
import org.jooq.test.oracle.generatedclasses.test.udt.UInvalidType;
import org.jooq.test.oracle.generatedclasses.test.udt.UStreetType;
import org.jooq.test.oracle.generatedclasses.test.udt.records.OInvalidTypeRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UAddressTypeRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UAuthorTypeRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UBookArrayRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UBookTableRecord;
@ -143,6 +145,7 @@ import org.jooq.test.oracle.generatedclasses.test.udt.records.UInvalidTypeRecord
import org.jooq.test.oracle.generatedclasses.test.udt.records.UNumberArrayRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UNumberLongArrayRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UNumberTableRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UStreetTypeRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.records.UStringArrayRecord;
import org.jooq.test.oracle.generatedclasses.test.udt.u_author_type.GetBooks;
import org.jooq.test.oracle2.generatedclasses.tables.records.DateAsTimestampT_976Record;
@ -1336,4 +1339,14 @@ public class jOOQOracleTest extends jOOQAbstractTest<
assertEquals(asList(3, 3, 3, 3), result2);
}
@Test
public void testOracleMultiSchemaFactories() throws Exception {
Factory create = new OracleFactory(getConnectionMultiSchema());
UAddressTypeRecord address = new UAddressTypeRecord();
address.setStreet(new UStreetTypeRecord());
address.getStreet().setNo("15");
assertEquals("15", Routines.pEnhanceAddress1(create, address));
}
}

View File

@ -94,9 +94,9 @@ class DefaultBindContext extends AbstractBindContext {
* href="http://stackoverflow.com/q/11439543/521799">http://stackoverflow
* .com/q/11439543/521799</a>
*/
static ThreadLocal<Configuration> localConfiguration = new ThreadLocal<Configuration>();
static final ThreadLocal<Configuration> LOCAL_CONFIGURATION = new ThreadLocal<Configuration>();
private final PreparedStatement stmt;
private final PreparedStatement stmt;
DefaultBindContext(Configuration configuration, PreparedStatement stmt) {
super(configuration);
@ -333,11 +333,11 @@ class DefaultBindContext extends AbstractBindContext {
try {
// [#1544] Set the local configuration, in case an array needs
// to be serialised to SQLOutput
localConfiguration.set(this);
LOCAL_CONFIGURATION.set(this);
stmt.setObject(nextIndex(), value);
}
finally {
localConfiguration.remove();
LOCAL_CONFIGURATION.remove();
}
}

View File

@ -351,7 +351,7 @@ public final class FieldTypeHelper {
// [#1544] We can safely assume that localConfiguration has been
// set on DefaultBindContext, prior to serialising arrays to SQLOut
Connection connection = getDriverConnection(DefaultBindContext.localConfiguration.get());
Connection connection = getDriverConnection(DefaultBindContext.LOCAL_CONFIGURATION.get());
ArrayRecord<?> arrayRecord = (ArrayRecord<?>) value;
stream.writeArray(on(connection).call("createARRAY", arrayRecord.getName(), arrayRecord.get()).<Array>get());
}

View File

@ -41,6 +41,7 @@ import java.sql.SQLOutput;
import org.jooq.Configuration;
import org.jooq.Field;
import org.jooq.Schema;
import org.jooq.UDT;
import org.jooq.UDTRecord;
@ -71,7 +72,22 @@ public class UDTRecordImpl<R extends UDTRecord<R>> extends AbstractRecord implem
@Override
public final String getSQLTypeName() throws SQLException {
return getUDT().getName();
StringBuilder sb = new StringBuilder();
// [#1693] This needs to return the fully qualified SQL type name, in
// case the connected user is not the owner of the UDT
Configuration configuration = DefaultBindContext.LOCAL_CONFIGURATION.get();
if (configuration != null) {
Schema schema = Util.getMappedSchema(configuration, getUDT().getSchema());
if (schema != null) {
sb.append(schema.getName());
sb.append(".");
}
}
sb.append(getUDT().getName());
return sb.toString();
}
@Override