From e96bca2fb6ac9576eba505df3b35ee4ccb633509 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 13 Jan 2010 20:32:33 +0000 Subject: [PATCH] HHH-4780 - Allow BigDecimal and BigInteger to be specified as numeric literal types git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18545 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../hql/ast/util/LiteralProcessor.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java b/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java index 186279002c..51eafc3c10 100644 --- a/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java +++ b/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java @@ -247,6 +247,13 @@ public class LiteralProcessor implements HqlSqlTokenTypes { private String determineIntegerRepresentation(String text, int type) { try { + if ( type == NUM_BIG_INTEGER ) { + String literalValue = text; + if ( literalValue.endsWith( "bi" ) || literalValue.endsWith( "BI" ) ) { + literalValue = literalValue.substring( 0, literalValue.length() - 2 ); + } + return new BigInteger( literalValue ).toString(); + } if ( type == NUM_INT ) { try { return Integer.valueOf( text ).toString(); @@ -255,21 +262,11 @@ public class LiteralProcessor implements HqlSqlTokenTypes { log.trace( "could not format incoming text [" + text + "] as a NUM_INT; assuming numeric overflow and attempting as NUM_LONG" ); } } - else if ( type == NUM_LONG ) { - String literalValue = text; - if ( literalValue.endsWith( "l" ) || literalValue.endsWith( "L" ) ) { - literalValue = literalValue.substring( 0, literalValue.length() - 1 ); - } - return Long.valueOf( literalValue ).toString(); + String literalValue = text; + if ( literalValue.endsWith( "l" ) || literalValue.endsWith( "L" ) ) { + literalValue = literalValue.substring( 0, literalValue.length() - 1 ); } - else if ( type == NUM_BIG_INTEGER ) { - String literalValue = text; - if ( literalValue.endsWith( "bi" ) || literalValue.endsWith( "BI" ) ) { - literalValue = literalValue.substring( 0, literalValue.length() - 2 ); - } - return new BigInteger( literalValue ).toString(); - } - throw new HibernateException( "Unknown literal type to parse as integer" ); + return Long.valueOf( literalValue ).toString(); } catch( Throwable t ) { throw new HibernateException( "Could not parse literal [" + text + "] as integer", t );