Class TypecheckUtil
x = y or x > y. An
assignment is an element of the set clause in an update query, or
an element of the values list in an insert query.
The rules here are not the same as the rules for the Java language, nor are they identical to the rules for SQL. For example:
- In Java, a comparison expression like
'1'.equals(1)is well-typed, and evaluates tofalse. In most SQL dialects, this expression evaluates totrue, via implicit type conversions. Here we reject such comparison expressions. - In Java, if two classes are related by inheritance, then one is assignable to the other. But here, this assignment is only legal if the two classes are entity types belonging to the same mapped entity inheritance hierarchy.
- On the other hand, in Java,
java.sql.Dateandjava.time.LocalDatemay not be compared nor assigned. But here they're considered inter-comparable and inter-assignable.
Two basic types are considered comparable if they map to the same "family" of JDBC types. Here we allow some latitude so that different numeric types are comparable, and different string types are comparable. However, we do not allow comparisons between types which involve more questionable/unportable implicit type conversions (between integers and strings, for example). This means that we accept comparisons between basic types which map completely unrelated types in Java.
Entity types have identity equality. That is, two entities are considered equal if their primary keys are equal.
Embeddable and tuple types have value equality. That is, they're considered equal if their members are equal. For convenience, an embeddable object may be compared directly to a tuple constructor.
Comparison of discriminators (that is, of literal entity types and type()
function application) is legal only when the entity types belong to the same mapped
entity hierarchy.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareTypesComparable(SqmExpressible<?> lhsType, SqmExpressible<?> rhsType, SessionFactoryImplementor factory) static voidassertAssignable(String hqlString, SqmPath<?> targetPath, SqmTypedNode<?> expression, SessionFactoryImplementor factory) static voidassertComparable(Expression<?> x, Expression<?> y, SessionFactoryImplementor factory) static voidassertDuration(SqmExpression<?> expression) static voidassertNumeric(SqmExpression<?> expression, UnaryArithmeticOperator op) static voidassertOperable(SqmExpression<?> left, SqmExpression<?> right, BinaryArithmeticOperator op) static voidassertString(SqmExpression<?> expression) static booleanisNumberArray(SqmExpressible<?> expressible)
-
Constructor Details
-
TypecheckUtil
public TypecheckUtil()
-
-
Method Details
-
areTypesComparable
public static boolean areTypesComparable(SqmExpressible<?> lhsType, SqmExpressible<?> rhsType, SessionFactoryImplementor factory) - Parameters:
lhsType- the type of the expression on the LHS of the comparison operatorrhsType- the type of the expression on the RHS of the comparison operator- See Also:
-
isTypeAssignable(SqmPathSource, SqmExpressible, SessionFactoryImplementor)
-
assertComparable
public static void assertComparable(Expression<?> x, Expression<?> y, SessionFactoryImplementor factory) -
assertAssignable
public static void assertAssignable(String hqlString, SqmPath<?> targetPath, SqmTypedNode<?> expression, SessionFactoryImplementor factory) -
assertOperable
public static void assertOperable(SqmExpression<?> left, SqmExpression<?> right, BinaryArithmeticOperator op) -
isNumberArray
-
assertString
-
assertDuration
-
assertNumeric
-