Move type adjustment from AdjustableBasicType to AdjustableJdbcTypeDescriptor
This commit is contained in:
parent
bb52778229
commit
bfe2da9d4f
|
@ -40,8 +40,9 @@ import org.hibernate.cfg.PropertyData;
|
|||
import org.hibernate.cfg.PropertyHolderBuilder;
|
||||
import org.hibernate.cfg.PropertyPreloadedData;
|
||||
import org.hibernate.cfg.SecondPass;
|
||||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.jdbc.Size;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.mapping.BasicValue;
|
||||
import org.hibernate.mapping.Collection;
|
||||
|
@ -471,7 +472,10 @@ public class MapBinder extends CollectionBinder {
|
|||
}
|
||||
|
||||
if ( fromAndWhere != null ) {
|
||||
formulaString = Template.renderWhereStringTemplate( formulaString, "$alias$", new HSQLDialect() );
|
||||
final Dialect dialect = buildingContext.getBootstrapContext().getServiceRegistry()
|
||||
.getService( JdbcServices.class )
|
||||
.getDialect();
|
||||
formulaString = Template.renderWhereStringTemplate( formulaString, "$alias$", dialect );
|
||||
formulaString = "(select " + formulaString + fromAndWhere + ")";
|
||||
formulaString = StringHelper.replace( formulaString, "$alias$", "a987" );
|
||||
}
|
||||
|
@ -513,7 +517,10 @@ public class MapBinder extends CollectionBinder {
|
|||
throw new AssertionFailure( "Unknown element in column iterator: " + current.getClass() );
|
||||
}
|
||||
if ( fromAndWhere != null ) {
|
||||
formulaString = Template.renderWhereStringTemplate( formulaString, "$alias$", new HSQLDialect() );
|
||||
final Dialect dialect = buildingContext.getBootstrapContext().getServiceRegistry()
|
||||
.getService( JdbcServices.class )
|
||||
.getDialect();
|
||||
formulaString = Template.renderWhereStringTemplate( formulaString, "$alias$", dialect );
|
||||
formulaString = "(select " + formulaString + fromAndWhere + ")";
|
||||
formulaString = StringHelper.replace(
|
||||
formulaString,
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.type;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.AdjustableJdbcTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
|
||||
/**
|
||||
|
@ -18,5 +20,18 @@ public interface AdjustableBasicType<J> extends BasicType<J> {
|
|||
/**
|
||||
* Perform the adjustment
|
||||
*/
|
||||
<X> BasicType<X> resolveIndicatedType(JdbcTypeDescriptorIndicators indicators, JavaTypeDescriptor<X> domainJtd);
|
||||
default <X> BasicType<X> resolveIndicatedType(JdbcTypeDescriptorIndicators indicators, JavaTypeDescriptor<X> domainJtd) {
|
||||
final JdbcTypeDescriptor jdbcTypeDescriptor = getJdbcTypeDescriptor();
|
||||
if ( jdbcTypeDescriptor instanceof AdjustableJdbcTypeDescriptor ) {
|
||||
final JdbcTypeDescriptor resolvedJdbcTypeDescriptor = ( (AdjustableJdbcTypeDescriptor) jdbcTypeDescriptor ).resolveIndicatedType(
|
||||
indicators,
|
||||
domainJtd
|
||||
);
|
||||
if ( resolvedJdbcTypeDescriptor != jdbcTypeDescriptor ) {
|
||||
return indicators.getTypeConfiguration().getBasicTypeRegistry()
|
||||
.resolve( domainJtd, resolvedJdbcTypeDescriptor, getName() );
|
||||
}
|
||||
}
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,17 +89,4 @@ public class BinaryType
|
|||
return PrimitiveByteArrayTypeDescriptor.INSTANCE.getComparator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <X> BasicType<X> resolveIndicatedType(JdbcTypeDescriptorIndicators indicators, JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( ! indicators.isLob() ) {
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
final JdbcTypeDescriptor jdbcType = jdbcTypeRegistry.getDescriptor( Types.BLOB );
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve( domainJtd, jdbcType, getName() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,31 +67,4 @@ public class BooleanType
|
|||
return dialect.toBooleanValueString( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
final int preferredSqlTypeCodeForBoolean = indicators.getPreferredSqlTypeCodeForBoolean();
|
||||
final JdbcTypeDescriptor jdbcTypeDescriptor;
|
||||
// We treat BIT like BOOLEAN because it uses the same JDBC access methods
|
||||
if ( preferredSqlTypeCodeForBoolean != Types.BIT && preferredSqlTypeCodeForBoolean != getJdbcTypeDescriptor().getJdbcTypeCode() ) {
|
||||
jdbcTypeDescriptor = indicators.getTypeConfiguration()
|
||||
.getJdbcTypeDescriptorRegistry()
|
||||
.getDescriptor( preferredSqlTypeCodeForBoolean );
|
||||
}
|
||||
else {
|
||||
jdbcTypeDescriptor = indicators.getTypeConfiguration()
|
||||
.getJdbcTypeDescriptorRegistry()
|
||||
.getDescriptor( Types.BOOLEAN );
|
||||
}
|
||||
if ( jdbcTypeDescriptor != getJdbcTypeDescriptor() ) {
|
||||
//noinspection unchecked
|
||||
return (BasicType<X>) indicators.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( getJavaTypeDescriptor(), jdbcTypeDescriptor, getName() );
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,11 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.PrimitiveCharacterArrayTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.VarcharTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link Types#VARCHAR VARCHAR} and {@code char[]}
|
||||
|
@ -39,24 +35,4 @@ public class CharArrayType
|
|||
return new String[] { getName(), "char[]", char[].class.getName() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
assert domainJtd != null;
|
||||
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
|
||||
final int jdbcTypeCode;
|
||||
if ( indicators.isLob() ) {
|
||||
jdbcTypeCode = indicators.isNationalized() ? Types.NCLOB : Types.CLOB;
|
||||
}
|
||||
else {
|
||||
jdbcTypeCode = indicators.isNationalized() ? Types.NVARCHAR : Types.VARCHAR;
|
||||
}
|
||||
|
||||
final JdbcTypeDescriptor jdbcType = jdbcTypeRegistry.getDescriptor( jdbcTypeCode );
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve( domainJtd, jdbcType, getName() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,26 +37,4 @@ public class CharacterArrayClobType
|
|||
// todo name these annotation types for addition to the registry
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( domainJtd != null && domainJtd.getJavaTypeClass() == char[].class ) {
|
||||
// domainJtd is a `char[]` instead of a `Character[]`....
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
final JdbcTypeDescriptor jdbcType = indicators.isNationalized()
|
||||
? jdbcTypeRegistry.getDescriptor( Types.NCLOB )
|
||||
: jdbcTypeRegistry.getDescriptor( Types.CLOB );
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( domainJtd.getJavaType() ),
|
||||
jdbcType,
|
||||
getName()
|
||||
);
|
||||
}
|
||||
|
||||
return (BasicType<X>) ( indicators.isNationalized() ? CharacterArrayNClobType.INSTANCE : this );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,7 @@ package org.hibernate.type;
|
|||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.CharacterArrayTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.NClobTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link Types#NCLOB NCLOB} and {@link Character Character[]}
|
||||
|
@ -38,24 +33,4 @@ public class CharacterArrayNClobType
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( domainJtd != null && domainJtd.getJavaTypeClass() == char[].class ) {
|
||||
// domainJtd is a `char[]` instead of a `Character[]`....
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
final JdbcTypeDescriptor jdbcType = jdbcTypeRegistry.getDescriptor( Types.NCLOB );
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( domainJtd.getJavaType() ),
|
||||
jdbcType,
|
||||
getName()
|
||||
);
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,11 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.CharacterArrayTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.VarcharTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link Types#VARCHAR VARCHAR} and {@link Character Character[]}
|
||||
|
@ -38,40 +34,4 @@ public class CharacterArrayType
|
|||
public String[] getRegistrationKeys() {
|
||||
return new String[] { getName(), Character[].class.getName(), "Character[]" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
|
||||
final int jdbcTypeCode;
|
||||
if ( indicators.isLob() ) {
|
||||
jdbcTypeCode = indicators.isNationalized() ? Types.NCLOB : Types.CLOB;
|
||||
}
|
||||
else {
|
||||
jdbcTypeCode = indicators.isNationalized() ? Types.NVARCHAR : Types.VARCHAR;
|
||||
}
|
||||
|
||||
final JdbcTypeDescriptor indicatedJdbcType = jdbcTypeRegistry.getDescriptor( jdbcTypeCode );
|
||||
|
||||
if ( domainJtd != null && domainJtd.getJavaTypeClass() == Character[].class ) {
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
typeConfiguration.getJavaTypeDescriptorRegistry().resolveDescriptor( domainJtd.getJavaType() ),
|
||||
indicatedJdbcType,
|
||||
getName()
|
||||
);
|
||||
}
|
||||
|
||||
if ( getJdbcTypeDescriptor() == indicatedJdbcType ) {
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
|
||||
return (BasicType<X>) typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
getJavaTypeDescriptor(),
|
||||
indicatedJdbcType,
|
||||
getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,7 @@ import java.sql.Types;
|
|||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.type.descriptor.java.CharacterTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.CharTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link Types#CHAR CHAR(1)} and {@link Character}
|
||||
|
@ -65,16 +60,4 @@ public class CharacterType
|
|||
return fromString( sequence );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
final JdbcTypeDescriptor jdbcType = indicators.isNationalized()
|
||||
? jdbcTypeRegistry.getDescriptor( Types.NCHAR )
|
||||
: jdbcTypeRegistry.getDescriptor( Types.CHAR );
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve( domainJtd, jdbcType, getName() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,6 @@ import java.sql.Types;
|
|||
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.type.descriptor.java.ClobTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link Types#CLOB CLOB} and {@link Clob}
|
||||
|
@ -43,23 +39,4 @@ public class ClobType extends AbstractSingleColumnStandardBasicType<Clob> implem
|
|||
protected Clob getReplacement(Clob original, Clob target, SharedSessionContractImplementor session) {
|
||||
return session.getJdbcServices().getJdbcEnvironment().getDialect().getLobMergeStrategy().mergeClob( original, target, session );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( ! indicators.isNationalized() ) {
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
domainJtd,
|
||||
jdbcTypeRegistry.getDescriptor( Types.NCLOB ),
|
||||
getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,11 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.ClobTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link Types#CLOB CLOB} and {@link String}
|
||||
|
@ -34,24 +30,4 @@ public class MaterializedClobType
|
|||
public String getName() {
|
||||
return "materialized_clob";
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( indicators.isNationalized() ) {
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
final JdbcTypeDescriptor nclobType = jdbcTypeRegistry.getDescriptor( Types.NCLOB );
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
domainJtd,
|
||||
nclobType,
|
||||
getName()
|
||||
);
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,9 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.PrimitiveCharacterArrayTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.ClobTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Map a char[] to a Clob
|
||||
|
@ -33,22 +28,4 @@ public class PrimitiveCharacterArrayClobType
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( ! indicators.isNationalized() ) {
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
domainJtd,
|
||||
jdbcTypeRegistry.getDescriptor( Types.NCLOB ),
|
||||
getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Additional contract for primitive / primitive wrapper types.
|
||||
*
|
||||
|
@ -41,9 +37,4 @@ public interface PrimitiveType<T> extends LiteralType<T>, AdjustableBasicType<T>
|
|||
*/
|
||||
Object getDefaultValue();
|
||||
|
||||
@Override
|
||||
default <X> BasicType<X> resolveIndicatedType(JdbcTypeDescriptorIndicators indicators, JavaTypeDescriptor<X> domainJtd) {
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve( domainJtd, getJdbcTypeDescriptor(), getName() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,13 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.query.internal.QueryLiteralHelper;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.VarcharTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link Types#VARCHAR VARCHAR} and {@link String}
|
||||
|
@ -53,34 +50,4 @@ public class StringType
|
|||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( ! indicators.isLob() && ! indicators.isNationalized() ) {
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
final int jdbcTypeCode;
|
||||
|
||||
if ( indicators.isLob() ) {
|
||||
jdbcTypeCode = indicators.isNationalized()
|
||||
? Types.NCLOB
|
||||
: Types.CLOB;
|
||||
}
|
||||
else {
|
||||
jdbcTypeCode = indicators.isNationalized()
|
||||
? Types.NVARCHAR
|
||||
: Types.VARCHAR;
|
||||
}
|
||||
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
domainJtd,
|
||||
jdbcTypeRegistry.getDescriptor( jdbcTypeCode ),
|
||||
getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.LongVarcharTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
|
||||
/**
|
||||
* A type that maps between {@link java.sql.Types#LONGVARCHAR LONGVARCHAR} and {@link String}
|
||||
|
@ -29,17 +28,4 @@ public class TextType
|
|||
public String getName() {
|
||||
return "text";
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( indicators.isNationalized() ) {
|
||||
//noinspection unchecked
|
||||
return (BasicType<X>) NTextType.INSTANCE;
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,11 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.ByteArrayTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.VarbinaryTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* A type mapping {@link Types#VARBINARY VARBINARY} and {@link Byte Byte[]}
|
||||
|
@ -36,22 +33,4 @@ public class WrapperBinaryType extends AbstractSingleColumnStandardBasicType<Byt
|
|||
//TODO find a decent name before documenting
|
||||
return "wrapper-binary";
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> BasicType<X> resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<X> domainJtd) {
|
||||
if ( ! indicators.isLob() ) {
|
||||
//noinspection unchecked
|
||||
return (BasicType<X>) this;
|
||||
}
|
||||
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
domainJtd,
|
||||
jdbcTypeRegistry.getDescriptor( Types.BLOB ),
|
||||
getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.type.descriptor.jdbc;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Extension contract for JdbcTypeDescriptor implementations that understand how to
|
||||
* adjust themselves relative to where/how they are used (e.g. accounting
|
||||
* for LOB, nationalized, primitive/wrapper, etc).
|
||||
*
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
public interface AdjustableJdbcTypeDescriptor extends JdbcTypeDescriptor {
|
||||
|
||||
/**
|
||||
* Perform the adjustment
|
||||
*/
|
||||
JdbcTypeDescriptor resolveIndicatedType(JdbcTypeDescriptorIndicators indicators, JavaTypeDescriptor<?> domainJtd);
|
||||
}
|
|
@ -25,7 +25,7 @@ import org.hibernate.type.spi.TypeConfiguration;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BooleanTypeDescriptor implements JdbcTypeDescriptor {
|
||||
public class BooleanTypeDescriptor implements AdjustableJdbcTypeDescriptor {
|
||||
public static final BooleanTypeDescriptor INSTANCE = new BooleanTypeDescriptor();
|
||||
|
||||
public BooleanTypeDescriptor() {
|
||||
|
@ -64,6 +64,18 @@ public class BooleanTypeDescriptor implements JdbcTypeDescriptor {
|
|||
return new JdbcLiteralFormatterBoolean( javaTypeDescriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcTypeDescriptor resolveIndicatedType(JdbcTypeDescriptorIndicators indicators, JavaTypeDescriptor<?> domainJtd) {
|
||||
final int preferredSqlTypeCodeForBoolean = indicators.getPreferredSqlTypeCodeForBoolean();
|
||||
// We treat BIT like BOOLEAN because it uses the same JDBC access methods
|
||||
if ( preferredSqlTypeCodeForBoolean != Types.BIT && preferredSqlTypeCodeForBoolean != Types.BOOLEAN ) {
|
||||
return indicators.getTypeConfiguration()
|
||||
.getJdbcTypeDescriptorRegistry()
|
||||
.getDescriptor( preferredSqlTypeCodeForBoolean );
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return new BasicBinder<X>( javaTypeDescriptor, this ) {
|
||||
@Override
|
||||
|
|
|
@ -5,8 +5,13 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.type.descriptor.jdbc;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Descriptor for {@link Types#CHAR CHAR} handling.
|
||||
*
|
||||
|
@ -27,4 +32,15 @@ public class CharTypeDescriptor extends VarcharTypeDescriptor {
|
|||
public int getJdbcTypeCode() {
|
||||
return Types.CHAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcTypeDescriptor resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<?> domainJtd) {
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
return indicators.isNationalized()
|
||||
? jdbcTypeRegistry.getDescriptor( Types.NCHAR )
|
||||
: jdbcTypeRegistry.getDescriptor( Types.CHAR );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,14 @@ import java.sql.SQLException;
|
|||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.engine.jdbc.CharacterStream;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.CharacterArrayNClobType;
|
||||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Descriptor for {@link Types#CLOB CLOB} handling.
|
||||
|
@ -25,7 +29,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
|||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public abstract class ClobTypeDescriptor implements JdbcTypeDescriptor {
|
||||
public abstract class ClobTypeDescriptor implements AdjustableJdbcTypeDescriptor {
|
||||
@Override
|
||||
public int getJdbcTypeCode() {
|
||||
return Types.CLOB;
|
||||
|
@ -46,6 +50,17 @@ public abstract class ClobTypeDescriptor implements JdbcTypeDescriptor {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcTypeDescriptor resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<?> domainJtd) {
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
return indicators.isNationalized()
|
||||
? jdbcTypeRegistry.getDescriptor( Types.NCLOB )
|
||||
: jdbcTypeRegistry.getDescriptor( Types.CLOB );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
|
||||
|
|
|
@ -8,6 +8,9 @@ package org.hibernate.type.descriptor.jdbc;
|
|||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
|
||||
/**
|
||||
* Descriptor for {@link Types#LONGVARCHAR LONGVARCHAR} handling.
|
||||
*
|
||||
|
@ -28,4 +31,15 @@ public class LongVarcharTypeDescriptor extends VarcharTypeDescriptor {
|
|||
public int getJdbcTypeCode() {
|
||||
return Types.LONGVARCHAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcTypeDescriptor resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<?> domainJtd) {
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeDescriptorRegistry = indicators.getTypeConfiguration()
|
||||
.getJdbcTypeDescriptorRegistry();
|
||||
return indicators.isNationalized()
|
||||
? jdbcTypeDescriptorRegistry.getDescriptor( Types.LONGNVARCHAR )
|
||||
: jdbcTypeDescriptorRegistry.getDescriptor( Types.LONGVARCHAR );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.BasicJavaDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterBinary;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
|
@ -25,7 +27,7 @@ import org.hibernate.type.spi.TypeConfiguration;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class VarbinaryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
public class VarbinaryTypeDescriptor implements AdjustableJdbcTypeDescriptor {
|
||||
public static final VarbinaryTypeDescriptor INSTANCE = new VarbinaryTypeDescriptor();
|
||||
public static final VarbinaryTypeDescriptor INSTANCE_WITHOUT_LITERALS = new VarbinaryTypeDescriptor( false );
|
||||
|
||||
|
@ -72,6 +74,14 @@ public class VarbinaryTypeDescriptor implements JdbcTypeDescriptor {
|
|||
return supportsLiterals ? new JdbcLiteralFormatterBinary( javaTypeDescriptor ) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcTypeDescriptor resolveIndicatedType(JdbcTypeDescriptorIndicators indicators, JavaTypeDescriptor<?> domainJtd) {
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = indicators.getTypeConfiguration().getJdbcTypeDescriptorRegistry();
|
||||
return indicators.isLob()
|
||||
? jdbcTypeRegistry.getDescriptor( Types.BLOB )
|
||||
: jdbcTypeRegistry.getDescriptor( Types.VARBINARY );
|
||||
}
|
||||
|
||||
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return new BasicBinder<X>( javaTypeDescriptor, this ) {
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.BasicJavaDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterCharacterData;
|
||||
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeDescriptorRegistry;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
|
@ -25,7 +26,7 @@ import org.hibernate.type.spi.TypeConfiguration;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class VarcharTypeDescriptor implements JdbcTypeDescriptor {
|
||||
public class VarcharTypeDescriptor implements AdjustableJdbcTypeDescriptor {
|
||||
public static final VarcharTypeDescriptor INSTANCE = new VarcharTypeDescriptor();
|
||||
|
||||
public VarcharTypeDescriptor() {
|
||||
|
@ -68,6 +69,26 @@ public class VarcharTypeDescriptor implements JdbcTypeDescriptor {
|
|||
return new JdbcLiteralFormatterCharacterData( javaTypeDescriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcTypeDescriptor resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor<?> domainJtd) {
|
||||
assert domainJtd != null;
|
||||
|
||||
final TypeConfiguration typeConfiguration = indicators.getTypeConfiguration();
|
||||
final JdbcTypeDescriptorRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeDescriptorRegistry();
|
||||
|
||||
final int jdbcTypeCode;
|
||||
if ( indicators.isLob() ) {
|
||||
jdbcTypeCode = indicators.isNationalized() ? Types.NCLOB : Types.CLOB;
|
||||
}
|
||||
else {
|
||||
jdbcTypeCode = indicators.isNationalized() ? Types.NVARCHAR : Types.VARCHAR;
|
||||
}
|
||||
|
||||
return jdbcTypeRegistry.getDescriptor( jdbcTypeCode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return new BasicBinder<X>( javaTypeDescriptor, this ) {
|
||||
|
|
|
@ -29,17 +29,4 @@ public class NamedStandardBasicTypeImpl<J> extends StandardBasicTypeImpl<J> {
|
|||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicType resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor domainJtd) {
|
||||
final JdbcTypeDescriptor recommendedSqlType = getJavaTypeDescriptor().getRecommendedJdbcType( indicators );
|
||||
if ( recommendedSqlType == getJdbcTypeDescriptor() ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return indicators.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( getJavaTypeDescriptor(), recommendedSqlType, getName() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,20 +44,6 @@ public class StandardBasicTypeImpl<J>
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicType resolveIndicatedType(
|
||||
JdbcTypeDescriptorIndicators indicators,
|
||||
JavaTypeDescriptor domainJtd) {
|
||||
final JdbcTypeDescriptor recommendedSqlType = getJavaTypeDescriptor().getRecommendedJdbcType( indicators );
|
||||
if ( recommendedSqlType == getJdbcTypeDescriptor() ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return indicators.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( getJavaTypeDescriptor(), recommendedSqlType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastType getCastType() {
|
||||
if ( getJavaTypeDescriptor() == BooleanTypeDescriptor.INSTANCE ) {
|
||||
|
|
Loading…
Reference in New Issue