You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by dr...@apache.org on 2011/03/09 22:26:44 UTC

svn commit: r1080011 [2/2] - in /tapestry/tapestry5/trunk/tapestry-jpa: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tapestry5/ src/main/java/org/apache/tapestry5/internal/ src/main/java/org/apa...

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/EncodeEntities.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/PersistEntity.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/PersistEntity.java?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/PersistEntity.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/PersistEntity.java Wed Mar  9 21:26:42 2011
@@ -0,0 +1,74 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// 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.example.app.pages;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceUnit;
+
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.jpa.CommitAfter;
+import org.example.app.AppConstants;
+import org.example.app.entities.User;
+
+public class PersistEntity
+{
+    @PersistenceUnit(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
+    private EntityManager entityManager;
+
+    @Persist("entity")
+    @Property
+    private User user;
+
+    @CommitAfter
+    @PersistenceUnit(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
+    void onCreateEntity()
+    {
+        final User user = new User();
+        user.setFirstName("name");
+
+        entityManager.persist(user);
+
+        this.user = user;
+    }
+
+    void onChangeName()
+    {
+        user.setFirstName("name2");
+
+        // No commit, so no real change.
+    }
+
+    void onSetToTransient()
+    {
+        user = new User();
+    }
+
+    void onSetToNull()
+    {
+        user = null;
+    }
+
+    @CommitAfter
+    @PersistenceUnit(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
+    void onDelete()
+    {
+        final List<User> users = entityManager.createQuery("select u from User u").getResultList();
+
+        entityManager.remove(users.get(0));
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/PersistEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/AppModule.java?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/AppModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/AppModule.java Wed Mar  9 21:26:42 2011
@@ -0,0 +1,43 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// 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.example.app.services;
+
+import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.SubModule;
+import org.apache.tapestry5.ioc.services.ApplicationDefaults;
+import org.apache.tapestry5.ioc.services.SymbolProvider;
+import org.apache.tapestry5.jpa.JpaModule;
+import org.example.app.services.impl.UserDAOImpl;
+
+@SubModule(JpaModule.class)
+public class AppModule
+{
+
+    public static void bind(final ServiceBinder binder)
+    {
+        binder.bind(UserDAO.class, UserDAOImpl.class);
+    }
+
+    @Contribute(SymbolProvider.class)
+    @ApplicationDefaults
+    public static void provideApplicationDefaults(
+            final MappedConfiguration<String, String> configuration)
+    {
+        configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/AppModule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java Wed Mar  9 21:26:42 2011
@@ -0,0 +1,16 @@
+package org.example.app.services;
+
+import java.util.List;
+
+import org.example.app.entities.User;
+
+public interface UserDAO
+{
+    void add(User user);
+
+    List<User> findAll();
+
+    void delete(User... users);
+
+    void deleteAll();
+}

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java Wed Mar  9 21:26:42 2011
@@ -0,0 +1,43 @@
+package org.example.app.services.impl;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceUnit;
+
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.example.app.entities.User;
+import org.example.app.services.UserDAO;
+
+public class UserDAOImpl implements UserDAO
+{
+    @Inject
+    @PersistenceUnit(unitName = "TestUnit")
+    private EntityManager entityManager;
+
+    public void add(final User user)
+    {
+        entityManager.persist(user);
+    }
+
+    @SuppressWarnings(
+    { "unchecked" })
+    public List<User> findAll()
+    {
+        return entityManager.createQuery("select u from User u order by u.id desc").getResultList();
+    }
+
+    public void delete(final User... users)
+    {
+        for (final User user : users)
+            entityManager.remove(user);
+    }
+
+    public void deleteAll()
+    {
+        for (final User u : findAll())
+        {
+            entityManager.remove(u);
+        }
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/META-INF/persistence.xml?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/META-INF/persistence.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/META-INF/persistence.xml Wed Mar  9 21:26:42 2011
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+	version="2.0">
+
+	<persistence-unit name="TestUnit" transaction-type="RESOURCE_LOCAL">
+		<class>org.example.app.entities.User</class>
+		<properties>
+			<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
+			<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
+			<property name="javax.persistence.jdbc.username" value="sa" />
+			<property name="eclipselink.ddl-generation" value="create-tables"/>
+			<property name="eclipselink.logging.level" value="fine"/>
+		</properties>
+	</persistence-unit>
+	
+	
+	<persistence-unit name="TestUnit2" transaction-type="RESOURCE_LOCAL">
+		<properties>
+			<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
+			<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
+			<property name="javax.persistence.jdbc.username" value="sa" />
+		</properties>
+	</persistence-unit>
+
+</persistence>
\ No newline at end of file

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/log4j.properties?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/log4j.properties (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/log4j.properties Wed Mar  9 21:26:42 2011
@@ -0,0 +1,29 @@
+# Copyright 2007, 2008 The Apache Software Foundation
+#
+# 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.
+
+log4j.rootCategory=WARN, A1
+
+# A1 is set to be a ConsoleAppender. 
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=[%p] %c{1} %m%n
+
+log4j.category.org.apache.tapestry5.TapestryFilter=info
+log4j.category.org.apache.tapestry=error
+log4j.category.tapestry=error
+log4j.category.tapestry.ioc.ClassFactory=error
+
+log4j.category.tapestry.hibernate=info

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/EncodeEntities.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/EncodeEntities.tml?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/EncodeEntities.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/EncodeEntities.tml Wed Mar  9 21:26:42 2011
@@ -0,0 +1,14 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+	<body>
+		<p>
+			entity name:
+			<span id="name">
+				<t:if test="user">${user.firstName}</t:if>
+			</span>
+		</p>
+		<p>
+			create entity:
+			<t:eventlink event="create" t:id="createentity">create an entity</t:eventlink>
+		</p>
+	</body>
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/PersistEntity.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/PersistEntity.tml?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/PersistEntity.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/PersistEntity.tml Wed Mar  9 21:26:42 2011
@@ -0,0 +1,25 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+	<body>
+		<p>
+			entity name:
+			<span id="name">
+				<t:if test="user">${user.firstName}</t:if>
+			</span>
+		</p>
+		<p>
+			<t:eventlink event="createEntity">create entity</t:eventlink>
+		</p>
+		<p>
+			<t:eventlink event="changeName">change the name</t:eventlink>
+		</p>
+		<p>
+			<t:eventlink event="setToNull">set to null</t:eventlink>
+		</p>
+		<p>
+			<t:eventlink event="delete">delete</t:eventlink>
+		</p>
+		<p>
+			<t:eventlink event="setToTransient">set to transient</t:eventlink>
+		</p>
+	</body>
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/WEB-INF/web.xml?rev=1080011&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/WEB-INF/web.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/WEB-INF/web.xml Wed Mar  9 21:26:42 2011
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+   Copyright 2011 The Apache Software Foundation
+
+   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.
+-->
+
+<!DOCTYPE web-app
+        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+        "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+    <display-name>Tapestry-JPA Integration Test Application</display-name>
+    <context-param>
+        <param-name>tapestry.app-package</param-name>
+        <param-value>org.example.app</param-value>
+    </context-param>
+    <filter>
+        <filter-name>app</filter-name>
+        <filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
+    </filter>
+    <filter-mapping>
+        <filter-name>app</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+</web-app>

Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain