[hibernate-commits] Hibernate SVN: r14276 - in entitymanager/trunk/src: java/org/hibernate/ejb/util and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jan 15 17:43:55 EST 2008


Author: epbernard
Date: 2008-01-15 17:43:55 -0500 (Tue, 15 Jan 2008)
New Revision: 14276

Modified:
   entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java
   entitymanager/trunk/src/java/org/hibernate/ejb/util/ConfigurationHelper.java
   entitymanager/trunk/src/test/org/hibernate/ejb/test/QueryTest.java
Log:
EJB-277 allow string values in query hints

Modified: entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java	2008-01-15 22:27:11 UTC (rev 14275)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java	2008-01-15 22:43:55 UTC (rev 14276)
@@ -15,7 +15,6 @@
 import static javax.persistence.TemporalType.*;
 import javax.persistence.TransactionRequiredException;
 
-import org.hibernate.CacheMode;
 import org.hibernate.FlushMode;
 import org.hibernate.HibernateException;
 import org.hibernate.QueryParameterException;
@@ -137,25 +136,25 @@
 	public Query setHint(String hintName, Object value) {
 		try {
 			if ( "org.hibernate.timeout".equals( hintName ) ) {
-				query.setTimeout( (Integer) value );
+				query.setTimeout( ConfigurationHelper.getInteger( value ) );
 			}
 			else if ( "org.hibernate.comment".equals( hintName ) ) {
 				query.setComment( (String) value );
 			}
 			else if ( "org.hibernate.fetchSize".equals( hintName ) ) {
-				query.setFetchSize( (Integer) value );
+				query.setFetchSize( ConfigurationHelper.getInteger( value ) );
 			}
 			else if ( "org.hibernate.cacheRegion".equals( hintName ) ) {
 				query.setCacheRegion( (String) value );
 			}
 			else if ( "org.hibernate.cacheable".equals( hintName ) ) {
-				query.setCacheable( (Boolean) value );
+				query.setCacheable( ConfigurationHelper.getBoolean( value ) );
 			}
 			else if ( "org.hibernate.readOnly".equals( hintName ) ) {
-				query.setReadOnly( (Boolean) value );
+				query.setReadOnly( ConfigurationHelper.getBoolean( value ) );
 			}
 			else if ( "org.hibernate.cacheMode".equals( hintName ) ) {
-				query.setCacheMode( (CacheMode) value );
+				query.setCacheMode( ConfigurationHelper.getCacheMode( value ) );
 			}
 			else if ( "org.hibernate.flushMode".equals( hintName ) ) {
 				query.setFlushMode( ConfigurationHelper.getFlushMode( value ) );

Modified: entitymanager/trunk/src/java/org/hibernate/ejb/util/ConfigurationHelper.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/util/ConfigurationHelper.java	2008-01-15 22:27:11 UTC (rev 14275)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/util/ConfigurationHelper.java	2008-01-15 22:43:55 UTC (rev 14276)
@@ -10,6 +10,7 @@
 
 import org.hibernate.FlushMode;
 import org.hibernate.AssertionFailure;
+import org.hibernate.CacheMode;
 
 /**
  * @author Emmanuel Bernard
@@ -57,4 +58,31 @@
 		}
 
 	}
+
+	public static Integer getInteger(Object value) {
+		if ( value instanceof Integer ) {
+			return (Integer) value;
+		}
+		else {
+			return Integer.valueOf( (String) value );
+		}
+	}
+
+	public static Boolean getBoolean(Object value) {
+		if ( value instanceof Boolean ) {
+			return (Boolean) value;
+		}
+		else {
+			return Boolean.valueOf( (String) value );
+		}
+	}
+
+	public static CacheMode getCacheMode(Object value) {
+		if ( value instanceof CacheMode ) {
+			return (CacheMode) value;
+		}
+		else {
+			return CacheMode.parse( (String) value );
+		}
+	}
 }

Modified: entitymanager/trunk/src/test/org/hibernate/ejb/test/QueryTest.java
===================================================================
--- entitymanager/trunk/src/test/org/hibernate/ejb/test/QueryTest.java	2008-01-15 22:27:11 UTC (rev 14275)
+++ entitymanager/trunk/src/test/org/hibernate/ejb/test/QueryTest.java	2008-01-15 22:43:55 UTC (rev 14276)
@@ -62,6 +62,9 @@
 
 		em.getTransaction().begin();
 		Query q = em.createQuery( "select item from Item item where item.name in (:names)" );
+		//test hint in value and string
+		q.setHint( "org.hibernate.fetchSize", 10 );
+		q.setHint( "org.hibernate.fetchSize", "10" );
 		List params = new ArrayList();
 		params.add( item.getName() );
 		params.add( item2.getName() );




More information about the hibernate-commits mailing list