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
This commit is contained in:
Steve Ebersole 2010-01-13 20:32:33 +00:00
parent fca1248487
commit e96bca2fb6
1 changed files with 11 additions and 14 deletions

View File

@ -247,6 +247,13 @@ public class LiteralProcessor implements HqlSqlTokenTypes {
private String determineIntegerRepresentation(String text, int type) { private String determineIntegerRepresentation(String text, int type) {
try { 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 ) { if ( type == NUM_INT ) {
try { try {
return Integer.valueOf( text ).toString(); return Integer.valueOf( text ).toString();
@ -255,22 +262,12 @@ 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" ); 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; String literalValue = text;
if ( literalValue.endsWith( "l" ) || literalValue.endsWith( "L" ) ) { if ( literalValue.endsWith( "l" ) || literalValue.endsWith( "L" ) ) {
literalValue = literalValue.substring( 0, literalValue.length() - 1 ); literalValue = literalValue.substring( 0, literalValue.length() - 1 );
} }
return Long.valueOf( literalValue ).toString(); return Long.valueOf( literalValue ).toString();
} }
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" );
}
catch( Throwable t ) { catch( Throwable t ) {
throw new HibernateException( "Could not parse literal [" + text + "] as integer", t ); throw new HibernateException( "Could not parse literal [" + text + "] as integer", t );
} }