Change JavaTypeDescriptor#fromString to accept a CharSequence instead of String and introduce CharSequence utilities to avoid creating intermediate strings

This commit is contained in:
Christian Beikov 2021-10-01 13:44:44 +02:00
parent 40ccad1db2
commit 9e83129fc3
101 changed files with 384 additions and 196 deletions

View File

@ -41,9 +41,9 @@ public class CommaDelimitedStringsJavaTypeDescriptor extends AbstractClassTypeDe
}
@Override
public List fromString(String string) {
public List fromString(CharSequence string) {
List<String> 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 <X> List wrap(X value, WrapperOptions options) {
return fromString( (String) value );
return fromString( (CharSequence) value );
}
}
//end::collections-comma-delimited-collection-example[]

View File

@ -61,7 +61,7 @@ public class TimestampEpochType
@Override
public Date fromStringValue(
String xml) throws HibernateException {
CharSequence xml) throws HibernateException {
return fromString( xml );
}
}

View File

@ -38,8 +38,8 @@ public class BitSetJavaType extends AbstractClassTypeDescriptor<BitSet> {
}
@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<BitSet> {
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;

View File

@ -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

View File

@ -21,8 +21,8 @@ public class GenderJavaTypeDescriptor extends AbstractClassTypeDescriptor<Gender
return value == null ? null : value.name();
}
public Gender fromString(String string) {
return string == null ? null : Gender.valueOf( string );
public Gender fromString(CharSequence string) {
return string == null ? null : Gender.valueOf( string.toString() );
}
public <X> X unwrap(Gender value, Class<X> type, WrapperOptions options) {

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 );
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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();
}
}

View File

@ -232,8 +232,8 @@ public class DiscriminatorType<T> extends AbstractType implements org.hibernate.
}
@Override
public T stringToObject(String xml) throws Exception {
return ( (org.hibernate.type.DiscriminatorType<T>) underlyingType ).stringToObject( xml );
public T stringToObject(CharSequence sequence) throws Exception {
return ( (org.hibernate.type.DiscriminatorType<T>) underlyingType ).stringToObject( sequence );
}
@Override

View File

@ -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<R> extends HqlParserBaseVisitor<Object> implem
private SqmLiteral<byte[]> 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()
);

View File

@ -2773,8 +2773,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> 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;

View File

@ -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<T>
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<T>
}
@Override
public T fromStringValue(String xml) throws HibernateException {
public T fromStringValue(CharSequence xml) throws HibernateException {
return fromString( xml );
}

View File

@ -44,7 +44,7 @@ public class BigIntegerType
}
@Override
public BigInteger stringToObject(String string) {
public BigInteger stringToObject(CharSequence string) {
return BigIntegerTypeDescriptor.INSTANCE.fromString( string );
}
}

View File

@ -58,7 +58,7 @@ public class BooleanType
return Boolean.FALSE;
}
@Override
public Boolean stringToObject(String string) {
public Boolean stringToObject(CharSequence string) {
return fromString( string );
}

View File

@ -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 );
}

View File

@ -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 );
}
}

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -432,7 +432,7 @@ public class EnumType<T extends Enum<T>>
@Override
@SuppressWarnings("RedundantCast")
public Object fromXMLString(String xmlValue) {
public Object fromXMLString(CharSequence xmlValue) {
verifyConfigured();
return (T) enumValueConverter.getDomainJavaDescriptor().wrap( xmlValue, null );
}

View File

@ -18,11 +18,11 @@ public interface IdentifierType<T> extends Type {
/**
* Convert the value from the mapping file to a Java object.
*
* @param xml the value of <tt>discriminator-value</tt> or <tt>unsaved-value</tt> attribute
* @param sequence the value of <tt>discriminator-value</tt> or <tt>unsaved-value</tt> 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;
}

View File

@ -56,8 +56,8 @@ public class IntegerType extends AbstractSingleColumnStandardBasicType<Integer>
}
@Override
public Integer stringToObject(String xml) {
return fromString( xml );
public Integer stringToObject(CharSequence sequence) {
return fromString( sequence );
}
@Override

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -24,7 +24,7 @@ public interface SingleColumnType<T> 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.

View File

@ -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) {

View File

@ -28,11 +28,11 @@ public interface StringRepresentableType<T> {
/**
* 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;
}

View File

@ -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) {

View File

@ -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 );
}

View File

@ -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

View File

@ -42,7 +42,7 @@ public class UrlType extends AbstractSingleColumnStandardBasicType<URL> 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 );
}
}

View File

@ -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

View File

@ -35,7 +35,7 @@ public interface BasicJavaDescriptor<T> extends JavaTypeDescriptor<T> {
}
@Override
default T fromString(String string) {
default T fromString(CharSequence string) {
throw new UnsupportedOperationException();
}
}

View File

@ -29,8 +29,8 @@ public class BigDecimalTypeDescriptor extends AbstractClassTypeDescriptor<BigDec
return value.toString();
}
public BigDecimal fromString(String string) {
return new BigDecimal( string );
public BigDecimal fromString(CharSequence string) {
return new BigDecimal( string.toString() );
}
@Override

View File

@ -31,8 +31,8 @@ public class BigIntegerTypeDescriptor extends AbstractClassTypeDescriptor<BigInt
}
@Override
public BigInteger fromString(String string) {
return new BigInteger( string );
public BigInteger fromString(CharSequence string) {
return new BigInteger( string.toString() );
}
@Override

View File

@ -81,7 +81,7 @@ public class BlobTypeDescriptor extends AbstractClassTypeDescriptor<Blob> {
}
@Override
public Blob fromString(String string) {
public Blob fromString(CharSequence string) {
return BlobProxy.generateProxy( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) );
}

View File

@ -46,8 +46,8 @@ public class BooleanTypeDescriptor extends AbstractClassTypeDescriptor<Boolean>
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" })

View File

@ -57,7 +57,7 @@ public class ByteArrayTypeDescriptor extends AbstractClassTypeDescriptor<Byte[]>
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[]>
}
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;

View File

@ -31,8 +31,8 @@ public class ByteTypeDescriptor extends AbstractClassTypeDescriptor<Byte> 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" })

View File

@ -68,9 +68,9 @@ public class CalendarDateTypeDescriptor extends AbstractTemporalTypeDescriptor<C
return DateTypeDescriptor.INSTANCE.toString( value.getTime() );
}
public Calendar fromString(String string) {
public Calendar fromString(CharSequence string) {
Calendar result = new GregorianCalendar();
result.setTime( DateTypeDescriptor.INSTANCE.fromString( string ) );
result.setTime( DateTypeDescriptor.INSTANCE.fromString( string.toString() ) );
return result;
}

View File

@ -65,9 +65,9 @@ public class CalendarTimeTypeDescriptor extends AbstractTemporalTypeDescriptor<C
return DateTypeDescriptor.INSTANCE.toString( value.getTime() );
}
public Calendar fromString(String string) {
public Calendar fromString(CharSequence string) {
Calendar result = new GregorianCalendar();
result.setTime( DateTypeDescriptor.INSTANCE.fromString( string ) );
result.setTime( DateTypeDescriptor.INSTANCE.fromString( string.toString() ) );
return result;
}

View File

@ -72,9 +72,9 @@ public class CalendarTypeDescriptor extends AbstractTemporalTypeDescriptor<Calen
return DateTypeDescriptor.INSTANCE.toString( value.getTime() );
}
public Calendar fromString(String string) {
public Calendar fromString(CharSequence string) {
Calendar result = new GregorianCalendar();
result.setTime( DateTypeDescriptor.INSTANCE.fromString( string ) );
result.setTime( DateTypeDescriptor.INSTANCE.fromString( string.toString() ) );
return result;
}

View File

@ -33,8 +33,8 @@ public class CharacterArrayTypeDescriptor extends AbstractClassTypeDescriptor<Ch
return new String( unwrapChars( value ) );
}
@Override
public Character[] fromString(String string) {
return wrapChars( string.toCharArray() );
public Character[] fromString(CharSequence string) {
return wrapChars( string.toString().toCharArray() );
}
@Override

View File

@ -28,7 +28,7 @@ public class CharacterTypeDescriptor extends AbstractClassTypeDescriptor<Charact
}
@Override
public Character fromString(String string) {
public Character fromString(CharSequence string) {
if ( string.length() != 1 ) {
throw new HibernateException( "multiple or zero characters found parsing string" );
}

View File

@ -25,13 +25,13 @@ public class ClassTypeDescriptor extends AbstractClassTypeDescriptor<Class> {
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<Class> {
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() );
}

View File

@ -60,8 +60,8 @@ public class ClobTypeDescriptor extends AbstractClassTypeDescriptor<Clob> {
return DataHelper.extractString( value );
}
public Clob fromString(String string) {
return ClobProxy.generateProxy( string );
public Clob fromString(CharSequence string) {
return ClobProxy.generateProxy( string.toString() );
}
@Override

View File

@ -28,8 +28,8 @@ public class CurrencyTypeDescriptor extends AbstractClassTypeDescriptor<Currency
}
@Override
public Currency fromString(String string) {
return Currency.getInstance( string );
public Currency fromString(CharSequence string) {
return Currency.getInstance( string.toString() );
}
@SuppressWarnings({ "unchecked" })

View File

@ -83,9 +83,9 @@ public class DateTypeDescriptor extends AbstractTemporalTypeDescriptor<Date> {
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 );

View File

@ -39,8 +39,8 @@ public class DoubleTypeDescriptor extends AbstractClassTypeDescriptor<Double> 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" })

View File

@ -60,14 +60,14 @@ public class DurationJavaDescriptor extends AbstractClassTypeDescriptor<Duration
}
@Override
public Duration fromString(String string) {
public Duration fromString(CharSequence string) {
if ( string == null ) {
return null;
}
int cutoff = string.length() - 9;
return Duration.ofSeconds(
Long.parseLong( string.substring( 0, cutoff ) ),
Long.parseLong( string.substring( cutoff ) )
Long.parseLong( string.subSequence( 0, cutoff ).toString() ),
Long.parseLong( string.subSequence( cutoff, string.length() ).toString() )
);
}

View File

@ -49,8 +49,8 @@ public class EnumJavaTypeDescriptor<T extends Enum<T>> 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

View File

@ -38,8 +38,8 @@ public class FloatTypeDescriptor extends AbstractClassTypeDescriptor<Float> 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" })

View File

@ -76,7 +76,7 @@ public class InstantJavaDescriptor extends AbstractTemporalTypeDescriptor<Instan
}
@Override
public Instant fromString(String string) {
public Instant fromString(CharSequence string) {
return Instant.from( DateTimeFormatter.ISO_INSTANT.parse( string ) );
}

View File

@ -30,8 +30,8 @@ public class IntegerTypeDescriptor extends AbstractClassTypeDescriptor<Integer>
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" })

View File

@ -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<T> 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.

View File

@ -88,9 +88,9 @@ public class JdbcDateTypeDescriptor extends AbstractTemporalTypeDescriptor<Date>
}
@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 );

View File

@ -84,9 +84,9 @@ public class JdbcTimeTypeDescriptor extends AbstractTemporalTypeDescriptor<Date>
}
@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 );

View File

@ -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(

View File

@ -63,7 +63,7 @@ public class LocalDateJavaDescriptor extends AbstractTemporalTypeDescriptor<Loca
}
@Override
public LocalDate fromString(String string) {
public LocalDate fromString(CharSequence string) {
return LocalDate.from( DateTimeFormatter.ISO_LOCAL_DATE.parse( string ) );
}

View File

@ -62,7 +62,7 @@ public class LocalDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor<
}
@Override
public LocalDateTime fromString(String string) {
public LocalDateTime fromString(CharSequence string) {
return LocalDateTime.from( DateTimeFormatter.ISO_DATE_TIME.parse( string ) );
}

View File

@ -66,7 +66,7 @@ public class LocalTimeJavaDescriptor extends AbstractTemporalTypeDescriptor<Loca
}
@Override
public LocalTime fromString(String string) {
public LocalTime fromString(CharSequence string) {
return LocalTime.from( DateTimeFormatter.ISO_LOCAL_TIME.parse( string ) );
}

View File

@ -40,13 +40,14 @@ public class LocaleTypeDescriptor extends AbstractClassTypeDescriptor<Locale> {
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<Locale> {
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() );
}

View File

@ -30,8 +30,8 @@ public class LongTypeDescriptor extends AbstractClassTypeDescriptor<Long> 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" })

View File

@ -65,8 +65,8 @@ public class NClobTypeDescriptor extends AbstractClassTypeDescriptor<NClob> {
return DataHelper.extractString( value );
}
public NClob fromString(String string) {
return NClobProxy.generateProxy( string );
public NClob fromString(CharSequence string) {
return NClobProxy.generateProxy( string.toString() );
}
@Override

View File

@ -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 ) );
}

View File

@ -66,7 +66,7 @@ public class OffsetTimeJavaDescriptor extends AbstractTemporalTypeDescriptor<Off
}
@Override
public OffsetTime fromString(String string) {
public OffsetTime fromString(CharSequence string) {
return OffsetTime.from( DateTimeFormatter.ISO_OFFSET_TIME.parse( string ) );
}

View File

@ -68,7 +68,8 @@ public class PrimitiveByteArrayTypeDescriptor extends AbstractClassTypeDescripto
return value == null ? super.extractLoggableRepresentation( null ) : Arrays.toString( value );
}
public byte[] fromString(String string) {
@Override
public byte[] fromString(CharSequence string) {
if ( string == null ) {
return null;
}
@ -77,7 +78,7 @@ public class PrimitiveByteArrayTypeDescriptor extends AbstractClassTypeDescripto
}
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;

View File

@ -33,8 +33,8 @@ public class PrimitiveCharacterArrayTypeDescriptor extends AbstractClassTypeDesc
return new String( value );
}
public char[] fromString(String string) {
return string.toCharArray();
public char[] fromString(CharSequence string) {
return string.toString().toCharArray();
}
@Override

View File

@ -65,7 +65,7 @@ public class RowVersionTypeDescriptor extends AbstractClassTypeDescriptor<byte[]
return (value == null) ? super.extractLoggableRepresentation( null ) : Arrays.toString( value );
}
public byte[] fromString(String string) {
public byte[] fromString(CharSequence string) {
if ( string == null ) {
return null;
}
@ -74,7 +74,7 @@ public class RowVersionTypeDescriptor extends AbstractClassTypeDescriptor<byte[]
}
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) + Byte.MIN_VALUE);
}
return bytes;

View File

@ -63,7 +63,7 @@ public class SerializableTypeDescriptor<T extends Serializable> extends Abstract
return PrimitiveByteArrayTypeDescriptor.INSTANCE.toString( toBytes( value ) );
}
public T fromString(String string) {
public T fromString(CharSequence string) {
return fromBytes( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) );
}

View File

@ -29,8 +29,8 @@ public class ShortTypeDescriptor extends AbstractClassTypeDescriptor<Short> 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" })

View File

@ -35,8 +35,8 @@ public class StringTypeDescriptor extends AbstractClassTypeDescriptor<String> {
return value;
}
public String fromString(String string) {
return string;
public String fromString(CharSequence string) {
return string.toString();
}
@Override

View File

@ -35,8 +35,8 @@ public class TimeZoneTypeDescriptor extends AbstractClassTypeDescriptor<TimeZone
return value.getID();
}
public TimeZone fromString(String string) {
return TimeZone.getTimeZone( string );
public TimeZone fromString(CharSequence string) {
return TimeZone.getTimeZone( string.toString() );
}
@Override
@ -59,8 +59,8 @@ public class TimeZoneTypeDescriptor extends AbstractClassTypeDescriptor<TimeZone
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() );
}

View File

@ -36,8 +36,8 @@ public class UUIDTypeDescriptor extends AbstractClassTypeDescriptor<UUID> {
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" })

View File

@ -36,9 +36,9 @@ public class UrlTypeDescriptor extends AbstractClassTypeDescriptor<URL> {
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<URL> {
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() );
}

View File

@ -38,8 +38,8 @@ public class ZoneOffsetJavaDescriptor extends AbstractClassTypeDescriptor<ZoneOf
return value.getId();
}
public ZoneOffset fromString(String string) {
return ZoneOffset.of( string );
public ZoneOffset fromString(CharSequence string) {
return ZoneOffset.of( string.toString() );
}
@Override
@ -69,8 +69,8 @@ public class ZoneOffsetJavaDescriptor extends AbstractClassTypeDescriptor<ZoneOf
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() );
}

View File

@ -80,7 +80,7 @@ public class ZonedDateTimeJavaDescriptor extends AbstractTemporalTypeDescriptor<
}
@Override
public ZonedDateTime fromString(String string) {
public ZonedDateTime fromString(CharSequence string) {
return ZonedDateTime.from( DateTimeFormatter.ISO_ZONED_DATE_TIME.parse( string ) );
}

View File

@ -43,7 +43,7 @@ public class CollectionJavaTypeDescriptor<C> extends AbstractClassTypeDescriptor
}
@Override
public C fromString(String string) {
public C fromString(CharSequence string) {
throw new UnsupportedOperationException( );
}

View File

@ -26,7 +26,7 @@ public class DynamicModelJtd implements JavaTypeDescriptor<Map<?,?>> {
}
@Override
public Map<?,?> fromString(String string) {
public Map<?,?> fromString(CharSequence string) {
throw new UnsupportedOperationException();
}

View File

@ -40,7 +40,7 @@ public class JavaTypeDescriptorBasicAdaptor<T> 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()
);

View File

@ -32,7 +32,7 @@ public class MapEntryJavaDescriptor extends AbstractClassTypeDescriptor<Map.Entr
}
@Override
public Map.Entry fromString(String string) {
public Map.Entry fromString(CharSequence string) {
throw new UnsupportedOperationException( "Unsupported attempt create Map.Entry from String" );
}

View File

@ -133,7 +133,7 @@ public class UserTypeJavaTypeWrapper<J> implements BasicJavaDescriptor<J> {
}
@Override
public J fromString(String string) {
public J fromString(CharSequence string) {
throw new UnsupportedOperationException( "No support for parsing UserType values from String: " + userType );
}

View File

@ -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 <a href="https://hibernate.onjira.com/browse/HHH-7776">HHH-7776</a> for details
* @param xmlValue
*/
@Deprecated
Object fromXMLString(String xmlValue);
Object fromXMLString(CharSequence xmlValue);
}

View File

@ -93,7 +93,7 @@ public class CollectionAsBasicTest {
}
@Override
public Set fromString(String string) {
public Set fromString(CharSequence string) {
return null;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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<MyCustomJ
}
@Override
public MyCustomJavaType fromString(String string) {
return StringHelper.isEmpty( string ) ? null : new MyCustomJavaType( string );
public MyCustomJavaType fromString(CharSequence string) {
return CharSequenceHelper.isEmpty( string ) ? null : new MyCustomJavaType( string.toString() );
}
@Override

View File

@ -93,7 +93,7 @@ public class JavaTypeDescriptorRegistryTest {
}
@Override
public CustomType fromString(String string) {
public CustomType fromString(CharSequence string) {
return null;
}

View File

@ -168,7 +168,7 @@ public class QueryParametersValidationArrayTest {
}
@Override
public String[] fromString(String string) {
public String[] fromString(CharSequence string) {
return null;
}

View File

@ -29,8 +29,8 @@ public class ArrayType
}
@Override
public Array stringToObject(String xml) throws Exception {
return fromString( xml );
public Array stringToObject(CharSequence sequence) throws Exception {
return fromString( sequence );
}
@Override

View File

@ -31,11 +31,11 @@ public class ArrayTypeDescriptor extends AbstractClassTypeDescriptor<Array> {
}
@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;

View File

@ -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) {

View File

@ -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<Clas
}
@Override
public Object fromXMLString(String xmlValue) {
return Classification.valueOf( xmlValue );
public Object fromXMLString(CharSequence xmlValue) {
return Classification.valueOf( xmlValue.toString() );
}
private String extractName(Object obj) {

View File

@ -24,8 +24,8 @@ public class InetJavaTypeDescriptor extends AbstractClassTypeDescriptor<Inet> {
return value.toString();
}
public Inet fromString(String string) {
return new Inet( string );
public Inet fromString(CharSequence string) {
return new Inet( string.toString() );
}
@Override

View File

@ -24,8 +24,8 @@ public class JsonJavaTypeDescriptor extends AbstractClassTypeDescriptor<Json> {
return value.toString();
}
public Json fromString(String string) {
return new Json( string );
public Json fromString(CharSequence string) {
return new Json( string.toString() );
}
@Override

View File

@ -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;
}

View File

@ -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 );

View File

@ -45,8 +45,8 @@ public class GeolatteGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<G
}
@Override
public Geometry fromString(String string) {
return Wkt.fromWkt( string );
public Geometry fromString(CharSequence string) {
return Wkt.fromWkt( string.toString() );
}
@Override
@ -77,8 +77,8 @@ public class GeolatteGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<G
if ( Geometry.class.isInstance( value ) ) {
return (Geometry) value;
}
if ( String.class.isInstance( value ) ) {
return fromString( (String) value );
if ( CharSequence.class.isInstance( value ) ) {
return fromString( (CharSequence) value );
}
if ( org.locationtech.jts.geom.Geometry.class.isInstance( value ) ) {

View File

@ -45,10 +45,10 @@ public class JTSGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<Geomet
}
@Override
public Geometry fromString(String string) {
public Geometry fromString(CharSequence string) {
final WKTReader reader = new WKTReader();
try {
return reader.read( string );
return reader.read( string.toString() );
}
catch (ParseException e) {
throw new RuntimeException( String.format( Locale.ENGLISH, "Can't parse string %s as WKT", string ) );
@ -88,8 +88,8 @@ public class JTSGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<Geomet
if ( org.geolatte.geom.Geometry.class.isInstance( value ) ) {
return JTS.to( (org.geolatte.geom.Geometry) value );
}
if ( String.class.isInstance( value ) ) {
return fromString( (String) value );
if ( CharSequence.class.isInstance( value ) ) {
return fromString( (CharSequence) value );
}
throw unknownWrap( value.getClass() );
}

View File

@ -38,7 +38,7 @@ public class CommaDelimitedStringMapJavaTypeDescriptor extends AbstractClassType
}
@Override
public Map fromString(String string) {
public Map fromString(CharSequence string) {
return null;
}

Some files were not shown because too many files have changed in this diff Show More