From: <one...@us...> - 2003-02-15 08:01:25
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister In directory sc8-pr-cvs1:/tmp/cvs-serv27994/sf/hibernate/persister Modified Files: AbstractEntityPersister.java EntityPersister.java Log Message: integrated latest cglib + reflection optimizer Index: AbstractEntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/AbstractEntityPersister.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** AbstractEntityPersister.java 2 Feb 2003 04:19:51 -0000 1.12 --- AbstractEntityPersister.java 15 Feb 2003 08:00:50 -0000 1.13 *************** *** 12,19 **** --- 12,22 ---- import org.apache.commons.logging.LogFactory; + import net.sf.cglib.MetaClass; + import net.sf.hibernate.HibernateException; import net.sf.hibernate.InstantiationException; import net.sf.hibernate.Lifecycle; import net.sf.hibernate.MappingException; + import net.sf.hibernate.PropertyAccessException; import net.sf.hibernate.QueryException; import net.sf.hibernate.StaleObjectStateException; *************** *** 118,121 **** --- 121,126 ---- private transient final Cascades.CascadeStyle[] cascadeStyles; private transient final CacheConcurrencyStrategy cache; + + private transient final MetaClass optimizer; public final Class getMappedClass() { *************** *** 213,216 **** --- 218,231 ---- */ public void setPropertyValues(Object object, Object[] values) throws HibernateException { + try{ + if (optimizer!=null) { + optimizer.setPropertyValues(object, values); + return; + } + } + catch (Throwable t) { + throw new PropertyAccessException(t, "exception setting property value with CGLIB", true, mappedClass, "?"); + } + for (int j=0; j<hydrateSpan; j++) getSetters()[j].set(object, values[j]); } *************** *** 220,223 **** --- 235,247 ---- */ public Object[] getPropertyValues(Object object) throws HibernateException { + try{ + if (optimizer!=null) { + return optimizer.getPropertyValues(object); + } + } + catch (Throwable t) { + throw new PropertyAccessException(t, "exception getting property value with CGLIB", false, mappedClass, "?"); + } + Object[] result = new Object[hydrateSpan]; for (int j=0; j<hydrateSpan; j++) result[j] = getGetters()[j].get(object); *************** *** 295,302 **** if (abstractClass) throw new HibernateException("Cannot instantiate abstract class or interface: " + className); try { return constructor.newInstance(null); } catch (Exception e) { ! throw new InstantiationException( "Could not instantiate entity ", mappedClass, e ); } } --- 319,334 ---- if (abstractClass) throw new HibernateException("Cannot instantiate abstract class or interface: " + className); try { + if (optimizer != null) { + try { + return optimizer.newInstance(); + } + catch (Throwable t) { + throw new InstantiationException("Could not instantiate entity with CGLIB: ", mappedClass, t); + } + } return constructor.newInstance(null); } catch (Exception e) { ! throw new InstantiationException("Could not instantiate entity: ", mappedClass, e); } } *************** *** 607,610 **** --- 639,645 ---- setters = new ReflectHelper.Setter[hydrateSpan]; cascadeStyles = new Cascades.CascadeStyle[hydrateSpan]; + String setterNames[] = new String[hydrateSpan]; + String getterNames[] = new String[hydrateSpan]; + Class types[] = new Class[hydrateSpan]; iter = model.getPropertyClosureIterator(); *************** *** 619,622 **** --- 654,660 ---- getters[i] = ReflectHelper.getGetter( mappedClass, propertyNames[i] ); setters[i] = ReflectHelper.getSetter( mappedClass, propertyNames[i] ); + getterNames[i]= getters[i].getMethod().getName(); + setterNames[i]= setters[i].getMethod().getName(); + types[i] = getters[i].getMethod().getReturnType(); propertyTypes[i] = prop.getType(); propertyUpdateability[i] = prop.isUpdateable(); *************** *** 629,632 **** --- 667,681 ---- } + MetaClass opt; + try { + opt = MetaClass.getInstance( mappedClass.getClassLoader(), mappedClass, getterNames, setterNames, types ); + opt.setPropertyValues( opt.newInstance(), opt.getPropertyValues( opt.newInstance() ) ); + } + catch(Throwable t) { + opt=null; + log.info("reflection optimizer disabled for: " + mappedClass); + } + optimizer=opt; + hasCascades = foundCascade; versionProperty = tempVersionProperty; *************** *** 707,711 **** return propertyInsertability; } ! } --- 756,760 ---- return propertyInsertability; } ! } Index: EntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/EntityPersister.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** EntityPersister.java 9 Feb 2003 06:28:15 -0000 1.16 --- EntityPersister.java 15 Feb 2003 08:00:50 -0000 1.17 *************** *** 114,121 **** AbstractComponentType actype = (AbstractComponentType) idType; String[] props = actype.getPropertyNames(); ! if (props.length!=columns.length) throw new MappingException("broken mapping for: " + getClassName() + StringHelper.DOT + path); for ( int i=0; i<props.length; i++ ) { String subidpath = idpath + StringHelper.DOT + props[i]; ! columnNamesByPropertyPath.put( subidpath, new String[] { columns[i] } ); mods.put( subidpath, actype.getSubtypes()[i] ); } --- 114,128 ---- AbstractComponentType actype = (AbstractComponentType) idType; String[] props = actype.getPropertyNames(); ! Type[] subtypes = actype.getSubtypes(); ! if ( actype.getColumnSpan(factory)!=columns.length ) ! throw new MappingException("broken mapping for: " + getClassName() + StringHelper.DOT + path); ! int j=0; for ( int i=0; i<props.length; i++ ) { String subidpath = idpath + StringHelper.DOT + props[i]; ! String[] componentColumns = new String[ subtypes[i].getColumnSpan(factory) ]; ! for (int k = 0; k < componentColumns.length; k++) { ! componentColumns[k] = columns[j++]; ! } ! columnNamesByPropertyPath.put(subidpath, componentColumns); mods.put( subidpath, actype.getSubtypes()[i] ); } |