[seam-commits] Seam SVN: r13915 - in branches/community/Seam_2_2/examples/spring: jboss6 and 11 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Nov 18 11:45:24 EST 2010
Author: manaRH
Date: 2010-11-18 11:45:22 -0500 (Thu, 18 Nov 2010)
New Revision: 13915
Added:
branches/community/Seam_2_2/examples/spring/build-jboss6.xml
branches/community/Seam_2_2/examples/spring/jboss6/
branches/community/Seam_2_2/examples/spring/jboss6/src/
branches/community/Seam_2_2/examples/spring/jboss6/src/javax/
branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/
branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/SharedCacheMode.java
branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/ValidationMode.java
branches/community/Seam_2_2/examples/spring/jboss6/src/org/
branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/
branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/orm/
branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/orm/jpa/
branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/orm/jpa/persistenceunit/
branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java
Modified:
branches/community/Seam_2_2/examples/spring/build.xml
branches/community/Seam_2_2/examples/spring/resources/META-INF/persistence-spring.xml
branches/community/Seam_2_2/examples/spring/resources/WEB-INF/applicationContext.xml
branches/community/Seam_2_2/examples/spring/src/org/jboss/seam/example/spring/UserService.java
Log:
JBSEAM-4565 hacked build script for deploying to jboss as 6
Added: branches/community/Seam_2_2/examples/spring/build-jboss6.xml
===================================================================
--- branches/community/Seam_2_2/examples/spring/build-jboss6.xml (rev 0)
+++ branches/community/Seam_2_2/examples/spring/build-jboss6.xml 2010-11-18 16:45:22 UTC (rev 13915)
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+
+<project name="Spring JBossWar for JBoss AS 6" default="jbosswar6" basedir=".">
+
+ <!-- Naming -->
+ <property name="Name" value="The Spring Example for JBoss War"/>
+ <property name="example.name" value="jboss-seam-spring"/>
+ <property name="jboss6" value="yes"/>
+
+ <property name="seam.ui.lib" value="true"/>
+ <property name="seam.debug.lib" value="true"/>
+ <property name="facelets.lib" value="true"/>
+ <property name="seam.ioc.war.lib" value="true"/>
+ <property name="spring.lib" value="true"/>
+ <!-- needed because jboss must include hibernate search -->
+ <property name="search.lib" value="true"/>
+ <property name="richfaces.lib" value="true"/>
+ <property name="cglib.lib" value="true"/>
+
+ <target name="init" depends="preparesrc">
+ <antcall target="SeamExample.init"/>
+ <path id="build.classpath.extras">
+ <fileset dir="${lib.search.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+ </target>
+
+ <target name="preparesrc">
+ <mkdir dir="${src.java.dir}"/>
+
+ <copy todir="${src.java.dir}">
+ <fileset includes="**" dir="jboss6/src" />
+ </copy>
+ <copy todir="${src.java.dir}">
+ <fileset includes="**" dir="src"/>
+ </copy>
+ </target>
+
+ <target name="mynoejb.jar" depends="jar">
+ <copy todir="${war.dir}/WEB-INF/classes">
+ <fileset dir="${jar.dir}">
+ <exclude name="**/ejb-jar.xml" />
+ <exclude name="javax/**"/> <!-- required jpa 2 classes for hacking jboss as6-->
+ </fileset>
+ <fileset refid="noejb.jar.extras" />
+ <fileset refid="noejb.jar.resources" />
+ </copy>
+ </target>
+
+ <target name="mynoejb.archive" depends="mynoejb.jar,noejb.war" description="Package the archives for non-ejb war">
+ <jar jarfile="${dist.dir}/${example.name}.war">
+ <fileset dir="${war.dir}" />
+ <zipfileset dir="${dist.dir}" prefix="WEB-INF/lib">
+ <include name="${example.name}.jar" />
+ </zipfileset>
+ </jar>
+ </target>
+
+ <target name="jbosswar6" depends="mynoejb.archive" >
+
+ <copy file="${dist.dir}/${example.name}.war" todir="${deploy.dir}" />
+ </target>
+
+ <import file="../build.xml"/>
+
+ <fileset id="noejb.jar.extras" dir="${resources.dir}">
+ <include name="META-INF/persistence-spring.xml"/>
+ </fileset>
+
+</project>
Property changes on: branches/community/Seam_2_2/examples/spring/build-jboss6.xml
___________________________________________________________________
Name: svn:executable
+ *
Modified: branches/community/Seam_2_2/examples/spring/build.xml
===================================================================
--- branches/community/Seam_2_2/examples/spring/build.xml 2010-11-18 08:29:28 UTC (rev 13914)
+++ branches/community/Seam_2_2/examples/spring/build.xml 2010-11-18 16:45:22 UTC (rev 13915)
@@ -18,9 +18,13 @@
<target name="all" depends="jbosswar" description="Build Spring Booking example, for deployment to all supported application servers"/>
- <target name="jboss42" description="Build the Spring example, and deploy to JBoss 4.2.x.GA">
+ <target name="jboss42" description="Build the Spring example, and deploy to JBoss AS 4.2.x.GA">
<ant antfile="build-jboss42.xml"/>
</target>
+
+ <target name="jboss6" description="Build the Spring example, and deploy to JBoss AS 6">
+ <ant antfile="build-jboss6.xml"/>
+ </target>
</project>
Added: branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/SharedCacheMode.java
===================================================================
--- branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/SharedCacheMode.java (rev 0)
+++ branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/SharedCacheMode.java 2010-11-18 16:45:22 UTC (rev 13915)
@@ -0,0 +1,40 @@
+package javax.persistence;
+
+/**
+ * Specifies how the provider must use a second-level cache for the
+ * persistence unit. Corresponds to the value of the <code>persistence.xml</code>
+ * <code>shared-cache-mode</code> element, and returned as the result of
+ * {@link javax.persistence.spi.PersistenceUnitInfo#getSharedCacheMode()}.
+ *
+ * @since Java Persistence 2.0
+ */
+public enum SharedCacheMode {
+ /**
+ * All entities and entity-related state and data are cached.
+ */
+ ALL,
+
+ /**
+ * Caching is disabled for the persistence unit.
+ */
+ NONE,
+
+ /**
+ * Caching is enabled for all entities for <code>Cacheable(true)</code>
+ * is specified. All other entities are not cached.
+ */
+ ENABLE_SELECTIVE,
+
+ /**
+ * Caching is enabled for all entities except those for which
+ * <code>Cacheable(false) is specified. Entities for which
+ * <code>Cacheable(false) is specified are not cached.
+ */
+ DISABLE_SELECTIVE,
+
+ /**
+ *
+ * Caching behavior is undefined: provider-specific defaults may apply.
+ */
+ UNSPECIFIED
+}
Added: branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/ValidationMode.java
===================================================================
--- branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/ValidationMode.java (rev 0)
+++ branches/community/Seam_2_2/examples/spring/jboss6/src/javax/persistence/ValidationMode.java 2010-11-18 16:45:22 UTC (rev 13915)
@@ -0,0 +1,8 @@
+package javax.persistence;
+
+public enum ValidationMode
+{
+ AUTO,
+ CALLBACK,
+ NONE
+}
Added: branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java
===================================================================
--- branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java (rev 0)
+++ branches/community/Seam_2_2/examples/spring/jboss6/src/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java 2010-11-18 16:45:22 UTC (rev 13915)
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2002-2008 the original author or authors.
+ *
+ * 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.springframework.orm.jpa.persistenceunit;
+
+import javax.persistence.SharedCacheMode;
+import javax.persistence.ValidationMode;
+import javax.persistence.spi.ClassTransformer;
+
+import org.springframework.core.DecoratingClassLoader;
+import org.springframework.instrument.classloading.LoadTimeWeaver;
+import org.springframework.instrument.classloading.SimpleThrowawayClassLoader;
+import org.springframework.util.Assert;
+
+/**
+ * Subclass of {@link MutablePersistenceUnitInfo} that adds instrumentation hooks based on
+ * Spring's {@link org.springframework.instrument.classloading.LoadTimeWeaver} abstraction.
+ *
+ * <p>This class is restricted to package visibility, in contrast to its superclass.
+ *
+ * @author Rod Johnson
+ * @author Juergen Hoeller
+ * @author Costin Leau
+ * @since 2.0
+ * @see PersistenceUnitManager
+ */
+class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo {
+
+ private LoadTimeWeaver loadTimeWeaver;
+
+ private ClassLoader classLoader;
+
+
+ /**
+ * Initialize this PersistenceUnitInfo with the LoadTimeWeaver SPI interface
+ * used by Spring to add instrumentation to the current class loader.
+ */
+ public void init(LoadTimeWeaver loadTimeWeaver) {
+ Assert.notNull(loadTimeWeaver, "LoadTimeWeaver must not be null");
+ this.loadTimeWeaver = loadTimeWeaver;
+ this.classLoader = loadTimeWeaver.getInstrumentableClassLoader();
+ }
+
+ /**
+ * Initialize this PersistenceUnitInfo with the current class loader
+ * (instead of with a LoadTimeWeaver).
+ */
+ public void init(ClassLoader classLoader) {
+ Assert.notNull(classLoader, "ClassLoader must not be null");
+ this.classLoader = classLoader;
+ }
+
+
+ /**
+ * This implementation returns the LoadTimeWeaver's instrumentable ClassLoader,
+ * if specified.
+ */
+ @Override
+ public ClassLoader getClassLoader() {
+ return this.classLoader;
+ }
+
+ /**
+ * This implementation delegates to the LoadTimeWeaver, if specified.
+ */
+ @Override
+ public void addTransformer(ClassTransformer classTransformer) {
+ if (this.loadTimeWeaver == null) {
+ throw new IllegalStateException("Cannot apply class transformer without LoadTimeWeaver specified");
+ }
+ this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer));
+ }
+
+ /**
+ * This implementation delegates to the LoadTimeWeaver, if specified.
+ */
+ @Override
+ public ClassLoader getNewTempClassLoader() {
+ ClassLoader tcl = (this.loadTimeWeaver != null ? this.loadTimeWeaver.getThrowawayClassLoader() :
+ new SimpleThrowawayClassLoader(this.classLoader));
+ String packageToExclude = getPersistenceProviderPackageName();
+ if (packageToExclude != null && tcl instanceof DecoratingClassLoader) {
+ ((DecoratingClassLoader) tcl).excludePackage(packageToExclude);
+ }
+ return tcl;
+ }
+
+ public ValidationMode getValidationMode() {
+
+ return null;
+ }
+
+ public SharedCacheMode getSharedCacheMode(){
+ return null;
+ }
+}
\ No newline at end of file
Modified: branches/community/Seam_2_2/examples/spring/resources/META-INF/persistence-spring.xml
===================================================================
--- branches/community/Seam_2_2/examples/spring/resources/META-INF/persistence-spring.xml 2010-11-18 08:29:28 UTC (rev 13914)
+++ branches/community/Seam_2_2/examples/spring/resources/META-INF/persistence-spring.xml 2010-11-18 16:45:22 UTC (rev 13915)
@@ -5,7 +5,7 @@
version="1.0">
<persistence-unit name="bookingDatabase" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
- <!-- classes must be enumerated due to a known bug in Seam 2.5.6, SPR-5787 -->
+ <!-- classes must be enumerated due to a known bug in Spring 2.5.6, SPR-5787 -->
<class>org.jboss.seam.example.spring.Booking</class>
<class>org.jboss.seam.example.spring.Hotel</class>
<class>org.jboss.seam.example.spring.User</class>
Modified: branches/community/Seam_2_2/examples/spring/resources/WEB-INF/applicationContext.xml
===================================================================
--- branches/community/Seam_2_2/examples/spring/resources/WEB-INF/applicationContext.xml 2010-11-18 08:29:28 UTC (rev 13914)
+++ branches/community/Seam_2_2/examples/spring/resources/WEB-INF/applicationContext.xml 2010-11-18 16:45:22 UTC (rev 13915)
@@ -28,7 +28,12 @@
<!-- Use alternate location to prevent JBoss AS from automatically loading persistence units (in-container) -->
<property name="persistenceXmlLocation" value="classpath*:/META-INF/persistence-spring.xml"/>
</bean>
+
+ <bean id="entityManagerWrapper" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
+ <property name="entityManagerFactory" ref="entityManagerFactory"/>
+ </bean>
+
<!-- This example uses resource local JpaTransactionManager. You could just as easily use a JtaTransactionManager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<!-- Be sure to specify the SeamManagedEntityManagerFactory since that will manage the EM that will be
@@ -39,7 +44,9 @@
<tx:annotation-driven proxy-target-class="true" />
<!-- Example using PersistenceAnnotationBeanPostProcessor for persistence -->
- <bean id="userService" class="org.jboss.seam.example.spring.UserService"/>
+ <bean id="userService" class="org.jboss.seam.example.spring.UserService">
+ <property name="entityManagerFactory" ref="seamEntityManagerFactory"/>
+ </bean>
<!-- Example using JpaDaoSupport for persistence -->
<bean id="bookingService" class="org.jboss.seam.example.spring.BookingService">
@@ -56,7 +63,7 @@
<seam:configure-scopes default-auto-create="true" />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
- <!-- Because we have multiple EntityManagerFactories in this applicaitonContext identify the
+ <!-- Because we have multiple EntityManagerFactories in this applicationContext identify the
SeamManagedEntityManagerFactory as the default -->
<property name="defaultPersistenceUnitName" value="conversationScoped"/>
</bean>
Modified: branches/community/Seam_2_2/examples/spring/src/org/jboss/seam/example/spring/UserService.java
===================================================================
--- branches/community/Seam_2_2/examples/spring/src/org/jboss/seam/example/spring/UserService.java 2010-11-18 08:29:28 UTC (rev 13914)
+++ branches/community/Seam_2_2/examples/spring/src/org/jboss/seam/example/spring/UserService.java 2010-11-18 16:45:22 UTC (rev 13915)
@@ -1,19 +1,21 @@
package org.jboss.seam.example.spring;
import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.transaction.annotation.Transactional;
/**
* @author Mike Youngstrom
*
*/
-public class UserService {
+public class UserService extends JpaDaoSupport {
- @PersistenceContext
- private EntityManager entityManager;
+ //@PersistenceContext
+ //@Autowired(required=true)
+ //private EntityManager entityManager;
@Transactional
public boolean changePassword(String username, String oldPassword, String newPassword) {
@@ -37,18 +39,19 @@
if (username == null || "".equals(username)) {
throw new IllegalArgumentException("Username cannot be null");
}
- return entityManager.find(User.class, username);
+ return getJpaTemplate().find(User.class, username);
}
@Transactional
public User findUser(String username, String password) {
try {
- return (User)
+ /*return (User)
entityManager.createQuery("select u from User u where u.username=:username and u.password=:password")
.setParameter("username", username)
.setParameter("password", password)
- .getSingleResult();
- } catch (PersistenceException e) {
+ .getSingleResult();*/
+ return (User) getJpaTemplate().find("select u from User u where u.username=?1 and u.password=?2", username, password).get(0);
+ } catch (DataAccessException e) {
return null;
}
}
@@ -63,6 +66,7 @@
if (existingUser != null) {
throw new ValidationException("Username "+user.getUsername()+" already exists");
}
- entityManager.persist(user);
+ getJpaTemplate().persist(user);
+ getJpaTemplate().flush();
}
}
More information about the seam-commits
mailing list