6 - Fix StandardBasicTypes not registering types into BasicTypeRegister when a SF is closed and recreated

This commit is contained in:
Andrea Boriero 2019-09-06 14:15:12 +01:00
parent 76b42a94c3
commit 1db0927e8e
2 changed files with 72 additions and 63 deletions

View File

@ -31,6 +31,7 @@ public class BasicTypeRegistry implements Serializable {
private final TypeConfiguration typeConfiguration; private final TypeConfiguration typeConfiguration;
private final Map<SqlTypeDescriptor,Map<JavaTypeDescriptor<?>,BasicType<?>>> registryValues = new ConcurrentHashMap<>(); private final Map<SqlTypeDescriptor,Map<JavaTypeDescriptor<?>,BasicType<?>>> registryValues = new ConcurrentHashMap<>();
private boolean primed;
/** /**
* TODO : analyze these sizing params; unfortunately this seems to be the only way to give a "concurrencyLevel" * TODO : analyze these sizing params; unfortunately this seems to be the only way to give a "concurrencyLevel"
@ -41,6 +42,13 @@ public class BasicTypeRegistry implements Serializable {
this.typeConfiguration = typeConfiguration; this.typeConfiguration = typeConfiguration;
} }
public boolean isPrimed() {
return primed;
}
public void primed() {
this.primed = true;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Access // Access

View File

@ -50,7 +50,6 @@ import org.hibernate.type.spi.TypeConfiguration;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public final class StandardBasicTypes { public final class StandardBasicTypes {
private static boolean primed;
private StandardBasicTypes() { private StandardBasicTypes() {
} }
@ -507,38 +506,41 @@ public final class StandardBasicTypes {
public static void prime(TypeConfiguration typeConfiguration) { public static void prime(TypeConfiguration typeConfiguration) {
if ( primed ) { BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
if ( basicTypeRegistry.isPrimed() ) {
return; return;
} }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// boolean data // boolean data
handle( handle(
BOOLEAN, BOOLEAN,
"org.hibernate.type.BooleanType", "org.hibernate.type.BooleanType",
typeConfiguration, basicTypeRegistry,
"boolean", boolean.class.getName(), Boolean.class.getName() "boolean", boolean.class.getName(), Boolean.class.getName()
); );
handle( handle(
NUMERIC_BOOLEAN, NUMERIC_BOOLEAN,
"org.hibernate.type.NumericBooleanType", "org.hibernate.type.NumericBooleanType",
typeConfiguration, basicTypeRegistry,
"numeric_boolean" "numeric_boolean"
); );
handle( handle(
TRUE_FALSE, TRUE_FALSE,
"org.hibernate.type.TrueFalseType", "org.hibernate.type.TrueFalseType",
typeConfiguration, basicTypeRegistry,
"true_false" "true_false"
); );
handle( handle(
YES_NO, YES_NO,
"org.hibernate.type.YesNoType", "org.hibernate.type.YesNoType",
typeConfiguration, basicTypeRegistry,
"yes_no" "yes_no"
); );
@ -549,35 +551,35 @@ public final class StandardBasicTypes {
handle( handle(
BYTE, BYTE,
"org.hibernate.type.ByteType", "org.hibernate.type.ByteType",
typeConfiguration, basicTypeRegistry,
"byte", byte.class.getName(), Byte.class.getName() "byte", byte.class.getName(), Byte.class.getName()
); );
handle( handle(
BINARY, BINARY,
"org.hibernate.type.BinaryType", "org.hibernate.type.BinaryType",
typeConfiguration, basicTypeRegistry,
"binary", "byte[]", byte[].class.getName() "binary", "byte[]", byte[].class.getName()
); );
handle( handle(
WRAPPER_BINARY, WRAPPER_BINARY,
"org.hibernate.type.WrapperBinaryType", "org.hibernate.type.WrapperBinaryType",
typeConfiguration, basicTypeRegistry,
"wrapper-binary", "Byte[]", Byte[].class.getName() "wrapper-binary", "Byte[]", Byte[].class.getName()
); );
handle( handle(
IMAGE, IMAGE,
"org.hibernate.type.ImageType", "org.hibernate.type.ImageType",
typeConfiguration, basicTypeRegistry,
"image" "image"
); );
handle( handle(
BLOB, BLOB,
"org.hibernate.type.BlobType", "org.hibernate.type.BlobType",
typeConfiguration, basicTypeRegistry,
"blob", "blob",
Blob.class.getName() Blob.class.getName()
); );
@ -585,14 +587,14 @@ public final class StandardBasicTypes {
handle( handle(
MATERIALIZED_BLOB, MATERIALIZED_BLOB,
"org.hibernate.type.MaterializedBlobType", "org.hibernate.type.MaterializedBlobType",
typeConfiguration, basicTypeRegistry,
"materialized_blob" "materialized_blob"
); );
handle( handle(
WrappedMaterializedBlobType.INSTANCE, WrappedMaterializedBlobType.INSTANCE,
"org.hibernate.type.MaterializedBlobType", "org.hibernate.type.MaterializedBlobType",
typeConfiguration, basicTypeRegistry,
"wrapped_materialized_blob" "wrapped_materialized_blob"
); );
@ -603,49 +605,49 @@ public final class StandardBasicTypes {
handle( handle(
SHORT, SHORT,
"org.hibernate.type.ShortType", "org.hibernate.type.ShortType",
typeConfiguration, basicTypeRegistry,
"short", short.class.getName(), Short.class.getName() "short", short.class.getName(), Short.class.getName()
); );
handle( handle(
INTEGER, INTEGER,
"org.hibernate.type.IntegerType", "org.hibernate.type.IntegerType",
typeConfiguration, basicTypeRegistry,
"integer", int.class.getName(), Integer.class.getName() "integer", int.class.getName(), Integer.class.getName()
); );
handle( handle(
LONG, LONG,
"org.hibernate.type.LongType", "org.hibernate.type.LongType",
typeConfiguration, basicTypeRegistry,
"long", long.class.getName(), Long.class.getName() "long", long.class.getName(), Long.class.getName()
); );
handle( handle(
FLOAT, FLOAT,
"org.hibernate.type.FloatType", "org.hibernate.type.FloatType",
typeConfiguration, basicTypeRegistry,
"float", float.class.getName(), Float.class.getName() "float", float.class.getName(), Float.class.getName()
); );
handle( handle(
DOUBLE, DOUBLE,
"org.hibernate.type.DoubleType", "org.hibernate.type.DoubleType",
typeConfiguration, basicTypeRegistry,
"double", double.class.getName(), Double.class.getName() "double", double.class.getName(), Double.class.getName()
); );
handle( handle(
BIG_INTEGER, BIG_INTEGER,
"org.hibernate.type.BigIntegerType", "org.hibernate.type.BigIntegerType",
typeConfiguration, basicTypeRegistry,
"big_integer", BigInteger.class.getName() "big_integer", BigInteger.class.getName()
); );
handle( handle(
BIG_DECIMAL, BIG_DECIMAL,
"org.hibernate.type.BigDecimalType", "org.hibernate.type.BigDecimalType",
typeConfiguration, basicTypeRegistry,
"big_decimal", BigDecimal.class.getName() "big_decimal", BigDecimal.class.getName()
); );
@ -656,112 +658,112 @@ public final class StandardBasicTypes {
handle( handle(
CHARACTER, CHARACTER,
"org.hibernate.type.CharacterType", "org.hibernate.type.CharacterType",
typeConfiguration, basicTypeRegistry,
"character", char.class.getName(), Character.class.getName() "character", char.class.getName(), Character.class.getName()
); );
handle( handle(
CHARACTER_NCHAR, CHARACTER_NCHAR,
null, null,
typeConfiguration, basicTypeRegistry,
"character_nchar" "character_nchar"
); );
handle( handle(
STRING, STRING,
"org.hibernate.type.StringType", "org.hibernate.type.StringType",
typeConfiguration, basicTypeRegistry,
"string", String.class.getName() "string", String.class.getName()
); );
handle( handle(
NSTRING, NSTRING,
"org.hibernate.type.StringNVarcharType", "org.hibernate.type.StringNVarcharType",
typeConfiguration, basicTypeRegistry,
"nstring" "nstring"
); );
handle( handle(
CHAR_ARRAY, CHAR_ARRAY,
"org.hibernate.type.CharArrayType", "org.hibernate.type.CharArrayType",
typeConfiguration, basicTypeRegistry,
"characters", "char[]", char[].class.getName() "characters", "char[]", char[].class.getName()
); );
handle( handle(
CHARACTER_ARRAY, CHARACTER_ARRAY,
"org.hibernate.type.CharacterArrayType", "org.hibernate.type.CharacterArrayType",
typeConfiguration, basicTypeRegistry,
"wrapper-characters", Character[].class.getName(), "Character[]" "wrapper-characters", Character[].class.getName(), "Character[]"
); );
handle( handle(
TEXT, TEXT,
"org.hibernate.type.TextType", "org.hibernate.type.TextType",
typeConfiguration, basicTypeRegistry,
"text" "text"
); );
handle( handle(
NTEXT, NTEXT,
"org.hibernate.type.NTextType", "org.hibernate.type.NTextType",
typeConfiguration, basicTypeRegistry,
"ntext" "ntext"
); );
handle( handle(
CLOB, CLOB,
"org.hibernate.type.ClobType", "org.hibernate.type.ClobType",
typeConfiguration, basicTypeRegistry,
"clob", Clob.class.getName() "clob", Clob.class.getName()
); );
handle( handle(
NCLOB, NCLOB,
"org.hibernate.type.NClobType", "org.hibernate.type.NClobType",
typeConfiguration, basicTypeRegistry,
"nclob", NClob.class.getName() "nclob", NClob.class.getName()
); );
handle( handle(
MATERIALIZED_CLOB, MATERIALIZED_CLOB,
"org.hibernate.type.MaterializedClobType", "org.hibernate.type.MaterializedClobType",
typeConfiguration, basicTypeRegistry,
"materialized_clob" "materialized_clob"
); );
handle( handle(
MATERIALIZED_CLOB_CHAR_ARRAY, MATERIALIZED_CLOB_CHAR_ARRAY,
"org.hibernate.type.PrimitiveCharacterArrayClobType", "org.hibernate.type.PrimitiveCharacterArrayClobType",
typeConfiguration, basicTypeRegistry,
"materialized_clob_char_array" "materialized_clob_char_array"
); );
handle( handle(
MATERIALIZED_CLOB_CHARACTER_ARRAY, MATERIALIZED_CLOB_CHARACTER_ARRAY,
"org.hibernate.type.CharacterArrayClobType", "org.hibernate.type.CharacterArrayClobType",
typeConfiguration, basicTypeRegistry,
"materialized_clob_character_array" "materialized_clob_character_array"
); );
handle( handle(
MATERIALIZED_NCLOB, MATERIALIZED_NCLOB,
"org.hibernate.type.MaterializedNClobType", "org.hibernate.type.MaterializedNClobType",
typeConfiguration, basicTypeRegistry,
"materialized_nclob" "materialized_nclob"
); );
handle( handle(
MATERIALIZED_NCLOB_CHARACTER_ARRAY, MATERIALIZED_NCLOB_CHARACTER_ARRAY,
"org.hibernate.type.CharacterArrayNClobType", "org.hibernate.type.CharacterArrayNClobType",
typeConfiguration, basicTypeRegistry,
"materialized_nclob_character_array" "materialized_nclob_character_array"
); );
handle( handle(
MATERIALIZED_NCLOB_CHAR_ARRAY, MATERIALIZED_NCLOB_CHAR_ARRAY,
"org.hibernate.type.PrimitiveCharacterArrayNClobType", "org.hibernate.type.PrimitiveCharacterArrayNClobType",
typeConfiguration, basicTypeRegistry,
"materialized_nclob_char_array" "materialized_nclob_char_array"
); );
@ -772,98 +774,98 @@ public final class StandardBasicTypes {
handle( handle(
DURATION, DURATION,
"org.hibernate.type.DurationType", "org.hibernate.type.DurationType",
typeConfiguration, basicTypeRegistry,
Duration.class.getSimpleName(), Duration.class.getName() Duration.class.getSimpleName(), Duration.class.getName()
); );
handle( handle(
LOCAL_DATE_TIME, LOCAL_DATE_TIME,
"org.hibernate.type.LocalDateTimeType", "org.hibernate.type.LocalDateTimeType",
typeConfiguration, basicTypeRegistry,
LocalDateTime.class.getSimpleName(), LocalDateTime.class.getName() LocalDateTime.class.getSimpleName(), LocalDateTime.class.getName()
); );
handle( handle(
LOCAL_DATE, LOCAL_DATE,
"org.hibernate.type.LocalDateType", "org.hibernate.type.LocalDateType",
typeConfiguration, basicTypeRegistry,
LocalDate.class.getSimpleName(), LocalDate.class.getName() LocalDate.class.getSimpleName(), LocalDate.class.getName()
); );
handle( handle(
LOCAL_TIME, LOCAL_TIME,
"org.hibernate.type.LocalTimeType", "org.hibernate.type.LocalTimeType",
typeConfiguration, basicTypeRegistry,
LocalTime.class.getSimpleName(), LocalTime.class.getName() LocalTime.class.getSimpleName(), LocalTime.class.getName()
); );
handle( handle(
OFFSET_DATE_TIME, OFFSET_DATE_TIME,
"org.hibernate.type.OffsetDateTimeType", "org.hibernate.type.OffsetDateTimeType",
typeConfiguration, basicTypeRegistry,
OffsetDateTime.class.getSimpleName(), OffsetDateTime.class.getName() OffsetDateTime.class.getSimpleName(), OffsetDateTime.class.getName()
); );
handle( handle(
OFFSET_TIME, OFFSET_TIME,
"org.hibernate.type.OffsetTimeType", "org.hibernate.type.OffsetTimeType",
typeConfiguration, basicTypeRegistry,
OffsetTime.class.getSimpleName(), OffsetTime.class.getName() OffsetTime.class.getSimpleName(), OffsetTime.class.getName()
); );
handle( handle(
ZONED_DATE_TIME, ZONED_DATE_TIME,
"org.hibernate.type.ZonedDateTimeType", "org.hibernate.type.ZonedDateTimeType",
typeConfiguration, basicTypeRegistry,
ZonedDateTime.class.getSimpleName(), ZonedDateTime.class.getName() ZonedDateTime.class.getSimpleName(), ZonedDateTime.class.getName()
); );
handle( handle(
DATE, DATE,
"org.hibernate.type.DateType", "org.hibernate.type.DateType",
typeConfiguration, basicTypeRegistry,
"date", java.sql.Date.class.getName() "date", java.sql.Date.class.getName()
); );
handle( handle(
TIME, TIME,
"org.hibernate.type.TimeType", "org.hibernate.type.TimeType",
typeConfiguration, basicTypeRegistry,
"time", java.sql.Time.class.getName() "time", java.sql.Time.class.getName()
); );
handle( handle(
TIMESTAMP, TIMESTAMP,
"org.hibernate.type.TimestampType", "org.hibernate.type.TimestampType",
typeConfiguration, basicTypeRegistry,
"timestamp", java.sql.Timestamp.class.getName(), Date.class.getName() "timestamp", java.sql.Timestamp.class.getName(), Date.class.getName()
); );
handle( handle(
CALENDAR, CALENDAR,
"org.hibernate.type.CalendarType", "org.hibernate.type.CalendarType",
typeConfiguration, basicTypeRegistry,
"calendar", Calendar.class.getName(), GregorianCalendar.class.getName() "calendar", Calendar.class.getName(), GregorianCalendar.class.getName()
); );
handle( handle(
CALENDAR_DATE, CALENDAR_DATE,
"org.hibernate.type.CalendarDateType", "org.hibernate.type.CalendarDateType",
typeConfiguration, basicTypeRegistry,
"calendar_date" "calendar_date"
); );
handle( handle(
CALENDAR_TIME, CALENDAR_TIME,
"org.hibernate.type.CalendarTimeType", "org.hibernate.type.CalendarTimeType",
typeConfiguration, basicTypeRegistry,
"calendar_date" "calendar_date"
); );
handle( handle(
INSTANT, INSTANT,
"org.hibernate.type.InstantType", "org.hibernate.type.InstantType",
typeConfiguration, basicTypeRegistry,
"instant", Instant.class.getName() "instant", Instant.class.getName()
); );
@ -874,14 +876,14 @@ public final class StandardBasicTypes {
handle( handle(
UUID_BINARY, UUID_BINARY,
"org.hibernate.type.UUIDBinaryType", "org.hibernate.type.UUIDBinaryType",
typeConfiguration, basicTypeRegistry,
"uuid-binary", UUID.class.getName() "uuid-binary", UUID.class.getName()
); );
handle( handle(
UUID_CHAR, UUID_CHAR,
"org.hibernate.type.UUIDCharType", "org.hibernate.type.UUIDCharType",
typeConfiguration, basicTypeRegistry,
"uuid-char" "uuid-char"
); );
@ -892,21 +894,21 @@ public final class StandardBasicTypes {
handle( handle(
CLASS, CLASS,
"org.hibernate.type.ClassType", "org.hibernate.type.ClassType",
typeConfiguration, basicTypeRegistry,
"class", Class.class.getName() "class", Class.class.getName()
); );
handle( handle(
CURRENCY, CURRENCY,
"org.hibernate.type.CurrencyType", "org.hibernate.type.CurrencyType",
typeConfiguration, basicTypeRegistry,
"currency", Currency.class.getSimpleName(), Currency.class.getName() "currency", Currency.class.getSimpleName(), Currency.class.getName()
); );
handle( handle(
LOCALE, LOCALE,
"org.hibernate.type.LocaleType", "org.hibernate.type.LocaleType",
typeConfiguration, basicTypeRegistry,
"locale", "locale",
Locale.class.getName() Locale.class.getName()
); );
@ -914,28 +916,28 @@ public final class StandardBasicTypes {
handle( handle(
SERIALIZABLE, SERIALIZABLE,
"org.hibernate.type.SerializableType", "org.hibernate.type.SerializableType",
typeConfiguration, basicTypeRegistry,
"serializable", Serializable.class.getName() "serializable", Serializable.class.getName()
); );
handle( handle(
TIMEZONE, TIMEZONE,
"org.hibernate.type.TimeZoneType", "org.hibernate.type.TimeZoneType",
typeConfiguration, basicTypeRegistry,
"timezone", TimeZone.class.getName() "timezone", TimeZone.class.getName()
); );
handle( handle(
URL, URL,
"org.hibernate.type.UrlType", "org.hibernate.type.UrlType",
typeConfiguration, basicTypeRegistry,
"url", java.net.URL.class.getName() "url", java.net.URL.class.getName()
); );
handle( handle(
ROW_VERSION, ROW_VERSION,
null, null,
typeConfiguration, basicTypeRegistry,
"row_version" "row_version"
); );
@ -946,17 +948,15 @@ public final class StandardBasicTypes {
//handle( new AdaptedImmutableType( DbTimestampType.INSTANCE ), typeConfiguration, //handle( new AdaptedImmutableType( DbTimestampType.INSTANCE ), typeConfiguration,
// basicTypeProducerRegistry, "imm_dbtimestamp" ); // basicTypeProducerRegistry, "imm_dbtimestamp" );
primed = true; basicTypeRegistry.primed();
} }
private static void handle( private static void handle(
BasicType type, BasicType type,
String legacyTypeClassName, String legacyTypeClassName,
TypeConfiguration typeConfiguration, BasicTypeRegistry basicTypeRegistry,
String... registrationKeys) { String... registrationKeys) {
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
// we add these // we add these
if ( StringHelper.isNotEmpty( legacyTypeClassName ) ) { if ( StringHelper.isNotEmpty( legacyTypeClassName ) ) {
basicTypeRegistry.register( type, legacyTypeClassName ); basicTypeRegistry.register( type, legacyTypeClassName );
@ -964,4 +964,5 @@ public final class StandardBasicTypes {
basicTypeRegistry.register( type, registrationKeys ); basicTypeRegistry.register( type, registrationKeys );
} }
} }