From: <one...@us...> - 2003-03-12 12:40:56
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl In directory sc8-pr-cvs1:/tmp/cvs-serv31825/cirrus/hibernate/impl Modified Files: QueryImpl.java Log Message: Query.setEntity(), etc, now aware of proxies (also improved hueristics for guessing types) Index: QueryImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/QueryImpl.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** QueryImpl.java 31 Jan 2003 08:50:49 -0000 1.24 --- QueryImpl.java 12 Mar 2003 12:40:52 -0000 1.25 *************** *** 25,28 **** --- 25,30 ---- import cirrus.hibernate.helpers.ReflectHelper; import cirrus.hibernate.helpers.StringHelper; + import cirrus.hibernate.proxy.HibernateProxyHelper; + import cirrus.hibernate.type.SerializableType; import cirrus.hibernate.type.Type; import cirrus.hibernate.type.TypeFactory; *************** *** 156,160 **** } ! public void setEntity(int position, Object val) { setParameter( position, val, Hibernate.association( val.getClass() ) ); } --- 158,163 ---- } ! public void setEntity(int position, Object val) throws HibernateException, SQLException { ! val = HibernateProxyHelper.unproxy(val, session); setParameter( position, val, Hibernate.association( val.getClass() ) ); } *************** *** 200,204 **** } ! public void setEntity(String name, Object val) { setParameter( name, val, Hibernate.association( val.getClass() ) ); } --- 203,208 ---- } ! public void setEntity(String name, Object val) throws HibernateException, SQLException { ! val = HibernateProxyHelper.unproxy(val, session); setParameter( name, val, Hibernate.association( val.getClass() ) ); } *************** *** 264,276 **** } ! public void setParameter(int position, Object val) throws HibernateException { setParameter( position, val, guessType(val) ); } ! public void setParameter(String name, Object val) throws HibernateException { setParameter( name, val, guessType(val) ); } ! private Type guessType(Object param) throws HibernateException { Class clazz = param.getClass(); return guessType(clazz); --- 268,281 ---- } ! public void setParameter(int position, Object val) throws HibernateException, SQLException { setParameter( position, val, guessType(val) ); } ! public void setParameter(String name, Object val) throws HibernateException, SQLException { setParameter( name, val, guessType(val) ); } ! private Type guessType(Object param) throws HibernateException, SQLException { ! param = HibernateProxyHelper.unproxy(param, session); Class clazz = param.getClass(); return guessType(clazz); *************** *** 280,293 **** String typename = clazz.getName(); Type type = TypeFactory.hueristicType(typename); ! if (type==null ) { try { session.getFactory().getPersister(clazz); } catch (MappingException me) { ! throw new HibernateException("Could not determine a type for class: " + typename); } ! type = Hibernate.association(clazz); } - return type; } --- 285,306 ---- String typename = clazz.getName(); Type type = TypeFactory.hueristicType(typename); ! boolean serializable = type!=null && type instanceof SerializableType; ! if (type==null || serializable) { try { session.getFactory().getPersister(clazz); } catch (MappingException me) { ! if (serializable) { ! return type; ! } ! else { ! throw new HibernateException("Could not determine a type for class: " + typename); ! } } ! return Hibernate.association(clazz); ! } ! else { ! return type; } } *************** *** 311,315 **** } ! public void setParameterList(String name, Collection vals) throws HibernateException { setParameterList(name, vals, guessType( vals.iterator().next() ) ); } --- 324,328 ---- } ! public void setParameterList(String name, Collection vals) throws HibernateException, SQLException { setParameterList(name, vals, guessType( vals.iterator().next() ) ); } *************** *** 319,323 **** } ! public void setProperties(Object bean) throws HibernateException { Class clazz = bean.getClass(); Iterator iter = session.getFactory().getNamedParameters(queryString).iterator(); --- 332,337 ---- } ! public void setProperties(Object bean) throws HibernateException, SQLException { ! bean = HibernateProxyHelper.unproxy(bean, session); Class clazz = bean.getClass(); Iterator iter = session.getFactory().getNamedParameters(queryString).iterator(); |