Got unary +, - working again

(They were unimplemented on the new 6 branch)
This commit is contained in:
gavinking 2020-01-26 13:40:29 +01:00 committed by Steve Ebersole
parent 9565d499af
commit 28232427ce
12 changed files with 29 additions and 113 deletions

View File

@ -1504,9 +1504,8 @@ public abstract class BaseSqmToSqlAstConverter
try {
return new UnaryOperation(
interpret( expression.getOperation() ),
(Expression) expression.getOperand().accept( this ),
determineValueMapping( expression )
toSqlExpression( expression.getOperand().accept(this) ),
(BasicValuedMapping) determineValueMapping( expression.getOperand() )
);
}
finally {
@ -1813,7 +1812,7 @@ public abstract class BaseSqmToSqlAstConverter
magnitude = new UnaryOperation(
UNARY_MINUS,
magnitude,
magnitude.getExpressionType()
(BasicValuedMapping) magnitude.getExpressionType()
);
}

View File

@ -57,19 +57,6 @@ public class Conversion
walker.visitConversion(this);
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
@Override
public DomainResult createDomainResult(
String resultVariable,

View File

@ -82,19 +82,6 @@ public abstract class AbstractLiteral<T>
);
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
@Override
public void visitJdbcTypes(
Consumer<JdbcMapping> action,

View File

@ -68,19 +68,6 @@ public class BinaryArithmeticExpression implements Expression, DomainResultProdu
);
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
/**
* Get the left-hand operand.
*

View File

@ -83,19 +83,6 @@ public class CaseSearchedExpression implements Expression, DomainResultProducer
);
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
@Override
public void accept(SqlAstWalker walker) {
walker.visitCaseSearchedExpression( this );

View File

@ -87,19 +87,6 @@ public class ColumnReference implements Expression, Assignable {
interpreter.visitColumnReference( this );
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
// todo (6.0) : potential use for runtime database model - interpretation of table and column references
// into metadata info such as java/sql type, binder, extractor
return new SqlSelectionImpl( jdbcPosition, valuesArrayPosition, this );
}
@Override
public String toString() {
return String.format(

View File

@ -56,19 +56,6 @@ public class Duration implements Expression, DomainResultProducer {
walker.visitDuration(this);
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
@Override
public DomainResult createDomainResult(
String resultVariable,

View File

@ -6,11 +6,11 @@
*/
package org.hibernate.sql.ast.tree.expression;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.spi.SqlSelectionProducer;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.spi.TypeConfiguration;
@ -31,6 +31,10 @@ public interface Expression extends SqlAstNode, SqlSelectionProducer {
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
throw new NotYetImplementedFor6Exception( getClass() );
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
}

View File

@ -160,16 +160,4 @@ public class JdbcLiteral<T> implements Literal, MappingModelExpressable<T>, Doma
);
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
}

View File

@ -84,19 +84,6 @@ public class QueryLiteral<T> implements Literal, DomainResultProducer<T> {
);
}
@Override
public SqlSelection createSqlSelection(
int jdbcPosition,
int valuesArrayPosition,
JavaTypeDescriptor javaTypeDescriptor,
TypeConfiguration typeConfiguration) {
return new SqlSelectionImpl(
jdbcPosition,
valuesArrayPosition,
this
);
}
@Override
public void visitJdbcTypes(
Consumer<JdbcMapping> action,

View File

@ -8,12 +8,15 @@
package org.hibernate.sql.ast.tree.expression;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.query.UnaryArithmeticOperator;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.basic.BasicResult;
/**
* @author Steve Ebersole
@ -23,9 +26,9 @@ public class UnaryOperation implements Expression, DomainResultProducer {
private final UnaryArithmeticOperator operator;
private final Expression operand;
private final MappingModelExpressable type;
private final BasicValuedMapping type;
public UnaryOperation(UnaryArithmeticOperator operator, Expression operand, MappingModelExpressable type) {
public UnaryOperation(UnaryArithmeticOperator operator, Expression operand, BasicValuedMapping type) {
this.operator = operator;
this.operand = operand;
this.type = type;
@ -53,7 +56,18 @@ public class UnaryOperation implements Expression, DomainResultProducer {
public DomainResult createDomainResult(
String resultVariable,
DomainResultCreationState creationState) {
throw new NotYetImplementedFor6Exception( getClass() );
final SqlSelection sqlSelection = creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection(
this,
type.getBasicType().getJavaTypeDescriptor(),
creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration()
);
//noinspection unchecked
return new BasicResult(
sqlSelection.getValuesArrayPosition(),
resultVariable,
type.getBasicType().getJavaTypeDescriptor()
);
}
@Override

View File

@ -135,9 +135,11 @@ public class FunctionTests extends SessionFactoryBasedFunctionalTest {
public void testMathFunctions(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("select +e.theInt, -e.theInt from EntityOfBasics e")
.list();
session.createQuery("select abs(e.theInt), sign(e.theInt), mod(e.theInt, 2) from EntityOfBasics e")
.list();
session.createQuery("select +e.theInt, -e.theInt, e.theInt % 2 from EntityOfBasics e")
session.createQuery("select e.theInt % 2 from EntityOfBasics e")
.list();
session.createQuery("select abs(e.theDouble), sign(e.theDouble), sqrt(e.theDouble) from EntityOfBasics e")
.list();