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 16:32:31 UTC
svn commit: r1081140 - in /tapestry/tapestry5/trunk/tapestry-jpa/src:
main/java/org/apache/tapestry5/internal/jpa/
main/java/org/apache/tapestry5/jpa/ test/java/org/example/app/pages/
test/java/org/example/app/services/ test/java/org/example/app/servic...
Author: drobiazko
Date: Sun Mar 13 15:32:30 2011
New Revision: 1081140
URL: http://svn.apache.org/viewvc?rev=1081140&view=rev
Log:
TAP5-1472: Made persistence configuration file configurable as symbol value.
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/internal/jpa/PersistenceContentHandler.java
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaModule.java
tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaSymbols.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/CommitAfterDemo.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java
tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java
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=1081140&r1=1081139&r2=1081140&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 15:32:30 2011
@@ -28,6 +28,7 @@ import javax.persistence.spi.Persistence
import javax.persistence.spi.PersistenceProviderResolverHolder;
import javax.persistence.spi.PersistenceUnitInfo;
+import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
@@ -46,7 +47,7 @@ public class EntityManagerSourceImpl imp
private final List<TapestryPersistenceUnitInfo> persistenceUnitInfos;
- public EntityManagerSourceImpl(final Logger logger,
+ public EntityManagerSourceImpl(final Logger logger, final Resource persistenceDescriptor,
final Map<String, PersistenceUnitConfigurer> configuration)
{
super();
@@ -54,12 +55,16 @@ public class EntityManagerSourceImpl imp
final PersistenceParser parser = new PersistenceParser();
- final InputStream inputStream = PersistenceParser.class
- .getResourceAsStream("/META-INF/persistence.xml");
+ InputStream inputStream = null;
try
{
+ inputStream = persistenceDescriptor.openStream();
persistenceUnitInfos = parser.parse(inputStream);
}
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
finally
{
InternalUtils.close(inputStream);
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=1081140&r1=1081139&r2=1081140&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 Sun Mar 13 15:32:30 2011
@@ -1,3 +1,17 @@
+// 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 java.util.List;
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=1081140&r1=1081139&r2=1081140&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 15:32:30 2011
@@ -36,6 +36,7 @@ import org.apache.tapestry5.ioc.LoggerSo
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.ObjectProvider;
import org.apache.tapestry5.ioc.OrderedConfiguration;
+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;
@@ -66,11 +67,13 @@ public class JpaModule
binder.bind(JpaTransactionAdvisor.class, JpaTransactionAdvisorImpl.class);
}
- public static EntityManagerSource buildEntityManagerSource(final Logger logger,
+ public static EntityManagerSource buildEntityManagerSource(final Logger logger,
+ @Symbol(JpaSymbols.PERSISTENCE_DESCRIPTOR)
+ Resource persistenceDescriptor,
final Map<String, PersistenceUnitConfigurer> configuration,
final RegistryShutdownHub hub)
{
- final EntityManagerSourceImpl ems = new EntityManagerSourceImpl(logger, configuration);
+ final EntityManagerSourceImpl ems = new EntityManagerSourceImpl(logger, persistenceDescriptor, configuration);
hub.addRegistryShutdownListener(ems);
@@ -137,6 +140,7 @@ public class JpaModule
configuration.add(JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERS, "true");
configuration.add(JpaSymbols.EARLY_START_UP, "true");
configuration.add(JpaSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED, "true");
+ configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR, "/META-INF/persistence.xml");
}
@Contribute(ValueEncoderSource.class)
Modified: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaSymbols.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaSymbols.java?rev=1081140&r1=1081139&r2=1081140&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaSymbols.java (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaSymbols.java Sun Mar 13 15:32:30 2011
@@ -14,6 +14,11 @@
package org.apache.tapestry5.jpa;
+/**
+ * Configuration symbols, for use with contributions to {@link org.apache.tapestry5.ioc.services.ApplicationDefaults}.
+ *
+ * @since 5.3.0
+ */
public class JpaSymbols
{
public static final String PROVIDE_ENTITY_VALUE_ENCODERS = "tapestry.jpa.provide-entity-value-encoders";
@@ -32,4 +37,12 @@ public class JpaSymbols
* @since 5.3.0
*/
public static final String ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED = "tapestry.jpa.entity-session-state-persistence-strategy-enabled";
+
+ /**
+ * The location of the persistence configuration file, located on the classpath. This
+ * will normally be <code>/META-INF/persistence.xml</code>.
+ *
+ * @since 5.3.0
+ */
+ public static final String PERSISTENCE_DESCRIPTOR = "tapestry.jpa.persistence-descriptor";
}
Modified: tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/CommitAfterDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/CommitAfterDemo.java?rev=1081140&r1=1081139&r2=1081140&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/CommitAfterDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/pages/CommitAfterDemo.java Sun Mar 13 15:32:30 2011
@@ -1,3 +1,17 @@
+// 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.sql.SQLException;
Modified: 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=1081140&r1=1081139&r2=1081140&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/UserDAO.java Sun Mar 13 15:32:30 2011
@@ -1,3 +1,17 @@
+// 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 java.util.List;
Modified: 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=1081140&r1=1081139&r2=1081140&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app/services/impl/UserDAOImpl.java Sun Mar 13 15:32:30 2011
@@ -1,3 +1,17 @@
+// 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.impl;
import java.util.List;