You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by di...@apache.org on 2012/04/30 19:15:19 UTC
svn commit: r1332299 - in
/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge:
Child.java ChildPK.java GrandChild.java GrandChildPK.java Parent.java
ParentPK.java TestMergeNew.java
Author: dianner
Date: Mon Apr 30 17:15:18 2012
New Revision: 1332299
URL: http://svn.apache.org/viewvc?rev=1332299&view=rev
Log:
OPENJPA-2142 - Add test cases
Added:
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Child.java (with props)
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ChildPK.java (with props)
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChild.java (with props)
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChildPK.java (with props)
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Parent.java (with props)
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ParentPK.java (with props)
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestMergeNew.java (with props)
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Child.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Child.java?rev=1332299&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Child.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Child.java Mon Apr 30 17:15:18 2012
@@ -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.merge;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+@Entity
+@IdClass(ChildPK.class)
+@Table(name = "MRG_CHILD")
+public class Child implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @JoinColumns({ @JoinColumn(name = "KEY_1", referencedColumnName = "KEY_1"),
+ @JoinColumn(name = "KEY_2", referencedColumnName = "KEY_2") })
+ @ManyToOne
+ private Parent parent;
+
+ @Id
+ @Column(name = "KEY_3")
+ private Integer childKey;
+
+ @OneToMany(mappedBy = "child", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ private Collection<GrandChild> grandChilds = new ArrayList<GrandChild>();
+
+ public Parent getParent() { return parent; }
+ public void setParent(Parent parent) { this.parent = parent; }
+ public Integer getChildKey() { return childKey; }
+ public void setChildKey(Integer childKey) { this.childKey = childKey; }
+ public Collection<GrandChild> getGrandChilds() { return grandChilds; }
+ public void setGrandChilds(Collection<GrandChild> grandChilds) { this.grandChilds = grandChilds; }
+@Override
+public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((childKey == null) ? 0 : childKey.hashCode());
+ result = prime * result
+ + ((grandChilds == null) ? 0 : grandChilds.hashCode());
+ result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+ return result;
+}
+@Override
+public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Child other = (Child) obj;
+ if (childKey == null) {
+ if (other.childKey != null)
+ return false;
+ } else if (!childKey.equals(other.childKey))
+ return false;
+ if (grandChilds == null) {
+ if (other.grandChilds != null)
+ return false;
+ } else if (!grandChilds.equals(other.grandChilds))
+ return false;
+ if (parent == null) {
+ if (other.parent != null)
+ return false;
+ } else if (!parent.equals(other.parent))
+ return false;
+ return true;
+}
+}
Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Child.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ChildPK.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ChildPK.java?rev=1332299&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ChildPK.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ChildPK.java Mon Apr 30 17:15:18 2012
@@ -0,0 +1,82 @@
+/*
+ * 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.merge;
+
+import java.io.Serializable;
+
+public class ChildPK implements Serializable{
+ private static final long serialVersionUID = 1L;
+
+ private ParentPK parent;
+
+ private Integer childKey;
+
+ public ParentPK getParent(){ return parent; }
+ public void setParent(ParentPK parent) { this.parent = parent; }
+ public Integer getChildKey() { return childKey; }
+ public void setChildKey(Integer childKey) { this.childKey = childKey; }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((childKey == null) ? 0 : childKey.hashCode());
+ result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ChildPK other = (ChildPK) obj;
+ if (childKey == null)
+ {
+ if (other.childKey != null)
+ return false;
+ }
+ else if (!childKey.equals(other.childKey))
+ return false;
+ if (parent == null)
+ {
+ if (other.parent != null)
+ return false;
+ }
+ else if (!parent.equals(other.parent))
+ return false;
+ return true;
+ }
+
+}
Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ChildPK.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChild.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChild.java?rev=1332299&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChild.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChild.java Mon Apr 30 17:15:18 2012
@@ -0,0 +1,90 @@
+/*
+ * 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.merge;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@IdClass(GrandChildPK.class)
+@Table(name = "MRG_GRANDCHILD")
+public class GrandChild implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @JoinColumns({ @JoinColumn(name = "KEY_1", referencedColumnName = "KEY_1"),
+ @JoinColumn(name = "KEY_2", referencedColumnName = "KEY_2"),
+ @JoinColumn(name = "KEY_3", referencedColumnName = "KEY_3") })
+ @ManyToOne
+ private Child child;
+
+ @Id
+ @Column(name = "KEY_4")
+ private Integer grandChildKey;
+
+ public Child getChild() {
+ return child;
+ }
+
+ public void setChild(Child child) {
+ this.child = child;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((child == null) ? 0 : child.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ GrandChild other = (GrandChild) obj;
+ if (child == null) {
+ if (other.child != null)
+ return false;
+ } else if (!child.equals(other.child))
+ return false;
+ return true;
+ }
+
+ public Integer getGrandChildKey() {
+ return grandChildKey;
+ }
+
+ public void setGrandChildKey(Integer grandChildKey) {
+ this.grandChildKey = grandChildKey;
+
+ }
+}
Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChild.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChildPK.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChildPK.java?rev=1332299&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChildPK.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChildPK.java Mon Apr 30 17:15:18 2012
@@ -0,0 +1,78 @@
+/*
+ * 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.merge;
+
+import java.io.Serializable;
+
+public class GrandChildPK implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private ChildPK child;
+
+ private Integer grandChildKey;
+
+ public ChildPK getChild() {
+ return child;
+ }
+
+ public void setChild(ChildPK child) {
+ this.child = child;
+ }
+
+ public Integer getGrandChildKey() {
+ return grandChildKey;
+ }
+
+ public void setGrandChildKey(Integer grandChildKey) {
+ this.grandChildKey = grandChildKey;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((child == null) ? 0 : child.hashCode());
+ result =
+ prime * result
+ + ((grandChildKey == null) ? 0 : grandChildKey.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ GrandChildPK other = (GrandChildPK) obj;
+ if (child == null) {
+ if (other.child != null)
+ return false;
+ } else if (!child.equals(other.child))
+ return false;
+ if (grandChildKey == null) {
+ if (other.grandChildKey != null)
+ return false;
+ } else if (!grandChildKey.equals(other.grandChildKey))
+ return false;
+ return true;
+ }
+}
Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/GrandChildPK.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Parent.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Parent.java?rev=1332299&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Parent.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Parent.java Mon Apr 30 17:15:18 2012
@@ -0,0 +1,96 @@
+/*
+ * 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.merge;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+@Entity
+@IdClass(ParentPK.class)
+@Table(name = "MRG_PARENT")
+public class Parent implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "KEY_1")
+ private String key1 = "00000000000000000000000000000000";
+
+ @Id
+ @Column(name = "KEY_2")
+ private Integer key2;
+
+ @OneToMany(mappedBy = "parent", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ private Collection<Child> childs = new ArrayList<Child>();
+
+ public Parent() {}
+
+ public String getKey1() { return key1; }
+ public void setKey1(String key1) { this.key1 = key1; }
+ public Integer getKey2() { return key2; }
+ public void setKey2(Integer key2) { this.key2 = key2; }
+ public Collection<Child> getChilds() { return childs; }
+ public void setChilds(Collection<Child> childs) { this.childs = childs; }
+@Override
+public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((childs == null) ? 0 : childs.hashCode());
+ result = prime * result + ((key1 == null) ? 0 : key1.hashCode());
+ result = prime * result + ((key2 == null) ? 0 : key2.hashCode());
+ return result;
+}
+@Override
+public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Parent other = (Parent) obj;
+ if (childs == null) {
+ if (other.childs != null)
+ return false;
+ } else if (!childs.equals(other.childs))
+ return false;
+ if (key1 == null) {
+ if (other.key1 != null)
+ return false;
+ } else if (!key1.equals(other.key1))
+ return false;
+ if (key2 == null) {
+ if (other.key2 != null)
+ return false;
+ } else if (!key2.equals(other.key2))
+ return false;
+ return true;
+}
+
+
+}
Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/Parent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ParentPK.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ParentPK.java?rev=1332299&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ParentPK.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ParentPK.java Mon Apr 30 17:15:18 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.merge;
+
+import java.io.Serializable;
+
+
+public class ParentPK implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String key1;
+
+ private Integer key2;
+
+ public ParentPK() {
+ this.key1 = "00000000000000000000000000000000";
+ }
+
+ public ParentPK(Integer key2) {
+ this();
+ this.key2 = key2;
+ }
+
+ public String getKey1() { return key1; }
+ public void setKey1(String key1) { this.key1 = key1; }
+ public Integer getKey2() { return key2; }
+ public void setKey2(Integer key2) { this.key2 = key2; }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((key1 == null) ? 0 : key1.hashCode());
+ result = prime * result + ((key2 == null) ? 0 : key2.hashCode());
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ParentPK other = (ParentPK) obj;
+ if (key1 == null)
+ {
+ if (other.key1 != null)
+ return false;
+ }
+ else if (!key1.equals(other.key1))
+ return false;
+ if (key2 == null)
+ {
+ if (other.key2 != null)
+ return false;
+ }
+ else if (!key2.equals(other.key2))
+ return false;
+ return true;
+ }
+
+}
Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/ParentPK.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestMergeNew.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestMergeNew.java?rev=1332299&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestMergeNew.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestMergeNew.java Mon Apr 30 17:15:18 2012
@@ -0,0 +1,154 @@
+/*
+ * 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.merge;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+/**
+ * Test the merge of a new object that has an Entity as
+ * part of its Id
+ */
+public class TestMergeNew extends SQLListenerTestCase {
+ public void setUp() {
+ setUp(CLEAR_TABLES, Parent.class,
+ Child.class, GrandChild.class);
+ assertNotNull(emf);
+ populate();
+ }
+
+ public void testMergeNewParent() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ ParentPK pk = new ParentPK(1);
+ pk.setKey1("K1");
+ Parent parent = em.find(Parent.class, pk);
+
+ Child child = new Child();
+ child.setChildKey(1);
+ child.setParent(parent);
+ parent.getChilds().add(child);
+
+ GrandChild grandChild = new GrandChild();
+ grandChild.setGrandChildKey(1);
+ grandChild.setChild(child);
+ child.getGrandChilds().add(grandChild);
+
+ Parent newParent = em.merge(parent);
+ assertNotNull(newParent);
+
+ // verify key fields
+ assertEquals(newParent.getKey1(), "K1");
+ assertEquals(newParent.getKey2(), new Integer(1));
+
+ // verify Child field
+ ArrayList<Child> childs = (ArrayList<Child>)newParent.getChilds();
+ assertNotNull(childs);
+ assertEquals(childs.size(), 1);
+ Child newChild = childs.get(0);
+ assertNotSame(child, newChild);
+ Parent childParent = newChild.getParent();
+ assertEquals(childParent, newParent);
+ assertEquals(newChild.getChildKey(), new Integer(1));
+
+ // verify GrandChild field
+ ArrayList<GrandChild> grandChilds = (ArrayList<GrandChild>)newChild.getGrandChilds();
+ assertNotNull(grandChilds);
+ assertEquals(grandChilds.size(), 1);
+ GrandChild newGrandChild = grandChilds.get(0);
+ assertNotSame(newGrandChild, grandChild);
+ Child grandChildChild = newGrandChild.getChild();
+ assertEquals(grandChildChild, newChild);
+
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testMergeParentRoundTrip()throws ClassNotFoundException, IOException {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ ParentPK pk = new ParentPK(1);
+ pk.setKey1("K1");
+ Parent parent = em.find(Parent.class, pk);
+
+ //Simulate an EJB Call to get the Parent from the server:
+ Parent p2 = (Parent) roundtrip(parent);
+
+ Child child = new Child();
+ child.setChildKey(1);
+ child.setParent(p2);
+ p2.getChilds().add(child);
+
+ GrandChild grandChild = new GrandChild();
+ grandChild.setChild(child);
+ grandChild.setGrandChildKey(1);
+ child.getGrandChilds().add(grandChild);
+
+ //Simulate an EJB Call to send the Parent back to the server:
+ Parent p3 = (Parent) roundtrip(p2);
+
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ Parent newParent = em.merge(p3);
+
+ em.getTransaction().commit();
+ assertNotNull(newParent);
+
+ // verify key fields
+ assertEquals(newParent.getKey1(), "K1");
+ assertEquals(newParent.getKey2(), new Integer(1));
+
+ // verify Child field
+ ArrayList<Child> childs = (ArrayList<Child>)newParent.getChilds();
+ assertNotNull(childs);
+ assertEquals(childs.size(), 1);
+ Child newChild = childs.get(0);
+ assertNotSame(child, newChild);
+ Parent childParent = newChild.getParent();
+ assertNotNull(childParent);
+ assertEquals(newChild.getChildKey(), new Integer(1));
+
+ // verify GrandChild field
+ ArrayList<GrandChild> grandChilds = (ArrayList<GrandChild>)newChild.getGrandChilds();
+ assertNotNull(grandChilds);
+ assertEquals(grandChilds.size(), 1);
+ GrandChild newGrandChild = grandChilds.get(0);
+ assertNotSame(newGrandChild, grandChild);
+ Child grandChildChild = newGrandChild.getChild();
+ assertNotNull(grandChildChild);
+ em.close();
+ }
+
+ private void populate() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ Parent p = new Parent();
+ p.setKey1("K1");
+ p.setKey2(1);
+ em.persist(p);
+ em.getTransaction().commit();
+ em.close();
+ }
+
+}
Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/merge/TestMergeNew.java
------------------------------------------------------------------------------
svn:eol-style = native