[jboss-cvs] jboss-seam/examples/spring/src/org/jboss/seam/example/spring ...
Michael Youngstrom
youngm at gmail.com
Wed Jul 11 13:22:51 EDT 2007
User: myoungstrom
Date: 07/07/11 13:22:51
Modified: examples/spring/src/org/jboss/seam/example/spring
RegisterAction.java
Added: examples/spring/src/org/jboss/seam/example/spring
HibernateTestService.java
Log:
JBSEAM-1346
Revision Changes Path
1.8 +5 -1 jboss-seam/examples/spring/src/org/jboss/seam/example/spring/RegisterAction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegisterAction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/spring/src/org/jboss/seam/example/spring/RegisterAction.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- RegisterAction.java 9 Jul 2007 23:10:53 -0000 1.7
+++ RegisterAction.java 11 Jul 2007 17:22:51 -0000 1.8
@@ -1,4 +1,4 @@
-//$Id: RegisterAction.java,v 1.7 2007/07/09 23:10:53 myoungstrom Exp $
+//$Id: RegisterAction.java,v 1.8 2007/07/11 17:22:51 myoungstrom Exp $
package org.jboss.seam.example.spring;
import static org.jboss.seam.ScopeType.EVENT;
@@ -18,6 +18,9 @@
@In("#{userService}")
private UserService userService;
+ @In("#{hibernateTestService}")
+ private HibernateTestService hibernateTestService;
+
@In
private FacesMessages facesMessages;
@@ -32,6 +35,7 @@
try {
userService.createUser(user);
+ hibernateTestService.testHibernateIntegration();
registered = true;
} catch(ValidationException e) {
facesMessages.add(e.getMessage());
1.1 date: 2007/07/11 17:22:51; author: myoungstrom; state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/example/spring/HibernateTestService.java
Index: HibernateTestService.java
===================================================================
/**
*
*/
package org.jboss.seam.example.spring;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
/**
* A Service to demonstrate/test some different methods of accessing Seam Managed Hibernate Session in Spring.
* @author Mike Youngstrom
*/
public class HibernateTestService extends HibernateDaoSupport {
private static final String HIBERNATE_HOTEL_NAME = "This is the Hibernate Hotel";
private static final String HIBERNATE_HOTEL_ADDRESS = "Hibernate Address";
private TransactionTemplate hibernateTransactionTemplate;
public void testHibernateIntegration() {
hibernateTransactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
// Testing access through HibernateTemplate
Hotel hotel = (Hotel)getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session session) throws HibernateException, SQLException {
return getFirstHotel(session);
}
});
hotel.setName(HIBERNATE_HOTEL_NAME);
return null;
}
});
hibernateTransactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
// Testing access through SessionFactory.getCurrentSession()
Hotel hotel = getFirstHotel(getSessionFactory().getCurrentSession());
if (!HIBERNATE_HOTEL_NAME.equals(hotel.getName())) {
throw new RuntimeException("Hotel name not set. Hibernate integration not working.");
}
hotel.setAddress(HIBERNATE_HOTEL_ADDRESS);
return null;
}
});
hibernateTransactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
// Testing access through SessionFactory.getCurrentSession()
Hotel hotel = getFirstHotel(getSessionFactory().getCurrentSession());
if (!HIBERNATE_HOTEL_ADDRESS.equals(hotel.getAddress())) {
throw new RuntimeException("Hotel address not set. Hibernate integration not working.");
}
return null;
}
});
}
/**
* @return
*/
private Hotel getFirstHotel(Session session) {
List<Hotel> results = session.createQuery("from Hotel").list();
if (results.size() <= 0) {
throw new RuntimeException("Hibernate integration is broken");
}
Hotel hotel = results.get(0);
return hotel;
}
/**
* @param transactionTemplate the transactionTemplate to set
*/
public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
this.hibernateTransactionTemplate = transactionTemplate;
}
}
More information about the jboss-cvs-commits
mailing list