You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/04/11 08:20:00 UTC
svn commit: r527396 - in
/incubator/openejb/trunk/openejb3/container/openejb-core/src:
main/java/org/apache/openejb/config/CmpJpaConversion.java
test/resources/convert/oej2/cmp/itest-2.2/itest-2.2-orm.xml
Author: dain
Date: Tue Apr 10 23:19:59 2007
New Revision: 527396
URL: http://svn.apache.org/viewvc?view=rev&rev=527396
Log:
Avoid creating duplicate mapped superclass and entity entries
Modified:
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/test/resources/convert/oej2/cmp/itest-2.2/itest-2.2-orm.xml
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java?view=diff&rev=527396&r1=527395&r2=527396
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java Tue Apr 10 23:19:59 2007
@@ -58,18 +58,34 @@
import org.apache.openejb.jee.jpa.unit.TransactionType;
import org.apache.openejb.jee.jpa.unit.Properties;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Arrays;
+import java.util.TreeMap;
import java.lang.reflect.Modifier;
public class CmpJpaConversion implements DynamicDeployer {
private static final String CMP_PERSISTENCE_UNIT_NAME = "cmp";
+ private static final Set<String> ENHANCEED_FIELDS = Collections.unmodifiableSet(new TreeSet<String>(Arrays.asList(
+ "pcInheritedFieldCount",
+ "pcFieldNames",
+ "pcFieldTypes",
+ "pcFieldFlags",
+ "pcPCSuperclass",
+ "pcStateManager",
+ "class$Ljava$lang$String",
+ "class$Ljava$lang$Integer",
+ "class$Lcom$sun$ts$tests$common$ejb$wrappers$CMP11Wrapper",
+ "pcDetachedState",
+ "serialVersionUID"
+ )));
+
public AppModule deploy(AppModule appModule) throws OpenEJBException {
// search for the cmp persistence unit
PersistenceUnit persistenceUnit = null;
@@ -143,7 +159,16 @@
OpenejbJar openejbJar = ejbModule.getOpenejbJar();
ClassLoader classLoader = ejbModule.getClassLoader();
- Map<String, Entity> entitiesByName = new HashMap<String,Entity>();
+ Map<String, MappedSuperclass> mappedSuperclassByClass = new TreeMap<String,MappedSuperclass>();
+ for (MappedSuperclass mappedSuperclass : entityMappings.getMappedSuperclass()) {
+ mappedSuperclassByClass.put(mappedSuperclass.getClazz(), mappedSuperclass);
+ }
+
+ Map<String, Entity> entitiesByName = new TreeMap<String,Entity>();
+ for (Entity entity : entityMappings.getEntity()) {
+ entitiesByName.put(entity.getName(), entity);
+ }
+
for (org.apache.openejb.jee.EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
// skip all non-CMP beans
if (!(enterpriseBean instanceof EntityBean) ||
@@ -155,6 +180,13 @@
// Always set the abstract schema name
if (bean.getAbstractSchemaName() == null) {
String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");
+ if (entitiesByName.containsKey(abstractSchemaName)) {
+ int i = 2;
+ while (entitiesByName.containsKey(abstractSchemaName + i)) {
+ i++;
+ }
+ abstractSchemaName = abstractSchemaName + i;
+ }
bean.setAbstractSchemaName(abstractSchemaName);
}
@@ -187,7 +219,9 @@
} else {
// map the cmp class, but if we are using a mapped super class, generate attribute-override instead of id and basic
Collection<MappedSuperclass> mappedSuperclasses = mapClass1x(bean.getEjbClass(), entity, bean, classLoader);
- entityMappings.getMappedSuperclass().addAll(mappedSuperclasses);
+ for (MappedSuperclass mappedSuperclass : mappedSuperclasses) {
+ mappedSuperclassByClass.put(mappedSuperclass.getClazz(), mappedSuperclass);
+ }
}
// process queries
@@ -240,6 +274,7 @@
}
}
}
+ entityMappings.getMappedSuperclass().addAll(mappedSuperclassByClass.values());
Relationships relationships = ejbJar.getRelationships();
if (relationships != null) {
@@ -533,7 +568,7 @@
private Map<String, MappedSuperclass> mapFields(Class clazz, Set<String> persistantFields) {
persistantFields = new TreeSet<String>(persistantFields);
- Map<String,MappedSuperclass> fields = new HashMap<String,MappedSuperclass>();
+ Map<String,MappedSuperclass> fields = new TreeMap<String,MappedSuperclass>();
while (!persistantFields.isEmpty() && !clazz.equals(Object.class)) {
MappedSuperclass superclass = new MappedSuperclass(clazz.getName());
@@ -542,8 +577,8 @@
if (persistantFields.contains(fieldName)) {
fields.put(fieldName, superclass);
persistantFields.remove(fieldName);
- } else {
- Transient transientField = new Transient(field.getName());
+ } else if (!ENHANCEED_FIELDS.contains(fieldName)){
+ Transient transientField = new Transient(fieldName);
superclass.addField(transientField);
}
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/resources/convert/oej2/cmp/itest-2.2/itest-2.2-orm.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/resources/convert/oej2/cmp/itest-2.2/itest-2.2-orm.xml?view=diff&rev=527396&r1=527395&r2=527396
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/resources/convert/oej2/cmp/itest-2.2/itest-2.2-orm.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/resources/convert/oej2/cmp/itest-2.2/itest-2.2-orm.xml Tue Apr 10 23:19:59 2007
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
- <mapped-superclass class="org.apache.openejb.test.entity.cmp.BasicCmpBean">
+ <mapped-superclass class="org.apache.openejb.test.entity.cmp.AllowedOperationsCmpBean">
<attributes>
<id name="primaryKey"/>
<basic name="firstName"/>
<basic name="lastName"/>
<transient name="nextId"/>
+ <transient name="number"/>
<transient name="ejbContext"/>
<transient name="allowedOperationsTable"/>
</attributes>
@@ -16,17 +17,6 @@
<basic name="firstName"/>
<basic name="lastName"/>
<transient name="nextId"/>
- <transient name="ejbContext"/>
- <transient name="allowedOperationsTable"/>
- </attributes>
- </mapped-superclass>
- <mapped-superclass class="org.apache.openejb.test.entity.cmp.AllowedOperationsCmpBean">
- <attributes>
- <id name="primaryKey"/>
- <basic name="firstName"/>
- <basic name="lastName"/>
- <transient name="nextId"/>
- <transient name="number"/>
<transient name="ejbContext"/>
<transient name="allowedOperationsTable"/>
</attributes>