mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 08:35:13 +00:00
HHH-12444 - Introduce BootstrapContext
HHH-12443 - Introduce TypeConfiguration
This commit is contained in:
parent
0d82dc7c83
commit
6721005208
@ -21,10 +21,23 @@
|
|||||||
public interface TypeContributions {
|
public interface TypeContributions {
|
||||||
void contributeType(BasicType type);
|
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);
|
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);
|
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);
|
void contributeType(CompositeUserType type, String... keys);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.hibernate.type.descriptor.java.spi;
|
package org.hibernate.type.descriptor.java.spi;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
@ -17,22 +19,25 @@
|
|||||||
*
|
*
|
||||||
* @since 5.3
|
* @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) {
|
public JavaTypeDescriptorRegistry(TypeConfiguration typeConfiguration) {
|
||||||
|
|
||||||
this.typeConfiguration = typeConfiguration;
|
this.typeConfiguration = typeConfiguration;
|
||||||
|
javaTypeDescriptorRegistry = org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> JavaTypeDescriptor<T> getDescriptor(Class<T> javaType) {
|
public <T> JavaTypeDescriptor<T> getDescriptor(Class<T> javaType) {
|
||||||
return super.getDescriptor( javaType );
|
return javaTypeDescriptorRegistry.getDescriptor( javaType );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDescriptor(JavaTypeDescriptor descriptor) {
|
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>();
|
private ConcurrentHashMap<Integer,SqlTypeDescriptor> descriptorMap = new ConcurrentHashMap<Integer, SqlTypeDescriptor>();
|
||||||
|
|
||||||
protected SqlTypeDescriptorRegistry() {
|
protected SqlTypeDescriptorRegistry() {
|
||||||
addDescriptor( BooleanTypeDescriptor.INSTANCE );
|
addDescriptorInternal( BooleanTypeDescriptor.INSTANCE );
|
||||||
|
|
||||||
addDescriptor( BitTypeDescriptor.INSTANCE );
|
addDescriptorInternal( BitTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( BigIntTypeDescriptor.INSTANCE );
|
addDescriptorInternal( BigIntTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( DecimalTypeDescriptor.INSTANCE );
|
addDescriptorInternal( DecimalTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( DoubleTypeDescriptor.INSTANCE );
|
addDescriptorInternal( DoubleTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( FloatTypeDescriptor.INSTANCE );
|
addDescriptorInternal( FloatTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( IntegerTypeDescriptor.INSTANCE );
|
addDescriptorInternal( IntegerTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( NumericTypeDescriptor.INSTANCE );
|
addDescriptorInternal( NumericTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( RealTypeDescriptor.INSTANCE );
|
addDescriptorInternal( RealTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( SmallIntTypeDescriptor.INSTANCE );
|
addDescriptorInternal( SmallIntTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( TinyIntTypeDescriptor.INSTANCE );
|
addDescriptorInternal( TinyIntTypeDescriptor.INSTANCE );
|
||||||
|
|
||||||
addDescriptor( DateTypeDescriptor.INSTANCE );
|
addDescriptorInternal( DateTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( TimestampTypeDescriptor.INSTANCE );
|
addDescriptorInternal( TimestampTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( TimeTypeDescriptor.INSTANCE );
|
addDescriptorInternal( TimeTypeDescriptor.INSTANCE );
|
||||||
|
|
||||||
addDescriptor( BinaryTypeDescriptor.INSTANCE );
|
addDescriptorInternal( BinaryTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( VarbinaryTypeDescriptor.INSTANCE );
|
addDescriptorInternal( VarbinaryTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( LongVarbinaryTypeDescriptor.INSTANCE );
|
addDescriptorInternal( LongVarbinaryTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( BlobTypeDescriptor.DEFAULT );
|
addDescriptorInternal( BlobTypeDescriptor.DEFAULT );
|
||||||
|
|
||||||
addDescriptor( CharTypeDescriptor.INSTANCE );
|
addDescriptorInternal( CharTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( VarcharTypeDescriptor.INSTANCE );
|
addDescriptorInternal( VarcharTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( LongVarcharTypeDescriptor.INSTANCE );
|
addDescriptorInternal( LongVarcharTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( ClobTypeDescriptor.DEFAULT );
|
addDescriptorInternal( ClobTypeDescriptor.DEFAULT );
|
||||||
|
|
||||||
addDescriptor( NCharTypeDescriptor.INSTANCE );
|
addDescriptorInternal( NCharTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( NVarcharTypeDescriptor.INSTANCE );
|
addDescriptorInternal( NVarcharTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( LongNVarcharTypeDescriptor.INSTANCE );
|
addDescriptorInternal( LongNVarcharTypeDescriptor.INSTANCE );
|
||||||
addDescriptor( NClobTypeDescriptor.DEFAULT );
|
addDescriptorInternal( NClobTypeDescriptor.DEFAULT );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,6 +84,10 @@ public void addDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
|||||||
descriptorMap.put( sqlTypeDescriptor.getSqlType(), sqlTypeDescriptor );
|
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.
|
* @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;
|
package org.hibernate.type.descriptor.sql.spi;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
@ -17,20 +19,25 @@
|
|||||||
*
|
*
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
public class SqlTypeDescriptorRegistry extends org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry {
|
public class SqlTypeDescriptorRegistry
|
||||||
private TypeConfiguration typeConfiguration;
|
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) {
|
public SqlTypeDescriptorRegistry(TypeConfiguration typeConfiguration) {
|
||||||
this.typeConfiguration = typeConfiguration;
|
this.typeConfiguration = typeConfiguration;
|
||||||
|
sqlTypeDescriptorRegistry = org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
public void addDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||||
super.addDescriptor( sqlTypeDescriptor );
|
sqlTypeDescriptorRegistry.addDescriptor( sqlTypeDescriptor );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SqlTypeDescriptor getDescriptor(int jdbcTypeCode) {
|
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…
x
Reference in New Issue
Block a user