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 2012/04/23 10:13:23 UTC
svn commit: r1329111 - in /tapestry/tapestry5/trunk/tapestry-jpa/src:
main/java/org/apache/tapestry5/internal/jpa/ test/app5/ test/app5/WEB-INF/
test/conf/ test/java/org/apache/tapestry5/jpa/integration/app5/
test/java/org/example/app5/ test/java/org/e...
Author: drobiazko
Date: Mon Apr 23 08:13:22 2012
New Revision: 1329111
URL: http://svn.apache.org/viewvc?rev=1329111&view=rev
Log:
TAP5-1848: Persistence providers defined for a unit is not ignored anymore
Added:
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/Index.tml
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/WEB-INF/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/WEB-INF/web.xml
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/ExplicitPersistenceProviderClassTest.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/pages/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/pages/Index.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/services/
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/services/AppModule.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/explicit-persistence-provider-class-persistence-unit.xml
Modified:
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.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=1329111&r1=1329110&r2=1329111&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 Mon Apr 23 08:13:22 2012
@@ -192,7 +192,6 @@ public class EntityManagerSourceImpl imp
private EntityManagerFactory createEntityManagerFactory(final String persistenceUnitName)
{
- final PersistenceProvider persistenceProvider = getPersistenceProvider();
for (final TapestryPersistenceUnitInfo info : persistenceUnitInfos)
{
@@ -201,6 +200,10 @@ public class EntityManagerSourceImpl imp
final Map<String, String> properties = CollectionFactory.newCaseInsensitiveMap();
properties.put(JpaConstants.PERSISTENCE_UNIT_NAME, persistenceUnitName);
+ String providerClassName = info.getPersistenceProviderClassName();
+
+ final PersistenceProvider persistenceProvider = getPersistenceProvider(persistenceUnitName, providerClassName);
+
return persistenceProvider.createContainerEntityManagerFactory(info, properties);
}
}
@@ -210,7 +213,7 @@ public class EntityManagerSourceImpl imp
persistenceUnitName));
}
- private PersistenceProvider getPersistenceProvider()
+ private PersistenceProvider getPersistenceProvider(final String persistenceUnitName, final String providerClassName)
{
final PersistenceProviderResolver resolver = PersistenceProviderResolverHolder
.getPersistenceProviderResolver();
@@ -218,12 +221,55 @@ public class EntityManagerSourceImpl imp
final List<PersistenceProvider> providers = resolver.getPersistenceProviders();
if (providers.isEmpty())
+ {
throw new IllegalStateException(
"No PersistenceProvider implementation available in the runtime environment.");
+ }
+
+ if(1 < providers.size() && providerClassName == null)
+ {
+ throw new IllegalStateException(
+ String.format("Persistence providers [%s] are available in the runtime environment " +
+ "but no provider class is defined for the persistence unit %s.", InternalUtils.join(toProviderClasses(providers)), persistenceUnitName));
+ }
+
+ if(providerClassName != null)
+ {
+ return findPersistenceProviderByName(providers, providerClassName);
+ }
return providers.get(0);
}
+ private PersistenceProvider findPersistenceProviderByName(final List<PersistenceProvider> providers, final String providerClassName)
+ {
+ PersistenceProvider provider = F.flow(providers).filter(new Predicate<PersistenceProvider>() {
+ @Override
+ public boolean accept(PersistenceProvider next) {
+ return next.getClass().getName().equals(providerClassName);
+ }
+ }).first();
+
+ if(provider == null)
+ {
+ throw new IllegalStateException(
+ String.format("No persistence provider of type %s found in the runtime environment. " +
+ "Following providers are available: [%s]", providerClassName, InternalUtils.join(toProviderClasses(providers))));
+ }
+
+ return provider;
+ }
+
+ private List<Class> toProviderClasses(final List<PersistenceProvider> providers)
+ {
+ return F.flow(providers).map(new Mapper<PersistenceProvider, Class>() {
+ @Override
+ public Class map(PersistenceProvider element) {
+ return element.getClass();
+ }
+ }).toList();
+ }
+
public EntityManager create(final String persistenceUnitName)
{
return getEntityManagerFactory(persistenceUnitName).createEntityManager();
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/Index.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/Index.tml?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/Index.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/Index.tml Mon Apr 23 08:13:22 2012
@@ -0,0 +1,7 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+<body>
+<p>
+ EntityManager Class Name: <span>${entityManagerClassName}</span>
+</p>
+</body>
+</html>
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/WEB-INF/web.xml?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/WEB-INF/web.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/app5/WEB-INF/web.xml Mon Apr 23 08:13:22 2012
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright 2012 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.app5</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>
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=1329111&r1=1329110&r2=1329111&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/conf/testng.xml Mon Apr 23 08:13:22 2012
@@ -31,6 +31,13 @@
</packages>
</test>
+ <test name="Explicit Provider Class Name In Persistence Unit Integration Tests" enabled="true">
+ <parameter name="tapestry.web-app-folder" value="src/test/app5" />
+ <packages>
+ <package name="org.apache.tapestry5.jpa.integration.app5" />
+ </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/app5/DummyEntityManager.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManager.java Mon Apr 23 08:13:22 2012
@@ -0,0 +1,240 @@
+// 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.app5;
+
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.metamodel.Metamodel;
+
+public class DummyEntityManager implements EntityManager
+{
+
+ public DummyEntityManager()
+ {
+
+ }
+
+ public void persist(Object entity)
+ {
+
+ }
+
+ public <T> T merge(T entity)
+ {
+ return null;
+ }
+
+ public void remove(Object entity)
+ {
+
+ }
+
+ public <T> T find(Class<T> entityClass, Object primaryKey)
+ {
+ return null;
+ }
+
+ public <T> T find(Class<T> entityClass, Object primaryKey, Map<String, Object> properties)
+ {
+ return null;
+ }
+
+ public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode)
+ {
+ return null;
+ }
+
+ public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode,
+ Map<String, Object> properties)
+ {
+ return null;
+ }
+
+ public <T> T getReference(Class<T> entityClass, Object primaryKey)
+ {
+ return null;
+ }
+
+ public void flush()
+ {
+
+ }
+
+ public void setFlushMode(FlushModeType flushMode)
+ {
+
+ }
+
+ public FlushModeType getFlushMode()
+ {
+ return null;
+ }
+
+ public void lock(Object entity, LockModeType lockMode)
+ {
+
+ }
+
+ public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties)
+ {
+
+ }
+
+ public void refresh(Object entity)
+ {
+
+ }
+
+ public void refresh(Object entity, Map<String, Object> properties)
+ {
+
+ }
+
+ public void refresh(Object entity, LockModeType lockMode)
+ {
+
+ }
+
+ public void refresh(Object entity, LockModeType lockMode, Map<String, Object> properties)
+ {
+
+ }
+
+ public void clear()
+ {
+
+ }
+
+ public void detach(Object entity)
+ {
+
+ }
+
+ public boolean contains(Object entity)
+ {
+ return false;
+ }
+
+ public LockModeType getLockMode(Object entity)
+ {
+ return null;
+ }
+
+ public void setProperty(String propertyName, Object value)
+ {
+
+ }
+
+ public Map<String, Object> getProperties()
+ {
+ return null;
+ }
+
+ public Query createQuery(String qlString)
+ {
+ return null;
+ }
+
+ public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
+ {
+ return null;
+ }
+
+ public <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass)
+ {
+ return null;
+ }
+
+ public Query createNamedQuery(String name)
+ {
+ return null;
+ }
+
+ public <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
+ {
+ return null;
+ }
+
+ public Query createNativeQuery(String sqlString)
+ {
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public Query createNativeQuery(String sqlString, Class resultClass)
+ {
+ return null;
+ }
+
+ public Query createNativeQuery(String sqlString, String resultSetMapping)
+ {
+ return null;
+ }
+
+ public void joinTransaction()
+ {
+
+ }
+
+ public <T> T unwrap(Class<T> cls)
+ {
+ return null;
+ }
+
+ public Object getDelegate()
+ {
+ return null;
+ }
+
+ public void close()
+ {
+
+ }
+
+ public boolean isOpen()
+ {
+ return false;
+ }
+
+ public EntityTransaction getTransaction()
+ {
+ return null;
+ }
+
+ public EntityManagerFactory getEntityManagerFactory()
+ {
+ return null;
+ }
+
+ public CriteriaBuilder getCriteriaBuilder()
+ {
+ return null;
+ }
+
+ public Metamodel getMetamodel()
+ {
+ return null;
+ }
+
+}
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyEntityManagerFactory.java Mon Apr 23 08:13:22 2012
@@ -0,0 +1,72 @@
+// Copyright 2012 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.app5;
+
+import javax.persistence.Cache;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnitUtil;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.metamodel.Metamodel;
+import java.util.Map;
+
+final class DummyEntityManagerFactory implements EntityManagerFactory
+{
+ public boolean isOpen()
+ {
+ return false;
+ }
+
+ public Map<String, Object> getProperties()
+ {
+ return null;
+ }
+
+ public PersistenceUnitUtil getPersistenceUnitUtil()
+ {
+ return null;
+ }
+
+ public Metamodel getMetamodel()
+ {
+ return null;
+ }
+
+ public CriteriaBuilder getCriteriaBuilder()
+ {
+ return null;
+ }
+
+ public Cache getCache()
+ {
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public EntityManager createEntityManager(Map map)
+ {
+ return new DummyEntityManager();
+ }
+
+ public EntityManager createEntityManager()
+ {
+ return new DummyEntityManager();
+ }
+
+ public void close()
+ {
+
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/DummyPersistenceProvider.java Mon Apr 23 08:13:22 2012
@@ -0,0 +1,41 @@
+// Copyright 2012 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.app5;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.ProviderUtil;
+import java.util.Map;
+
+@SuppressWarnings("rawtypes")
+public class DummyPersistenceProvider implements PersistenceProvider
+{
+ public EntityManagerFactory createEntityManagerFactory(String emName, Map map)
+ {
+ return new DummyEntityManagerFactory();
+ }
+
+ public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map)
+ {
+ return new DummyEntityManagerFactory();
+ }
+
+ public ProviderUtil getProviderUtil()
+ {
+ return null;
+ }
+
+}
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/ExplicitPersistenceProviderClassTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/ExplicitPersistenceProviderClassTest.java?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/ExplicitPersistenceProviderClassTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/apache/tapestry5/jpa/integration/app5/ExplicitPersistenceProviderClassTest.java Mon Apr 23 08:13:22 2012
@@ -0,0 +1,31 @@
+// Copyright 2012 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.app5;
+
+import org.apache.tapestry5.test.SeleniumTestCase;
+import org.testng.annotations.Test;
+
+public class ExplicitPersistenceProviderClassTest extends SeleniumTestCase
+{
+
+ @Test
+ public void check_entitymanager_class_name() throws Exception
+ {
+
+ open("/");
+
+ assertEquals(getText("//span"), DummyEntityManager.class.getName());
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/pages/Index.java?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/pages/Index.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/pages/Index.java Mon Apr 23 08:13:22 2012
@@ -0,0 +1,29 @@
+// Copyright 2012 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.app5.pages;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+public class Index
+{
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ public String getEntityManagerClassName() {
+ return entityManager.getClass().getName();
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/services/AppModule.java?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/services/AppModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app5/services/AppModule.java Mon Apr 23 08:13:22 2012
@@ -0,0 +1,58 @@
+// Copyright 2012 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.app5.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;
+import org.apache.tapestry5.jpa.integration.app5.DummyPersistenceProvider;
+
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceProviderResolver;
+import javax.persistence.spi.PersistenceProviderResolverHolder;
+import java.util.Arrays;
+import java.util.List;
+
+@SubModule(JpaModule.class)
+public class AppModule {
+
+ static {
+
+ PersistenceProviderResolverHolder.setPersistenceProviderResolver(new PersistenceProviderResolver() {
+ @Override
+ public List<PersistenceProvider> getPersistenceProviders() {
+ return Arrays.<PersistenceProvider>asList(new DummyPersistenceProvider());
+ }
+
+ @Override
+ public void clearCachedProviders() {
+ }
+ }
+
+ );
+ }
+
+ @Contribute(SymbolProvider.class)
+ @ApplicationDefaults
+ public static void provideApplicationDefaults(
+ final MappedConfiguration<String, String> configuration) {
+ configuration.add(JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERS, "false");
+ configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR, "/explicit-persistence-provider-class-persistence-unit.xml");
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/explicit-persistence-provider-class-persistence-unit.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/explicit-persistence-provider-class-persistence-unit.xml?rev=1329111&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/explicit-persistence-provider-class-persistence-unit.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/resources/explicit-persistence-provider-class-persistence-unit.xml Mon Apr 23 08:13:22 2012
@@ -0,0 +1,16 @@
+<?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">
+ <provider>org.apache.tapestry5.jpa.integration.app5.DummyPersistenceProvider</provider>
+ <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>