HHH-12444 - Introduce BootstrapContext
HHH-12443 - Introduce TypeConfiguration
This commit is contained in:
parent
0d82dc7c83
commit
6721005208
|
@ -21,10 +21,23 @@ import org.hibernate.usertype.UserType;
|
|||
public interface TypeContributions {
|
||||
void contributeType(BasicType type);
|
||||
|
||||
/**
|
||||
* @deprecated (since 5.3) It will be replaced by {@link #contributeType(BasicType)}
|
||||
* but do not move to it before 6.0
|
||||
*/
|
||||
@Deprecated
|
||||
void contributeType(BasicType type, String... keys);
|
||||
|
||||
/**
|
||||
* @deprecated (since 5.3) It will be replaced by {@link #contributeType(BasicType)}
|
||||
* but do not move to it before 6.0
|
||||
*/
|
||||
void contributeType(UserType type, String... keys);
|
||||
|
||||
/**
|
||||
* @deprecated (since 5.3) It will be replaced by {@link #contributeType(BasicType)}
|
||||
* but do not move to it before 6.0
|
||||
*/
|
||||
void contributeType(CompositeUserType type, String... keys);
|
||||
|
||||
/*
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.type.descriptor.java.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
|
@ -17,22 +19,25 @@ import org.hibernate.type.spi.TypeConfiguration;
|
|||
*
|
||||
* @since 5.3
|
||||
*/
|
||||
public class JavaTypeDescriptorRegistry extends org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry {
|
||||
public class JavaTypeDescriptorRegistry
|
||||
extends org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry
|
||||
implements Serializable {
|
||||
|
||||
private TypeConfiguration typeConfiguration;
|
||||
private final TypeConfiguration typeConfiguration;
|
||||
private final org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry javaTypeDescriptorRegistry;
|
||||
|
||||
public JavaTypeDescriptorRegistry(TypeConfiguration typeConfiguration) {
|
||||
|
||||
this.typeConfiguration = typeConfiguration;
|
||||
javaTypeDescriptorRegistry = org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> JavaTypeDescriptor<T> getDescriptor(Class<T> javaType) {
|
||||
return super.getDescriptor( javaType );
|
||||
return javaTypeDescriptorRegistry.getDescriptor( javaType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDescriptor(JavaTypeDescriptor descriptor) {
|
||||
super.addDescriptor( descriptor );
|
||||
javaTypeDescriptorRegistry.addDescriptor( descriptor );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,37 +43,37 @@ public class SqlTypeDescriptorRegistry implements Serializable {
|
|||
private ConcurrentHashMap<Integer,SqlTypeDescriptor> descriptorMap = new ConcurrentHashMap<Integer, SqlTypeDescriptor>();
|
||||
|
||||
protected SqlTypeDescriptorRegistry() {
|
||||
addDescriptor( BooleanTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( BooleanTypeDescriptor.INSTANCE );
|
||||
|
||||
addDescriptor( BitTypeDescriptor.INSTANCE );
|
||||
addDescriptor( BigIntTypeDescriptor.INSTANCE );
|
||||
addDescriptor( DecimalTypeDescriptor.INSTANCE );
|
||||
addDescriptor( DoubleTypeDescriptor.INSTANCE );
|
||||
addDescriptor( FloatTypeDescriptor.INSTANCE );
|
||||
addDescriptor( IntegerTypeDescriptor.INSTANCE );
|
||||
addDescriptor( NumericTypeDescriptor.INSTANCE );
|
||||
addDescriptor( RealTypeDescriptor.INSTANCE );
|
||||
addDescriptor( SmallIntTypeDescriptor.INSTANCE );
|
||||
addDescriptor( TinyIntTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( BitTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( BigIntTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( DecimalTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( DoubleTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( FloatTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( IntegerTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( NumericTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( RealTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( SmallIntTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( TinyIntTypeDescriptor.INSTANCE );
|
||||
|
||||
addDescriptor( DateTypeDescriptor.INSTANCE );
|
||||
addDescriptor( TimestampTypeDescriptor.INSTANCE );
|
||||
addDescriptor( TimeTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( DateTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( TimestampTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( TimeTypeDescriptor.INSTANCE );
|
||||
|
||||
addDescriptor( BinaryTypeDescriptor.INSTANCE );
|
||||
addDescriptor( VarbinaryTypeDescriptor.INSTANCE );
|
||||
addDescriptor( LongVarbinaryTypeDescriptor.INSTANCE );
|
||||
addDescriptor( BlobTypeDescriptor.DEFAULT );
|
||||
addDescriptorInternal( BinaryTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( VarbinaryTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( LongVarbinaryTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( BlobTypeDescriptor.DEFAULT );
|
||||
|
||||
addDescriptor( CharTypeDescriptor.INSTANCE );
|
||||
addDescriptor( VarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptor( LongVarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptor( ClobTypeDescriptor.DEFAULT );
|
||||
addDescriptorInternal( CharTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( VarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( LongVarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( ClobTypeDescriptor.DEFAULT );
|
||||
|
||||
addDescriptor( NCharTypeDescriptor.INSTANCE );
|
||||
addDescriptor( NVarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptor( LongNVarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptor( NClobTypeDescriptor.DEFAULT );
|
||||
addDescriptorInternal( NCharTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( NVarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( LongNVarcharTypeDescriptor.INSTANCE );
|
||||
addDescriptorInternal( NClobTypeDescriptor.DEFAULT );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,6 +84,10 @@ public class SqlTypeDescriptorRegistry implements Serializable {
|
|||
descriptorMap.put( sqlTypeDescriptor.getSqlType(), sqlTypeDescriptor );
|
||||
}
|
||||
|
||||
private void addDescriptorInternal(SqlTypeDescriptor sqlTypeDescriptor){
|
||||
descriptorMap.put( sqlTypeDescriptor.getSqlType(), sqlTypeDescriptor );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated (5.3) Use {@link org.hibernate.type.descriptor.sql.spi.SqlTypeDescriptorRegistry#getDescriptor(int)} instead.
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.type.descriptor.sql.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
|
@ -17,20 +19,25 @@ import org.hibernate.type.spi.TypeConfiguration;
|
|||
*
|
||||
* @since 5.3
|
||||
*/
|
||||
public class SqlTypeDescriptorRegistry extends org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry {
|
||||
private TypeConfiguration typeConfiguration;
|
||||
public class SqlTypeDescriptorRegistry
|
||||
extends org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry
|
||||
implements Serializable {
|
||||
|
||||
private final TypeConfiguration typeConfiguration;
|
||||
private final org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry sqlTypeDescriptorRegistry;
|
||||
|
||||
public SqlTypeDescriptorRegistry(TypeConfiguration typeConfiguration) {
|
||||
this.typeConfiguration = typeConfiguration;
|
||||
sqlTypeDescriptorRegistry = org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
super.addDescriptor( sqlTypeDescriptor );
|
||||
sqlTypeDescriptorRegistry.addDescriptor( sqlTypeDescriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlTypeDescriptor getDescriptor(int jdbcTypeCode) {
|
||||
return super.getDescriptor( jdbcTypeCode );
|
||||
return sqlTypeDescriptorRegistry.getDescriptor( jdbcTypeCode );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.MutabilityPlan;
|
||||
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class JavaTypeDescriptorRegistryTest {
|
||||
|
||||
@Test
|
||||
public void testGetJavaTypeDescriptorRegistry(){
|
||||
TypeConfiguration typeConfiguration = new TypeConfiguration();
|
||||
JavaTypeDescriptor<String> descriptor = typeConfiguration.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( String.class );
|
||||
|
||||
assertThat(descriptor, instanceOf(StringTypeDescriptor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterJavaTypeDescriptorRegistry(){
|
||||
TypeConfiguration typeConfiguration = new TypeConfiguration();
|
||||
typeConfiguration.getJavaTypeDescriptorRegistry().addDescriptor( new CustomJavaTypeDescriptor() );
|
||||
JavaTypeDescriptor descriptor = typeConfiguration.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( CustomType.class );
|
||||
|
||||
assertThat(descriptor, instanceOf(CustomJavaTypeDescriptor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDirectlyToJavaTypeDescriptorRegistry(){
|
||||
TypeConfiguration typeConfiguration = new TypeConfiguration();
|
||||
org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE.addDescriptor( new CustomJavaTypeDescriptor() );
|
||||
JavaTypeDescriptor descriptor = typeConfiguration.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( CustomType.class );
|
||||
|
||||
assertThat(descriptor, instanceOf(CustomJavaTypeDescriptor.class));
|
||||
}
|
||||
|
||||
public class CustomType {}
|
||||
|
||||
public class CustomJavaTypeDescriptor implements JavaTypeDescriptor{
|
||||
@Override
|
||||
public Class getJavaTypeClass() {
|
||||
return CustomType.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutabilityPlan getMutabilityPlan() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator getComparator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractHashCode(Object value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areEqual(Object one, Object another) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String extractLoggableRepresentation(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object wrap(Object value, WrapperOptions options) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value, Class type, WrapperOptions options) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue