HHH-17076 - Numeric literal typing
This commit is contained in:
parent
19b04003fa
commit
42b7d79bd5
|
@ -3623,13 +3623,35 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
|
|||
}
|
||||
|
||||
private SqmHqlNumericLiteral<Integer> integerLiteral(String text) {
|
||||
text = text.replace( "_", "" );
|
||||
|
||||
// special handling for octal and hexadecimal literals
|
||||
if ( isHexOrOctal( text ) ) {
|
||||
final int intValue = Integer.decode( text );
|
||||
text = Integer.toString( intValue );
|
||||
}
|
||||
|
||||
return new SqmHqlNumericLiteral<>(
|
||||
text.replace( "_", "" ),
|
||||
text,
|
||||
integerDomainType,
|
||||
creationContext.getNodeBuilder()
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
private boolean isHexOrOctal(String text) {
|
||||
if ( text.startsWith( "0x" ) || text.startsWith( "-0x" ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ( text.startsWith( "0" ) && text.length() > 1 )
|
||||
|| ( text.startsWith( "-0" ) && text.length() > 2 ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private SqmHqlNumericLiteral<Long> longLiteral(String text) {
|
||||
assert text.endsWith( "l" ) || text.endsWith( "L" );
|
||||
return new SqmHqlNumericLiteral<>(
|
||||
|
|
|
@ -296,6 +296,16 @@ public class LiteralTests {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOctalLiteral(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
assertThat( session.createQuery( "select 015053" )
|
||||
.getSingleResult(), is(6699) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigLiterals(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
|
|
Loading…
Reference in New Issue