[hibernate-commits] Hibernate SVN: r15408 - in core/branches/Branch_3_3: core/src/main/java/org/hibernate/tuple/entity and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Oct 27 17:28:22 EDT 2008


Author: steve.ebersole at jboss.com
Date: 2008-10-27 17:28:22 -0400 (Mon, 27 Oct 2008)
New Revision: 15408

Added:
   core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/
   core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/Mappings.hbm.xml
   core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/SubclassDynamicMapTest.java
Modified:
   core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
   core/branches/Branch_3_3/core/src/main/java/org/hibernate/tuple/entity/DynamicMapEntityTuplizer.java
Log:
HHH-3351 : dynamic map entity-persister and subclassing

Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java	2008-10-27 19:58:10 UTC (rev 15407)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java	2008-10-27 21:28:22 UTC (rev 15408)
@@ -3642,7 +3642,14 @@
 		else {
 			final String concreteEntityName = getTuplizer( entityMode )
 					.determineConcreteSubclassEntityName( instance, factory );
-			return factory.getEntityPersister( concreteEntityName );
+			if ( concreteEntityName == null || getEntityName().equals( concreteEntityName ) ) {
+				// the contract of EntityTuplizer.determineConcreteSubclassEntityName says that returning null
+				// is an indication that the specified entity-name (this.getEntityName) should be used.
+				return this;
+			}
+			else {
+				return factory.getEntityPersister( concreteEntityName );
+			}
 		}
 	}
 

Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/tuple/entity/DynamicMapEntityTuplizer.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/tuple/entity/DynamicMapEntityTuplizer.java	2008-10-27 19:58:10 UTC (rev 15407)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/tuple/entity/DynamicMapEntityTuplizer.java	2008-10-27 21:28:22 UTC (rev 15408)
@@ -20,7 +20,6 @@
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
- *
  */
 package org.hibernate.tuple.entity;
 
@@ -57,6 +56,9 @@
 		super(entityMetamodel, mappedEntity);
 	}
 	
+	/**
+	 * {@inheritDoc}
+	 */
 	public EntityMode getEntityMode() {
 		return EntityMode.MAP;
 	}
@@ -70,18 +72,30 @@
 		}
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
 		return buildPropertyAccessor(mappedProperty).getGetter( null, mappedProperty.getName() );
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
 		return buildPropertyAccessor(mappedProperty).getSetter( null, mappedProperty.getName() );
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	protected Instantiator buildInstantiator(PersistentClass mappingInfo) {
         return new DynamicMapInstantiator( mappingInfo );
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {
 
 		ProxyFactory pf = new MapProxyFactory();
@@ -103,24 +117,38 @@
 		return pf;
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public Class getMappedClass() {
 		return Map.class;
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public Class getConcreteProxyClass() {
 		return Map.class;
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public boolean isInstrumented() {
 		return false;
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public EntityNameResolver[] getEntityNameResolvers() {
 		return new EntityNameResolver[] { BasicEntityNameResolver.INSTANCE };
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
-		// TODO : do we need an explicit isInstance check here, or is that asserted prior to here?
 		return extractEmbeddedEntityName( ( Map ) entityInstance );
 	}
 
@@ -131,6 +159,9 @@
 	public static class BasicEntityNameResolver implements EntityNameResolver {
 		public static final BasicEntityNameResolver INSTANCE = new BasicEntityNameResolver();
 
+		/**
+		 * {@inheritDoc}
+		 */
 		public String resolveEntityName(Object entity) {
 			final String entityName = extractEmbeddedEntityName( ( Map ) entity );
 			if ( entityName == null ) {
@@ -139,10 +170,16 @@
 			return entityName;
 		}
 
+		/**
+		 * {@inheritDoc}
+		 */
 		public boolean equals(Object obj) {
 			return getClass().equals( obj.getClass() );
 		}
 
+		/**
+		 * {@inheritDoc}
+		 */
 		public int hashCode() {
 			return getClass().hashCode();
 		}

Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/Mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/Mappings.hbm.xml	                        (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/Mappings.hbm.xml	2008-10-27 21:28:22 UTC (rev 15408)
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ Hibernate, Relational Persistence for Idiomatic Java
+  ~
+  ~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+  ~ indicated by the @author tags or express copyright attribution
+  ~ statements applied by the authors.  All third-party contributions are
+  ~ distributed under license by Red Hat Middleware LLC.
+  ~
+  ~ This copyrighted material is made available to anyone wishing to use, modify,
+  ~ copy, or redistribute it subject to the terms and conditions of the GNU
+  ~ Lesser General Public License, as published by the Free Software Foundation.
+  ~
+  ~ This program is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  ~ or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+  ~ for more details.
+  ~
+  ~ You should have received a copy of the GNU Lesser General Public License
+  ~ along with this distribution; if not, write to:
+  ~ Free Software Foundation, Inc.
+  ~ 51 Franklin Street, Fifth Floor
+  ~ Boston, MA  02110-1301  USA
+  -->
+<!DOCTYPE hibernate-mapping PUBLIC
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+
+    <class entity-name="Superclass" discriminator-value="A">
+        <id name="id" type="integer"><generator class="native"/></id>
+        <discriminator column="DISC" type="string" />
+        <property name="dataA" type="string"/>
+
+        <subclass entity-name="Subclass" discriminator-value="B">
+            <property name="dataB" type="string"/>
+        </subclass>
+    </class>
+
+</hibernate-mapping>
\ No newline at end of file

Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/SubclassDynamicMapTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/SubclassDynamicMapTest.java	                        (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/entitymode/map/subclass/SubclassDynamicMapTest.java	2008-10-27 21:28:22 UTC (rev 15408)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.test.entitymode.map.subclass;
+
+import java.util.HashMap;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.Session;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class SubclassDynamicMapTest extends FunctionalTestCase {
+	public SubclassDynamicMapTest(String string) {
+		super( string );
+	}
+
+	public String[] getMappings() {
+		return new String[] { "entitymode/map/subclass/Mappings.hbm.xml" };
+	}
+
+	public void testConcreateSubclassDeterminationOnEmptyDynamicMap() {
+		Session s = openSession();
+		s.beginTransaction();
+		s.persist( "Superclass", new HashMap() );
+		s.getTransaction().commit();
+		s.close();
+
+		s = openSession();
+		s.beginTransaction();
+		s.createQuery( "delete Superclass" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+}




More information about the hibernate-commits mailing list