From: <one...@us...> - 2003-04-16 06:31:23
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl In directory sc8-pr-cvs1:/tmp/cvs-serv13811/impl Modified Files: FilterImpl.java QueryImpl.java SessionImpl.java Log Message: bugfixes from 2.0 stream * now uses interface proxies correctly * bugfixes to Filters * reference to self for a native id Index: FilterImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/FilterImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FilterImpl.java 26 Nov 2002 03:35:42 -0000 1.2 --- FilterImpl.java 16 Apr 2003 06:30:50 -0000 1.3 *************** *** 2,7 **** --- 2,9 ---- import java.sql.SQLException; + import java.util.HashMap; import java.util.Iterator; import java.util.List; + import java.util.Map; import cirrus.hibernate.HibernateException; *************** *** 24,42 **** /** ! * @see cirrus.hibernate.Query#iterate() */ ! public Iterator iterate() throws SQLException, HibernateException { ! values.add(0, null); ! types.add(0, null); ! return session.iterateFilter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } ! /** ! * @see cirrus.hibernate.Query#list() */ ! public List list() throws SQLException, HibernateException { ! values.add(0, null); ! types.add(0, null); ! return session.filter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } --- 26,44 ---- /** ! * @see net.sf.hibernate.Query#iterate() */ ! public Iterator iterate() throws HibernateException, SQLException { ! Map namedParams = new HashMap( getNamedParams() ); ! String query = bindParameterLists(namedParams); ! return getSession().iterateFilter(collection, query, valueArray(), typeArray(), getSelection(), namedParams); } ! /** ! * @see net.sf.hibernate.Query#list() */ ! public List list() throws HibernateException, SQLException { ! Map namedParams = new HashMap( getNamedParams() ); ! String query = bindParameterLists(namedParams); ! return getSession().filter(collection, query, valueArray(), typeArray(), getSelection(), namedParams); } *************** *** 48,50 **** --- 50,68 ---- } + private Type[] typeArray() { + List typeList = getTypes(); + int size = typeList.size(); + Type[] result = new Type[size+1]; + for (int i=0; i<size; i++) result[i+1] = (Type) typeList.get(i); + return result; + } + + private Object[] valueArray() { + List valueList = getValues(); + int size = valueList.size(); + Object[] result = new Object[size+1]; + for (int i=0; i<size; i++) result[i+1] = valueList.get(i); + return result; + } + } Index: QueryImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/QueryImpl.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** QueryImpl.java 13 Mar 2003 02:52:19 -0000 1.26 --- QueryImpl.java 16 Apr 2003 06:30:50 -0000 1.27 *************** *** 35,42 **** String queryString; ! RowSelection selection; ! ArrayList values = new ArrayList(4); ! ArrayList types = new ArrayList(4); ! Map namedParams = new HashMap(4); public QueryImpl(String queryString, SessionImplementor session) { --- 35,43 ---- String queryString; ! private RowSelection selection; ! private ArrayList values = new ArrayList(4); ! private ArrayList types = new ArrayList(4); ! private Map namedParameters = new HashMap(4); ! private Map namedParameterLists = new HashMap(4); public QueryImpl(String queryString, SessionImplementor session) { *************** *** 63,75 **** public Iterator iterate() throws SQLException, HibernateException { ! return session.iterate(queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } public ScrollableResults scroll() throws SQLException, HibernateException { ! return session.scroll(queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } public List list() throws SQLException, HibernateException { ! return session.find(queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } --- 64,82 ---- public Iterator iterate() throws SQLException, HibernateException { ! Map namedParams = new HashMap(namedParameters); ! String query = bindParameterLists(namedParams); ! return session.iterate(query, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } public ScrollableResults scroll() throws SQLException, HibernateException { ! Map namedParams = new HashMap(namedParameters); ! String query = bindParameterLists(namedParams); ! return session.scroll(query, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } public List list() throws SQLException, HibernateException { ! Map namedParams = new HashMap(namedParameters); ! String query = bindParameterLists(namedParams); ! return session.find(query, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); } *************** *** 235,239 **** public void setParameter(String name, Object val, Type type) { ! namedParams.put(name, new TypedValue(type, val) ); } --- 242,246 ---- public void setParameter(String name, Object val, Type type) { ! namedParameters.put(name, new TypedValue(type, val) ); } *************** *** 308,324 **** public void setParameterList(String name, Collection vals, Type type) throws HibernateException { ! ! StringBuffer list = new StringBuffer(16); ! Iterator iter = vals.iterator(); ! int i=0; ! while ( iter.hasNext() ) { ! String alias = name + i++ + '_'; ! setParameter(alias, iter.next(), type); ! list.append( ':' + alias ); ! if ( iter.hasNext() ) list.append(", "); ! } ! queryString = StringHelper.replaceOnce( queryString, ':' + name, list.toString() ); } ! public void setParameterList(String name, Collection vals) throws HibernateException, SQLException { setParameterList(name, vals, guessType( vals.iterator().next() ) ); --- 315,321 ---- public void setParameterList(String name, Collection vals, Type type) throws HibernateException { ! namedParameterLists.put( name, new TypedValue(type, vals) ); } ! public void setParameterList(String name, Collection vals) throws HibernateException, SQLException { setParameterList(name, vals, guessType( vals.iterator().next() ) ); *************** *** 346,348 **** --- 343,391 ---- } + SessionImplementor getSession() { + return session; + } + + ArrayList getValues() { + return values; + } + + ArrayList getTypes() { + return types; + } + + Map getNamedParams() { + return namedParameters; + } + + RowSelection getSelection() { + return selection; + } + + protected String bindParameterLists(Map namedParams) { + Iterator iter = namedParameterLists.entrySet().iterator(); + String query = queryString; + while ( iter.hasNext() ) { + Map.Entry me = (Map.Entry) iter.next(); + query = bindParameterList( queryString, (String) me.getKey(), (TypedValue) me.getValue(), namedParams ); + } + return query; + } + private String bindParameterList(String queryString, String name, TypedValue typedList, Map namedParams) { + Collection vals = (Collection) typedList.value; + Type type = typedList.type; + StringBuffer list = new StringBuffer(16); + Iterator iter = vals.iterator(); + int i=0; + while ( iter.hasNext() ) { + String alias = name + i++ + "_"; + namedParams.put(alias, new TypedValue( type, iter.next() ) ); + list.append( ':' + alias ); + if ( iter.hasNext() ) list.append(", "); + } + + return StringHelper.replace( queryString, ':' + name, list.toString() ); + } + + } Index: SessionImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/SessionImpl.java,v retrieving revision 1.165 retrieving revision 1.166 diff -C2 -d -r1.165 -r1.166 *** SessionImpl.java 20 Mar 2003 13:58:45 -0000 1.165 --- SessionImpl.java 16 Apr 2003 06:30:50 -0000 1.166 *************** *** 648,652 **** ! if (object==self) return false; // was a reference to self, so don't need to nullify // See if the entity is already bound to this session, if not look at the --- 648,652 ---- ! if (object==self) return earlyInsert; // was a reference to self, so don't need to nullify (unless id is generated by identity column) // See if the entity is already bound to this session, if not look at the |