Hibernate SVN: r10591 - trunk/Hibernate3/src/org/hibernate
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-17 04:57:26 -0400 (Tue, 17 Oct 2006)
New Revision: 10591
Modified:
trunk/Hibernate3/src/org/hibernate/Query.java
Log:
missing commit of Query for HHH-2037
+ updated docs for setParameter regarding how parameter types are guessed/determined.
Modified: trunk/Hibernate3/src/org/hibernate/Query.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/Query.java 2006-10-17 08:57:22 UTC (rev 10590)
+++ trunk/Hibernate3/src/org/hibernate/Query.java 2006-10-17 08:57:26 UTC (rev 10591)
@@ -10,6 +10,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.Type;
@@ -226,8 +227,9 @@
public Query setParameter(String name, Object val, Type type);
/**
- * Bind a value to a JDBC-style query parameter, guessing the
- * Hibernate type from the class of the given object.
+ * Bind a value to a JDBC-style query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the given object.
* @param position the position of the parameter in the query
* string, numbered from <tt>0</tt>.
* @param val the non-null parameter value
@@ -235,8 +237,9 @@
*/
public Query setParameter(int position, Object val) throws HibernateException;
/**
- * Bind a value to a named query parameter, guessing the Hibernate
- * type from the class of the given object.
+ * Bind a value to a named query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the given object.
* @param name the name of the parameter
* @param val the non-null parameter value
* @throws org.hibernate.HibernateException if no type could be determined
@@ -258,8 +261,9 @@
public Query setParameterList(String name, Collection vals, Type type) throws HibernateException;
/**
- * Bind multiple values to a named query parameter, guessing the Hibernate type from the
- * class of the first object in the collection. This is useful for binding a list of values
+ * Bind multiple values to a named query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the first object in the collection. This is useful for binding a list of values
* to an expression such as <tt>foo.bar in (:value_list)</tt>.
* @param name the name of the parameter
* @param vals a collection of values to list
@@ -276,8 +280,9 @@
public Query setParameterList(String name, Object[] vals, Type type) throws HibernateException;
/**
- * Bind multiple values to a named query parameter, guessing the Hibernate type from the
- * class of the first object in the array. This is useful for binding a list of values
+ * Bind multiple values to a named query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the first object in the array. This is useful for binding a list of values
* to an expression such as <tt>foo.bar in (:value_list)</tt>.
* @param name the name of the parameter
* @param vals a collection of values to list
@@ -289,8 +294,16 @@
* matching property names with parameter names and mapping property types to
* Hibernate types using hueristics.
* @param bean any JavaBean or POJO
+ */
+ public Query setProperties(Object bean) throws HibernateException;
+
+ /**
+ * Bind the values of the given Map for each named parameters of the query,
+ * matching key names with parameter names and mapping value types to
+ * Hibernate types using hueristics.
+ * @param bean a java.util.Map
*/
- public Query setProperties(Object bean) throws HibernateException;
+ public Query setProperties(Map bean) throws HibernateException;
public Query setString(int position, String val);
public Query setCharacter(int position, char val);
17 years, 6 months
Hibernate SVN: r10590 - branches/Branch_3_2/Hibernate3/src/org/hibernate
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-17 04:57:22 -0400 (Tue, 17 Oct 2006)
New Revision: 10590
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/Query.java
Log:
missing commit of Query for HHH-2037
+ updated docs for setParameter regarding how parameter types are guessed/determined.
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/Query.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/Query.java 2006-10-16 15:47:37 UTC (rev 10589)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/Query.java 2006-10-17 08:57:22 UTC (rev 10590)
@@ -10,6 +10,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.Type;
@@ -226,8 +227,9 @@
public Query setParameter(String name, Object val, Type type);
/**
- * Bind a value to a JDBC-style query parameter, guessing the
- * Hibernate type from the class of the given object.
+ * Bind a value to a JDBC-style query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the given object.
* @param position the position of the parameter in the query
* string, numbered from <tt>0</tt>.
* @param val the non-null parameter value
@@ -235,8 +237,9 @@
*/
public Query setParameter(int position, Object val) throws HibernateException;
/**
- * Bind a value to a named query parameter, guessing the Hibernate
- * type from the class of the given object.
+ * Bind a value to a named query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the given object.
* @param name the name of the parameter
* @param val the non-null parameter value
* @throws org.hibernate.HibernateException if no type could be determined
@@ -258,8 +261,9 @@
public Query setParameterList(String name, Collection vals, Type type) throws HibernateException;
/**
- * Bind multiple values to a named query parameter, guessing the Hibernate type from the
- * class of the first object in the collection. This is useful for binding a list of values
+ * Bind multiple values to a named query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the first object in the collection. This is useful for binding a list of values
* to an expression such as <tt>foo.bar in (:value_list)</tt>.
* @param name the name of the parameter
* @param vals a collection of values to list
@@ -276,8 +280,9 @@
public Query setParameterList(String name, Object[] vals, Type type) throws HibernateException;
/**
- * Bind multiple values to a named query parameter, guessing the Hibernate type from the
- * class of the first object in the array. This is useful for binding a list of values
+ * Bind multiple values to a named query parameter. The Hibernate type of the parameter is
+ * first detected via the usage/position in the query and if not sufficient secondly
+ * guessed from the class of the first object in the array. This is useful for binding a list of values
* to an expression such as <tt>foo.bar in (:value_list)</tt>.
* @param name the name of the parameter
* @param vals a collection of values to list
@@ -289,8 +294,17 @@
* matching property names with parameter names and mapping property types to
* Hibernate types using hueristics.
* @param bean any JavaBean or POJO
+ */
+ public Query setProperties(Object bean) throws HibernateException;
+
+ /**
+ * Bind the values of the given Map for each named parameters of the query,
+ * matching key names with parameter names and mapping value types to
+ * Hibernate types using hueristics.
+ * @param bean a java.util.Map
*/
- public Query setProperties(Object bean) throws HibernateException;
+ public Query setProperties(Map bean) throws HibernateException;
+
public Query setString(int position, String val);
public Query setCharacter(int position, char val);
17 years, 6 months
Hibernate SVN: r10589 - in trunk/Hibernate3: src/org/hibernate/collection test/org/hibernate/test/collection/set
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-16 11:47:37 -0400 (Mon, 16 Oct 2006)
New Revision: 10589
Modified:
trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java
trunk/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java
Log:
HHH-2145 set.retainAll calling set.addAll (with unittest)
Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java 2006-10-16 15:47:19 UTC (rev 10588)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java 2006-10-16 15:47:37 UTC (rev 10589)
@@ -260,7 +260,7 @@
*/
public boolean retainAll(Collection coll) {
initialize( true );
- if ( set.addAll( coll ) ) {
+ if ( set.retainAll( coll ) ) {
dirty();
return true;
}
Modified: trunk/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java 2006-10-16 15:47:19 UTC (rev 10588)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java 2006-10-16 15:47:37 UTC (rev 10589)
@@ -60,6 +60,10 @@
assertFalse( children.removeAll( otherSet ) );
assertFalse( children.isDirty() );
+ assertTrue( children.retainAll( otherSet ));
+ assertTrue( children.isDirty() );
+ assertTrue( children.isEmpty() );
+
children.clear();
session.delete( child );
assertTrue( children.isDirty() );
17 years, 6 months
Hibernate SVN: r10588 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/collection test/org/hibernate/test/collection/set
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-16 11:47:19 -0400 (Mon, 16 Oct 2006)
New Revision: 10588
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentSet.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java
Log:
HHH-2145 set.retainAll calling set.addAll (with unittest)
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentSet.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentSet.java 2006-10-16 14:59:57 UTC (rev 10587)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/collection/PersistentSet.java 2006-10-16 15:47:19 UTC (rev 10588)
@@ -260,7 +260,7 @@
*/
public boolean retainAll(Collection coll) {
initialize( true );
- if ( set.addAll( coll ) ) {
+ if ( set.retainAll( coll ) ) {
dirty();
return true;
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java 2006-10-16 14:59:57 UTC (rev 10587)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/collection/set/PersistentSetTest.java 2006-10-16 15:47:19 UTC (rev 10588)
@@ -59,6 +59,10 @@
otherSet.add( otherChild );
assertFalse( children.removeAll( otherSet ) );
assertFalse( children.isDirty() );
+
+ assertTrue( children.retainAll( otherSet ));
+ assertTrue( children.isDirty() );
+ assertTrue( children.isEmpty() );
children.clear();
session.delete( child );
@@ -73,4 +77,5 @@
session.getTransaction().commit();
session.close();
}
+
}
17 years, 6 months
Hibernate SVN: r10587 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/impl test/org/hibernate/test/legacy
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-16 10:59:57 -0400 (Mon, 16 Oct 2006)
New Revision: 10587
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java
Log:
HHH-2037 provide Query.setProperties(Map) (merge from head)
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java 2006-10-16 14:56:30 UTC (rev 10586)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java 2006-10-16 14:59:57 UTC (rev 10587)
@@ -741,6 +741,30 @@
return setParameterList( name, Arrays.asList(vals) );
}
+ public Query setProperties(Map map) throws HibernateException {
+ String[] params = getNamedParameters();
+ for (int i = 0; i < params.length; i++) {
+ String namedParam = params[i];
+ final Object object = map.get(namedParam);
+ if(object==null) {
+ continue;
+ }
+ Class retType = object.getClass();
+ if ( Collection.class.isAssignableFrom( retType ) ) {
+ setParameterList( namedParam, ( Collection ) object );
+ }
+ else if ( retType.isArray() ) {
+ setParameterList( namedParam, ( Object[] ) object );
+ }
+ else {
+ setParameter( namedParam, object, determineType( namedParam, retType ) );
+ }
+
+
+ }
+ return this;
+ }
+
public Query setProperties(Object bean) throws HibernateException {
Class clazz = bean.getClass();
String[] params = getNamedParameters();
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java 2006-10-16 14:56:30 UTC (rev 10586)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java 2006-10-16 14:59:57 UTC (rev 10587)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -29,7 +30,6 @@
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.engine.SessionFactoryImplementor;
public class SQLFunctionsTest extends LegacyTestCase {
@@ -138,6 +138,38 @@
s.close();
}
+ public void testSetPropertiesMap() throws Exception {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Simple simple = new Simple();
+ simple.setName("Simple 1");
+ s.save(simple, new Long(10) );
+ Map parameters = new HashMap();
+ parameters.put("name", simple.getName());
+ parameters.put("count", new Integer(simple.getCount()));
+
+ Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count");
+ q.setProperties(((Map)parameters));
+ assertTrue( q.list().get(0)==simple );
+
+ List l = new ArrayList();
+ l.add("Simple 1");
+ l.add("Slimeball");
+ parameters.put("several", l);
+ q = s.createQuery("from Simple s where s.name in (:several)");
+ q.setProperties(parameters);
+ assertTrue( q.list().get(0)==simple );
+
+
+ parameters.put("stuff", l.toArray(new String[0]));
+ q = s.createQuery("from Simple s where s.name in (:stuff)");
+ q.setProperties(parameters);
+ assertTrue( q.list().get(0)==simple );
+ s.delete(simple);
+ t.commit();
+ s.close();
+ }
+
public void testBroken() throws Exception {
if (getDialect() instanceof Oracle9Dialect) return;
Session s = openSession();
17 years, 6 months
Hibernate SVN: r10586 - in trunk/Hibernate3: src/org/hibernate/impl test/org/hibernate/test/legacy
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-10-16 10:56:30 -0400 (Mon, 16 Oct 2006)
New Revision: 10586
Modified:
trunk/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java
trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java
Log:
HHH-2037 provide Query.setProperties(Map)
Modified: trunk/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java 2006-10-16 04:11:41 UTC (rev 10585)
+++ trunk/Hibernate3/src/org/hibernate/impl/AbstractQueryImpl.java 2006-10-16 14:56:30 UTC (rev 10586)
@@ -741,6 +741,30 @@
return setParameterList( name, Arrays.asList(vals) );
}
+ public Query setProperties(Map map) throws HibernateException {
+ String[] params = getNamedParameters();
+ for (int i = 0; i < params.length; i++) {
+ String namedParam = params[i];
+ final Object object = map.get(namedParam);
+ if(object==null) {
+ continue;
+ }
+ Class retType = object.getClass();
+ if ( Collection.class.isAssignableFrom( retType ) ) {
+ setParameterList( namedParam, ( Collection ) object );
+ }
+ else if ( retType.isArray() ) {
+ setParameterList( namedParam, ( Object[] ) object );
+ }
+ else {
+ setParameter( namedParam, object, determineType( namedParam, retType ) );
+ }
+
+
+ }
+ return this;
+ }
+
public Query setProperties(Object bean) throws HibernateException {
Class clazz = bean.getClass();
String[] params = getNamedParameters();
Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java 2006-10-16 04:11:41 UTC (rev 10585)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java 2006-10-16 14:56:30 UTC (rev 10586)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -29,7 +30,6 @@
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.engine.SessionFactoryImplementor;
public class SQLFunctionsTest extends LegacyTestCase {
@@ -138,6 +138,37 @@
s.close();
}
+ public void testSetPropertiesMap() throws Exception {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Simple simple = new Simple();
+ simple.setName("Simple 1");
+ s.save(simple, new Long(10) );
+ Map parameters = new HashMap();
+ parameters.put("name", simple.getName());
+ parameters.put("count", new Integer(simple.getCount()));
+
+ Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count");
+ q.setProperties(((Map)parameters));
+ assertTrue( q.list().get(0)==simple );
+
+ List l = new ArrayList();
+ l.add("Simple 1");
+ l.add("Slimeball");
+ parameters.put("several", l);
+ q = s.createQuery("from Simple s where s.name in (:several)");
+ q.setProperties(parameters);
+ assertTrue( q.list().get(0)==simple );
+
+
+ parameters.put("stuff", l.toArray(new String[0]));
+ q = s.createQuery("from Simple s where s.name in (:stuff)");
+ q.setProperties(parameters);
+ assertTrue( q.list().get(0)==simple );
+ s.delete(simple);
+ t.commit();
+ s.close();
+ }
public void testBroken() throws Exception {
if (getDialect() instanceof Oracle9Dialect) return;
Session s = openSession();
17 years, 6 months
Hibernate SVN: r10585 - tags/entitymanager_v3_2_0_GA
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-16 00:11:41 -0400 (Mon, 16 Oct 2006)
New Revision: 10585
Added:
tags/entitymanager_v3_2_0_GA/HibernateExt/
Log:
made a copy
Copied: tags/entitymanager_v3_2_0_GA/HibernateExt (from rev 10584, trunk/HibernateExt)
17 years, 6 months
Hibernate SVN: r10584 - tags/annotations_v3_2_0_GA
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-16 00:11:04 -0400 (Mon, 16 Oct 2006)
New Revision: 10584
Added:
tags/annotations_v3_2_0_GA/HibernateExt/
Log:
made a copy
Copied: tags/annotations_v3_2_0_GA/HibernateExt (from rev 10583, trunk/HibernateExt)
17 years, 6 months
Hibernate SVN: r10583 - tags
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-16 00:09:16 -0400 (Mon, 16 Oct 2006)
New Revision: 10583
Added:
tags/entitymanager_v3_2_0_GA/
Log:
GA release
17 years, 6 months
Hibernate SVN: r10582 - tags
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-16 00:09:00 -0400 (Mon, 16 Oct 2006)
New Revision: 10582
Added:
tags/annotations_v3_2_0_GA/
Log:
GA release
17 years, 6 months