|
From: <hib...@li...> - 2006-07-14 00:15:14
|
Author: ste...@jb...
Date: 2006-07-13 20:09:19 -0400 (Thu, 13 Jul 2006)
New Revision: 10119
Added:
trunk/Hibernate3/src/org/hibernate/tuple/EntityModeToTuplizerMapping.java
trunk/Hibernate3/src/org/hibernate/tuple/component/
trunk/Hibernate3/src/org/hibernate/tuple/component/AbstractComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/component/ComponentEntityModeToTuplizerMapping.java
trunk/Hibernate3/src/org/hibernate/tuple/component/ComponentMetamodel.java
trunk/Hibernate3/src/org/hibernate/tuple/component/ComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/component/Dom4jComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/component/DynamicMapComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/component/PojoComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/
trunk/Hibernate3/src/org/hibernate/tuple/entity/AbstractEntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/Dom4jEntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/DynamicMapEntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityEntityModeToTuplizerMapping.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityMetamodel.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/EntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/entity/PojoEntityTuplizer.java
Removed:
trunk/Hibernate3/src/org/hibernate/tuple/AbstractComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/AbstractEntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/ComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/Dom4jComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/Dom4jEntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapEntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/EntityMetamodel.java
trunk/Hibernate3/src/org/hibernate/tuple/EntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/PojoComponentTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/PojoEntityTuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/TuplizerLookup.java
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
trunk/Hibernate3/src/org/hibernate/mapping/Component.java
trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
trunk/Hibernate3/src/org/hibernate/mapping/Subclass.java
trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
trunk/Hibernate3/src/org/hibernate/tuple/PropertyFactory.java
trunk/Hibernate3/src/org/hibernate/tuple/StandardProperty.java
trunk/Hibernate3/src/org/hibernate/tuple/Tuplizer.java
trunk/Hibernate3/src/org/hibernate/tuple/VersionProperty.java
trunk/Hibernate3/src/org/hibernate/type/ComponentType.java
trunk/Hibernate3/src/org/hibernate/type/EmbeddedComponentType.java
Log:
HHH-1907 : initial work
Modified: trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1755,11 +1755,20 @@
}
- public static void bindComponent(Element node, Component component, String ownerClassName,
- String parentProperty, String path, boolean isNullable, boolean isEmbedded,
- Mappings mappings, java.util.Map inheritedMetas, boolean isIdentifierMapper) throws MappingException {
+ public static void bindComponent(
+ Element node,
+ Component component,
+ String ownerClassName,
+ String parentProperty,
+ String path,
+ boolean isNullable,
+ boolean isEmbedded,
+ Mappings mappings,
+ java.util.Map inheritedMetas,
+ boolean isIdentifierMapper) throws MappingException {
component.setEmbedded( isEmbedded );
+ component.setRoleName( path );
component.setMetaAttributes( getMetas( node, inheritedMetas ) );
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Component.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Component.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Component.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -7,10 +7,8 @@
import java.util.Map;
import org.hibernate.EntityMode;
-import org.hibernate.FetchMode;
import org.hibernate.MappingException;
-import org.hibernate.engine.CascadeStyle;
-import org.hibernate.tuple.TuplizerLookup;
+import org.hibernate.tuple.component.ComponentMetamodel;
import org.hibernate.type.ComponentType;
import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.Type;
@@ -33,9 +31,30 @@
private Map metaAttributes;
private String nodeName;
private boolean isKey;
+ private String roleName;
private java.util.Map tuplizerImpls;
+ public Component(PersistentClass owner) throws MappingException {
+ super( owner.getTable() );
+ this.owner = owner;
+ }
+
+ public Component(Component component) throws MappingException {
+ super( component.getTable() );
+ this.owner = component.getOwner();
+ }
+
+ public Component(Join join) throws MappingException {
+ super( join.getTable() );
+ this.owner = join.getPersistentClass();
+ }
+
+ public Component(Collection collection) throws MappingException {
+ super( collection.getCollectionTable() );
+ this.owner = collection.getOwner();
+ }
+
public int getPropertySpan() {
return properties.size();
}
@@ -67,26 +86,6 @@
return new JoinedIterator(iters);
}
- public Component(PersistentClass owner) throws MappingException {
- super( owner.getTable() );
- this.owner = owner;
- }
-
- public Component(Component component) throws MappingException {
- super( component.getTable() );
- this.owner = component.getOwner();
- }
-
- public Component(Join join) throws MappingException {
- super( join.getTable() );
- this.owner = join.getPersistentClass();
- }
-
- public Component(Collection collection) throws MappingException {
- super( collection.getCollectionTable() );
- this.owner = collection.getOwner();
- }
-
public void setTypeByReflection(String propertyClass, String propertyName) {}
public boolean isEmbedded() {
@@ -149,49 +148,14 @@
}
private Type buildType() {
- final int span = getPropertySpan();
- String[] names = new String[span];
- org.hibernate.type.Type[] types = new org.hibernate.type.Type[span];
- boolean[] nullabilities = new boolean[span];
- CascadeStyle[] cascade = new CascadeStyle[span];
- FetchMode[] joinedFetch = new FetchMode[span];
- Iterator props = getPropertyIterator();
- int j=0;
- while ( props.hasNext() ) {
- Property prop = (Property) props.next();
- names[j] = prop.getName();
- types[j] = prop.getType();
- cascade[j] = prop.getCascadeStyle();
- joinedFetch[j] = prop.getValue().getFetchMode();
- nullabilities[j] = prop.isNullable();
- j++;
- }
-
- TuplizerLookup tuplizers = TuplizerLookup.create(this);
-
+ // TODO : temporary initial step towards HHH-1907
+ ComponentMetamodel metamodel = new ComponentMetamodel( this );
if ( isEmbedded() ) {
- return new EmbeddedComponentType(
- names,
- types,
- nullabilities,
- joinedFetch,
- cascade,
- isKey,
- tuplizers
- );
+ return new EmbeddedComponentType( metamodel );
}
else {
- return new ComponentType(
- names,
- types,
- nullabilities,
- joinedFetch,
- cascade,
- isKey,
- tuplizers
- );
+ return new ComponentType( metamodel );
}
-
}
public void setTypeUsingReflection(String className, String propertyName)
@@ -271,10 +235,20 @@
}
public String getTuplizerImplClassName(EntityMode mode) {
- if ( tuplizerImpls == null ) return null;
+ // todo : remove this once ComponentMetamodel is complete and merged
+ if ( tuplizerImpls == null ) {
+ return null;
+ }
return ( String ) tuplizerImpls.get( mode );
}
+ public Map getTuplizerMap() {
+ if ( tuplizerImpls == null ) {
+ return null;
+ }
+ return java.util.Collections.unmodifiableMap( tuplizerImpls );
+ }
+
public Property getProperty(String propertyName) throws MappingException {
Iterator iter = getPropertyIterator();
while ( iter.hasNext() ) {
@@ -286,6 +260,14 @@
throw new MappingException("component property not found: " + propertyName);
}
+ public String getRoleName() {
+ return roleName;
+ }
+
+ public void setRoleName(String roleName) {
+ this.roleName = roleName;
+ }
+
public String toString() {
return getClass().getName() + '(' + properties.toString() + ')';
}
Modified: trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -2,12 +2,8 @@
package org.hibernate.mapping;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
+import java.util.*;
import java.util.Set;
-import java.util.StringTokenizer;
import org.hibernate.MappingException;
import org.hibernate.EntityMode;
@@ -712,7 +708,14 @@
if ( tuplizerImpls == null ) return null;
return ( String ) tuplizerImpls.get( mode );
}
-
+
+ public java.util.Map getTuplizerMap() {
+ if ( tuplizerImpls == null ) {
+ return null;
+ }
+ return java.util.Collections.unmodifiableMap( tuplizerImpls );
+ }
+
public boolean hasNaturalId() {
Iterator props = getRootClass().getPropertyIterator();
while ( props.hasNext() ) {
Modified: trunk/Hibernate3/src/org/hibernate/mapping/Subclass.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/mapping/Subclass.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/mapping/Subclass.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -151,7 +151,9 @@
}
public void createForeignKey() {
- if ( !isJoinedSubclass() ) throw new AssertionFailure("not a joined-subclass");
+ if ( !isJoinedSubclass() ) {
+ throw new AssertionFailure( "not a joined-subclass" );
+ }
getKey().createForeignKeyOfEntity( getSuperclass().getEntityName() );
}
@@ -226,6 +228,24 @@
return impl;
}
+ public Map getTuplizerMap() {
+ Map specificTuplizerDefs = super.getTuplizerMap();
+ Map superclassTuplizerDefs = getSuperclass().getTuplizerMap();
+ if ( specificTuplizerDefs == null && superclassTuplizerDefs == null ) {
+ return null;
+ }
+ else {
+ Map combined = new HashMap();
+ if ( superclassTuplizerDefs != null ) {
+ combined.putAll( superclassTuplizerDefs );
+ }
+ if ( specificTuplizerDefs != null ) {
+ combined.putAll( specificTuplizerDefs );
+ }
+ return java.util.Collections.unmodifiableMap( combined );
+ }
+ }
+
public Component getIdentifierMapper() {
return superclass.getIdentifierMapper();
}
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -2,11 +2,9 @@
package org.hibernate.persister.entity;
import java.io.Serializable;
-import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -73,8 +71,8 @@
import org.hibernate.sql.SimpleSelect;
import org.hibernate.sql.Template;
import org.hibernate.sql.Update;
-import org.hibernate.tuple.EntityMetamodel;
-import org.hibernate.tuple.EntityTuplizer;
+import org.hibernate.tuple.entity.EntityMetamodel;
+import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.tuple.Tuplizer;
import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/AbstractComponentTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/AbstractComponentTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/AbstractComponentTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,102 +0,0 @@
-//$Id$
-package org.hibernate.tuple;
-
-import java.lang.reflect.Method;
-import java.util.Iterator;
-
-import org.hibernate.HibernateException;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Property;
-import org.hibernate.property.Getter;
-import org.hibernate.property.Setter;
-
-/**
- * @author Gavin King
- */
-public abstract class AbstractComponentTuplizer implements ComponentTuplizer {
-
- protected final Getter[] getters;
- protected final Setter[] setters;
- protected final int propertySpan;
- protected final Instantiator instantiator;
- protected final boolean hasCustomAccessors;
-
- protected abstract Instantiator buildInstantiator(Component component);
- protected abstract Getter buildGetter(Component component, Property prop);
- protected abstract Setter buildSetter(Component component, Property prop);
-
- protected AbstractComponentTuplizer(Component component) {
- propertySpan = component.getPropertySpan();
- getters = new Getter[propertySpan];
- setters = new Setter[propertySpan];
-
- Iterator iter = component.getPropertyIterator();
- boolean foundCustomAccessor=false;
- int i=0;
- while ( iter.hasNext() ) {
- Property prop = (Property) iter.next();
- getters[i] = buildGetter(component, prop);
- setters[i] = buildSetter(component, prop);
- if ( !prop.isBasicPropertyAccessor() ) foundCustomAccessor = true;
- i++;
- }
- hasCustomAccessors = foundCustomAccessor;
-
- String[] getterNames = new String[propertySpan];
- String[] setterNames = new String[propertySpan];
- Class[] propTypes = new Class[propertySpan];
- for ( int j = 0; j < propertySpan; j++ ) {
- getterNames[j] = getters[j].getMethodName();
- setterNames[j] = setters[j].getMethodName();
- propTypes[j] = getters[j].getReturnType();
- }
- instantiator = buildInstantiator(component);
- }
-
- public Object getPropertyValue(Object component, int i) throws HibernateException {
- return getters[i].get( component );
- }
-
- public Object[] getPropertyValues(Object component) throws HibernateException {
- Object[] values = new Object[propertySpan];
- for ( int i = 0; i < propertySpan; i++ ) {
- values[i] = getPropertyValue( component, i );
- }
- return values;
- }
-
- public boolean isInstance(Object object) {
- return instantiator.isInstance(object);
- }
-
- public void setPropertyValues(Object component, Object[] values) throws HibernateException {
- for ( int i = 0; i < propertySpan; i++ ) {
- setters[i].set( component, values[i], null );
- }
- }
-
- /**
- * This method does not populate the component parent
- */
- public Object instantiate() throws HibernateException {
- return instantiator.instantiate();
- }
-
- public Object getParent(Object component) {
- return null;
- }
-
- public boolean hasParentProperty() {
- return false;
- }
-
- public boolean isMethodOf(Method method) {
- return false;
- }
-
- public void setParent(Object component, Object parent, SessionFactoryImplementor factory) {
- throw new UnsupportedOperationException();
- }
-
-}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/AbstractEntityTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/AbstractEntityTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/AbstractEntityTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,403 +0,0 @@
-// $Id$
-package org.hibernate.tuple;
-
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.id.Assigned;
-import org.hibernate.intercept.LazyPropertyInitializer;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-import org.hibernate.property.Getter;
-import org.hibernate.property.Setter;
-import org.hibernate.proxy.ProxyFactory;
-import org.hibernate.type.AbstractComponentType;
-import org.hibernate.type.ComponentType;
-
-
-/**
- * Support base class for EntityTuplizer implementations.
- *
- * @author Steve Ebersole
- */
-public abstract class AbstractEntityTuplizer implements EntityTuplizer {
-
- //TODO: currently keeps Getters and Setters (instead of PropertyAccessors) because of the way getGetter() and getSetter() are implemented currently; yuck!
-
- private final EntityMetamodel entityMetamodel;
-
- private final Getter idGetter;
- private final Setter idSetter;
-
- protected final Getter[] getters;
- protected final Setter[] setters;
- protected final int propertySpan;
- protected final boolean hasCustomAccessors;
- private final Instantiator instantiator;
- private final ProxyFactory proxyFactory;
- private final AbstractComponentType identifierMapperType;
-
-
- /**
- * Return the entity-mode handled by this tuplizer instance.
- *
- * @return The entity-mode
- */
- protected abstract EntityMode getEntityMode();
-
- /**
- * Build an appropriate Getter for the given property.
- *
- * @param mappedProperty The property to be accessed via the built Getter.
- * @param mappedEntity The entity information regarding the mapped entity owning this property.
- * @return An appropriate Getter instance.
- */
- protected abstract Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity);
-
- /**
- * Build an appropriate Setter for the given property.
- *
- * @param mappedProperty The property to be accessed via the built Setter.
- * @param mappedEntity The entity information regarding the mapped entity owning this property.
- * @return An appropriate Setter instance.
- */
- protected abstract Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity);
-
- /**
- * Build an appropriate Instantiator for the given mapped entity.
- *
- * @param mappingInfo The mapping information regarding the mapped entity.
- * @return An appropriate Instantiator instance.
- */
- protected abstract Instantiator buildInstantiator(PersistentClass mappingInfo);
-
- /**
- * Build an appropriate ProxyFactory for the given mapped entity.
- *
- * @param mappingInfo The mapping information regarding the mapped entity.
- * @param idGetter The constructed Getter relating to the entity's id property.
- * @param idSetter The constructed Setter relating to the entity's id property.
- * @return An appropriate ProxyFactory instance.
- */
- protected abstract ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter);
-
- /**
- * Constructs a new AbstractEntityTuplizer instance.
- *
- * @param entityMetamodel The "interpreted" information relating to the mapped entity.
- * @param mappingInfo The parsed "raw" mapping data relating to the given entity.
- */
- public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) {
- this.entityMetamodel = entityMetamodel;
-
- if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) {
- idGetter = buildPropertyGetter( mappingInfo.getIdentifierProperty(), mappingInfo );
- idSetter = buildPropertySetter( mappingInfo.getIdentifierProperty(), mappingInfo );
- }
- else {
- idGetter = null;
- idSetter = null;
- }
-
- propertySpan = entityMetamodel.getPropertySpan();
-
- getters = new Getter[propertySpan];
- setters = new Setter[propertySpan];
-
- Iterator iter = mappingInfo.getPropertyClosureIterator();
- boolean foundCustomAccessor=false;
- int i=0;
- while ( iter.hasNext() ) {
- //TODO: redesign how PropertyAccessors are acquired...
- Property property = (Property) iter.next();
- getters[i] = buildPropertyGetter(property, mappingInfo);
- setters[i] = buildPropertySetter(property, mappingInfo);
- if ( !property.isBasicPropertyAccessor() ) foundCustomAccessor = true;
- i++;
- }
- hasCustomAccessors = foundCustomAccessor;
-
- instantiator = buildInstantiator( mappingInfo );
-
- if ( entityMetamodel.isLazy() ) {
- proxyFactory = buildProxyFactory( mappingInfo, idGetter, idSetter );
- }
- else {
- proxyFactory = null;
- }
-
- Component mapper = mappingInfo.getIdentifierMapper();
- identifierMapperType = mapper==null ? null : (AbstractComponentType) mapper.getType();
- }
-
- /** Retreives the defined entity-name for the tuplized entity.
- *
- * @return The entity-name.
- */
- protected String getEntityName() {
- return entityMetamodel.getName();
- }
-
- /**
- * Retreives the defined entity-names for any subclasses defined for this
- * entity.
- *
- * @return Any subclass entity-names.
- */
- protected Set getSubclassEntityNames() {
- return entityMetamodel.getSubclassEntityNames();
- }
-
- public Serializable getIdentifier(Object entity) throws HibernateException {
- final Object id;
- if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
- id = entity;
- }
- else {
- if ( idGetter == null ) {
- if (identifierMapperType==null) {
- throw new HibernateException( "The class has no identifier property: " + getEntityName() );
- }
- else {
- ComponentType copier = (ComponentType) entityMetamodel.getIdentifierProperty().getType();
- id = copier.instantiate( getEntityMode() );
- copier.setPropertyValues( id, identifierMapperType.getPropertyValues( entity, getEntityMode() ), getEntityMode() );
- }
- }
- else {
- id = idGetter.get( entity );
- }
- }
-
- try {
- return (Serializable) id;
- }
- catch ( ClassCastException cce ) {
- StringBuffer msg = new StringBuffer( "Identifier classes must be serializable. " );
- if ( id != null ) {
- msg.append( id.getClass().getName() + " is not serializable. " );
- }
- if ( cce.getMessage() != null ) {
- msg.append( cce.getMessage() );
- }
- throw new ClassCastException( msg.toString() );
- }
- }
-
-
- public void setIdentifier(Object entity, Serializable id) throws HibernateException {
- if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
- if ( entity != id ) {
- AbstractComponentType copier = (AbstractComponentType) entityMetamodel.getIdentifierProperty().getType();
- copier.setPropertyValues( entity, copier.getPropertyValues( id, getEntityMode() ), getEntityMode() );
- }
- }
- else if ( idSetter != null ) {
- idSetter.set( entity, id, getFactory() );
- }
- }
-
- public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion) {
- if ( entityMetamodel.getIdentifierProperty().getIdentifierGenerator() instanceof Assigned ) {
- //return currentId;
- }
- else {
- //reset the id
- Serializable result = entityMetamodel.getIdentifierProperty()
- .getUnsavedValue()
- .getDefaultValue( currentId );
- setIdentifier( entity, result );
- //reset the version
- VersionProperty versionProperty = entityMetamodel.getVersionProperty();
- if ( entityMetamodel.isVersioned() ) {
- setPropertyValue(
- entity,
- entityMetamodel.getVersionPropertyIndex(),
- versionProperty.getUnsavedValue().getDefaultValue( currentVersion )
- );
- }
- //return the id, so we can use it to reset the proxy id
- //return result;
- }
- }
-
- public Object getVersion(Object entity) throws HibernateException {
- if ( !entityMetamodel.isVersioned() ) return null;
- return getters[ entityMetamodel.getVersionPropertyIndex() ].get( entity );
- }
-
- protected boolean shouldGetAllProperties(Object entity) {
- return !hasUninitializedLazyProperties( entity );
- }
-
- public Object[] getPropertyValues(Object entity) throws HibernateException {
- boolean getAll = shouldGetAllProperties( entity );
- final int span = entityMetamodel.getPropertySpan();
- final Object[] result = new Object[span];
-
- for ( int j = 0; j < span; j++ ) {
- StandardProperty property = entityMetamodel.getProperties()[j];
- if ( getAll || !property.isLazy() ) {
- result[j] = getters[j].get( entity );
- }
- else {
- result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
- }
- }
- return result;
- }
-
- public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session)
- throws HibernateException {
- final int span = entityMetamodel.getPropertySpan();
- final Object[] result = new Object[span];
-
- for ( int j = 0; j < span; j++ ) {
- result[j] = getters[j].getForInsert( entity, mergeMap, session );
- }
- return result;
- }
-
- public Object getPropertyValue(Object entity, int i) throws HibernateException {
- return getters[i].get( entity );
- }
-
- public Object getPropertyValue(Object entity, String propertyPath) throws HibernateException {
-
- int loc = propertyPath.indexOf('.');
- String basePropertyName = loc>0 ?
- propertyPath.substring(0, loc) : propertyPath;
-
- int index = entityMetamodel.getPropertyIndex( basePropertyName );
- Object baseValue = getPropertyValue( entity, index );
- if ( loc>0 ) {
- ComponentType type = (ComponentType) entityMetamodel.getPropertyTypes()[index];
- return getComponentValue( type, baseValue, propertyPath.substring(loc+1) );
- }
- else {
- return baseValue;
- }
- }
-
- /**
- * Extract a component property value.
- *
- * @param type The component property types.
- * @param component The component instance itself.
- * @param propertyPath The property path for the property to be extracted.
- * @return The property value extracted.
- */
- protected Object getComponentValue(ComponentType type, Object component, String propertyPath) {
-
- int loc = propertyPath.indexOf('.');
- String basePropertyName = loc>0 ?
- propertyPath.substring(0, loc) : propertyPath;
-
- String[] propertyNames = type.getPropertyNames();
- int index=0;
- for ( ; index<propertyNames.length; index++ ) {
- if ( basePropertyName.equals( propertyNames[index] ) ) break;
- }
- if (index==propertyNames.length) {
- throw new MappingException( "component property not found: " + basePropertyName );
- }
-
- Object baseValue = type.getPropertyValue( component, index, getEntityMode() );
-
- if ( loc>0 ) {
- ComponentType subtype = (ComponentType) type.getSubtypes()[index];
- return getComponentValue( subtype, baseValue, propertyPath.substring(loc+1) );
- }
- else {
- return baseValue;
- }
-
- }
-
- public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
- boolean setAll = !entityMetamodel.hasLazyProperties();
-
- for ( int j = 0; j < entityMetamodel.getPropertySpan(); j++ ) {
- if ( setAll || values[j] != LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
- setters[j].set( entity, values[j], getFactory() );
- }
- }
- }
-
- public void setPropertyValue(Object entity, int i, Object value) throws HibernateException {
- setters[i].set( entity, value, getFactory() );
- }
-
- public void setPropertyValue(Object entity, String propertyName, Object value) throws HibernateException {
- setters[ entityMetamodel.getPropertyIndex( propertyName ) ].set( entity, value, getFactory() );
- }
-
- public final Object instantiate(Serializable id) throws HibernateException {
- Object result = getInstantiator().instantiate( id );
- if ( id != null ) {
- setIdentifier( result, id );
- }
- return result;
- }
-
- public final Object instantiate() throws HibernateException {
- return instantiate( null );
- }
-
- public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session) {}
-
- public boolean hasUninitializedLazyProperties(Object entity) {
- // the default is to simply not lazy fetch properties for now...
- return false;
- }
-
- public final boolean isInstance(Object object) {
- return getInstantiator().isInstance( object );
- }
-
- public boolean hasProxy() {
- return entityMetamodel.isLazy();
- }
-
- public final Object createProxy(Serializable id, SessionImplementor session)
- throws HibernateException {
- return getProxyFactory().getProxy( id, session );
- }
-
- public boolean isLifecycleImplementor() {
- return false;
- }
-
- public boolean isValidatableImplementor() {
- return false;
- }
-
- protected final EntityMetamodel getEntityMetamodel() {
- return entityMetamodel;
- }
-
- protected final SessionFactoryImplementor getFactory() {
- return entityMetamodel.getSessionFactory();
- }
-
- protected final Instantiator getInstantiator() {
- return instantiator;
- }
-
- protected final ProxyFactory getProxyFactory() {
- return proxyFactory;
- }
-
- public String toString() {
- return getClass().getName() + '(' + getEntityMetamodel().getName() + ')';
- }
-
-}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/ComponentTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/ComponentTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/ComponentTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,51 +0,0 @@
-//$Id$
-package org.hibernate.tuple;
-
-import java.io.Serializable;
-import java.lang.reflect.Method;
-
-import org.hibernate.engine.SessionFactoryImplementor;
-
-/**
- * Defines further responsibilities reagarding tuplization based on
- * a mapped components.
- * </p>
- * ComponentTuplizer implementations should have the following constructor signature:
- * (org.hibernate.mapping.Component)
- *
- * @author Gavin King
- */
-public interface ComponentTuplizer extends Tuplizer, Serializable {
- /**
- * Retreive the current value of the parent property.
- *
- * @param component The component instance from which to extract the parent
- * property value.
- * @return The current value of the parent property.
- */
- public Object getParent(Object component);
-
- /**
- * Set the value of the parent property.
- *
- * @param component The component instance on which to set the parent.
- * @param parent The parent to be set on the comonent.
- * @param factory The current session factory.
- */
- public void setParent(Object component, Object parent, SessionFactoryImplementor factory);
-
- /**
- * Does the component managed by this tuuplizer contain a parent property?
- *
- * @return True if the component does contain a parent property; false otherwise.
- */
- public boolean hasParentProperty();
-
- /**
- * Is the given method available via the managed component as a property getter?
- *
- * @param method The method which to check against the managed component.
- * @return True if the managed component is available from the managed component; else false.
- */
- public boolean isMethodOf(Method method);
-}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/Dom4jComponentTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/Dom4jComponentTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/Dom4jComponentTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,42 +0,0 @@
-//$Id$
-package org.hibernate.tuple;
-
-import org.dom4j.Element;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Property;
-import org.hibernate.property.Getter;
-import org.hibernate.property.PropertyAccessor;
-import org.hibernate.property.PropertyAccessorFactory;
-import org.hibernate.property.Setter;
-
-/**
- * @author Gavin King
- */
-public class Dom4jComponentTuplizer extends AbstractComponentTuplizer {
-
- public Class getMappedClass() {
- return Element.class;
- }
-
- public Dom4jComponentTuplizer(Component component) {
- super(component);
- }
-
- protected Instantiator buildInstantiator(Component component) {
- return new Dom4jInstantiator( component );
- }
-
- private PropertyAccessor buildPropertyAccessor(Property property) {
- //TODO: currently we don't know a SessionFactory reference when building the Tuplizer
- // THIS IS A BUG (embedded-xml=false on component)
- return PropertyAccessorFactory.getDom4jPropertyAccessor( property.getNodeName(), property.getType(), null );
- }
-
- protected Getter buildGetter(Component component, Property prop) {
- return buildPropertyAccessor(prop).getGetter( null, prop.getName() );
- }
- protected Setter buildSetter(Component component, Property prop) {
- return buildPropertyAccessor(prop).getSetter( null, prop.getName() );
- }
-
-}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/Dom4jEntityTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/Dom4jEntityTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/Dom4jEntityTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,120 +0,0 @@
-// $Id$
-package org.hibernate.tuple;
-
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-import org.hibernate.proxy.ProxyFactory;
-import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.proxy.dom4j.Dom4jProxyFactory;
-import org.hibernate.property.PropertyAccessor;
-import org.hibernate.property.PropertyAccessorFactory;
-import org.hibernate.property.Getter;
-import org.hibernate.property.Setter;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.type.AbstractComponentType;
-import org.dom4j.Element;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Iterator;
-
-/**
- * Implementation of Dom4jEntityTuplizer.
- *
- * @author Steve Ebersole
- */
-public class Dom4jEntityTuplizer extends AbstractEntityTuplizer {
-
- static final Log log = LogFactory.getLog( Dom4jEntityTuplizer.class );
-
- private Set subclassNodeNames = new HashSet();
-
- Dom4jEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
- super(entityMetamodel, mappedEntity);
- Iterator itr = mappedEntity.getSubclassClosureIterator();
- while( itr.hasNext() ) {
- final PersistentClass mapping = ( PersistentClass ) itr.next();
- subclassNodeNames.add( mapping.getNodeName() );
- }
- }
-
- public EntityMode getEntityMode() {
- return EntityMode.DOM4J;
- }
-
- private PropertyAccessor buildPropertyAccessor(Property mappedProperty) {
- if ( mappedProperty.isBackRef() ) {
- return mappedProperty.getPropertyAccessor(null);
- }
- else {
- return PropertyAccessorFactory.getDom4jPropertyAccessor(
- mappedProperty.getNodeName(),
- mappedProperty.getType(),
- getEntityMetamodel().getSessionFactory()
- );
- }
- }
-
- protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
- return buildPropertyAccessor(mappedProperty).getGetter( null, mappedProperty.getName() );
- }
-
- protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
- return buildPropertyAccessor(mappedProperty).getSetter( null, mappedProperty.getName() );
- }
-
- protected Instantiator buildInstantiator(PersistentClass persistentClass) {
- return new Dom4jInstantiator( persistentClass );
- }
-
- public Serializable getIdentifier(Object entityOrId) throws HibernateException {
- if (entityOrId instanceof Element) {
- return super.getIdentifier(entityOrId);
- }
- else {
- //it was not embedded, so the argument is just an id
- return (Serializable) entityOrId;
- }
- }
-
- protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {
- HashSet proxyInterfaces = new HashSet();
- proxyInterfaces.add( HibernateProxy.class );
- proxyInterfaces.add( Element.class );
-
- ProxyFactory pf = new Dom4jProxyFactory();
- try {
- pf.postInstantiate(
- getEntityName(),
- Element.class,
- proxyInterfaces,
- null,
- null,
- mappingInfo.hasEmbeddedIdentifier() ?
- (AbstractComponentType) mappingInfo.getIdentifier().getType() :
- null
- );
- }
- catch ( HibernateException he ) {
- log.warn( "could not create proxy factory for:" + getEntityName(), he );
- pf = null;
- }
- return pf;
- }
-
- public Class getMappedClass() {
- return Element.class;
- }
-
- public Class getConcreteProxyClass() {
- return Element.class;
- }
-
- public boolean isInstrumented() {
- return false;
- }
-}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapComponentTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapComponentTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapComponentTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,42 +0,0 @@
-//$Id$
-package org.hibernate.tuple;
-
-import java.util.Map;
-
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Property;
-import org.hibernate.property.Getter;
-import org.hibernate.property.PropertyAccessor;
-import org.hibernate.property.PropertyAccessorFactory;
-import org.hibernate.property.Setter;
-
-/**
- * @author Gavin King
- */
-public class DynamicMapComponentTuplizer extends AbstractComponentTuplizer {
-
- public Class getMappedClass() {
- return Map.class;
- }
-
- protected Instantiator buildInstantiator(Component component) {
- return new DynamicMapInstantiator();
- }
-
- public DynamicMapComponentTuplizer(Component component) {
- super(component);
- }
-
- private PropertyAccessor buildPropertyAccessor(Property property) {
- return PropertyAccessorFactory.getDynamicMapPropertyAccessor();
- }
-
- protected Getter buildGetter(Component component, Property prop) {
- return buildPropertyAccessor(prop).getGetter( null, prop.getName() );
- }
-
- protected Setter buildSetter(Component component, Property prop) {
- return buildPropertyAccessor(prop).getSetter( null, prop.getName() );
- }
-
-}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapEntityTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapEntityTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/DynamicMapEntityTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,89 +0,0 @@
-// $Id$
-package org.hibernate.tuple;
-
-import java.util.Map;
-
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-import org.hibernate.property.Getter;
-import org.hibernate.property.PropertyAccessor;
-import org.hibernate.property.PropertyAccessorFactory;
-import org.hibernate.property.Setter;
-import org.hibernate.proxy.map.MapProxyFactory;
-import org.hibernate.proxy.ProxyFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Implementation of DynamicMapEntityTuplizer.
- *
- * @author Steve Ebersole
- */
-public class DynamicMapEntityTuplizer extends AbstractEntityTuplizer {
-
- static final Log log = LogFactory.getLog( DynamicMapEntityTuplizer.class );
-
- DynamicMapEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
- super(entityMetamodel, mappedEntity);
- }
-
- public EntityMode getEntityMode() {
- return EntityMode.MAP;
- }
-
- private PropertyAccessor buildPropertyAccessor(Property mappedProperty) {
- if ( mappedProperty.isBackRef() ) {
- return mappedProperty.getPropertyAccessor(null);
- }
- else {
- return PropertyAccessorFactory.getDynamicMapPropertyAccessor();
- }
- }
-
- protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
- return buildPropertyAccessor(mappedProperty).getGetter( null, mappedProperty.getName() );
- }
-
- protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
- return buildPropertyAccessor(mappedProperty).getSetter( null, mappedProperty.getName() );
- }
-
- protected Instantiator buildInstantiator(PersistentClass mappingInfo) {
- return new DynamicMapInstantiator( mappingInfo );
- }
-
- protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {
-
- ProxyFactory pf = new MapProxyFactory();
- try {
- //TODO: design new lifecycle for ProxyFactory
- pf.postInstantiate(
- getEntityName(),
- null,
- null,
- null,
- null,
- null
- );
- }
- catch ( HibernateException he ) {
- log.warn( "could not create proxy factory for:" + getEntityName(), he );
- pf = null;
- }
- return pf;
- }
-
- public Class getMappedClass() {
- return Map.class;
- }
-
- public Class getConcreteProxyClass() {
- return Map.class;
- }
-
- public boolean isInstrumented() {
- return false;
- }
-}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/EntityMetamodel.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/EntityMetamodel.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/EntityMetamodel.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,481 +0,0 @@
-// $Id$
-package org.hibernate.tuple;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.intercept.FieldInterceptionHelper;
-import org.hibernate.engine.CascadeStyle;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.engine.Versioning;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-import org.hibernate.type.AbstractComponentType;
-import org.hibernate.type.AssociationType;
-import org.hibernate.type.EntityType;
-import org.hibernate.type.Type;
-import org.hibernate.type.TypeFactory;
-import org.hibernate.util.ArrayHelper;
-import org.hibernate.util.ReflectHelper;
-
-/**
- * Centralizes metamodel information about an entity.
- *
- * @author Steve Ebersole
- */
-public class EntityMetamodel implements Serializable {
-
- private static final Log log = LogFactory.getLog(EntityMetamodel.class);
-
- private static final int NO_VERSION_INDX = -66;
-
- private final SessionFactoryImplementor sessionFactory;
-
- private final String name;
- private final String rootName;
- private final EntityType entityType;
-
- private final IdentifierProperty identifierProperty;
- private final boolean versioned;
-
- private final int propertySpan;
- private final int versionPropertyIndex;
- private final StandardProperty[] properties;
- // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- private final String[] propertyNames;
- private final Type[] propertyTypes;
- private final boolean[] propertyLaziness;
- private final boolean[] propertyUpdateability;
- private final boolean[] nonlazyPropertyUpdateability;
- private final boolean[] propertyCheckability;
- private final boolean[] propertyInsertability;
- private final boolean[] propertyInsertGeneration;
- private final boolean[] propertyUpdateGeneration;
- private final boolean[] propertyNullability;
- private final boolean[] propertyVersionability;
- private final CascadeStyle[] cascadeStyles;
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- private final Map propertyIndexes = new HashMap();
- private final boolean hasCollections;
- private final boolean hasMutableProperties;
- private final boolean hasLazyProperties;
-
- private final int[] naturalIdPropertyNumbers;
-
- private final boolean lazy;
- private final boolean hasCascades;
- private final boolean mutable;
- private final boolean isAbstract;
- private final boolean selectBeforeUpdate;
- private final boolean dynamicUpdate;
- private final boolean dynamicInsert;
- private final int optimisticLockMode;
-
- private final boolean polymorphic;
- private final String superclass; // superclass entity-name
- private final boolean explicitPolymorphism;
- private final boolean inherited;
- private final boolean hasSubclasses;
- private final Set subclassEntityNames = new HashSet();
-
- private final TuplizerLookup tuplizers;
-
- public EntityTuplizer getTuplizer(EntityMode entityMode) {
- return (EntityTuplizer) tuplizers.getTuplizer(entityMode);
- }
-
- public EntityTuplizer getTuplizerOrNull(EntityMode entityMode) {
- return (EntityTuplizer) tuplizers.getTuplizerOrNull(entityMode);
- }
-
- public EntityMode guessEntityMode(Object object) {
- return tuplizers.guessEntityMode(object);
- }
-
- public EntityMetamodel(PersistentClass persistentClass, SessionFactoryImplementor sessionFactory) {
- this.sessionFactory = sessionFactory;
-
- name = persistentClass.getEntityName();
- rootName = persistentClass.getRootClass().getEntityName();
- entityType = TypeFactory.manyToOne( name );
-
- identifierProperty = PropertyFactory.buildIdentifierProperty(
- persistentClass,
- sessionFactory.getIdentifierGenerator( rootName )
- );
-
- versioned = persistentClass.isVersioned();
-
- boolean lazyAvailable = persistentClass.hasPojoRepresentation() &&
- FieldInterceptionHelper.isInstrumented( persistentClass.getMappedClass() );
- boolean hasLazy = false;
-
- propertySpan = persistentClass.getPropertyClosureSpan();
- properties = new StandardProperty[propertySpan];
- List naturalIdNumbers = new ArrayList();
- // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- propertyNames = new String[propertySpan];
- propertyTypes = new Type[propertySpan];
- propertyUpdateability = new boolean[propertySpan];
- propertyInsertability = new boolean[propertySpan];
- propertyInsertGeneration = new boolean[propertySpan];
- propertyUpdateGeneration = new boolean[propertySpan];
- nonlazyPropertyUpdateability = new boolean[propertySpan];
- propertyCheckability = new boolean[propertySpan];
- propertyNullability = new boolean[propertySpan];
- propertyVersionability = new boolean[propertySpan];
- propertyLaziness = new boolean[propertySpan];
- cascadeStyles = new CascadeStyle[propertySpan];
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
- Iterator iter = persistentClass.getPropertyClosureIterator();
- int i = 0;
- int tempVersionProperty = NO_VERSION_INDX;
- boolean foundCascade = false;
- boolean foundCollection = false;
- boolean foundMutable = false;
-
- while ( iter.hasNext() ) {
- Property prop = ( Property ) iter.next();
-
- if ( prop == persistentClass.getVersion() ) {
- tempVersionProperty = i;
- properties[i] = PropertyFactory.buildVersionProperty( prop, lazyAvailable );
- }
- else {
- properties[i] = PropertyFactory.buildStandardProperty( prop, lazyAvailable );
- }
-
- if ( prop.isNaturalIdentifier() ) {
- naturalIdNumbers.add( new Integer(i) );
- }
-
- // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- boolean lazy = prop.isLazy() && lazyAvailable;
- if ( lazy ) hasLazy = true;
- propertyLaziness[i] = lazy;
-
- propertyNames[i] = properties[i].getName();
- propertyTypes[i] = properties[i].getType();
- propertyNullability[i] = properties[i].isNullable();
- propertyUpdateability[i] = properties[i].isUpdateable();
- propertyInsertability[i] = properties[i].isInsertable();
- propertyInsertGeneration[i] = properties[i].isInsertGenerated();
- propertyUpdateGeneration[i] = properties[i].isUpdateGenerated();
- propertyVersionability[i] = properties[i].isVersionable();
- nonlazyPropertyUpdateability[i] = properties[i].isUpdateable() && !lazy;
- propertyCheckability[i] = propertyUpdateability[i] ||
- ( propertyTypes[i].isAssociationType() && ( (AssociationType) propertyTypes[i] ).isAlwaysDirtyChecked() );
-
- cascadeStyles[i] = properties[i].getCascadeStyle();
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- if ( properties[i].isLazy() ) {
- hasLazy = true;
- }
-
- if ( properties[i].getCascadeStyle() != CascadeStyle.NONE ) {
- foundCascade = true;
- }
-
- if ( indicatesCollection( properties[i].getType() ) ) {
- foundCollection = true;
- }
-
- if ( propertyTypes[i].isMutable() && propertyCheckability[i] ) {
- foundMutable = true;
- }
-
- mapPropertyToIndex(prop, i);
- i++;
- }
-
- if (naturalIdNumbers.size()==0) {
- naturalIdPropertyNumbers = null;
- }
- else {
- naturalIdPropertyNumbers = ArrayHelper.toIntArray(naturalIdNumbers);
- }
-
- hasCascades = foundCascade;
- versionPropertyIndex = tempVersionProperty;
- hasLazyProperties = hasLazy;
- if (hasLazyProperties) log.info("lazy property fetching available for: " + name);
-
- lazy = persistentClass.isLazy() && (
- // TODO: this disables laziness even in non-pojo entity modes:
- !persistentClass.hasPojoRepresentation() ||
- !ReflectHelper.isFinalClass( persistentClass.getProxyInterface() )
- );
- mutable = persistentClass.isMutable();
- if ( persistentClass.isAbstract() == null ) {
- // legacy behavior (with no abstract attribute specified)
- isAbstract = persistentClass.hasPojoRepresentation() &&
- ReflectHelper.isAbstractClass( persistentClass.getMappedClass() );
- }
- else {
- isAbstract = persistentClass.isAbstract().booleanValue();
- if ( !isAbstract && persistentClass.hasPojoRepresentation() &&
- ReflectHelper.isAbstractClass( persistentClass.getMappedClass() ) ) {
- log.warn( "entity [" + name + "] is abstract-class/interface explicitly mapped as non-abstract; be sure to supply entity-names" );
- }
- }
- selectBeforeUpdate = persistentClass.hasSelectBeforeUpdate();
- dynamicUpdate = persistentClass.useDynamicUpdate();
- dynamicInsert = persistentClass.useDynamicInsert();
-
- polymorphic = persistentClass.isPolymorphic();
- explicitPolymorphism = persistentClass.isExplicitPolymorphism();
- inherited = persistentClass.isInherited();
- superclass = inherited ?
- persistentClass.getSuperclass().getEntityName() :
- null;
- hasSubclasses = persistentClass.hasSubclasses();
-
- optimisticLockMode = persistentClass.getOptimisticLockMode();
- if ( optimisticLockMode > Versioning.OPTIMISTIC_LOCK_VERSION && !dynamicUpdate ) {
- throw new MappingException( "optimistic-lock setting requires dynamic-update=\"true\": " + name );
- }
-
- hasCollections = foundCollection;
- hasMutableProperties = foundMutable;
-
- tuplizers = TuplizerLookup.create(persistentClass, this);
-
- iter = persistentClass.getSubclassIterator();
- while ( iter.hasNext() ) {
- subclassEntityNames.add( ( (PersistentClass) iter.next() ).getEntityName() );
- }
- subclassEntityNames.add( name );
-
- }
-
- private void mapPropertyToIndex(Property prop, int i) {
- propertyIndexes.put( prop.getName(), new Integer(i) );
- if ( prop.getValue() instanceof Component ) {
- Iterator iter = ( (Component) prop.getValue() ).getPropertyIterator();
- while ( iter.hasNext() ) {
- Property subprop = (Property) iter.next();
- propertyIndexes.put(
- prop.getName() + '.' + subprop.getName(),
- new Integer(i)
- );
- }
- }
- }
-
- public int[] getNaturalIdentifierProperties() {
- return naturalIdPropertyNumbers;
- }
-
- public boolean hasNaturalIdentifier() {
- return naturalIdPropertyNumbers!=null;
- }
-
- public Set getSubclassEntityNames() {
- return subclassEntityNames;
- }
-
- private boolean indicatesCollection(Type type) {
- if ( type.isCollectionType() ) {
- return true;
- }
- else if ( type.isComponentType() ) {
- Type[] subtypes = ( ( AbstractComponentType ) type ).getSubtypes();
- for ( int i = 0; i < subtypes.length; i++ ) {
- if ( indicatesCollection( subtypes[i] ) ) {
- return true;
- }
- }
- }
- return false;
- }
-
- public SessionFactoryImplementor getSessionFactory() {
- return sessionFactory;
- }
-
- public String getName() {
- return name;
- }
-
- public String getRootName() {
- return rootName;
- }
-
- public EntityType getEntityType() {
- return entityType;
- }
-
- public IdentifierProperty getIdentifierProperty() {
- return identifierProperty;
- }
-
- public int getPropertySpan() {
- return propertySpan;
- }
-
- public int getVersionPropertyIndex() {
- return versionPropertyIndex;
- }
-
- public VersionProperty getVersionProperty() {
- if ( NO_VERSION_INDX == versionPropertyIndex ) {
- return null;
- }
- else {
- return ( VersionProperty ) properties[ versionPropertyIndex ];
- }
- }
-
- public StandardProperty[] getProperties() {
- return properties;
- }
-
- public int getPropertyIndex(String propertyName) {
- Integer index = getPropertyIndexOrNull(propertyName);
- if ( index == null ) {
- throw new HibernateException("Unable to resolve property: " + propertyName);
- }
- return index.intValue();
- }
-
- public Integer getPropertyIndexOrNull(String propertyName) {
- return (Integer) propertyIndexes.get( propertyName );
- }
-
- public boolean hasCollections() {
- return hasCollections;
- }
-
- public boolean hasMutableProperties() {
- return hasMutableProperties;
- }
-
- public boolean hasLazyProperties() {
- return hasLazyProperties;
- }
-
- public boolean hasCascades() {
- return hasCascades;
- }
-
- public boolean isMutable() {
- return mutable;
- }
-
- public boolean isSelectBeforeUpdate() {
- return selectBeforeUpdate;
- }
-
- public boolean isDynamicUpdate() {
- return dynamicUpdate;
- }
-
- public boolean isDynamicInsert() {
- return dynamicInsert;
- }
-
- public int getOptimisticLockMode() {
- return optimisticLockMode;
- }
-
- public boolean isPolymorphic() {
- return polymorphic;
- }
-
- public String getSuperclass() {
- return superclass;
- }
-
- public boolean isExplicitPolymorphism() {
- return explicitPolymorphism;
- }
-
- public boolean isInherited() {
- return inherited;
- }
-
- public boolean hasSubclasses() {
- return hasSubclasses;
- }
-
- public boolean isLazy() {
- return lazy;
- }
-
- public boolean isVersioned() {
- return versioned;
- }
-
- public boolean isAbstract() {
- return isAbstract;
- }
-
- public String toString() {
- return "EntityMetamodel(" + name + ':' + ArrayHelper.toString(properties) + ')';
- }
-
- // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public String[] getPropertyNames() {
- return propertyNames;
- }
-
- public Type[] getPropertyTypes() {
- return propertyTypes;
- }
-
- public boolean[] getPropertyLaziness() {
- return propertyLaziness;
- }
-
- public boolean[] getPropertyUpdateability() {
- return propertyUpdateability;
- }
-
- public boolean[] getPropertyCheckability() {
- return propertyCheckability;
- }
-
- public boolean[] getNonlazyPropertyUpdateability() {
- return nonlazyPropertyUpdateability;
- }
-
- public boolean[] getPropertyInsertability() {
- return propertyInsertability;
- }
-
- public boolean[] getPropertyInsertGeneration() {
- return propertyInsertGeneration;
- }
-
- public boolean[] getPropertyUpdateGeneration() {
- return propertyUpdateGeneration;
- }
-
- public boolean[] getPropertyNullability() {
- return propertyNullability;
- }
-
- public boolean[] getPropertyVersionability() {
- return propertyVersionability;
- }
-
- public CascadeStyle[] getCascadeStyles() {
- return cascadeStyles;
- }
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-}
Added: trunk/Hibernate3/src/org/hibernate/tuple/EntityModeToTuplizerMapping.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/EntityModeToTuplizerMapping.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/EntityModeToTuplizerMapping.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -0,0 +1,72 @@
+package org.hibernate.tuple;
+
+import org.apache.commons.collections.SequencedHashMap;
+
+import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+
+import java.util.Map;
+import java.util.Collections;
+import java.util.Iterator;
+import java.io.Serializable;
+
+/**
+ * Centralizes handling of {@link EntityMode} to {@link Tuplizer} mappings.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class EntityModeToTuplizerMapping implements Serializable {
+
+ // map of EntityMode -> Tuplizer
+ private final Map tuplizers = Collections.synchronizedMap( new SequencedHashMap() );
+
+ protected void addTuplizer(EntityMode entityMode, Tuplizer tuplizer) {
+ tuplizers.put( entityMode, tuplizer );
+ }
+
+ /**
+ * Given a supposed instance of an entity/component, guess its entity mode.
+ *
+ * @param object The supposed instance of the entity/component.
+ * @return The guessed entity mode.
+ */
+ public EntityMode guessEntityMode(Object object) {
+ Iterator itr = tuplizers.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry entry = ( Map.Entry ) itr.next();
+ Tuplizer tuplizer = ( Tuplizer ) entry.getValue();
+ if ( tuplizer.isInstance( object ) ) {
+ return ( EntityMode ) entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Locate the contained tuplizer responsible for the given entity-mode. If
+ * no such tuplizer is defined on this mapping, then return null.
+ *
+ * @param entityMode The entity-mode for which the caller wants a tuplizer.
+ * @return The tuplizer, or null if not found.
+ */
+ public Tuplizer getTuplizerOrNull(EntityMode entityMode) {
+ return ( Tuplizer ) tuplizers.get( entityMode );
+ }
+
+ /**
+ * Locate the tuplizer contained within this mapping which is responsible
+ * for the given entity-mode. If no such tuplizer is defined on this
+ * mapping, then an exception is thrown.
+ *
+ * @param entityMode The entity-mode for which the caller wants a tuplizer.
+ * @return The tuplizer.
+ * @throws HibernateException Unable to locate the requested tuplizer.
+ */
+ public Tuplizer getTuplizer(EntityMode entityMode) {
+ Tuplizer tuplizer = getTuplizerOrNull( entityMode );
+ if ( tuplizer == null ) {
+ throw new HibernateException( "No tuplizer found for entity-mode [" + entityMode + "]");
+ }
+ return tuplizer;
+ }
+}
Deleted: trunk/Hibernate3/src/org/hibernate/tuple/EntityTuplizer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/tuple/EntityTuplizer.java 2006-07-13 21:38:41 UTC (rev 10118)
+++ trunk/Hibernate3/src/org/hibernate/tuple/EntityTuplizer.java 2006-07-14 00:09:19 UTC (rev 10119)
@@ -1,176 +0,0 @@
-//$Id$
-package org.hibernate.tuple;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import org.hibernate.HibernateException;
-import org.hibernate.engine.SessionImplementor;
-
-/**
- * Defines further responsibilities reagarding tuplization based on
- * a mapped entity.
- * <p/>
- * EntityTuplizer implementations should have the following constructor signature:
- * (org.hibernate.tuple.EntityMetamodel, org.hibernate.mapping.PersistentClass)
- *
- * @author Gavin King
- */
-public interface EntityTuplizer extends Tuplizer {
-
- /**
- * Create an entity instance initialized with the given identifier.
- *
- * @param id The identifier value for the entity to be instantiated.
- * @return The instantiated entity.
- * @throws HibernateException
- */
- public Object instantiate(Serializable id) throws HibernateException;
-
- /**
- * Extract the ide...
[truncated message content] |