openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r747239 - in /openjpa/trunk/openjpa-persistence-jdbc/src: main/java/org/apache/openjpa/persistence/jdbc/ test/java/org/apache/openjpa/persistence/embed/attrOverrides/ test/resources/org/apache/openjpa/persistence/embed/
Date Tue, 24 Feb 2009 00:39:49 GMT
Author: faywang
Date: Tue Feb 24 00:39:48 2009
New Revision: 747239

URL: http://svn.apache.org/viewvc?rev=747239&view=rev
Log:
OPENJPA-930: orm xml support for AttributeOverride

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/AddressXml.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/CustomerXml.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverridesXml.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/ZipcodeXml.java
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?rev=747239&r1=747238&r2=747239&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
Tue Feb 24 00:39:48 2009
@@ -1259,7 +1259,7 @@
         }
     }
     
-    private FieldMapping getEmbeddedFieldMapping(FieldMapping fm, String attrName) {
+    public static FieldMapping getEmbeddedFieldMapping(FieldMapping fm, String attrName)
{
         ClassMapping embed = null;
         boolean isKey = false;
         boolean isValue = false;
@@ -1300,7 +1300,7 @@
         return getAttributeOverrideField(attrName, fm, embed);
     }
     
-    private ClassMapping getEmbeddedMapping(ValueMapping val) {
+    public static ClassMapping getEmbeddedMapping(ValueMapping val) {
         ClassMapping embed = val.getEmbeddedMapping();
         if (embed != null) 
             return embed;
@@ -1310,7 +1310,7 @@
 
     }
     
-    public FieldMapping getAttributeOverrideField(String attrName, FieldMapping fm, ClassMapping
embed) {
+    public static FieldMapping getAttributeOverrideField(String attrName, FieldMapping fm,
ClassMapping embed) {
         FieldMapping efm;
         int idxOfDot = attrName.indexOf("."); 
         if (idxOfDot == -1) {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?rev=747239&r1=747238&r2=747239&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
Tue Feb 24 00:39:48 2009
@@ -42,6 +42,7 @@
 import org.apache.openjpa.jdbc.meta.MappingRepository;
 import org.apache.openjpa.jdbc.meta.QueryResultMapping;
 import org.apache.openjpa.jdbc.meta.SequenceMapping;
+import org.apache.openjpa.jdbc.meta.ValueMapping;
 import org.apache.openjpa.jdbc.meta.strats.EnumValueHandler;
 import org.apache.openjpa.jdbc.meta.strats.FlatClassStrategy;
 import org.apache.openjpa.jdbc.meta.strats.FullClassStrategy;
@@ -661,19 +662,10 @@
     /**
      * Return the proper override.
      */
-    private FieldMapping getAttributeOverride(FieldMapping fm)
-        throws SAXException {
-        ClassMapping embed = fm.getEmbeddedMapping();
-        if (embed == null) {
-            embed = fm.getElementMapping().getEmbeddedMapping();
-            if (embed == null)
-                throw getException(_loc.get("not-embedded", fm));
-        }
-        FieldMapping efm = embed.getFieldMapping(_override);
-        if (efm == null)
-            throw getException(_loc.get("embed-override-name",
-                fm, _override));
-        return efm;
+    private FieldMapping getAttributeOverride(FieldMapping fm) 
+    throws SAXException {
+        return AnnotationPersistenceMappingParser.getEmbeddedFieldMapping(fm, 
+            _override);
     }
 
     /**

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/AddressXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/AddressXml.java?rev=747239&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/AddressXml.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/AddressXml.java
Tue Feb 24 00:39:48 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.embed.attrOverrides;
+
+public class AddressXml {
+    protected String street;
+    protected String city;
+    protected String state;
+    protected ZipcodeXml zipcode;
+    
+    public String getStreet() {
+        return street;
+    }
+    
+    public void setStreet(String street) {
+        this.street = street;
+    }
+    
+    public String getCity() {
+        return city;
+    }
+    
+    public void setCity(String city) {
+        this.city = city;
+    }
+    
+    public String getState() {
+        return state;
+    }
+    
+    public void setState(String state) {
+        this.state = state;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/CustomerXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/CustomerXml.java?rev=747239&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/CustomerXml.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/CustomerXml.java
Tue Feb 24 00:39:48 2009
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.embed.attrOverrides;
+
+public class CustomerXml {
+    protected Integer id;
+    
+    protected String name;
+    
+    protected AddressXml address;
+    
+    public Integer getId() {
+    	return id;
+    }
+    
+    public void setId(Integer id) {
+    	this.id = id;
+    }
+    
+    public String getName() {
+    	return name;
+    }
+    
+    public void setName(String name) {
+    	this.name = name;
+    }
+    
+    public AddressXml getAddress() {
+    	return address;
+    }
+    
+    public void setAddress(AddressXml address) {
+    	this.address = address;
+    }
+}
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverridesXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverridesXml.java?rev=747239&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverridesXml.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/TestAttrOverridesXml.java
Tue Feb 24 00:39:48 2009
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.embed.attrOverrides;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import junit.framework.Assert;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestAttrOverridesXml extends SingleEMFTestCase {
+   
+    public int numPersons = 4;
+    public List<String> namedQueries = new ArrayList<String>();
+    public int eId = 1;
+    
+    public void setUp() {
+        setUp(CLEAR_TABLES);
+    }
+    
+    @Override
+    protected String getPersistenceUnitName() {
+        return "embed-pu";
+    }
+    
+    public void testAttrOverride1() {
+    	createObj1();
+    	findObj1();
+    	queryObj1();
+    }
+    
+    public void createObj1() {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        for (int i = 0; i < numPersons; i++)
+        	createCustomer1(em, eId++);
+        tran.begin();
+        em.flush();
+        tran.commit();
+        em.close();
+    }
+
+    public CustomerXml createCustomer1(EntityManager em, int id) {
+    	CustomerXml p = new CustomerXml();
+    	p.setId(id);
+    	AddressXml addr = new AddressXml();
+    	addr.setCity("city_" + id);
+    	addr.setState("state_" + id);
+    	addr.setStreet("street_" + id);
+    	p.setAddress(addr);
+    	p.setName("name_" + id);
+        em.persist(p);
+        return p;
+    }
+
+    public void findObj1() {
+        EntityManager em = emf.createEntityManager();
+        CustomerXml p = em.find(CustomerXml.class, 1);
+        Assert.assertEquals(p.getId(), new Integer(1));
+        Assert.assertEquals(p.getAddress().getCity(), "city_1");
+        Assert.assertEquals(p.getAddress().getStreet(), "street_1");
+        Assert.assertEquals(p.getAddress().getState(), "state_1");
+        Assert.assertEquals(p.getName(), "name_1");
+    }
+
+    public void queryObj1() {
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+        tran.begin();
+        String jpql = "select p from CustomerXml1 p";
+        Query q = em.createQuery(jpql);
+        List<CustomerXml> ps = q.getResultList();
+        Assert.assertEquals(ps.size(), numPersons);
+        tran.commit();
+        em.close();
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/ZipcodeXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/ZipcodeXml.java?rev=747239&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/ZipcodeXml.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/attrOverrides/ZipcodeXml.java
Tue Feb 24 00:39:48 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.embed.attrOverrides;
+
+public class ZipcodeXml {
+	protected String zip;
+	protected String plusFour;
+	
+	public String getZip() {
+		return zip;
+	}
+	
+	public void setZip(String zip) {
+		this.zip = zip;
+	}
+	
+	public String getPlusFour() {
+		return plusFour;
+	}
+	
+	public void setPlusFour(String plusFour) {
+		this.plusFour = plusFour;
+	}
+}

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml?rev=747239&r1=747238&r2=747239&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
Tue Feb 24 00:39:48 2009
@@ -149,6 +149,44 @@
 		</attributes>
 	</entity>
 
+    <entity name="CustomerXml1" 
+        class="org.apache.openjpa.persistence.embed.attrOverrides.CustomerXml" 
+        access="FIELD">
+        <attributes>
+            <id name="id"><column length="12"/></id>
+            <basic name="name"><column length="12"/></basic>
+            <embedded name="address">
+                <attribute-override name="state">
+                    <column name="ADDR_STATE" />
+                </attribute-override>
+                <attribute-override name="zipcode.zip">
+                    <column name="ADDR_ZIP" />
+                </attribute-override>
+            </embedded>
+        </attributes>
+    </entity>
+
+    <embeddable 
+        class="org.apache.openjpa.persistence.embed.attrOverrides.AddressXml" 
+        access="FIELD">
+        <attributes>
+            <basic name="street"><column length="12"/>
+            </basic>
+            <basic name="city"><column length="12"/></basic>
+            <basic name="state"><column length="12"/></basic>
+            <embedded name="zipcode"/>
+        </attributes>
+    </embeddable>
+
+    <embeddable 
+        class="org.apache.openjpa.persistence.embed.attrOverrides.ZipcodeXml" 
+        access="FIELD">
+        <attributes>
+            <basic name="zip"><column length="12"/></basic>
+            <basic name="plusFour"><column length="12"/></basic>
+        </attributes>
+    </embeddable>
+
 	<embeddable
 		class="org.apache.openjpa.persistence.embed.Embed_EmbedXml"
 		access="FIELD">



Mime
View raw message