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/14 22:46:30 UTC
svn commit: r1081575 - in /tapestry/tapestry5/trunk/tapestry-jpa/src:
main/java/org/apache/tapestry5/internal/jpa/ test/app3/ test/app3/META-INF/
test/app3/WEB-INF/ test/conf/
test/java/org/apache/tapestry5/jpa/integration/app3/
test/java/org/example/a...
Author: drobiazko
Date: Mon Mar 14 21:46:29 2011
New Revision: 1081575
URL: http://svn.apache.org/viewvc?rev=1081575&view=rev
Log:
TAP5-1472: Configuring persistence unit using non-jta DataSource.
Added:
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/context.xml (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/PersistThing.tml
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/WEB-INF/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/WEB-INF/web.xml (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app3/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app3/JndiDataSourceTest.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/entities/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/entities/Thing.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/PersistThing.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/AppModule.java (with props)
tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/jndi-datasource-persistence-unit.xml (with props)
Modified:
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContentHandler.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/PersistenceContentHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContentHandler.java?rev=1081575&r1=1081574&r2=1081575&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContentHandler.java (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContentHandler.java Mon Mar 14 21:46:29 2011
@@ -16,9 +16,13 @@ package org.apache.tapestry5.internal.jp
import java.util.List;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo;
@@ -129,6 +133,10 @@ public class PersistenceContentHandler i
{
persistenceUnitInfo.setValidationMode(toEnum(ValidationMode.class, string));
}
+ else if (ELEMENT_NON_JTA_DATA_SOURCE.equals(localName))
+ {
+ persistenceUnitInfo.setNonJtaDataSource(lookupDataSource(string));
+ }
else if (ELEMENT_PERSISTENCE_UNIT.equals(localName))
{
if (persistenceUnitInfo != null)
@@ -172,4 +180,22 @@ public class PersistenceContentHandler i
{
return Enum.valueOf(enumType, value);
}
+
+ private DataSource lookupDataSource(final String name)
+ {
+ try
+ {
+ //TODO: Create InitialContext with environment properties?
+ final Context initContext = new InitialContext();
+
+ final Context envContext = (Context) initContext.lookup("java:comp/env");
+
+ return (DataSource) envContext.lookup(name);
+ }
+ catch (final NamingException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/context.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/context.xml?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/context.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/context.xml Mon Mar 14 21:46:29 2011
@@ -0,0 +1,25 @@
+<?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.
+-->
+<Context>
+ <Resource name="jdbc/JPATest" auth="Container" type="javax.sql.DataSource"
+
+ driverClassName="org.h2.Driver" url="jdbc:h2:mem:test" username="sa"
+
+ password="" maxActive="20" maxIdle="10" maxWait="-1" />
+
+
+</Context>
\ No newline at end of file
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/META-INF/context.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/PersistThing.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/PersistThing.tml?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/PersistThing.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/PersistThing.tml Mon Mar 14 21:46:29 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="thing">${thing.name}</t:if>
+ </span>
+ </p>
+ <p>
+ <t:eventlink event="createEntity">create thing</t:eventlink>
+ </p>
+ </body>
+</html>
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/WEB-INF/web.xml?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/WEB-INF/web.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/WEB-INF/web.xml Mon Mar 14 21:46:29 2011
@@ -0,0 +1,42 @@
+<?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.app3</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>
+
+ <resource-ref>
+ <description>Non Jta DataSource</description>
+ <res-ref-name>jdbc/JPATest</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ <res-auth>Container</res-auth>
+ </resource-ref>
+</web-app>
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app3/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=1081575&r1=1081574&r2=1081575&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml Mon Mar 14 21:46:29 2011
@@ -23,6 +23,14 @@
</packages>
</test>
+ <test name="JNDI DataSource Integration Tests" enabled="true">
+ <parameter name="tapestry.web-app-folder" value="src/test/app3" />
+ <parameter name="tapestry.servlet-container" value="tomcat6" />
+ <packages>
+ <package name="org.apache.tapestry5.jpa.integration.app3" />
+ </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/app3/JndiDataSourceTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app3/JndiDataSourceTest.java?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app3/JndiDataSourceTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app3/JndiDataSourceTest.java Mon Mar 14 21:46:29 2011
@@ -0,0 +1,31 @@
+// 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.app3;
+
+import org.apache.tapestry5.test.SeleniumTestCase;
+import org.testng.annotations.Test;
+
+public class JndiDataSourceTest extends SeleniumTestCase
+{
+ @Test
+ public void persist_thing()
+ {
+ open("/persistthing");
+ assertEquals(getText("//span[@id='name']").length(), 0);
+
+ clickAndWait("link=create thing");
+ assertText("//span[@id='name']", "name");
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app3/JndiDataSourceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app3/JndiDataSourceTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/entities/Thing.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/entities/Thing.java?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/entities/Thing.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/entities/Thing.java Mon Mar 14 21:46:29 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.app3.entities;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Thing
+{
+ @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/app3/entities/Thing.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/entities/Thing.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/PersistThing.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/PersistThing.java?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/PersistThing.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/PersistThing.java Mon Mar 14 21:46:29 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.app3.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.JpaPersistenceConstants;
+import org.apache.tapestry5.jpa.annotations.CommitAfter;
+import org.example.app3.entities.Thing;
+
+public class PersistThing
+{
+ @PersistenceUnit
+ private EntityManager entityManager;
+
+ @Persist(JpaPersistenceConstants.ENTITY)
+ @Property
+ private Thing thing;
+
+ @CommitAfter
+ void onCreateEntity()
+ {
+ final Thing thing = new Thing();
+ thing.setName("name");
+
+ entityManager.persist(thing);
+
+ this.thing = thing;
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/PersistThing.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/pages/PersistThing.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/AppModule.java?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/AppModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/AppModule.java Mon Mar 14 21:46:29 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.app3.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, "/jndi-datasource-persistence-unit.xml");
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/AppModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app3/services/AppModule.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/jndi-datasource-persistence-unit.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/jndi-datasource-persistence-unit.xml?rev=1081575&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/jndi-datasource-persistence-unit.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/jndi-datasource-persistence-unit.xml Mon Mar 14 21:46:29 2011
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ version="2.0">
+
+ <persistence-unit name="JndiDataSourcePersistenceUnit" transaction-type="RESOURCE_LOCAL">
+ <non-jta-data-source>jdbc/JPATest</non-jta-data-source>
+ <properties>
+ <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/jndi-datasource-persistence-unit.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/jndi-datasource-persistence-unit.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain