You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2009/07/17 19:27:04 UTC
svn commit: r795156 - in /openjpa/trunk/openjpa-persistence-jdbc/src:
main/ant/ test/java/org/apache/openjpa/persistence/property/
Author: jrbauer
Date: Fri Jul 17 17:27:04 2009
New Revision: 795156
URL: http://svn.apache.org/viewvc?rev=795156&view=rev
Log:
OPENJPA-1176 Committing test contributed by Tim McConnell. Tests the use of PrivatePersistentProperties compatibility option with private embeddable property.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EmbeddableAddress.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EntityContact.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IAddress.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IContact.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestCompatible.java (with props)
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml?rev=795156&r1=795155&r2=795156&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml Fri Jul 17 17:27:04 2009
@@ -81,6 +81,8 @@
<exclude name="**/AbstractUnenhanced*.class" />
<exclude name="**/unenhanced/*.class" />
<exclude name="**/persistence/property/PrivAccessModsEntity.class"/>
+ <exclude name="**/persistence/property/EntityContact.class"/>
+ <exclude name="**/persistence/property/EmbeddableAddress.class"/>
</fileset>
<openjpac>
<classpath refid="cp" />
@@ -105,6 +107,8 @@
<classpath refid="cp" />
<fileset dir="${project.build.testOutputDirectory}">
<include name="**/persistence/property/PrivAccessModsEntity.class"/>
+ <include name="**/persistence/property/EntityContact.class"/>
+ <include name="**/persistence/property/EmbeddableAddress.class"/>
</fileset>
<config log="DefaultLevel=${openjpa.loglevel}" />
</openjpac>
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EmbeddableAddress.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EmbeddableAddress.java?rev=795156&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EmbeddableAddress.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EmbeddableAddress.java Fri Jul 17 17:27:04 2009
@@ -0,0 +1,84 @@
+/*
+ * 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 agEmployee_Last_Name 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.property;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class EmbeddableAddress implements IAddress {
+
+ private String line1;
+ private String line2;
+ private String city;
+ private String state;
+ private String zipCode;
+ private String country;
+
+ public String getLine1() {
+ return line1;
+ }
+ public void setLine1(String line1) {
+ this.line1 = line1;
+ }
+
+ public String getLine2() {
+ return line2;
+ }
+ public void setLine2(String line2) {
+ this.line2 = line2;
+ }
+
+ 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;
+ }
+
+ public String getZipCode() {
+ return zipCode;
+ }
+ public void setZipCode(String zipCode) {
+ this.zipCode = zipCode;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String toString() {
+ return( "org.apache.openjpa.persistence.compatible.EmbeddableAddress: " +
+ " line1: " + getLine1() +
+ " line2: " + getLine2() +
+ " city: " + getCity() +
+ " state: " + getState() +
+ " zipCode: " + getZipCode() +
+ " country: " + getCountry() );
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EmbeddableAddress.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EntityContact.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EntityContact.java?rev=795156&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EntityContact.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EntityContact.java Fri Jul 17 17:27:04 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 agEmployee_Last_Name 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.property;
+
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+
+@Entity
+public class EntityContact implements IContact {
+
+ private String id;
+ private String email;
+ private String phone;
+ private String type;
+ private EmbeddableAddress theAddress;
+
+ @Transient
+ public IAddress getAddress() {
+ return(IAddress) this.getTheAddress();
+ }
+ public void setAddress(IAddress address) {
+ if (address instanceof EmbeddableAddress) {
+ this.setTheAddress((EmbeddableAddress)address);
+ }
+ else if (address == null) {
+ this.setTheAddress(null);
+ }
+ else {
+ throw new ClassCastException("Invalid Implementaion of IAddress. " +
+ "Class must be instance of org.apache.openjpa.persistence.compatible.EmbeddableAddress");
+ }
+ }
+
+ @Id
+ public String getId() {
+ return id;
+ }
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @Embedded
+ private EmbeddableAddress getTheAddress() {
+ return theAddress;
+ }
+ private void setTheAddress(EmbeddableAddress address) {
+ this.theAddress = address;
+ }
+
+ public String toString() {
+ return( "org.apache.openjpa.persistence.compatible.EntityContact: " +
+ " id: " + getId() +
+ " email: " + getEmail() +
+ " phone: " + getPhone() +
+ " type: " + getType() +
+ " address: " + getAddress() );
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/EntityContact.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IAddress.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IAddress.java?rev=795156&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IAddress.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IAddress.java Fri Jul 17 17:27:04 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 agEmployee_Last_Name 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.property;
+
+public interface IAddress {
+
+ public String getCity();
+ public void setCity(String city);
+
+ public String getCountry();
+ public void setCountry(String country);
+
+ public String getLine1();
+ public void setLine1(String line1);
+
+ public String getLine2();
+ public void setLine2(String line2);
+
+ public String getState();
+ public void setState(String state);
+
+ public String getZipCode();
+ public void setZipCode(String zipCode);
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IAddress.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IContact.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IContact.java?rev=795156&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IContact.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IContact.java Fri Jul 17 17:27:04 2009
@@ -0,0 +1,35 @@
+/*
+ * 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 agEmployee_Last_Name 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.property;
+
+public interface IContact {
+
+ public IAddress getAddress();
+ public void setAddress(IAddress address);
+
+ public String getEmail();
+ public void setEmail(String email);
+
+ public String getPhone();
+ public void setPhone(String phone);
+
+ public String getType();
+ public void setType(String type);
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/IContact.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestCompatible.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestCompatible.java?rev=795156&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestCompatible.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestCompatible.java Fri Jul 17 17:27:04 2009
@@ -0,0 +1,106 @@
+/*
+ * 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 agEmployee_Last_Name 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.property;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * <b>TestCompatibile</b> is used to test various backwards compatibility
+ * scenarios between JPA 2.0 and JPA 1.x.
+ *
+ * <p>The following scenarios are tested:
+ * <ol>
+ * <li>private persistent embeddable, which was valid in JPA 1.2 but no longer
+ * in JPA 2.x
+ * <li>TBD
+ * </ol>
+ * <p>
+ * <b>Note(s):</b>
+ * <ul>
+ * <li>N/A
+ * </ul>
+ */
+public class TestCompatible extends SingleEMFTestCase {
+
+ public void setUp() {
+ setUp(EntityContact.class,
+ EmbeddableAddress.class,
+ "openjpa.Compatibility", "PrivatePersistentProperties=true",
+ DROP_TABLES);
+ }
+
+ public void testPrivateEmbbeddable() {
+
+ EntityManager em = emf.createEntityManager();
+
+ //
+ // Create and persist the contact entity
+ //
+ EntityContact contactCreate = new EntityContact();
+ contactCreate.setId("Contact id");
+ contactCreate.setEmail("Contact email address");
+ contactCreate.setPhone("Contact phone number");
+ contactCreate.setType("HOME");
+ EmbeddableAddress address = new EmbeddableAddress();
+ address.setLine1("Address line 1");
+ address.setLine2("Address line 2");
+ address.setCity("Address city");
+ address.setState("Address state");
+ address.setZipCode("Address zipcode");
+ address.setCountry("Address country");
+ contactCreate.setAddress(address);
+
+ em.getTransaction().begin();
+ em.persist(contactCreate);
+ em.getTransaction().commit();
+
+ em.clear();
+ em.close();
+
+ //
+ // Find and verify the contact entity
+ //
+ em = emf.createEntityManager();
+ EntityContact contactFind = em.find(EntityContact.class, "Contact id");
+ assertTrue(contactFind != null);
+ assertTrue(contactFind.getId().equals("Contact id"));
+ assertTrue(contactFind.getEmail().equals("Contact email address"));
+ assertTrue(contactFind.getPhone().equals("Contact phone number"));
+ assertTrue(contactFind.getType().equals("HOME"));
+ assertTrue(contactFind.getAddress() != null);
+ assertTrue(contactFind.getAddress().getLine1().equals("Address line 1"));
+ assertTrue(contactFind.getAddress().getLine2().equals("Address line 2"));
+ assertTrue(contactFind.getAddress().getCity().equals("Address city"));
+ assertTrue(contactFind.getAddress().getState().equals("Address state"));
+ assertTrue(contactFind.getAddress().getZipCode().equals("Address zipcode"));
+ assertTrue(contactFind.getAddress().getCountry().equals("Address country"));
+
+ //
+ // Remove the contact entity
+ //
+ em.getTransaction().begin();
+ em.remove(contactFind);
+ em.getTransaction().commit();
+
+ em.clear();
+ em.close();
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestCompatible.java
------------------------------------------------------------------------------
svn:eol-style = native