From: <one...@us...> - 2003-02-03 10:28:51
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type In directory sc8-pr-cvs1:/tmp/cvs-serv20343/hibernate/type Modified Files: AbstractComponentType.java ComponentType.java CustomType.java DynaBeanType.java Log Message: added warning in custom type made <parent> proxy-aware Index: AbstractComponentType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/AbstractComponentType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractComponentType.java 19 Jan 2003 11:47:08 -0000 1.4 --- AbstractComponentType.java 3 Feb 2003 10:28:48 -0000 1.5 *************** *** 15,19 **** public void setPropertyValues(Object component, Object[] values) throws HibernateException; public Object getPropertyValue(Object component, int i) throws HibernateException; ! public Object instantiate(Object parent) throws HibernateException; public Cascades.CascadeStyle cascade(int i); public int enableJoinedFetch(int i); --- 15,19 ---- public void setPropertyValues(Object component, Object[] values) throws HibernateException; public Object getPropertyValue(Object component, int i) throws HibernateException; ! //public Object instantiate(Object parent, SessionImplementor session) throws HibernateException; public Cascades.CascadeStyle cascade(int i); public int enableJoinedFetch(int i); Index: ComponentType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/ComponentType.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ComponentType.java 2 Feb 2003 04:19:52 -0000 1.6 --- ComponentType.java 3 Feb 2003 10:28:48 -0000 1.7 *************** *** 128,132 **** if (notNull) { ! Object result = instantiate(owner); for ( int i=0; i<propertySpan; i++ ) { setters[i].set( result, values[i] ); --- 128,132 ---- if (notNull) { ! Object result = instantiate(owner, session); for ( int i=0; i<propertySpan; i++ ) { setters[i].set( result, values[i] ); *************** *** 201,217 **** values[i] = types[i].deepCopy( values[i] ); } ! Object result = instantiate(null); //TODO: note that this doesn't copy reference to parent. Is that okay?? setPropertyValues(result, values); return result; } ! public Object instantiate(Object parent) throws HibernateException { try { ! Object inst = constructor.newInstance(null); ! if (parentSetter!=null && parent!=null) parentSetter.set(inst, parent); ! return inst; } catch (Exception e) { ! throw new InstantiationException("Could not instantiate component ", componentClass, e); } } --- 201,226 ---- values[i] = types[i].deepCopy( values[i] ); } ! Object result = instantiate(); //TODO: note that this doesn't copy reference to parent. Is that okay?? setPropertyValues(result, values); return result; } ! public Object instantiate() throws HibernateException { try { ! return constructor.newInstance(null); } catch (Exception e) { ! throw new InstantiationException("Could not instantiate component: ", componentClass, e); ! } ! } ! ! public Object instantiate(Object parent, SessionImplementor session) throws HibernateException { ! Object result = instantiate(); ! try { ! if (parentSetter!=null && parent!=null) parentSetter.set( result, session.proxyFor(parent) ); ! return result; ! } ! catch (Exception e) { ! throw new InstantiationException("Could not set component parent for: ", componentClass, e); } } *************** *** 250,254 **** assembled[i] = types[i].assemble( (Serializable) values[i], session, owner ); } ! Object result = instantiate(owner); setPropertyValues(result, assembled); return result; --- 259,263 ---- assembled[i] = types[i].assemble( (Serializable) values[i], session, owner ); } ! Object result = instantiate(); setPropertyValues(result, assembled); return result; Index: CustomType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/CustomType.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CustomType.java 25 Jan 2003 01:26:07 -0000 1.5 --- CustomType.java 3 Feb 2003 10:28:48 -0000 1.6 *************** *** 2,9 **** --- 2,12 ---- package net.sf.hibernate.type; + import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; + import org.apache.commons.logging.LogFactory; + import net.sf.hibernate.HibernateException; import net.sf.hibernate.MappingException; *************** *** 26,30 **** --- 29,35 ---- public CustomType(Class userTypeClass) throws MappingException { + name = userTypeClass.getName(); + try { userType = (UserType) userTypeClass.newInstance(); *************** *** 40,43 **** --- 45,53 ---- } types = userType.sqlTypes(); + + if ( !Serializable.class.isAssignableFrom( userType.returnedClass() ) ) { + LogFactory.getLog(CustomType.class).warn("custom type does not implement Serializable: " + userTypeClass); + } + } Index: DynaBeanType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/type/DynaBeanType.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DynaBeanType.java 2 Feb 2003 04:19:52 -0000 1.2 --- DynaBeanType.java 3 Feb 2003 10:28:48 -0000 1.3 *************** *** 95,99 **** * @see net.sf.hibernate.type.AbstractComponentType#instantiate(java.lang.Object) */ ! public Object instantiate(Object parent) throws HibernateException { try { return clazz.newInstance(); --- 95,99 ---- * @see net.sf.hibernate.type.AbstractComponentType#instantiate(java.lang.Object) */ ! public Object instantiate() throws HibernateException { try { return clazz.newInstance(); *************** *** 125,129 **** values[i] = propertyTypes[i].deepCopy( values[i] ); } ! Object result = instantiate(null); //TODO: note that this doesn't copy reference to parent. Is that okay?? setPropertyValues(result, values); return result; --- 125,129 ---- values[i] = propertyTypes[i].deepCopy( values[i] ); } ! Object result = instantiate(); //TODO: note that this doesn't copy reference to parent. Is that okay?? setPropertyValues(result, values); return result; *************** *** 231,235 **** if (notNull) { ! DynaBean result = (DynaBean) instantiate(owner); for ( int i=0; i<propertySpan; i++ ) { result.set( propertyNames[i], values[i] ); --- 231,235 ---- if (notNull) { ! DynaBean result = (DynaBean) instantiate(); for ( int i=0; i<propertySpan; i++ ) { result.set( propertyNames[i], values[i] ); |