get rid of warnings involving JdbcFormatter

also get rid of som explicit type args using <>
This commit is contained in:
Gavin King 2022-02-05 12:26:09 +01:00
parent 2f08812187
commit c2f0ab8fcf
41 changed files with 142 additions and 137 deletions

View File

@ -54,7 +54,7 @@ public class DurationIntervalSecondJdbcType implements JdbcType {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -71,7 +71,7 @@ public class DurationIntervalSecondJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getObject( paramIndex, Duration.class ), options );

View File

@ -91,7 +91,7 @@ public class PostgreSQLIntervalSecondJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -136,7 +136,7 @@ public class PostgreSQLIntervalSecondJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return getJavaType().wrap( rs.getString( paramIndex ), options );

View File

@ -83,7 +83,7 @@ public abstract class PostgreSQLPGObjectJdbcType implements JdbcType {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -126,7 +126,7 @@ public abstract class PostgreSQLPGObjectJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return ( (PostgreSQLPGObjectJdbcType) getJdbcType() ).fromString(

View File

@ -6,8 +6,6 @@
*/
package org.hibernate.sql.ast.spi;
import java.io.IOException;
/**
* Access to appending SQL fragments to an in-flight buffer
*

View File

@ -46,13 +46,12 @@ public class BigIntJdbcType implements JdbcType {
@Override
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
//noinspection unchecked
return new JdbcLiteralFormatterNumericData( javaType, Long.class );
return new JdbcLiteralFormatterNumericData<>( javaType, Long.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setLong( index, javaType.unwrap( value, Long.class, options ) );
@ -69,7 +68,7 @@ public class BigIntJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getLong( paramIndex ), options );

View File

@ -57,7 +57,7 @@ public abstract class BlobJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getBlob( paramIndex ), options );
@ -91,7 +91,7 @@ public abstract class BlobJdbcType implements JdbcType {
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -131,7 +131,7 @@ public abstract class BlobJdbcType implements JdbcType {
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
public void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -155,7 +155,7 @@ public abstract class BlobJdbcType implements JdbcType {
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -179,7 +179,7 @@ public abstract class BlobJdbcType implements JdbcType {
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {

View File

@ -55,8 +55,7 @@ public class BooleanJdbcType implements AdjustableJdbcType {
@Override
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
//noinspection unchecked
return new JdbcLiteralFormatterBoolean( javaType );
return new JdbcLiteralFormatterBoolean<>( javaType );
}
@Override
@ -72,7 +71,7 @@ public class BooleanJdbcType implements AdjustableJdbcType {
}
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options) throws SQLException {
st.setNull( index, options.getPreferredSqlTypeCodeForBoolean() );
@ -80,7 +79,7 @@ public class BooleanJdbcType implements AdjustableJdbcType {
@Override
protected void doBindNull(CallableStatement st, String name, WrapperOptions options) throws SQLException {
st.setNull( name, options.getPreferredSqlTypeCodeForBoolean() );;
st.setNull( name, options.getPreferredSqlTypeCodeForBoolean() );
}
@Override
@ -97,7 +96,7 @@ public class BooleanJdbcType implements AdjustableJdbcType {
}
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getBoolean( paramIndex ), options );

View File

@ -56,7 +56,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getClob( paramIndex ), options );
@ -92,7 +92,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -126,7 +126,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -143,7 +143,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getString( paramIndex ), options );
@ -172,7 +172,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -196,7 +196,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -230,7 +230,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -257,7 +257,7 @@ public abstract class ClobJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getCharacterStream( paramIndex ), options );

View File

@ -59,14 +59,13 @@ public class DateJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterTemporal( javaType, TemporalType.DATE );
return new JdbcLiteralFormatterTemporal<>( javaType, TemporalType.DATE );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
final Date date = javaType.unwrap( value, Date.class, options );
@ -94,7 +93,7 @@ public class DateJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getDate( paramIndex ), options );

View File

@ -57,13 +57,12 @@ public class DecimalJdbcType implements JdbcType {
@Override
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
//noinspection unchecked
return new JdbcLiteralFormatterNumericData( javaType, BigDecimal.class );
return new JdbcLiteralFormatterNumericData<>( javaType, BigDecimal.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setBigDecimal( index, javaType.unwrap( value, BigDecimal.class, options ) );
@ -79,7 +78,7 @@ public class DecimalJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getBigDecimal( paramIndex ), options );

View File

@ -67,13 +67,12 @@ public class DoubleJdbcType implements JdbcType {
@Override
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
//noinspection unchecked
return new JdbcLiteralFormatterNumericData( javaType, Double.class );
return new JdbcLiteralFormatterNumericData<>( javaType, Double.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setDouble( index, javaType.unwrap( value, Double.class, options ) );
@ -89,7 +88,7 @@ public class DoubleJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getDouble( paramIndex ), options );

View File

@ -59,14 +59,13 @@ public class FloatJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterNumericData( javaType, Float.class );
return new JdbcLiteralFormatterNumericData<>( javaType, Float.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setFloat( index, javaType.unwrap( value, Float.class, options ) );
@ -82,7 +81,7 @@ public class FloatJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getFloat( paramIndex ), options );

View File

@ -55,14 +55,13 @@ public class IntegerJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterNumericData( javaType, Integer.class );
return new JdbcLiteralFormatterNumericData<>( javaType, Integer.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setInt( index, javaType.unwrap( value, Integer.class, options ) );
@ -78,7 +77,7 @@ public class IntegerJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getInt( paramIndex ), options );

View File

@ -9,27 +9,39 @@ package org.hibernate.type.descriptor.jdbc;
import org.hibernate.dialect.Dialect;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaType;
/**
* A formatter object for creating JDBC literals of a given type.
* <p/>
* Generally this is obtained from the {@link JdbcType#getJdbcLiteralFormatter} method
* and would be specific to that Java and SQL type.
* <p/>
* Performs a similar function as the legacy LiteralType, except continuing the paradigm
* shift from inheritance to composition/delegation.
* A formatter object for rendering values of a given {@linkplain JavaType Java type}
* as SQL literals of a certain {@linkplain JdbcType JDBC/SQL type}. Usually, an
* instance is obtained by calling {@link JdbcType#getJdbcLiteralFormatter(JavaType)}.
*
* @param <T> the Java type that this instance formats as a SQL literal
*
* @author Steve Ebersole
*/
@FunctionalInterface
public interface JdbcLiteralFormatter<T> {
String NULL = "null";
/**
* Produces a string containing a SQL literal value representing the given Java value.
*
* @param value a Java object whose value can be represented as a SQL literal
* @param dialect the SQL dialect
* @return the SQL literal as a string
*/
default String toJdbcLiteral(T value, Dialect dialect, WrapperOptions wrapperOptions) {
final StringBuilder sb = new StringBuilder();
appendJdbcLiteral( sb::append, value, dialect, wrapperOptions );
return sb.toString();
}
/**
* Append a SQL literal representing the given Java value to a fragment of SQL which
* is being built.
*
* @param appender an operation that appends to the SQL fragment
* @param value a Java object whose value can be represented as a SQL literal
* @param dialect the SQL dialect
*/
void appendJdbcLiteral(SqlAppender appender, T value, Dialect dialect, WrapperOptions wrapperOptions);
}

View File

@ -45,7 +45,7 @@ public class JsonJdbcType implements JdbcType {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -72,7 +72,7 @@ public class JsonJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return options.getSessionFactory().getFastSessionServices().getJsonFormatMapper().fromString(

View File

@ -43,7 +43,7 @@ public abstract class NClobJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getNClob( paramIndex ), options );
@ -79,7 +79,7 @@ public abstract class NClobJdbcType implements JdbcType {
@Override
public <X> BasicBinder<X> getNClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -113,7 +113,7 @@ public abstract class NClobJdbcType implements JdbcType {
@Override
public <X> BasicBinder<X> getNClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -137,7 +137,7 @@ public abstract class NClobJdbcType implements JdbcType {
@Override
public <X> BasicBinder<X> getNClobBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {

View File

@ -86,7 +86,7 @@ public class NVarcharJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setNString( index, javaType.unwrap( value, String.class, options ) );
@ -102,7 +102,7 @@ public class NVarcharJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getNString( paramIndex ), options );

View File

@ -39,7 +39,7 @@ public class NullJdbcType implements JdbcType {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options) throws SQLException {

View File

@ -51,7 +51,7 @@ public class ObjectJdbcType implements JdbcType {
return VarbinaryJdbcType.INSTANCE.getBinder( javaType );
}
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -73,7 +73,7 @@ public class ObjectJdbcType implements JdbcType {
return VarbinaryJdbcType.INSTANCE.getExtractor( javaType );
}
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return (X) rs.getObject( paramIndex );

View File

@ -37,7 +37,7 @@ public class ObjectNullAsBinaryTypeJdbcType extends ObjectJdbcType {
return VarbinaryJdbcType.INSTANCE.getBinder( javaType );
}
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options)

View File

@ -37,7 +37,7 @@ public class ObjectNullAsNullTypeJdbcType extends ObjectJdbcType {
return VarbinaryJdbcType.INSTANCE.getBinder( javaType );
}
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options)

View File

@ -37,7 +37,7 @@ public class ObjectNullResolvingJdbcType extends ObjectJdbcType {
return VarbinaryJdbcType.INSTANCE.getBinder( javaType );
}
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options)

View File

@ -55,14 +55,13 @@ public class SmallIntJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterNumericData( javaType, Short.class );
return new JdbcLiteralFormatterNumericData<>( javaType, Short.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setShort( index, javaType.unwrap( value, Short.class, options ) );
@ -78,7 +77,7 @@ public class SmallIntJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getShort( paramIndex ), options );

View File

@ -59,14 +59,13 @@ public class TimeJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterTemporal( javaType, TemporalType.TIME );
return new JdbcLiteralFormatterTemporal<>( javaType, TemporalType.TIME );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
final Time time = javaType.unwrap( value, Time.class, options );
@ -100,7 +99,7 @@ public class TimeJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return options.getJdbcTimeZone() != null ?

View File

@ -59,14 +59,13 @@ public class TimestampJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterTemporal( javaType, TemporalType.TIMESTAMP );
return new JdbcLiteralFormatterTemporal<>( javaType, TemporalType.TIMESTAMP );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
final Timestamp timestamp = javaType.unwrap( value, Timestamp.class, options );
@ -100,7 +99,7 @@ public class TimestampJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return options.getJdbcTimeZone() != null ?

View File

@ -58,14 +58,13 @@ public class TimestampWithTimeZoneJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterTemporal( javaType, TemporalType.TIMESTAMP );
return new JdbcLiteralFormatterTemporal<>( javaType, TemporalType.TIMESTAMP );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(
PreparedStatement st,
@ -107,7 +106,7 @@ public class TimestampWithTimeZoneJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int position, WrapperOptions wrapperOptions) throws SQLException {
try {

View File

@ -58,14 +58,13 @@ public class TinyIntJdbcType implements JdbcType {
}
@Override
@SuppressWarnings("unchecked")
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterNumericData( javaType, Byte.class );
return new JdbcLiteralFormatterNumericData<>( javaType, Byte.class );
}
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setByte( index, javaType.unwrap( value, Byte.class, options ) );
@ -81,7 +80,7 @@ public class TinyIntJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getByte( paramIndex ), options );

View File

@ -47,7 +47,7 @@ public class UUIDJdbcType implements JdbcType {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
@ -64,7 +64,7 @@ public class UUIDJdbcType implements JdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return getJavaType().wrap( rs.getObject( paramIndex, UUID.class ), options );

View File

@ -64,8 +64,7 @@ public class VarbinaryJdbcType implements AdjustableJdbcType {
@Override
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
//noinspection unchecked
return supportsLiterals ? new JdbcLiteralFormatterBinary( javaType ) : null;
return supportsLiterals ? new JdbcLiteralFormatterBinary<>( javaType ) : null;
}
@Override
@ -77,7 +76,7 @@ public class VarbinaryJdbcType implements AdjustableJdbcType {
}
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -93,7 +92,7 @@ public class VarbinaryJdbcType implements AdjustableJdbcType {
}
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getBytes( paramIndex ), options );

View File

@ -86,7 +86,7 @@ public class VarcharJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setString( index, javaType.unwrap( value, String.class, options ) );
@ -102,7 +102,7 @@ public class VarcharJdbcType implements AdjustableJdbcType {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getString( paramIndex ), options );

View File

@ -13,12 +13,13 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.spi.BasicJdbcLiteralFormatter;
/**
* JdbcLiteralFormatter implementation for handling binary literals
* {@link org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter}
* implementation for handling binary literals
*
* @author Gavin King
*/
public class JdbcLiteralFormatterBinary extends BasicJdbcLiteralFormatter {
public JdbcLiteralFormatterBinary(JavaType<?> javaType) {
public class JdbcLiteralFormatterBinary<T> extends BasicJdbcLiteralFormatter<T> {
public JdbcLiteralFormatterBinary(JavaType<T> javaType) {
super( javaType );
}

View File

@ -13,12 +13,13 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.spi.BasicJdbcLiteralFormatter;
/**
* JdbcLiteralFormatter implementation for handling boolean literals
* {@link org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter}
* implementation for handling boolean literals
*
* @author Steve Ebersole
*/
public class JdbcLiteralFormatterBoolean extends BasicJdbcLiteralFormatter {
public JdbcLiteralFormatterBoolean(JavaType<?> javaType) {
public class JdbcLiteralFormatterBoolean<T> extends BasicJdbcLiteralFormatter<T> {
public JdbcLiteralFormatterBoolean(JavaType<T> javaType) {
super( javaType );
}

View File

@ -13,20 +13,21 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.spi.BasicJdbcLiteralFormatter;
/**
* JdbcLiteralFormatter implementation for handling character data
* {@link org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter}
* implementation for handling character data
*
* @author Steve Ebersole
*/
public class JdbcLiteralFormatterCharacterData extends BasicJdbcLiteralFormatter {
public class JdbcLiteralFormatterCharacterData<T> extends BasicJdbcLiteralFormatter<T> {
public static final String NATIONALIZED_PREFIX = "n";
private final boolean isNationalized;
public JdbcLiteralFormatterCharacterData(JavaType<?> javaType) {
public JdbcLiteralFormatterCharacterData(JavaType<T> javaType) {
this( javaType, false );
}
public JdbcLiteralFormatterCharacterData(JavaType<?> javaType, boolean isNationalized) {
public JdbcLiteralFormatterCharacterData(JavaType<T> javaType, boolean isNationalized) {
super( javaType );
this.isNationalized = isNationalized;
}

View File

@ -13,12 +13,15 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.spi.BasicJdbcLiteralFormatter;
/**
* {@link org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter}
* implementation for handling numeric data
*
* @author Steve Ebersole
*/
public class JdbcLiteralFormatterNumericData extends BasicJdbcLiteralFormatter {
public class JdbcLiteralFormatterNumericData<T> extends BasicJdbcLiteralFormatter<T> {
private final Class<? extends Number> unwrapJavaType;
public JdbcLiteralFormatterNumericData(JavaType<?> javaType, Class<? extends Number> unwrapJavaType) {
public JdbcLiteralFormatterNumericData(JavaType<T> javaType, Class<? extends Number> unwrapJavaType) {
super( javaType );
this.unwrapJavaType = unwrapJavaType;
}

View File

@ -17,12 +17,15 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.spi.BasicJdbcLiteralFormatter;
/**
* {@link org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter}
* implementation for handling date/time literals
*
* @author Steve Ebersole
*/
public class JdbcLiteralFormatterTemporal extends BasicJdbcLiteralFormatter {
public class JdbcLiteralFormatterTemporal<T> extends BasicJdbcLiteralFormatter<T> {
private final TemporalType precision;
public JdbcLiteralFormatterTemporal(JavaType<?> javaType, TemporalType precision) {
public JdbcLiteralFormatterTemporal(JavaType<T> javaType, TemporalType precision) {
super( javaType );
this.precision = precision;
}

View File

@ -76,7 +76,7 @@ public class JdbcTypeBaseline {
target.addDescriptor( ClobJdbcType.DEFAULT );
// Assume `NationalizationSupport#IMPLICIT`. Dialects needing the
// explicit type will map them..
// explicit type will map them.
target.addDescriptor( Types.NCHAR, CharJdbcType.INSTANCE );
target.addDescriptor( Types.NVARCHAR, VarcharJdbcType.INSTANCE );
target.addDescriptor( Types.LONGNVARCHAR, LongVarcharJdbcType.INSTANCE );

View File

@ -10,18 +10,18 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter;
/**
* Abstract JdbcLiteralFormatter implementation managing the JavaTypeDescriptor
* Abstract {@link JdbcLiteralFormatter} implementation managing the {@link JavaType}
*
* @author Steve Ebersole
*/
public abstract class AbstractJdbcLiteralFormatter<T> implements JdbcLiteralFormatter {
private final JavaType javaType;
public abstract class AbstractJdbcLiteralFormatter<T> implements JdbcLiteralFormatter<T> {
private final JavaType<T> javaType;
public AbstractJdbcLiteralFormatter(JavaType javaType) {
public AbstractJdbcLiteralFormatter(JavaType<T> javaType) {
this.javaType = javaType;
}
protected JavaType getJavaType() {
protected JavaType<T> getJavaType() {
return javaType;
}
}

View File

@ -10,12 +10,13 @@ import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaType;
/**
* Support for JdbcLiteralFormatter implementations with a basic implementation of an unwrap method
* Support for {@link org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter}
* implementations with a basic implementation of an {@link #unwrap} method
*
* @author Steve Ebersole
*/
public abstract class BasicJdbcLiteralFormatter extends AbstractJdbcLiteralFormatter {
public BasicJdbcLiteralFormatter(JavaType<?> javaType) {
public abstract class BasicJdbcLiteralFormatter<T> extends AbstractJdbcLiteralFormatter<T> {
public BasicJdbcLiteralFormatter(JavaType<T> javaType) {
super( javaType );
}
@ -29,17 +30,17 @@ public abstract class BasicJdbcLiteralFormatter extends AbstractJdbcLiteralForma
}
if ( !getJavaType().isInstance( value ) ) {
final Object coerce = getJavaType().coerce( value, wrapperOptions.getSession() );
final T coerce = getJavaType().coerce( value, wrapperOptions.getSession() );
if ( unwrapType.isInstance( coerce ) ) {
return (X) coerce;
}
return (X) getJavaType().unwrap(
return getJavaType().unwrap(
coerce,
unwrapType,
wrapperOptions
);
}
return (X) getJavaType().unwrap( value, unwrapType, wrapperOptions );
return getJavaType().unwrap( (T) value, unwrapType, wrapperOptions );
}
}

View File

@ -47,7 +47,7 @@ public class PayloadWrapperJdbcType implements JdbcType {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
final String valueStr = javaType.unwrap( value, String.class, options );

View File

@ -51,15 +51,14 @@ public class QueryParametersValidationArrayTest {
@Test
public void setParameterWithWrongTypeShouldNotThrowIllegalArgumentException(EntityManagerFactoryScope scope) {
scope.inTransaction(
(entityManager) -> {
entityManager ->
entityManager.createNativeQuery(
"select id " +
"from Event " +
"where readings = :readings" )
.unwrap( NativeQuery.class )
.setParameter( "readings", new String[]{null, "a"}, StringArrayType.INSTANCE )
.getResultList();
}
.getResultList()
);
}
@ -104,7 +103,7 @@ public class QueryParametersValidationArrayTest {
@Override
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this) {
return new BasicBinder<>( javaType, this) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
StringArrayTypeDescriptor arrayTypeDescriptor = (StringArrayTypeDescriptor) javaType;
@ -115,8 +114,7 @@ public class QueryParametersValidationArrayTest {
}
@Override
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
throws SQLException {
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) {
throw new UnsupportedOperationException("Binding by name is not supported!");
}
};
@ -124,7 +122,7 @@ public class QueryParametersValidationArrayTest {
@Override
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this) {
return new BasicExtractor<>( javaType, this) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaType.wrap( rs.getArray( paramIndex ), options);

View File

@ -35,7 +35,7 @@ public class StoredPrefixedStringType
public static final JdbcType PREFIXED_VARCHAR_TYPE_DESCRIPTOR =
new VarcharJdbcType() {
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
return new BasicBinder<X>( javaType, this ) {
return new BasicBinder<>( javaType, this ) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
String stringValue = javaType.unwrap( value, String.class, options );
@ -52,7 +52,7 @@ public class StoredPrefixedStringType
}
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
return new BasicExtractor<X>( javaType, this ) {
return new BasicExtractor<>( javaType, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
String stringValue = rs.getString( paramIndex );