You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2010/01/12 22:55:57 UTC
svn commit: r898537 - in
/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach:
./ IntVersionEntity.java NoVersionEntity.java TestDetachReloadProp.java
TimestampVersionEntity.java
Author: curtisr7
Date: Tue Jan 12 21:55:57 2010
New Revision: 898537
URL: http://svn.apache.org/viewvc?rev=898537&view=rev
Log:
OPENJPA-1414: Committing test case. Patch contributed by Dianne Richards.
Added:
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/NoVersionEntity.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachReloadProp.java (with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TimestampVersionEntity.java (with props)
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java?rev=898537&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java Tue Jan 12 21:55:57 2010
@@ -0,0 +1,79 @@
+/*
+ * 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.detach;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Version;
+
+@Entity
+public class IntVersionEntity {
+
+ @Id
+ private int id;
+ private String name;
+
+ @Version
+ private int version;
+
+ public int getVersion() {
+ return version;
+ }
+
+ @OneToOne(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
+ private TimestampVersionEntity e2;
+
+ public IntVersionEntity(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public TimestampVersionEntity getE2() {
+ return e2;
+ }
+
+ public void setE2(TimestampVersionEntity e2) {
+ this.e2 = e2;
+ }
+
+ public IntVersionEntity() {
+ }
+
+ public void printE2() {
+ System.out.println("e2 - " + e2);
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/NoVersionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/NoVersionEntity.java?rev=898537&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/NoVersionEntity.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/NoVersionEntity.java Tue Jan 12 21:55:57 2010
@@ -0,0 +1,54 @@
+/*
+ * 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.detach;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class NoVersionEntity {
+
+ @Id
+ private int id;
+ private String name;
+
+ public NoVersionEntity(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public NoVersionEntity() {
+ }
+
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/NoVersionEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachReloadProp.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachReloadProp.java?rev=898537&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachReloadProp.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachReloadProp.java Tue Jan 12 21:55:57 2010
@@ -0,0 +1,95 @@
+/*
+ * 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.detach;
+
+import org.apache.openjpa.conf.Compatibility;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestDetachReloadProp extends SQLListenerTestCase {
+ IntVersionEntity intVer;
+ TimestampVersionEntity tsVer;
+ NoVersionEntity noVer;
+ int id;
+ OpenJPAEntityManager em;
+ Compatibility compat;
+
+ public void setUp() {
+ setUp(org.apache.openjpa.persistence.detach.IntVersionEntity.class,
+ org.apache.openjpa.persistence.detach.TimestampVersionEntity.class,
+ org.apache.openjpa.persistence.detach.NoVersionEntity.class);
+ compat = emf.getConfiguration().getCompatibilityInstance();
+ id++;
+ create(id);
+ persist();
+ }
+
+ private void create(int id) {
+ intVer = new IntVersionEntity(id);
+ intVer.setName("xxx");
+ tsVer = new TimestampVersionEntity(id);
+ tsVer.setName("yyy");
+ intVer.setE2(tsVer);
+ noVer = new NoVersionEntity(id);
+ noVer.setName("zzz");
+ }
+
+ private void persist() {
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+ em.persist(noVer);
+ em.persist(intVer); // also persists referenced tsVer
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testReloadTrue() {
+ compat.setReloadOnDetach(true);
+ detachProcessing();
+ }
+
+ public void testReloadFalse() {
+ compat.setReloadOnDetach(false);
+ detachProcessing();
+ }
+
+ private void detachProcessing() {
+ // Detach individual entities explicitly
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+ intVer = em.find(IntVersionEntity.class, id);
+ tsVer = em.find(TimestampVersionEntity.class, id);
+ noVer = em.find(NoVersionEntity.class, id);
+ em.detach(intVer);
+ em.detach(tsVer);
+ em.detach(noVer);
+ em.getTransaction().commit();
+ em.close();
+
+ // Detach all internal implicitly with close()
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+ intVer = em.find(IntVersionEntity.class, id);
+ tsVer = em.find(TimestampVersionEntity.class, id);
+ noVer = em.find(NoVersionEntity.class, id);
+ em.getTransaction().commit();
+ em.close();
+
+ }
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachReloadProp.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TimestampVersionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TimestampVersionEntity.java?rev=898537&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TimestampVersionEntity.java (added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TimestampVersionEntity.java Tue Jan 12 21:55:57 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.detach;
+
+import java.sql.Timestamp;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity
+public class TimestampVersionEntity {
+
+ @Id
+ private int id;
+ private String name;
+
+ @Version
+ private Timestamp version;
+
+ public Timestamp getVersion() {
+ return version;
+ }
+
+ public TimestampVersionEntity() {}
+
+ public TimestampVersionEntity(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TimestampVersionEntity.java
------------------------------------------------------------------------------
svn:eol-style = native