mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-15461 Replace uses of method references for SqlAppender with proper implementation
This commit is contained in:
parent
84c276b3cc
commit
271cba0603
@ -162,7 +162,7 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
|
||||
ddlTypeRegistry.addDescriptor(
|
||||
CapacityDependentDdlType.builder( NVARCHAR, columnType( LONG32NVARCHAR ), this )
|
||||
.withTypeCapacity( 255, "varchar($l)" )
|
||||
.withTypeCapacity( getMaxVarcharLength(), columnType( NVARCHAR ) )
|
||||
.withTypeCapacity( getMaxNVarcharLength(), columnType( NVARCHAR ) )
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl;
|
||||
import org.hibernate.engine.query.spi.NativeQueryInterpreter;
|
||||
import org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl;
|
||||
import org.hibernate.orm.test.jpa.JpaComplianceStub;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
@ -20,6 +19,7 @@
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JdbcDateJavaType;
|
||||
import org.hibernate.type.descriptor.java.JdbcTimestampJavaType;
|
||||
@ -121,26 +121,4 @@ public void testCurrentDateFunction() {
|
||||
assertEquals( "today", appender.toString() );
|
||||
}
|
||||
|
||||
private static class StringBuilderSqlAppender implements SqlAppender {
|
||||
private final StringBuilder sb;
|
||||
|
||||
public StringBuilderSqlAppender() {
|
||||
this.sb = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSql(String fragment) {
|
||||
sb.append( fragment );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSql(char fragment) {
|
||||
sb.append( fragment );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,6 +133,7 @@
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
|
||||
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
|
||||
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
|
||||
@ -2265,7 +2266,7 @@ public int getMaxIdentifierLength() {
|
||||
*/
|
||||
public String toBooleanValueString(boolean bool) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
appendBooleanValueString( sb::append, bool );
|
||||
appendBooleanValueString( new StringBuilderSqlAppender( sb ), bool );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -3499,7 +3500,7 @@ public boolean supportsWait() {
|
||||
*/
|
||||
public String inlineLiteral(String literal) {
|
||||
final StringBuilder sb = new StringBuilder( literal.length() + 2 );
|
||||
appendLiteral( sb::append, literal );
|
||||
appendLiteral( new StringBuilderSqlAppender( sb ), literal );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ public void visitColumnReference(ColumnReference columnReference) {
|
||||
if ( currentQuerySpec != null && !currentQuerySpec.isRoot()
|
||||
&& (roots = currentQuerySpec.getFromClause().getRoots()).size() == 1
|
||||
&& roots.get( 0 ).getPrimaryTableReference() instanceof UnionTableReference ) {
|
||||
appendSql( columnReference.getExpressionText() );
|
||||
columnReference.appendReadExpression( this );
|
||||
}
|
||||
// for now, use the unqualified form
|
||||
else if ( columnReference.isColumnExpressionFormula() ) {
|
||||
@ -359,7 +359,7 @@ else if ( columnReference.isColumnExpressionFormula() ) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
appendSql( columnReference.getExpressionText() );
|
||||
columnReference.appendReadExpression( this );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||
import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression;
|
||||
import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression;
|
||||
@ -207,9 +208,10 @@ public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
|
||||
.getDialect();
|
||||
Expression formatExpression = null;
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final StringBuilderSqlAppender sqlAppender = new StringBuilderSqlAppender( sb );
|
||||
final String delimiter;
|
||||
if ( supportsPatternLiterals ) {
|
||||
dialect.appendDatetimeFormat( sb::append, "'a'" );
|
||||
dialect.appendDatetimeFormat( sqlAppender, "'a'" );
|
||||
delimiter = sb.substring( 0, sb.indexOf( "a" ) ).replace( "''", "'" );
|
||||
}
|
||||
else {
|
||||
@ -241,7 +243,7 @@ public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
|
||||
continue;
|
||||
}
|
||||
sb.setLength( 0 );
|
||||
dialect.appendDatetimeFormat( sb::append, smallParts[l] );
|
||||
dialect.appendDatetimeFormat( sqlAppender, smallParts[l] );
|
||||
final String formatPart = sb.toString();
|
||||
if ( supportsPatternLiterals ) {
|
||||
formatExpression = concat(
|
||||
@ -333,7 +335,7 @@ public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
|
||||
final String formatLiteralPart;
|
||||
if ( supportsPatternLiterals ) {
|
||||
sb.setLength( 0 );
|
||||
dialect.appendDatetimeFormat( sb::append, "'" + chunks[i + 1] + "'" );
|
||||
dialect.appendDatetimeFormat( sqlAppender, "'" + chunks[i + 1] + "'" );
|
||||
formatLiteralPart = sb.toString().replace( "''", "'" );
|
||||
}
|
||||
else {
|
||||
|
@ -309,11 +309,7 @@ protected Expression resolveColumnReference(
|
||||
SqlExpressionResolver.createColumnReferenceKey( tableReference, selectableMapping.getSelectionExpression() ),
|
||||
(processingState) -> new ColumnReference(
|
||||
tableReference,
|
||||
selectableMapping.getSelectionExpression(),
|
||||
selectableMapping.isFormula(),
|
||||
selectableMapping.getCustomReadExpression(),
|
||||
selectableMapping.getCustomWriteExpression(),
|
||||
selectableMapping.getJdbcMapping(),
|
||||
selectableMapping,
|
||||
sessionFactory
|
||||
)
|
||||
);
|
||||
|
@ -76,7 +76,7 @@ public LoaderSqlAstCreationState(
|
||||
this.sf = sf;
|
||||
this.processingState = new SqlAstQueryPartProcessingStateImpl(
|
||||
queryPart,
|
||||
this,
|
||||
null,
|
||||
this,
|
||||
() -> Clause.IRRELEVANT,
|
||||
true
|
||||
|
@ -51,6 +51,7 @@
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
@ -520,6 +521,7 @@ protected String generateSubquery(Set<String> treated) {
|
||||
// Create a union sub-query for the table names, like generateSubquery(PersistentClass model, Mapping mapping)
|
||||
final StringBuilder buf = new StringBuilder( subquery.length() )
|
||||
.append( "( " );
|
||||
final StringBuilderSqlAppender sqlAppender = new StringBuilderSqlAppender( buf );
|
||||
|
||||
for ( String name : getSubclassEntityNames() ) {
|
||||
final AbstractEntityPersister persister = (AbstractEntityPersister) metamodel.findEntityDescriptor( name );
|
||||
@ -536,9 +538,7 @@ protected String generateSubquery(Set<String> treated) {
|
||||
buf.append( dialect.getSelectClauseNullString( sqlType, getFactory().getTypeConfiguration() ) )
|
||||
.append( " as " );
|
||||
}
|
||||
buf.append(
|
||||
new ColumnReference( (String) null, selectableMapping, getFactory() ).getExpressionText()
|
||||
);
|
||||
new ColumnReference( (String) null, selectableMapping, getFactory() ).appendReadExpression( sqlAppender );
|
||||
buf.append( ", " );
|
||||
}
|
||||
buf.append( persister.getDiscriminatorSQLValue() ).append( " as clazz_" );
|
||||
|
@ -4285,7 +4285,7 @@ public void visitColumnReference(ColumnReference columnReference) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
appendSql( columnReference.getExpressionText() );
|
||||
columnReference.appendReadExpression( this );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.sql.ast.spi;
|
||||
|
||||
/**
|
||||
* Access to appending SQL fragments to a StringBuilder
|
||||
*/
|
||||
public class StringBuilderSqlAppender implements SqlAppender {
|
||||
|
||||
private final StringBuilder sb;
|
||||
|
||||
public StringBuilderSqlAppender() {
|
||||
this(new StringBuilder());
|
||||
}
|
||||
|
||||
public StringBuilderSqlAppender(StringBuilder sb) {
|
||||
this.sb = sb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSql(String fragment) {
|
||||
sb.append( fragment );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSql(char fragment) {
|
||||
sb.append( fragment );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSql(int value) {
|
||||
sb.append( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSql(long value) {
|
||||
sb.append( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSql(boolean value) {
|
||||
sb.append( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Appendable append(CharSequence csq) {
|
||||
return sb.append( csq );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Appendable append(CharSequence csq, int start, int end) {
|
||||
return sb.append( csq, start, end );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Appendable append(char c) {
|
||||
return sb.append( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
import org.hibernate.metamodel.mapping.MappingModelExpressible;
|
||||
import org.hibernate.sql.Template;
|
||||
import org.hibernate.sql.ast.SqlAstWalker;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||
import org.hibernate.sql.ast.tree.update.Assignable;
|
||||
|
||||
@ -190,6 +191,10 @@ public String getExpressionText() {
|
||||
return readExpression;
|
||||
}
|
||||
|
||||
public void appendReadExpression(SqlAppender appender) {
|
||||
appender.append( getExpressionText() );
|
||||
}
|
||||
|
||||
public String renderSqlFragment(SessionFactoryImplementor sessionFactory) {
|
||||
return getExpressionText();
|
||||
}
|
||||
|
@ -12,9 +12,7 @@
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
|
@ -18,6 +18,7 @@
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.compare.RowVersionComparator;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
|
||||
/**
|
||||
@ -50,9 +51,9 @@ public int extractHashCode(byte[] bytes) {
|
||||
}
|
||||
|
||||
public String toString(byte[] bytes) {
|
||||
final StringBuilder buf = new StringBuilder( bytes.length * 2 );
|
||||
appendString( buf::append, bytes );
|
||||
return buf.toString();
|
||||
final StringBuilder sb = new StringBuilder( bytes.length * 2 );
|
||||
appendString( new StringBuilderSqlAppender( sb ), bytes );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void appendString(SqlAppender appender, byte[] bytes) {
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
@ -33,7 +34,7 @@ public interface JdbcLiteralFormatter<T> extends Serializable {
|
||||
*/
|
||||
default String toJdbcLiteral(T value, Dialect dialect, WrapperOptions wrapperOptions) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
appendJdbcLiteral( sb::append, value, dialect, wrapperOptions );
|
||||
appendJdbcLiteral( new StringBuilderSqlAppender( sb ), value, dialect, wrapperOptions );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ public void testConvertedHqlInterpretation(SessionFactoryScope scope) {
|
||||
final Expression selectedExpression = sqlSelection.getExpression();
|
||||
assertThat( selectedExpression, instanceOf( ColumnReference.class ) );
|
||||
final ColumnReference columnReference = (ColumnReference) selectedExpression;
|
||||
assertThat( columnReference.renderSqlFragment( scope.getSessionFactory() ), is( "s1_0.gender" ) );
|
||||
assertThat( columnReference.getExpressionText(), is( "s1_0.gender" ) );
|
||||
|
||||
final JdbcMappingContainer selectedExpressible = selectedExpression.getExpressionType();
|
||||
assertThat( selectedExpressible, instanceOf( CustomType.class ) );
|
||||
|
@ -24,6 +24,7 @@
|
||||
import org.hibernate.dialect.TimeZoneSupport;
|
||||
import org.hibernate.dialect.TiDBDialect;
|
||||
import org.hibernate.query.sqm.FetchClauseType;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
|
||||
import org.hibernate.testing.DialectCheck;
|
||||
|
||||
@ -330,7 +331,7 @@ public boolean apply(Dialect dialect) {
|
||||
public static class SupportsFormat implements DialectFeatureCheck {
|
||||
public boolean apply(Dialect dialect) {
|
||||
try {
|
||||
dialect.appendDatetimeFormat( new StringBuilder()::append, "" );
|
||||
dialect.appendDatetimeFormat( new StringBuilderSqlAppender(), "" );
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -342,7 +343,7 @@ public boolean apply(Dialect dialect) {
|
||||
public static class SupportsTruncateThroughCast implements DialectFeatureCheck {
|
||||
public boolean apply(Dialect dialect) {
|
||||
try {
|
||||
dialect.appendDatetimeFormat( new StringBuilder()::append, "" );
|
||||
dialect.appendDatetimeFormat( new StringBuilderSqlAppender(), "" );
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user