From 9e83129fc3a389a5ab08e4bc40521d545a218354 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Fri, 1 Oct 2021 13:44:44 +0200 Subject: [PATCH] Change JavaTypeDescriptor#fromString to accept a CharSequence instead of String and introduce CharSequence utilities to avoid creating intermediate strings --- ...mmaDelimitedStringsJavaTypeDescriptor.java | 6 +- .../collections/type/TimestampEpochType.java | 2 +- .../mapping/basic/BitSetJavaType.java | 8 +- .../userguide/mapping/basic/BitSetType.java | 4 +- .../basic/GenderJavaTypeDescriptor.java | 4 +- .../internal/util/CharSequenceHelper.java | 105 ++++++++++++++++++ .../hibernate/internal/util/SubSequence.java | 75 +++++++++++++ .../persister/entity/DiscriminatorType.java | 4 +- .../hql/internal/SemanticQueryBuilder.java | 4 +- .../sqm/sql/BaseSqmToSqlAstConverter.java | 4 +- .../type/AbstractStandardBasicType.java | 5 +- .../org/hibernate/type/BigIntegerType.java | 2 +- .../java/org/hibernate/type/BooleanType.java | 2 +- .../java/org/hibernate/type/ByteType.java | 6 +- .../hibernate/type/CharacterNCharType.java | 4 +- .../org/hibernate/type/CharacterType.java | 4 +- .../java/org/hibernate/type/CustomType.java | 10 +- .../java/org/hibernate/type/DateType.java | 4 +- .../java/org/hibernate/type/EnumType.java | 2 +- .../org/hibernate/type/IdentifierType.java | 4 +- .../java/org/hibernate/type/IntegerType.java | 4 +- .../java/org/hibernate/type/LongType.java | 4 +- .../hibernate/type/NumericBooleanType.java | 2 +- .../java/org/hibernate/type/ShortType.java | 4 +- .../org/hibernate/type/SingleColumnType.java | 2 +- .../hibernate/type/StringNVarcharType.java | 4 +- .../type/StringRepresentableType.java | 4 +- .../java/org/hibernate/type/StringType.java | 4 +- .../org/hibernate/type/TimestampType.java | 2 +- .../org/hibernate/type/TrueFalseType.java | 4 +- .../main/java/org/hibernate/type/UrlType.java | 4 +- .../java/org/hibernate/type/YesNoType.java | 4 +- .../descriptor/java/BasicJavaDescriptor.java | 2 +- .../java/BigDecimalTypeDescriptor.java | 4 +- .../java/BigIntegerTypeDescriptor.java | 4 +- .../descriptor/java/BlobTypeDescriptor.java | 2 +- .../java/BooleanTypeDescriptor.java | 4 +- .../java/ByteArrayTypeDescriptor.java | 4 +- .../descriptor/java/ByteTypeDescriptor.java | 4 +- .../java/CalendarDateTypeDescriptor.java | 4 +- .../java/CalendarTimeTypeDescriptor.java | 4 +- .../java/CalendarTypeDescriptor.java | 4 +- .../java/CharacterArrayTypeDescriptor.java | 4 +- .../java/CharacterTypeDescriptor.java | 2 +- .../descriptor/java/ClassTypeDescriptor.java | 8 +- .../descriptor/java/ClobTypeDescriptor.java | 4 +- .../java/CurrencyTypeDescriptor.java | 4 +- .../descriptor/java/DateTypeDescriptor.java | 4 +- .../descriptor/java/DoubleTypeDescriptor.java | 4 +- .../java/DurationJavaDescriptor.java | 6 +- .../java/EnumJavaTypeDescriptor.java | 4 +- .../descriptor/java/FloatTypeDescriptor.java | 4 +- .../java/InstantJavaDescriptor.java | 2 +- .../java/IntegerTypeDescriptor.java | 4 +- .../descriptor/java/JavaTypeDescriptor.java | 3 +- .../java/JdbcDateTypeDescriptor.java | 4 +- .../java/JdbcTimeTypeDescriptor.java | 4 +- .../java/JdbcTimestampTypeDescriptor.java | 2 +- .../java/LocalDateJavaDescriptor.java | 2 +- .../java/LocalDateTimeJavaDescriptor.java | 2 +- .../java/LocalTimeJavaDescriptor.java | 2 +- .../descriptor/java/LocaleTypeDescriptor.java | 9 +- .../descriptor/java/LongTypeDescriptor.java | 4 +- .../descriptor/java/NClobTypeDescriptor.java | 4 +- .../java/OffsetDateTimeJavaDescriptor.java | 2 +- .../java/OffsetTimeJavaDescriptor.java | 2 +- .../PrimitiveByteArrayTypeDescriptor.java | 5 +- ...PrimitiveCharacterArrayTypeDescriptor.java | 4 +- .../java/RowVersionTypeDescriptor.java | 4 +- .../java/SerializableTypeDescriptor.java | 2 +- .../descriptor/java/ShortTypeDescriptor.java | 4 +- .../descriptor/java/StringTypeDescriptor.java | 4 +- .../java/TimeZoneTypeDescriptor.java | 8 +- .../descriptor/java/UUIDTypeDescriptor.java | 4 +- .../descriptor/java/UrlTypeDescriptor.java | 8 +- .../java/ZoneOffsetJavaDescriptor.java | 8 +- .../java/ZonedDateTimeJavaDescriptor.java | 2 +- .../spi/CollectionJavaTypeDescriptor.java | 2 +- .../descriptor/java/spi/DynamicModelJtd.java | 2 +- .../spi/JavaTypeDescriptorBasicAdaptor.java | 2 +- .../java/spi/MapEntryJavaDescriptor.java | 2 +- .../internal/UserTypeJavaTypeWrapper.java | 2 +- .../hibernate/usertype/EnhancedUserType.java | 5 +- .../basic/CollectionAsBasicTest.java | 2 +- .../basics/CustomTypeResolutionTests.java | 8 +- .../ExplicitJavaTypeDescriptorTest.java | 4 +- .../custom/MyCustomJavaTypeDescriptor.java | 6 +- .../java/JavaTypeDescriptorRegistryTest.java | 2 +- .../QueryParametersValidationArrayTest.java | 2 +- .../orm/test/type/contributor/ArrayType.java | 4 +- .../type/contributor/ArrayTypeDescriptor.java | 6 +- .../StoredPrefixedStringType.java | 4 +- .../test/hql/ClassificationType.java | 5 +- .../usertype/inet/InetJavaTypeDescriptor.java | 4 +- .../usertype/json/JsonJavaTypeDescriptor.java | 4 +- .../type/LongListTypeContributorTest.java | 8 +- .../type/StandardBasicTypeTemplateTest.java | 4 +- .../GeolatteGeometryJavaTypeDescriptor.java | 8 +- .../JTSGeometryJavaTypeDescriptor.java | 8 +- ...aDelimitedStringMapJavaTypeDescriptor.java | 2 +- ...mmaDelimitedStringsJavaTypeDescriptor.java | 4 +- 101 files changed, 384 insertions(+), 196 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/internal/util/CharSequenceHelper.java create mode 100644 hibernate-core/src/main/java/org/hibernate/internal/util/SubSequence.java diff --git a/documentation/src/test/java/org/hibernate/userguide/collections/type/CommaDelimitedStringsJavaTypeDescriptor.java b/documentation/src/test/java/org/hibernate/userguide/collections/type/CommaDelimitedStringsJavaTypeDescriptor.java index cb2d9e4756..010a3a8755 100644 --- a/documentation/src/test/java/org/hibernate/userguide/collections/type/CommaDelimitedStringsJavaTypeDescriptor.java +++ b/documentation/src/test/java/org/hibernate/userguide/collections/type/CommaDelimitedStringsJavaTypeDescriptor.java @@ -41,9 +41,9 @@ public class CommaDelimitedStringsJavaTypeDescriptor extends AbstractClassTypeDe } @Override - public List fromString(String string) { + public List fromString(CharSequence string) { List values = new ArrayList<>(); - Collections.addAll( values, string.split( DELIMITER ) ); + Collections.addAll( values, string.toString().split( DELIMITER ) ); return values; } @@ -54,7 +54,7 @@ public class CommaDelimitedStringsJavaTypeDescriptor extends AbstractClassTypeDe @Override public List wrap(X value, WrapperOptions options) { - return fromString( (String) value ); + return fromString( (CharSequence) value ); } } //end::collections-comma-delimited-collection-example[] diff --git a/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java b/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java index cbcccdd667..424acfac36 100644 --- a/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java +++ b/documentation/src/test/java/org/hibernate/userguide/collections/type/TimestampEpochType.java @@ -61,7 +61,7 @@ public class TimestampEpochType @Override public Date fromStringValue( - String xml) throws HibernateException { + CharSequence xml) throws HibernateException { return fromString( xml ); } } diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetJavaType.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetJavaType.java index 512da3c655..17e3958f17 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetJavaType.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetJavaType.java @@ -38,8 +38,8 @@ public class BitSetJavaType extends AbstractClassTypeDescriptor { } @Override - public BitSet fromString(String string) { - return BitSetHelper.stringToBitSet( string ); + public BitSet fromString(CharSequence string) { + return BitSetHelper.stringToBitSet( string.toString() ); } @SuppressWarnings({"unchecked"}) @@ -65,8 +65,8 @@ public class BitSetJavaType extends AbstractClassTypeDescriptor { if ( value == null ) { return null; } - if ( value instanceof String ) { - return fromString( (String) value ); + if ( value instanceof CharSequence ) { + return fromString( (CharSequence) value ); } if ( value instanceof BitSet ) { return (BitSet) value; diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetType.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetType.java index c7522d8da4..354f6cad92 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetType.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetType.java @@ -22,8 +22,8 @@ public class BitSetType } @Override - public BitSet stringToObject(String xml) throws Exception { - return fromString( xml ); + public BitSet stringToObject(CharSequence sequence) throws Exception { + return fromString( sequence ); } @Override diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/GenderJavaTypeDescriptor.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/GenderJavaTypeDescriptor.java index 4d13ed90e5..17555c645c 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/GenderJavaTypeDescriptor.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/GenderJavaTypeDescriptor.java @@ -21,8 +21,8 @@ public class GenderJavaTypeDescriptor extends AbstractClassTypeDescriptor X unwrap(Gender value, Class type, WrapperOptions options) { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/CharSequenceHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/CharSequenceHelper.java new file mode 100644 index 0000000000..3c43b5d1ed --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/CharSequenceHelper.java @@ -0,0 +1,105 @@ +/* + * 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 . + */ +package org.hibernate.internal.util; + +/** + * @author Christian Beikov + */ +public final class CharSequenceHelper { + + private CharSequenceHelper() { + } + + public static CharSequence subSequence(CharSequence sequence, int start, int end) { + if ( sequence instanceof SubSequence ) { + return sequence.subSequence( start, end ); + } + else { + return new SubSequence( sequence, start, end ); + } + } + + public static boolean isEmpty(CharSequence string) { + return string == null || string.length() == 0; + } + + public static int lastIndexOf(CharSequence charSequence, char c) { + return lastIndexOf( charSequence, c, 0, charSequence.length() - 1 ); + } + + public static int lastIndexOf(CharSequence charSequence, char c, int fromIndex, int endIndex) { + if ( charSequence instanceof String ) { + int idx = ( (String) charSequence ).lastIndexOf( c, endIndex ); + if ( idx < fromIndex ) { + return -1; + } + return idx; + } + else if ( charSequence instanceof SubSequence ) { + int idx = ( (SubSequence) charSequence ).lastIndexOf( c, fromIndex, endIndex ); + if ( idx == -1 ) { + return -1; + } + return idx; + } + else { + return lastIndexOf( charSequence.toString(), c, fromIndex, endIndex ); + } + } + + public static int indexOf(CharSequence charSequence, char c) { + return indexOf( charSequence, c, 0 ); + } + + public static int indexOf(CharSequence charSequence, char c, int fromIndex) { + return indexOf( charSequence, c, fromIndex, charSequence.length() - 1 ); + } + + public static int indexOf(CharSequence charSequence, char c, int fromIndex, int endIndex) { + if ( charSequence instanceof String ) { + int idx = ( (String) charSequence ).indexOf( c, fromIndex ); + if ( idx > endIndex ) { + return -1; + } + return idx; + } + else if ( charSequence instanceof SubSequence ) { + int idx = ( (SubSequence) charSequence ).indexOf( c, fromIndex, endIndex ); + if ( idx == -1 ) { + return -1; + } + return idx; + } + else { + return indexOf( charSequence.toString(), c, fromIndex, endIndex ); + } + } + + public static int indexOf(CharSequence charSequence, String target, int fromIndex) { + return indexOf( charSequence, target, fromIndex, charSequence.length() - 1 ); + } + + public static int indexOf(CharSequence charSequence, String target, int fromIndex, int endIndex) { + if ( charSequence instanceof String ) { + int idx = ( (String) charSequence ).indexOf( target, fromIndex ); + if ( idx > endIndex ) { + return -1; + } + return idx; + } + else if ( charSequence instanceof SubSequence ) { + int idx = ( (SubSequence) charSequence ).indexOf( target, fromIndex, endIndex ); + if ( idx == -1 ) { + return -1; + } + return idx; + } + else { + return indexOf( charSequence.toString(), target, fromIndex, endIndex ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/SubSequence.java b/hibernate-core/src/main/java/org/hibernate/internal/util/SubSequence.java new file mode 100644 index 0000000000..3ab5d62a19 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/SubSequence.java @@ -0,0 +1,75 @@ +/* + * 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 . + */ +package org.hibernate.internal.util; + +/** + * @author Christian Beikov + */ +public final class SubSequence implements CharSequence { + private final CharSequence sequence; + private final int start; + private final int length; + + public SubSequence(CharSequence sequence, int start, int end) { + this.sequence = sequence; + this.start = start; + this.length = end - start; + } + + @Override + public int length() { + return length; + } + + @Override + public char charAt(int index) { + if ( index < 0 || index >= length ) { + throw new StringIndexOutOfBoundsException( index ); + } + return sequence.charAt( index + start ); + } + + @Override + public CharSequence subSequence(int start, int end) { + if ( start < 0 || start >= length ) { + throw new StringIndexOutOfBoundsException( start ); + } + if ( end > length ) { + throw new StringIndexOutOfBoundsException( end ); + } + return sequence.subSequence( this.start + start, this.start + end ); + } + + public int lastIndexOf(char c, int fromIndex, int endIndex) { + int idx = CharSequenceHelper.lastIndexOf( sequence, c, start + fromIndex, this.start + endIndex ); + if ( idx == -1 ) { + return -1; + } + return idx - this.start; + } + + public int indexOf(char c, int fromIndex, int endIndex) { + int idx = CharSequenceHelper.indexOf( sequence, c, this.start + fromIndex, this.start + endIndex ); + if ( idx == -1 ) { + return -1; + } + return idx - this.start; + } + + public int indexOf(String s, int fromIndex, int endIndex) { + int idx = CharSequenceHelper.indexOf( sequence, s, this.start + fromIndex, this.start + endIndex ); + if ( idx == -1 ) { + return -1; + } + return idx - this.start; + } + + @Override + public String toString() { + return sequence.subSequence( start, start + length ).toString(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java index cb91a415f5..9e1badcfb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/DiscriminatorType.java @@ -232,8 +232,8 @@ public class DiscriminatorType extends AbstractType implements org.hibernate. } @Override - public T stringToObject(String xml) throws Exception { - return ( (org.hibernate.type.DiscriminatorType) underlyingType ).stringToObject( xml ); + public T stringToObject(CharSequence sequence) throws Exception { + return ( (org.hibernate.type.DiscriminatorType) underlyingType ).stringToObject( sequence ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 169140f792..f695fab964 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -40,6 +40,8 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.grammars.hql.HqlLexer; import org.hibernate.grammars.hql.HqlParser; import org.hibernate.grammars.hql.HqlParserBaseVisitor; +import org.hibernate.internal.util.CharSequenceHelper; +import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.Stack; import org.hibernate.internal.util.collections.StandardStack; import org.hibernate.metamodel.CollectionClassification; @@ -2967,7 +2969,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem private SqmLiteral binaryLiteral(String text) { return new SqmLiteral<>( - StandardBasicTypes.BINARY.fromStringValue( text.substring( 2, text.length()-1 ) ), + StandardBasicTypes.BINARY.fromStringValue( CharSequenceHelper.subSequence( text, 2, text.length() - 1 ) ), resolveExpressableTypeBasic( byte[].class ), creationContext.getNodeBuilder() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 5f6a1e72a1..13b05647a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -2773,8 +2773,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base if ( javaTypeDescriptor.getJavaTypeClass().isInstance( literalValue ) ) { discriminatorValue = literalValue; } - else if ( literalValue instanceof String ) { - discriminatorValue = javaTypeDescriptor.fromString( (String) literalValue ); + else if ( literalValue instanceof CharSequence ) { + discriminatorValue = javaTypeDescriptor.fromString( (CharSequence) literalValue ); } else if ( creationContext.getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled() ) { discriminatorValue = literalValue; diff --git a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java index 70d7d49c77..2064e61b19 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java @@ -16,7 +16,6 @@ import java.util.Map; import org.hibernate.Hibernate; import org.hibernate.HibernateException; import org.hibernate.MappingException; -import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.spi.Mapping; @@ -86,7 +85,7 @@ public abstract class AbstractStandardBasicType return getExpressableJavaTypeDescriptor().getJavaTypeClass(); } - public T fromString(String string) { + public T fromString(CharSequence string) { return javaTypeDescriptor.fromString( string ); } @@ -96,7 +95,7 @@ public abstract class AbstractStandardBasicType } @Override - public T fromStringValue(String xml) throws HibernateException { + public T fromStringValue(CharSequence xml) throws HibernateException { return fromString( xml ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/BigIntegerType.java b/hibernate-core/src/main/java/org/hibernate/type/BigIntegerType.java index 153b0ac1bb..93d7afbceb 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BigIntegerType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BigIntegerType.java @@ -44,7 +44,7 @@ public class BigIntegerType } @Override - public BigInteger stringToObject(String string) { + public BigInteger stringToObject(CharSequence string) { return BigIntegerTypeDescriptor.INSTANCE.fromString( string ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/BooleanType.java b/hibernate-core/src/main/java/org/hibernate/type/BooleanType.java index ff17b39b75..f821bb909a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BooleanType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BooleanType.java @@ -58,7 +58,7 @@ public class BooleanType return Boolean.FALSE; } @Override - public Boolean stringToObject(String string) { + public Boolean stringToObject(CharSequence string) { return fromString( string ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/ByteType.java b/hibernate-core/src/main/java/org/hibernate/type/ByteType.java index fb01ebcf6f..e4a16d5fa6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ByteType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ByteType.java @@ -58,12 +58,12 @@ public class ByteType } @Override - public Byte stringToObject(String xml) { - return fromString( xml ); + public Byte stringToObject(CharSequence sequence) { + return fromString( sequence ); } @Override - public Byte fromStringValue(String xml) { + public Byte fromStringValue(CharSequence xml) { return fromString( xml ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/CharacterNCharType.java b/hibernate-core/src/main/java/org/hibernate/type/CharacterNCharType.java index c235fc01ef..1dd8efbb27 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CharacterNCharType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CharacterNCharType.java @@ -50,8 +50,8 @@ public class CharacterNCharType return new String( chars ); } - public Character stringToObject(String xml) { - return fromString( xml ); + public Character stringToObject(CharSequence sequence) { + return fromString( sequence ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/CharacterType.java b/hibernate-core/src/main/java/org/hibernate/type/CharacterType.java index 100b24abf2..8b9b72102d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CharacterType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CharacterType.java @@ -61,8 +61,8 @@ public class CharacterType return new String( chars ); } - public Character stringToObject(String xml) { - return fromString( xml ); + public Character stringToObject(CharSequence sequence) { + return fromString( sequence ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java index a3013d9a43..6edfc75df9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java @@ -252,8 +252,8 @@ public class CustomType } @Override - public Object stringToObject(String xml) { - return fromStringValue( xml ); + public Object stringToObject(CharSequence sequence) { + return fromStringValue( sequence ); } @Override @@ -318,13 +318,13 @@ public class CustomType } @Override - public Object fromStringValue(String string) throws HibernateException { + public Object fromStringValue(CharSequence sequence) throws HibernateException { if ( getUserType() instanceof StringRepresentableType ) { - return ( (StringRepresentableType) getUserType() ).fromStringValue( string ); + return ( (StringRepresentableType) getUserType() ).fromStringValue( sequence ); } if ( getUserType() instanceof EnhancedUserType ) { //noinspection deprecation - return ( (EnhancedUserType) getUserType() ).fromXMLString( string ); + return ( (EnhancedUserType) getUserType() ).fromXMLString( sequence ); } throw new HibernateException( String.format( diff --git a/hibernate-core/src/main/java/org/hibernate/type/DateType.java b/hibernate-core/src/main/java/org/hibernate/type/DateType.java index 689919f468..d61993fa67 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/DateType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/DateType.java @@ -57,8 +57,8 @@ public class DateType return StringType.INSTANCE.objectToSQLString( jdbcDate.toString(), dialect ); } - public Date stringToObject(String xml) { - return fromString( xml ); + public Date stringToObject(CharSequence sequence) { + return fromString( sequence ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java index bc1a3fa675..7d17a3ca0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java @@ -432,7 +432,7 @@ public class EnumType> @Override @SuppressWarnings("RedundantCast") - public Object fromXMLString(String xmlValue) { + public Object fromXMLString(CharSequence xmlValue) { verifyConfigured(); return (T) enumValueConverter.getDomainJavaDescriptor().wrap( xmlValue, null ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/IdentifierType.java b/hibernate-core/src/main/java/org/hibernate/type/IdentifierType.java index af965530e7..c291482f86 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/IdentifierType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/IdentifierType.java @@ -18,11 +18,11 @@ public interface IdentifierType extends Type { /** * Convert the value from the mapping file to a Java object. * - * @param xml the value of discriminator-value or unsaved-value attribute + * @param sequence the value of discriminator-value or unsaved-value attribute * @return The converted value of the string representation. * * @throws Exception Indicates a problem converting from the string */ - public T stringToObject(String xml) throws Exception; + public T stringToObject(CharSequence sequence) throws Exception; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java b/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java index cf79e6a048..68d9340c26 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/IntegerType.java @@ -56,8 +56,8 @@ public class IntegerType extends AbstractSingleColumnStandardBasicType } @Override - public Integer stringToObject(String xml) { - return fromString( xml ); + public Integer stringToObject(CharSequence sequence) { + return fromString( sequence ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/LongType.java b/hibernate-core/src/main/java/org/hibernate/type/LongType.java index 0636d60fa7..739a1da140 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/LongType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/LongType.java @@ -53,8 +53,8 @@ public class LongType } @Override - public Long stringToObject(String xml) throws Exception { - return Long.valueOf( xml ); + public Long stringToObject(CharSequence sequence) throws Exception { + return Long.valueOf( sequence.toString() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/NumericBooleanType.java b/hibernate-core/src/main/java/org/hibernate/type/NumericBooleanType.java index 7fdc555916..c470ccfddf 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/NumericBooleanType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/NumericBooleanType.java @@ -43,7 +43,7 @@ public class NumericBooleanType return Boolean.FALSE; } @Override - public Boolean stringToObject(String string) { + public Boolean stringToObject(CharSequence string) { return fromString( string ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/ShortType.java b/hibernate-core/src/main/java/org/hibernate/type/ShortType.java index 5a96cac2ac..822ba63425 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ShortType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ShortType.java @@ -58,8 +58,8 @@ public class ShortType } @Override - public Short stringToObject(String xml) { - return Short.valueOf( xml ); + public Short stringToObject(CharSequence sequence) { + return Short.valueOf( sequence.toString() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/SingleColumnType.java b/hibernate-core/src/main/java/org/hibernate/type/SingleColumnType.java index e6d65972f3..d7f84ec9fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SingleColumnType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SingleColumnType.java @@ -24,7 +24,7 @@ public interface SingleColumnType extends Type { String toString(T value) throws HibernateException; - T fromStringValue(String xml) throws HibernateException; + T fromStringValue(CharSequence sequence) throws HibernateException; /** * Get a column value from a result set by name. diff --git a/hibernate-core/src/main/java/org/hibernate/type/StringNVarcharType.java b/hibernate-core/src/main/java/org/hibernate/type/StringNVarcharType.java index 5856a701e6..d18cc94e8a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/StringNVarcharType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/StringNVarcharType.java @@ -40,8 +40,8 @@ public class StringNVarcharType return QueryLiteralHelper.toStringLiteral( value ); } - public String stringToObject(String xml) throws Exception { - return xml; + public String stringToObject(CharSequence sequence) throws Exception { + return sequence.toString(); } public String toString(String value) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/StringRepresentableType.java b/hibernate-core/src/main/java/org/hibernate/type/StringRepresentableType.java index 1ad961ed32..e15b693b79 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/StringRepresentableType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/StringRepresentableType.java @@ -28,11 +28,11 @@ public interface StringRepresentableType { /** * Consume the given string representation back into this types java form. * - * @param string The string representation to be consumed. + * @param sequence The string representation to be consumed. * * @return The java type representation * * @throws HibernateException Problem consuming */ - T fromStringValue(String string) throws HibernateException; + T fromStringValue(CharSequence sequence) throws HibernateException; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/StringType.java b/hibernate-core/src/main/java/org/hibernate/type/StringType.java index 850835901e..26cffc57f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/StringType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/StringType.java @@ -45,8 +45,8 @@ public class StringType return QueryLiteralHelper.toStringLiteral( value ); } - public String stringToObject(String xml) throws Exception { - return xml; + public String stringToObject(CharSequence sequence) throws Exception { + return sequence.toString(); } public String toString(String value) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java b/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java index 337f20b382..d14d3b517d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/TimestampType.java @@ -61,7 +61,7 @@ public class TimestampType } @Override - public Date fromStringValue(String xml) throws HibernateException { + public Date fromStringValue(CharSequence xml) throws HibernateException { return fromString( xml ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/TrueFalseType.java b/hibernate-core/src/main/java/org/hibernate/type/TrueFalseType.java index 6d461c6a7c..413964792d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/TrueFalseType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/TrueFalseType.java @@ -44,8 +44,8 @@ public class TrueFalseType } @Override - public Boolean stringToObject(String xml) throws Exception { - return fromString( xml ); + public Boolean stringToObject(CharSequence sequence) throws Exception { + return fromString( sequence ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/UrlType.java b/hibernate-core/src/main/java/org/hibernate/type/UrlType.java index 1512e41461..1af453b878 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/UrlType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/UrlType.java @@ -42,7 +42,7 @@ public class UrlType extends AbstractSingleColumnStandardBasicType implemen return StringType.INSTANCE.objectToSQLString( toString( value ), dialect ); } - public URL stringToObject(String xml) throws Exception { - return UrlTypeDescriptor.INSTANCE.fromString( xml ); + public URL stringToObject(CharSequence sequence) throws Exception { + return UrlTypeDescriptor.INSTANCE.fromString( sequence ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/YesNoType.java b/hibernate-core/src/main/java/org/hibernate/type/YesNoType.java index 93e75c9513..11b0475350 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/YesNoType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/YesNoType.java @@ -45,8 +45,8 @@ public class YesNoType } @Override - public Boolean stringToObject(String xml) throws Exception { - return fromString( xml ); + public Boolean stringToObject(CharSequence sequence) throws Exception { + return fromString( sequence ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaDescriptor.java index 265bbfc9cf..93c717b9b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BasicJavaDescriptor.java @@ -35,7 +35,7 @@ public interface BasicJavaDescriptor extends JavaTypeDescriptor { } @Override - default T fromString(String string) { + default T fromString(CharSequence string) { throw new UnsupportedOperationException(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java index 33a299dbdf..adc368f3e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java @@ -29,8 +29,8 @@ public class BigDecimalTypeDescriptor extends AbstractClassTypeDescriptor { } @Override - public Blob fromString(String string) { + public Blob fromString(CharSequence string) { return BlobProxy.generateProxy( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java index 6ec8c41145..3af882563d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java @@ -46,8 +46,8 @@ public class BooleanTypeDescriptor extends AbstractClassTypeDescriptor return value == null ? null : value.toString(); } @Override - public Boolean fromString(String string) { - return Boolean.valueOf( string ); + public Boolean fromString(CharSequence string) { + return Boolean.valueOf( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java index 16deb78949..80326961f5 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java @@ -57,7 +57,7 @@ public class ByteArrayTypeDescriptor extends AbstractClassTypeDescriptor return buf.toString(); } @Override - public Byte[] fromString(String string) { + public Byte[] fromString(CharSequence string) { if ( string == null ) { return null; } @@ -66,7 +66,7 @@ public class ByteArrayTypeDescriptor extends AbstractClassTypeDescriptor } Byte[] bytes = new Byte[string.length() / 2]; for ( int i = 0; i < bytes.length; i++ ) { - final String hexStr = string.substring( i * 2, (i + 1) * 2 ); + final String hexStr = string.subSequence( i * 2, (i + 1) * 2 ).toString(); bytes[i] = (byte) Integer.parseInt( hexStr, 16 ); } return bytes; diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java index a07fc72f89..fa0b233573 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java @@ -31,8 +31,8 @@ public class ByteTypeDescriptor extends AbstractClassTypeDescriptor implem return value == null ? null : value.toString(); } @Override - public Byte fromString(String string) { - return Byte.valueOf( string ); + public Byte fromString(CharSequence string) { + return Byte.valueOf( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java index a0f84f9be3..64b16b17fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java @@ -68,9 +68,9 @@ public class CalendarDateTypeDescriptor extends AbstractTemporalTypeDescriptor { return value.getName(); } - public Class fromString(String string) { + public Class fromString(CharSequence string) { if ( string == null ) { return null; } try { - return ReflectHelper.classForName( string ); + return ReflectHelper.classForName( string.toString() ); } catch ( ClassNotFoundException e ) { throw new HibernateException( "Unable to locate named class " + string ); @@ -59,8 +59,8 @@ public class ClassTypeDescriptor extends AbstractClassTypeDescriptor { if ( Class.class.isInstance( value ) ) { return (Class) value; } - if ( String.class.isInstance( value ) ) { - return fromString( (String)value ); + if ( CharSequence.class.isInstance( value ) ) { + return fromString( (CharSequence) value ); } throw unknownWrap( value.getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java index 00b3cc1b2c..77c042f811 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java @@ -60,8 +60,8 @@ public class ClobTypeDescriptor extends AbstractClassTypeDescriptor { return DataHelper.extractString( value ); } - public Clob fromString(String string) { - return ClobProxy.generateProxy( string ); + public Clob fromString(CharSequence string) { + return ClobProxy.generateProxy( string.toString() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java index dec8792387..8f70a70b12 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java @@ -28,8 +28,8 @@ public class CurrencyTypeDescriptor extends AbstractClassTypeDescriptor { return new SimpleDateFormat( DATE_FORMAT ).format( value ); } @Override - public Date fromString(String string) { + public Date fromString(CharSequence string) { try { - return new SimpleDateFormat(DATE_FORMAT).parse( string ); + return new SimpleDateFormat(DATE_FORMAT).parse( string.toString() ); } catch ( ParseException pe) { throw new HibernateException( "could not parse date string" + string, pe ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java index 6f01b777f5..3f9cbfcb45 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java @@ -39,8 +39,8 @@ public class DoubleTypeDescriptor extends AbstractClassTypeDescriptor im return value == null ? null : value.toString(); } @Override - public Double fromString(String string) { - return Double.valueOf( string ); + public Double fromString(CharSequence string) { + return Double.valueOf( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaDescriptor.java index 75b8fc1b74..fcd1daade6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaDescriptor.java @@ -60,14 +60,14 @@ public class DurationJavaDescriptor extends AbstractClassTypeDescriptor> extends AbstractClassType } @Override - public T fromString(String string) { - return string == null ? null : Enum.valueOf( getJavaTypeClass(), string ); + public T fromString(CharSequence string) { + return string == null ? null : Enum.valueOf( getJavaTypeClass(), string.toString() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java index 950ff91b42..11fa1e8a10 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java @@ -38,8 +38,8 @@ public class FloatTypeDescriptor extends AbstractClassTypeDescriptor impl return value == null ? null : value.toString(); } @Override - public Float fromString(String string) { - return Float.valueOf( string ); + public Float fromString(CharSequence string) { + return Float.valueOf( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java index e34745eadd..df88a2a3a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaDescriptor.java @@ -76,7 +76,7 @@ public class InstantJavaDescriptor extends AbstractTemporalTypeDescriptor return value == null ? null : value.toString(); } @Override - public Integer fromString(String string) { - return string == null ? null : Integer.valueOf( string ); + public Integer fromString(CharSequence string) { + return string == null ? null : Integer.valueOf( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java index 67e468c91d..f5f89fcfab 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java @@ -15,6 +15,7 @@ import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.Size; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.compare.ComparableComparator; +import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; @@ -147,7 +148,7 @@ public interface JavaTypeDescriptor extends Serializable { return value == null ? "null" : value.toString(); } - T fromString(String string); + T fromString(CharSequence string); /** * Unwrap an instance of our handled Java type into the requested type. diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java index 237be775fa..bcbff6c701 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java @@ -88,9 +88,9 @@ public class JdbcDateTypeDescriptor extends AbstractTemporalTypeDescriptor } @Override - public Date fromString(String string) { + public Date fromString(CharSequence string) { try { - return new Date( new SimpleDateFormat(DATE_FORMAT).parse( string ).getTime() ); + return new Date( new SimpleDateFormat(DATE_FORMAT).parse( string.toString() ).getTime() ); } catch ( ParseException pe) { throw new HibernateException( "could not parse date string" + string, pe ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java index 5a4ce079c0..b405867423 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java @@ -84,9 +84,9 @@ public class JdbcTimeTypeDescriptor extends AbstractTemporalTypeDescriptor } @Override - public Date fromString(String string) { + public Date fromString(CharSequence string) { try { - return new Time( new SimpleDateFormat( TIME_FORMAT ).parse( string ).getTime() ); + return new Time( new SimpleDateFormat( TIME_FORMAT ).parse( string.toString() ).getTime() ); } catch ( ParseException pe ) { throw new HibernateException( "could not parse time string" + string, pe ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java index bf0d56d2f3..0619caa4ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java @@ -90,7 +90,7 @@ public class JdbcTimestampTypeDescriptor extends AbstractTemporalTypeDescriptor< } @Override - public Date fromString(String string) { + public Date fromString(CharSequence string) { try { final TemporalAccessor accessor = LITERAL_FORMATTER.parse( string ); return new Timestamp( diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java index 35e58d768f..d2b82b45e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java @@ -63,7 +63,7 @@ public class LocalDateJavaDescriptor extends AbstractTemporalTypeDescriptor { return value.toString(); } - public Locale fromString(String string) { + public Locale fromString(CharSequence sequence) { // TODO : Ultimately switch to Locale.Builder for this. However, Locale.Builder is Java 7 - if ( string == null ) { + if ( sequence == null ) { return null; } + String string = sequence.toString(); if( string.isEmpty() ) { return Locale.ROOT; } @@ -105,8 +106,8 @@ public class LocaleTypeDescriptor extends AbstractClassTypeDescriptor { if ( value == null ) { return null; } - if ( String.class.isInstance( value ) ) { - return fromString( (String) value ); + if ( CharSequence.class.isInstance( value ) ) { + return fromString( (CharSequence) value ); } throw unknownWrap( value.getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java index b5a1c3a3eb..c25fab7caf 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java @@ -30,8 +30,8 @@ public class LongTypeDescriptor extends AbstractClassTypeDescriptor implem return value == null ? null : value.toString(); } @Override - public Long fromString(String string) { - return Long.valueOf( string ); + public Long fromString(CharSequence string) { + return Long.valueOf( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobTypeDescriptor.java index 9def020557..2c84d3b1b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/NClobTypeDescriptor.java @@ -65,8 +65,8 @@ public class NClobTypeDescriptor extends AbstractClassTypeDescriptor { return DataHelper.extractString( value ); } - public NClob fromString(String string) { - return NClobProxy.generateProxy( string ); + public NClob fromString(CharSequence string) { + return NClobProxy.generateProxy( string.toString() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java index b86370529c..8050ee8807 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaDescriptor.java @@ -81,7 +81,7 @@ public class OffsetDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor } @Override - public OffsetDateTime fromString(String string) { + public OffsetDateTime fromString(CharSequence string) { return OffsetDateTime.from( DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetTimeJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetTimeJavaDescriptor.java index 8724850aa7..0537734464 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetTimeJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetTimeJavaDescriptor.java @@ -66,7 +66,7 @@ public class OffsetTimeJavaDescriptor extends AbstractTemporalTypeDescriptor extends Abstract return PrimitiveByteArrayTypeDescriptor.INSTANCE.toString( toBytes( value ) ); } - public T fromString(String string) { + public T fromString(CharSequence string) { return fromBytes( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java index 7aac212c4a..0794e7645c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java @@ -29,8 +29,8 @@ public class ShortTypeDescriptor extends AbstractClassTypeDescriptor impl return value == null ? null : value.toString(); } @Override - public Short fromString(String string) { - return Short.valueOf( string ); + public Short fromString(CharSequence string) { + return Short.valueOf( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java index e5e93a7d9c..56a4520a7a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java @@ -35,8 +35,8 @@ public class StringTypeDescriptor extends AbstractClassTypeDescriptor { return value; } - public String fromString(String string) { - return string; + public String fromString(CharSequence string) { + return string.toString(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java index cbd8e5d78a..d20d6e8db4 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java @@ -35,8 +35,8 @@ public class TimeZoneTypeDescriptor extends AbstractClassTypeDescriptor { return ToStringTransformer.INSTANCE.transform( value ); } - public UUID fromString(String string) { - return ToStringTransformer.INSTANCE.parse( string ); + public UUID fromString(CharSequence string) { + return ToStringTransformer.INSTANCE.parse( string.toString() ); } @SuppressWarnings({ "unchecked" }) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java index 7f76de9470..ddc055da29 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java @@ -36,9 +36,9 @@ public class UrlTypeDescriptor extends AbstractClassTypeDescriptor { return value.toExternalForm(); } - public URL fromString(String string) { + public URL fromString(CharSequence string) { try { - return new URL( string ); + return new URL( string.toString() ); } catch ( MalformedURLException e ) { throw new HibernateException( "Unable to convert string [" + string + "] to URL : " + e ); @@ -60,8 +60,8 @@ public class UrlTypeDescriptor extends AbstractClassTypeDescriptor { if ( value == null ) { return null; } - if ( String.class.isInstance( value ) ) { - return fromString( (String) value ); + if ( CharSequence.class.isInstance( value ) ) { + return fromString( (CharSequence) value ); } throw unknownWrap( value.getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaDescriptor.java index 8bf5fa2e6c..5462481a5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaDescriptor.java @@ -38,8 +38,8 @@ public class ZoneOffsetJavaDescriptor extends AbstractClassTypeDescriptor extends AbstractClassTypeDescriptor } @Override - public C fromString(String string) { + public C fromString(CharSequence string) { throw new UnsupportedOperationException( ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/DynamicModelJtd.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/DynamicModelJtd.java index 80011a6022..f87acc7f86 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/DynamicModelJtd.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/DynamicModelJtd.java @@ -26,7 +26,7 @@ public class DynamicModelJtd implements JavaTypeDescriptor> { } @Override - public Map fromString(String string) { + public Map fromString(CharSequence string) { throw new UnsupportedOperationException(); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBasicAdaptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBasicAdaptor.java index 72a75a3746..e7b30812f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBasicAdaptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeDescriptorBasicAdaptor.java @@ -40,7 +40,7 @@ public class JavaTypeDescriptorBasicAdaptor extends AbstractClassTypeDescript } @Override - public T fromString(String string) { + public T fromString(CharSequence string) { throw new UnsupportedOperationException( "Conversion from String strategy not known for this Java type : " + getJavaType().getTypeName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/MapEntryJavaDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/MapEntryJavaDescriptor.java index 57ce9d91d3..b100ca4db7 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/MapEntryJavaDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/MapEntryJavaDescriptor.java @@ -32,7 +32,7 @@ public class MapEntryJavaDescriptor extends AbstractClassTypeDescriptor implements BasicJavaDescriptor { } @Override - public J fromString(String string) { + public J fromString(CharSequence string) { throw new UnsupportedOperationException( "No support for parsing UserType values from String: " + userType ); } diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/EnhancedUserType.java b/hibernate-core/src/main/java/org/hibernate/usertype/EnhancedUserType.java index cee6af7afd..7c33a66c76 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/EnhancedUserType.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/EnhancedUserType.java @@ -30,9 +30,10 @@ public interface EnhancedUserType extends UserType { * Parse a string representation of this value, as it appears in an XML document * * @deprecated To be removed in 5. Implement - * {@link org.hibernate.type.StringRepresentableType#fromStringValue(String)} instead. + * {@link org.hibernate.type.StringRepresentableType#fromStringValue(CharSequence)} instead. * See HHH-7776 for details + * @param xmlValue */ @Deprecated - Object fromXMLString(String xmlValue); + Object fromXMLString(CharSequence xmlValue); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/basic/CollectionAsBasicTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/basic/CollectionAsBasicTest.java index ea0e150e1a..9927979f2d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/basic/CollectionAsBasicTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/basic/CollectionAsBasicTest.java @@ -93,7 +93,7 @@ public class CollectionAsBasicTest { } @Override - public Set fromString(String string) { + public Set fromString(CharSequence string) { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/CustomTypeResolutionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/CustomTypeResolutionTests.java index 495fbd1446..1badcfbc95 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/CustomTypeResolutionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/CustomTypeResolutionTests.java @@ -277,15 +277,15 @@ public class CustomTypeResolutionTests { } @Override - public Gender fromString(String string) { - if ( StringHelper.isEmpty( string ) ) { + public Gender fromString(CharSequence string) { + if ( string == null || string.length() == 0 ) { return null; } - if ( "M".equalsIgnoreCase( string ) ) { + if ( "M".equalsIgnoreCase( string.toString() ) ) { return Gender.MALE; } - else if ( "F".equalsIgnoreCase( string ) ) { + else if ( "F".equalsIgnoreCase( string.toString() ) ) { return Gender.FEMALE; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java index 7e5c683707..58d9f4da3e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java @@ -330,8 +330,8 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT } @Override - public PseudoMutableState fromString(String string) { - return string == null ? null : new PseudoMutableState( string ); + public PseudoMutableState fromString(CharSequence string) { + return string == null ? null : new PseudoMutableState( string.toString() ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/MyCustomJavaTypeDescriptor.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/MyCustomJavaTypeDescriptor.java index b60b7e0423..ed39d976dc 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/MyCustomJavaTypeDescriptor.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/MyCustomJavaTypeDescriptor.java @@ -6,7 +6,7 @@ */ package org.hibernate.orm.test.mapping.converted.converter.custom; -import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.CharSequenceHelper; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.BasicJavaDescriptor; import org.hibernate.type.descriptor.java.MutabilityPlan; @@ -49,8 +49,8 @@ public class MyCustomJavaTypeDescriptor implements BasicJavaDescriptor { } @Override - public Array fromString(String string) { - if ( string == null || string.isEmpty() ) { + public Array fromString(CharSequence string) { + if ( string == null || string.length() == 0 ) { return null; } - String[] tokens = string.split( DELIMITER ); + String[] tokens = string.toString().split( DELIMITER ); Array array = new Array(); array.addAll( Arrays.asList(tokens) ); return array; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/StoredPrefixedStringType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/StoredPrefixedStringType.java index dc1acb5225..dbc2acd738 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/StoredPrefixedStringType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/StoredPrefixedStringType.java @@ -107,8 +107,8 @@ public class StoredPrefixedStringType return StringType.INSTANCE.objectToSQLString( value, dialect ); } - public String stringToObject(String xml) throws Exception { - return StringType.INSTANCE.stringToObject( xml ); + public String stringToObject(CharSequence sequence) throws Exception { + return StringType.INSTANCE.stringToObject( sequence ); } public String toString(String value) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/ClassificationType.java b/hibernate-core/src/test/java/org/hibernate/test/hql/ClassificationType.java index d3518fd85b..d2bc565554 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/ClassificationType.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/ClassificationType.java @@ -15,7 +15,6 @@ import java.sql.Types; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.type.IntegerType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; @@ -108,8 +107,8 @@ public class ClassificationType implements EnhancedUserType, ValueExtractor { return value.toString(); } - public Inet fromString(String string) { - return new Inet( string ); + public Inet fromString(CharSequence string) { + return new Inet( string.toString() ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/id/usertype/json/JsonJavaTypeDescriptor.java b/hibernate-core/src/test/java/org/hibernate/test/id/usertype/json/JsonJavaTypeDescriptor.java index 7896f0714c..524da5848a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/id/usertype/json/JsonJavaTypeDescriptor.java +++ b/hibernate-core/src/test/java/org/hibernate/test/id/usertype/json/JsonJavaTypeDescriptor.java @@ -24,8 +24,8 @@ public class JsonJavaTypeDescriptor extends AbstractClassTypeDescriptor { return value.toString(); } - public Json fromString(String string) { - return new Json( string ); + public Json fromString(CharSequence string) { + return new Json( string.toString() ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/LongListTypeContributorTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/LongListTypeContributorTest.java index f20441b763..0e22cc6792 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/LongListTypeContributorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/LongListTypeContributorTest.java @@ -201,8 +201,12 @@ public class LongListTypeContributorTest extends BaseEntityManagerFunctionalTest } @Override - public LongList fromString(String string) { - if ( string == null || "null".equals( string ) ) { + public LongList fromString(CharSequence sequence) { + if ( sequence == null ) { + return null; + } + final String string = sequence.toString(); + if ( "null".equals( string ) ) { return null; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/StandardBasicTypeTemplateTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/StandardBasicTypeTemplateTest.java index 754e16f240..7da49849ea 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/StandardBasicTypeTemplateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/StandardBasicTypeTemplateTest.java @@ -54,8 +54,8 @@ public class StandardBasicTypeTemplateTest extends BaseUnitTestCase { public static final ValidatingUrlJavaTypeDescriptor INSTANCE = new ValidatingUrlJavaTypeDescriptor(); @Override - public URL fromString(String string) { - if ( "invalid".equals( string ) ) { + public URL fromString(CharSequence string) { + if ( "invalid".equals( string.toString() ) ) { throw new IllegalStateException( "Invalid url" ); } return super.fromString( string ); diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/GeolatteGeometryJavaTypeDescriptor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/GeolatteGeometryJavaTypeDescriptor.java index 0c7c2b2643..8355a14794 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/GeolatteGeometryJavaTypeDescriptor.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/GeolatteGeometryJavaTypeDescriptor.java @@ -45,8 +45,8 @@ public class GeolatteGeometryJavaTypeDescriptor extends AbstractTypeDescriptor values = new ArrayList<>(); - Collections.addAll( values, string.split( DELIMITER ) ); + Collections.addAll( values, string.toString().split( DELIMITER ) ); return values; }