very minor cleanup to ColumnReference

This commit is contained in:
Gavin 2022-12-03 08:59:41 +01:00 committed by Gavin King
parent 5ad9677728
commit 0359e01c77
1 changed files with 9 additions and 10 deletions

View File

@ -15,14 +15,15 @@ import java.util.function.Consumer;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.sql.Template;
import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender; import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.from.TableReference;
import org.hibernate.sql.ast.tree.update.Assignable; import org.hibernate.sql.ast.tree.update.Assignable;
import static org.hibernate.internal.util.StringHelper.replace;
import static org.hibernate.metamodel.relational.RuntimeRelationModelHelper.DEFAULT_COLUMN_WRITE_EXPRESSION; import static org.hibernate.metamodel.relational.RuntimeRelationModelHelper.DEFAULT_COLUMN_WRITE_EXPRESSION;
import static org.hibernate.sql.Template.TEMPLATE;
/** /**
* Models a reference to a Column in a SQL AST * Models a reference to a Column in a SQL AST
@ -76,7 +77,7 @@ public class ColumnReference implements Expression, Assignable {
if ( isFormula ) { if ( isFormula ) {
assert qualifier != null; assert qualifier != null;
this.columnExpression = StringHelper.replace( columnExpression, Template.TEMPLATE, qualifier ); this.columnExpression = replace( columnExpression, TEMPLATE, qualifier );
} }
else { else {
this.columnExpression = columnExpression; this.columnExpression = columnExpression;
@ -85,16 +86,14 @@ public class ColumnReference implements Expression, Assignable {
this.isFormula = isFormula; this.isFormula = isFormula;
this.readExpression = customReadExpression; this.readExpression = customReadExpression;
//TODO: writeExpression is never used, can it be removed?
if ( isFormula ) { if ( isFormula ) {
this.writeExpression = null; this.writeExpression = null;
} }
else if ( customWriteExpression != null ) { else if ( customWriteExpression != null ) {
if ( this.qualifier == null ) { this.writeExpression = this.qualifier == null
this.writeExpression = StringHelper.replace( customWriteExpression, Template.TEMPLATE + ".", "" ); ? replace( customWriteExpression, TEMPLATE + ".", "" )
} : replace( customWriteExpression, TEMPLATE, qualifier );
else {
this.writeExpression = StringHelper.replace( customWriteExpression, Template.TEMPLATE, qualifier );
}
} }
else { else {
this.writeExpression = DEFAULT_COLUMN_WRITE_EXPRESSION; this.writeExpression = DEFAULT_COLUMN_WRITE_EXPRESSION;
@ -176,10 +175,10 @@ public class ColumnReference implements Expression, Assignable {
} }
else if ( readExpression != null ) { else if ( readExpression != null ) {
if ( qualifier == null ) { if ( qualifier == null ) {
appender.append( StringHelper.replace( readExpression, Template.TEMPLATE + ".", "" ) ); appender.append( replace( readExpression, TEMPLATE + ".", "" ) );
} }
else { else {
appender.append( StringHelper.replace( readExpression, Template.TEMPLATE, qualifier ) ); appender.append( replace( readExpression, TEMPLATE, qualifier ) );
} }
} }
else { else {