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/13 21:54:36 UTC
svn commit: r1081219 - in /tapestry/tapestry5/trunk/tapestry-jpa/src:
main/java/org/apache/tapestry5/internal/jpa/
main/java/org/apache/tapestry5/jpa/ test/app2/ test/app2/WEB-INF/
test/conf/ test/java/org/apache/tapestry5/jpa/integration/app2/ test/ja...
Author: drobiazko
Date: Sun Mar 13 20:54:35 2011
New Revision: 1081219
URL: http://svn.apache.org/viewvc?rev=1081219&view=rev
Log:
TAP5-1472: Added support for entity configuration based on package name, when only a single persistence unit used.
Added:
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PackageNamePersistenceUnitConfigurer.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaEntityPackageManager.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/PersistItem.tml
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/WEB-INF/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/WEB-INF/web.xml (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/SimpleEntityManagerIntegrationTest.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/Item.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/PersistItem.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/AppModule.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/single-persistence-unit.xml (with props)
Modified:
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaModule.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml
Modified: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java?rev=1081219&r1=1081218&r2=1081219&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java Sun Mar 13 20:54:35 2011
@@ -47,7 +47,7 @@ public class EntityManagerSourceImpl imp
private final List<TapestryPersistenceUnitInfo> persistenceUnitInfos;
- public EntityManagerSourceImpl(final Logger logger, final Resource persistenceDescriptor,
+ public EntityManagerSourceImpl(final Logger logger, final Resource persistenceDescriptor, PersistenceUnitConfigurer packageNamePersistenceUnitConfigurer,
final Map<String, PersistenceUnitConfigurer> configuration)
{
super();
@@ -70,6 +70,9 @@ public class EntityManagerSourceImpl imp
InternalUtils.close(inputStream);
}
+ if(persistenceUnitInfos.size() == 1)
+ packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
+
for (final TapestryPersistenceUnitInfo info : persistenceUnitInfos)
{
final PersistenceUnitConfigurer configurer = configuration.get(info
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PackageNamePersistenceUnitConfigurer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PackageNamePersistenceUnitConfigurer.java?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PackageNamePersistenceUnitConfigurer.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PackageNamePersistenceUnitConfigurer.java Sun Mar 13 20:54:35 2011
@@ -0,0 +1,50 @@
+// 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.apache.tapestry5.internal.jpa;
+
+import org.apache.tapestry5.ioc.services.ClassNameLocator;
+import org.apache.tapestry5.jpa.JpaEntityPackageManager;
+import org.apache.tapestry5.jpa.PersistenceUnitConfigurer;
+import org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo;
+
+public class PackageNamePersistenceUnitConfigurer implements PersistenceUnitConfigurer
+{
+ private final JpaEntityPackageManager packageManager;
+
+ private final ClassNameLocator classNameLocator;
+
+ public PackageNamePersistenceUnitConfigurer(JpaEntityPackageManager packageManager,
+ ClassNameLocator classNameLocator)
+ {
+ this.packageManager = packageManager;
+ this.classNameLocator = classNameLocator;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void configure(TapestryPersistenceUnitInfo unitInfo)
+ {
+ for (String packageName : packageManager.getPackageNames())
+ {
+ for (String className : classNameLocator.locateClassNames(packageName))
+ {
+ unitInfo.addManagedClassName(className);
+ }
+ }
+
+ }
+
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PackageNamePersistenceUnitConfigurer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PackageNamePersistenceUnitConfigurer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaEntityPackageManager.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaEntityPackageManager.java?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaEntityPackageManager.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaEntityPackageManager.java Sun Mar 13 20:54:35 2011
@@ -0,0 +1,35 @@
+// 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.apache.tapestry5.jpa;
+
+import java.util.Collection;
+
+import org.apache.tapestry5.ioc.annotations.UsesConfiguration;
+
+/**
+ * Contains a set of contributed package names from which to load entities.
+ * <p/>
+ * The service's configuration is the names of Java packages to search for JPA entities.
+ *
+ * @since 5.3.0
+ */
+@UsesConfiguration(String.class)
+public interface JpaEntityPackageManager
+{
+ /**
+ * Returns packages from which read entity classes
+ */
+ Collection<String> getPackageNames();
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaEntityPackageManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaEntityPackageManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaModule.java?rev=1081219&r1=1081218&r2=1081219&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaModule.java Sun Mar 13 20:54:35 2011
@@ -14,6 +14,7 @@
package org.apache.tapestry5.jpa;
+import java.util.Collection;
import java.util.Map;
import javax.persistence.EntityManagerFactory;
@@ -22,6 +23,7 @@ import javax.persistence.metamodel.Metam
import javax.persistence.spi.PersistenceUnitInfo;
import org.apache.tapestry5.ValueEncoder;
+import org.apache.tapestry5.internal.InternalConstants;
import org.apache.tapestry5.internal.jpa.CommitAfterWorker;
import org.apache.tapestry5.internal.jpa.EntityApplicationStatePersistenceStrategy;
import org.apache.tapestry5.internal.jpa.EntityManagerManagerImpl;
@@ -30,8 +32,10 @@ import org.apache.tapestry5.internal.jpa
import org.apache.tapestry5.internal.jpa.EntityPersistentFieldStrategy;
import org.apache.tapestry5.internal.jpa.JpaTransactionAdvisorImpl;
import org.apache.tapestry5.internal.jpa.JpaValueEncoder;
+import org.apache.tapestry5.internal.jpa.PackageNamePersistenceUnitConfigurer;
import org.apache.tapestry5.internal.jpa.PersistenceUnitWorker;
import org.apache.tapestry5.internal.services.PersistentFieldManager;
+import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.LoggerSource;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.ObjectProvider;
@@ -40,6 +44,7 @@ import org.apache.tapestry5.ioc.Resource
import org.apache.tapestry5.ioc.ScopeConstants;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.Local;
import org.apache.tapestry5.ioc.annotations.Scope;
import org.apache.tapestry5.ioc.annotations.Startup;
import org.apache.tapestry5.ioc.annotations.Symbol;
@@ -65,21 +70,42 @@ public class JpaModule
public static void bind(final ServiceBinder binder)
{
binder.bind(JpaTransactionAdvisor.class, JpaTransactionAdvisorImpl.class);
+ binder.bind(PersistenceUnitConfigurer.class, PackageNamePersistenceUnitConfigurer.class).withId("PackageNamePersistenceUnitConfigurer");
}
- public static EntityManagerSource buildEntityManagerSource(final Logger logger,
+ public static EntityManagerSource buildEntityManagerSource(
+ final Logger logger,
+
@Symbol(JpaSymbols.PERSISTENCE_DESCRIPTOR)
Resource persistenceDescriptor,
+
+ @Local
+ PersistenceUnitConfigurer persistenceUnitConfigurer,
+
final Map<String, PersistenceUnitConfigurer> configuration,
+
final RegistryShutdownHub hub)
{
- final EntityManagerSourceImpl ems = new EntityManagerSourceImpl(logger, persistenceDescriptor, configuration);
+ final EntityManagerSourceImpl ems = new EntityManagerSourceImpl(logger,
+ persistenceDescriptor, persistenceUnitConfigurer, configuration);
hub.addRegistryShutdownListener(ems);
return ems;
}
+ public static JpaEntityPackageManager buildJpaEntityPackageManager(
+ final Collection<String> packageNames)
+ {
+ return new JpaEntityPackageManager()
+ {
+ public Collection<String> getPackageNames()
+ {
+ return packageNames;
+ }
+ };
+ }
+
@Scope(ScopeConstants.PERTHREAD)
public static EntityManagerManager buildEntityManagerManager(
final EntityManagerSource entityManagerSource, final PerthreadManager perthreadManager,
@@ -93,6 +119,15 @@ public class JpaModule
return service;
}
+ @Contribute(JpaEntityPackageManager.class)
+ public static void provideEntityPackages(Configuration<String> configuration,
+
+ @Symbol(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM)
+ String appRootPackage)
+ {
+ configuration.add(appRootPackage + ".entities");
+ }
+
@Contribute(PersistentFieldManager.class)
public static void provideEntityPersistentFieldStrategies(
final MappedConfiguration<String, PersistentFieldStrategy> configuration)
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/PersistItem.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/PersistItem.tml?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/PersistItem.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/PersistItem.tml Sun Mar 13 20:54:35 2011
@@ -0,0 +1,13 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+ <body>
+ <p>
+ entity name:
+ <span id="name">
+ <t:if test="item">${item.name}</t:if>
+ </span>
+ </p>
+ <p>
+ <t:eventlink event="createEntity">create item</t:eventlink>
+ </p>
+ </body>
+</html>
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/WEB-INF/web.xml?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/WEB-INF/web.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/WEB-INF/web.xml Sun Mar 13 20:54:35 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.app2</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/app2/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app2/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml?rev=1081219&r1=1081218&r2=1081219&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml Sun Mar 13 20:54:35 2011
@@ -16,6 +16,13 @@
</packages>
</test>
+ <test name="Tapestry JPA Simple EntityManager Integration Tests" enabled="true">
+ <parameter name="tapestry.web-app-folder" value="src/test/app2" />
+ <packages>
+ <package name="org.apache.tapestry5.jpa.integration.app2" />
+ </packages>
+ </test>
+
<test name="Tapestry JPA Unit Tests" enabled="true">
<packages>
<package name="org.apache.tapestry5.internal.jpa" />
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/SimpleEntityManagerIntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/SimpleEntityManagerIntegrationTest.java?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/SimpleEntityManagerIntegrationTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/SimpleEntityManagerIntegrationTest.java Sun Mar 13 20:54:35 2011
@@ -0,0 +1,32 @@
+// 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.apache.tapestry5.jpa.integration.app2;
+
+import org.apache.tapestry5.test.SeleniumTestCase;
+import org.testng.annotations.Test;
+
+public class SimpleEntityManagerIntegrationTest extends SeleniumTestCase
+{
+
+ @Test
+ public void persist_entities()
+ {
+ open("/persistitem");
+ assertEquals(getText("//span[@id='name']").length(), 0);
+
+ clickAndWait("link=create item");
+ assertText("//span[@id='name']", "name");
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/SimpleEntityManagerIntegrationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app2/SimpleEntityManagerIntegrationTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/Item.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/Item.java?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/Item.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/Item.java Sun Mar 13 20:54:35 2011
@@ -0,0 +1,50 @@
+// 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.app2.entities;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Item
+{
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String name;
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/Item.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/entities/Item.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/PersistItem.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/PersistItem.java?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/PersistItem.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/PersistItem.java Sun Mar 13 20:54:35 2011
@@ -0,0 +1,45 @@
+// 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.app2.pages;
+
+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.annotations.CommitAfter;
+import org.example.app2.entities.Item;
+
+public class PersistItem
+{
+ @PersistenceUnit(unitName = "App2PersistenceUnit")
+ private EntityManager entityManager;
+
+ @Persist("entity")
+ @Property
+ private Item item;
+
+ @CommitAfter
+ @PersistenceUnit(unitName = "App2PersistenceUnit")
+ void onCreateEntity()
+ {
+ final Item item = new Item();
+ item.setName("name");
+
+ entityManager.persist(item);
+
+ this.item = item;
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/PersistItem.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/pages/PersistItem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/AppModule.java?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/AppModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/AppModule.java Sun Mar 13 20:54:35 2011
@@ -0,0 +1,35 @@
+// 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.app2.services;
+
+import org.apache.tapestry5.ioc.MappedConfiguration;
+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.apache.tapestry5.jpa.JpaSymbols;
+
+@SubModule(JpaModule.class)
+public class AppModule
+{
+ @Contribute(SymbolProvider.class)
+ @ApplicationDefaults
+ public static void provideFactoryDefaults(
+ final MappedConfiguration<String, String> configuration)
+ {
+ configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR, "/single-persistence-unit.xml");
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/AppModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app2/services/AppModule.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/single-persistence-unit.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/single-persistence-unit.xml?rev=1081219&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/single-persistence-unit.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/single-persistence-unit.xml Sun Mar 13 20:54:35 2011
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ version="2.0">
+
+ <persistence-unit name="App2PersistenceUnit" 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" />
+ <property name="eclipselink.ddl-generation" value="create-tables"/>
+ <property name="eclipselink.logging.level" value="fine"/>
+ </properties>
+ </persistence-unit>
+
+</persistence>
\ No newline at end of file
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/single-persistence-unit.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/single-persistence-unit.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain