tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kao...@apache.org
Subject [1/2] tapestry-5 git commit: TAP5-2553: Support pseudo nested JPA transactions etc.
Date Wed, 08 Jun 2016 17:06:09 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master f29b64e7b -> 5047220cf


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5047220c/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingOne.java
----------------------------------------------------------------------
diff --git a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingOne.java
b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingOne.java
new file mode 100644
index 0000000..42e3722
--- /dev/null
+++ b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingOne.java
@@ -0,0 +1,92 @@
+/**
+ * Licensed 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.tapestry5.jpa.test.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EntityListeners;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+import org.apache.tapestry5.jpa.test.CommitCounter;
+
+@Entity
+@EntityListeners(CommitCounter.class)
+public class ThingOne
+{
+    private Integer id;
+
+    private String name;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    public Integer getId()
+    {
+        return id;
+    }
+
+    /**
+     * @param id
+     *            The id to set.
+     */
+    public void setId(Integer id)
+    {
+        this.id = id;
+    }
+
+    /**
+     * @return Returns the name.
+     */
+    @Column(nullable = false)
+    public String getName()
+    {
+        return name;
+    }
+
+    /**
+     * @param name
+     *            The name to set.
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o)
+            return true;
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        ThingOne thing = (ThingOne) o;
+
+        return getId() != null ? getId().equals(thing.getId()) : thing.getId() == null;
+
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return (getId() != null ? getId().hashCode() : 0);
+    }
+
+    public String toString()
+    {
+        return getName();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5047220c/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingTwo.java
----------------------------------------------------------------------
diff --git a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingTwo.java
b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingTwo.java
new file mode 100644
index 0000000..1c38cfd
--- /dev/null
+++ b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/ThingTwo.java
@@ -0,0 +1,92 @@
+/**
+ * Licensed 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.tapestry5.jpa.test.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EntityListeners;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+import org.apache.tapestry5.jpa.test.CommitCounter;
+
+@Entity
+@EntityListeners(CommitCounter.class)
+public class ThingTwo
+{
+    private Integer id;
+
+    private String name;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    public Integer getId()
+    {
+        return id;
+    }
+
+    /**
+     * @param id
+     *            The id to set.
+     */
+    public void setId(Integer id)
+    {
+        this.id = id;
+    }
+
+    /**
+     * @return Returns the name.
+     */
+    @Column(nullable = false)
+    public String getName()
+    {
+        return name;
+    }
+
+    /**
+     * @param name
+     *            The name to set.
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o)
+            return true;
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        ThingTwo thing = (ThingTwo) o;
+
+        return getId() != null ? getId().equals(thing.getId()) : thing.getId() == null;
+
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return (getId() != null ? getId().hashCode() : 0);
+    }
+
+    public String toString()
+    {
+        return getName();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5047220c/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/VersionedThing.java
----------------------------------------------------------------------
diff --git a/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/VersionedThing.java
b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/VersionedThing.java
new file mode 100644
index 0000000..4c06cd7
--- /dev/null
+++ b/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/test/entities/VersionedThing.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed 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.tapestry5.jpa.test.entities;
+
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Version;
+
+@Entity
+public class VersionedThing
+{
+    @Id
+    // @GeneratedValue(strategy = GenerationType.AUTO)
+    // @GeneratedValue(strategy = GenerationType.IDENTITY)
+    // @Column(name = "id", insertable = true, updatable = true, unique = true, nullable
= false)
+    private Integer id;
+
+    @Version
+    private Integer version;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    private Date lastTouched;
+
+    public Integer getId()
+    {
+        return id;
+    }
+
+    public void setId(Integer id)
+    {
+        this.id = id;
+    }
+
+    public int getVersion()
+    {
+        return version;
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o)
+            return true;
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        VersionedThing thing = (VersionedThing) o;
+
+        return getId() != null ? getId().equals(thing.getId()) : thing.getId() == null;
+
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return (getId() != null ? getId().hashCode() : 0);
+    }
+
+    public Date getLastTouched()
+    {
+        return lastTouched;
+    }
+
+    public void setLastTouched(Date lastTouched)
+    {
+        this.lastTouched = lastTouched;
+    }
+
+    public void setVersion(int version)
+    {
+        this.version = version;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5047220c/tapestry-jpa/src/test/java/org/example/app6/services/UserDAO.java
----------------------------------------------------------------------
diff --git a/tapestry-jpa/src/test/java/org/example/app6/services/UserDAO.java b/tapestry-jpa/src/test/java/org/example/app6/services/UserDAO.java
index 9d0c93d..88715b6 100644
--- a/tapestry-jpa/src/test/java/org/example/app6/services/UserDAO.java
+++ b/tapestry-jpa/src/test/java/org/example/app6/services/UserDAO.java
@@ -16,15 +16,27 @@ package org.example.app6.services;
 
 import java.util.List;
 
+import javax.persistence.PersistenceContext;
+
+import org.apache.tapestry5.jpa.annotations.CommitAfter;
+import org.example.app6.AppConstants;
 import org.example.app6.entities.User;
 
 public interface UserDAO
 {
+    @CommitAfter
+    @PersistenceContext(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
     void add(User user);
 
+    @CommitAfter
+    @PersistenceContext(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
     List<User> findAll();
 
+    @CommitAfter
+    @PersistenceContext(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
     void delete(User... users);
 
+    @CommitAfter
+    @PersistenceContext(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
     void deleteAll();
 }


Mime
View raw message