Index: data/hibernate/src/test/java/org/appfuse/dao/UserDaoTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/src/test/java/org/appfuse/dao/UserDaoTest.java (revision 3592) +++ data/hibernate/src/test/java/org/appfuse/dao/UserDaoTest.java (revision ) @@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.hibernate4.HibernateSystemException; import org.springframework.test.annotation.ExpectedException; import org.springframework.test.annotation.NotTransactional; @@ -24,10 +25,6 @@ private UserDao dao; @Autowired private RoleDao rdao; - @Autowired - private CompassTemplate compassTemplate; - @Autowired - private CompassGps compassGps; @Test @ExpectedException(DataAccessException.class) @@ -55,7 +52,7 @@ @Test @NotTransactional - @ExpectedException(DataIntegrityViolationException.class) + @ExpectedException(HibernateSystemException.class) public void testUpdateUser() throws Exception { User user = dao.get(-1L); @@ -149,45 +146,5 @@ public void testUserNotExists() throws Exception { boolean b = dao.exists(111L); assertFalse(b); - } - - @Test - public void testUserSearch() throws Exception { - // reindex all the data - compassGps.index(); - - User user = compassTemplate.get(User.class, -2); - assertNotNull(user); - assertEquals("Matt", user.getFirstName()); - - compassTemplate.execute(new CompassCallbackWithoutResult() { - @Override - protected void doInCompassWithoutResult(CompassSession compassSession) throws CompassException { - CompassHits hits = compassSession.find("Matt"); - assertEquals(1, hits.length()); - assertEquals("Matt", ((User) hits.data(0)).getFirstName()); - assertEquals("Matt", hits.resource(0).getValue("firstName")); - } - }); - - // test mirroring - user = dao.get(-2L); - user.setFirstName("MattX"); - dao.saveUser(user); - flush(); - - // now verify it is reflected in the index - user = compassTemplate.get(User.class, -2); - assertNotNull(user); - assertEquals("MattX", user.getFirstName()); - - compassTemplate.execute(new CompassCallbackWithoutResult() { - @Override - protected void doInCompassWithoutResult(CompassSession compassSession) throws CompassException { - CompassHits hits = compassSession.find("MattX"); - assertEquals(1, hits.length()); - assertEquals("MattX", ((User) hits.data(0)).getFirstName()); - } - }); } } Index: data/hibernate/src/main/java/org/appfuse/dao/hibernate/GenericDaoHibernate.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/src/main/java/org/appfuse/dao/hibernate/GenericDaoHibernate.java (revision 3592) +++ data/hibernate/src/main/java/org/appfuse/dao/hibernate/GenericDaoHibernate.java (revision ) @@ -38,7 +38,6 @@ */ protected final Log log = LogFactory.getLog(getClass()); private Class persistentClass; - private HibernateTemplate hibernateTemplate; private SessionFactory sessionFactory; /** @@ -60,13 +59,8 @@ public GenericDaoHibernate(final Class persistentClass, SessionFactory sessionFactory) { this.persistentClass = persistentClass; this.sessionFactory = sessionFactory; - this.hibernateTemplate = new HibernateTemplate(sessionFactory); } - public HibernateTemplate getHibernateTemplate() { - return this.hibernateTemplate; - } - public SessionFactory getSessionFactory() { return this.sessionFactory; } @@ -75,7 +69,6 @@ @Required public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; - this.hibernateTemplate = new HibernateTemplate(sessionFactory); } /** @@ -83,7 +76,7 @@ */ @SuppressWarnings("unchecked") public List getAll() { - return hibernateTemplate.loadAll(this.persistentClass); + return sessionFactory.getCurrentSession().createQuery("from " + this.persistentClass).list(); } /** @@ -100,7 +93,7 @@ */ @SuppressWarnings("unchecked") public T get(PK id) { - T entity = (T) hibernateTemplate.get(this.persistentClass, id); + T entity = (T) sessionFactory.getCurrentSession().get(this.persistentClass, id); if (entity == null) { log.warn("Uh oh, '" + this.persistentClass + "' object with id '" + id + "' not found..."); @@ -115,7 +108,7 @@ */ @SuppressWarnings("unchecked") public boolean exists(PK id) { - T entity = (T) hibernateTemplate.get(this.persistentClass, id); + T entity = (T) sessionFactory.getCurrentSession().get(this.persistentClass, id); return entity != null; } @@ -124,14 +117,14 @@ */ @SuppressWarnings("unchecked") public T save(T object) { - return (T) hibernateTemplate.merge(object); + return (T) sessionFactory.getCurrentSession().merge(object); } /** * {@inheritDoc} */ public void remove(PK id) { - hibernateTemplate.delete(this.get(id)); + sessionFactory.getCurrentSession().delete(this.get(id)); } /** @@ -141,13 +134,13 @@ public List findByNamedQuery(String queryName, Map queryParams) { String[] params = new String[queryParams.size()]; Object[] values = new Object[queryParams.size()]; - + int index = 0; for (String s : queryParams.keySet()) { params[index] = s; values[index++] = queryParams.get(s); } - return hibernateTemplate.findByNamedQueryAndNamedParam(queryName, params, values); + return null; // hibernateTemplate.findByNamedQueryAndNamedParam(queryName, params, values); } } Index: pom.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- pom.xml (revision 3592) +++ pom.xml (revision ) @@ -557,7 +557,7 @@ 2.0.3 1.2 1.1.14 - 3.6.1.Final + 4.0.1.Final 3.6.1.Final 2.3.4.726 1.4.1 Index: data/hibernate/src/main/java/org/appfuse/dao/hibernate/LookupDaoHibernate.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/src/main/java/org/appfuse/dao/hibernate/LookupDaoHibernate.java (revision 3592) +++ data/hibernate/src/main/java/org/appfuse/dao/hibernate/LookupDaoHibernate.java (revision ) @@ -19,16 +19,8 @@ @Repository public class LookupDaoHibernate implements LookupDao { private Log log = LogFactory.getLog(LookupDaoHibernate.class); - private HibernateTemplate hibernateTemplate; - - /** - * Initialize LookupDaoHibernate with Hibernate SessionFactory. - * @param sessionFactory - */ @Autowired - public LookupDaoHibernate(final SessionFactory sessionFactory) { - this.hibernateTemplate = new HibernateTemplate(sessionFactory); - } + private SessionFactory sessionFactory; /** * {@inheritDoc} @@ -37,6 +29,6 @@ public List getRoles() { log.debug("Retrieving all role names..."); - return hibernateTemplate.find("from Role order by name"); + return sessionFactory.getCurrentSession().createQuery("from Role order by name").list(); } } Index: data/hibernate/src/main/java/org/appfuse/dao/hibernate/RoleDaoHibernate.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/src/main/java/org/appfuse/dao/hibernate/RoleDaoHibernate.java (revision 3592) +++ data/hibernate/src/main/java/org/appfuse/dao/hibernate/RoleDaoHibernate.java (revision ) @@ -27,7 +27,8 @@ * {@inheritDoc} */ public Role getRoleByName(String rolename) { - List roles = getHibernateTemplate().find("from Role where name=?", rolename); + List roles = getSessionFactory().getCurrentSession().createQuery("from Role where name=?") + .setParameter(0, rolename).list(); if (roles.isEmpty()) { return null; } else { @@ -40,6 +41,6 @@ */ public void removeRole(String rolename) { Object role = getRoleByName(rolename); - getHibernateTemplate().delete(role); + getSessionFactory().getCurrentSession().delete(role); } } Index: data/hibernate/pom.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/pom.xml (revision 3592) +++ data/hibernate/pom.xml (revision ) @@ -152,4 +152,9 @@ ${ehcache.version} + + + 2.3.1 + 4.0.1.Final + Index: data/hibernate/src/main/java/org/appfuse/dao/BaseDaoTestCase.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/src/main/java/org/appfuse/dao/BaseDaoTestCase.java (revision 3592) +++ data/hibernate/src/main/java/org/appfuse/dao/BaseDaoTestCase.java (revision ) @@ -6,7 +6,6 @@ import org.hibernate.SessionFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; @@ -85,8 +84,6 @@ * when can't find 'sessionFactory' bean */ protected void flush() throws BeansException { - HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory); - hibernateTemplate.flush(); - hibernateTemplate.clear(); + sessionFactory.getCurrentSession().flush(); } } Index: data/hibernate/src/main/java/org/appfuse/dao/hibernate/UserDaoHibernate.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/src/main/java/org/appfuse/dao/hibernate/UserDaoHibernate.java (revision 3592) +++ data/hibernate/src/main/java/org/appfuse/dao/hibernate/UserDaoHibernate.java (revision ) @@ -2,7 +2,9 @@ import org.appfuse.dao.UserDao; import org.appfuse.model.User; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.orm.hibernate3.SessionFactoryUtils; import org.springframework.security.core.userdetails.UserDetails; @@ -11,6 +13,7 @@ import org.springframework.stereotype.Repository; import javax.persistence.Table; +import javax.sql.DataSource; import java.util.List; /** @@ -26,6 +29,9 @@ @Repository("userDao") public class UserDaoHibernate extends GenericDaoHibernate implements UserDao, UserDetailsService { + @Autowired + private DataSource dataSource; + /** * Constructor that sets the entity to User.class. */ @@ -38,7 +44,7 @@ */ @SuppressWarnings("unchecked") public List getUsers() { - return getHibernateTemplate().find("from User u order by upper(u.username)"); + return getSessionFactory().getCurrentSession().createQuery("from User u order by upper(u.username)").list(); } /** @@ -48,9 +54,9 @@ if (log.isDebugEnabled()) { log.debug("user's id: " + user.getId()); } - getHibernateTemplate().saveOrUpdate(user); + getSessionFactory().getCurrentSession().saveOrUpdate(user); // necessary to throw a DataIntegrityViolation and catch it in UserManager - getHibernateTemplate().flush(); + getSessionFactory().getCurrentSession().flush(); return user; } @@ -71,7 +77,8 @@ * {@inheritDoc} */ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - List users = getHibernateTemplate().find("from User where username=?", username); + List users = getSessionFactory().getCurrentSession() + .createQuery("from User where username=?").setParameter(0, username).list(); if (users == null || users.isEmpty()) { throw new UsernameNotFoundException("user '" + username + "' not found..."); } else { @@ -83,8 +90,7 @@ * {@inheritDoc} */ public String getUserPassword(String username) { - SimpleJdbcTemplate jdbcTemplate = - new SimpleJdbcTemplate(SessionFactoryUtils.getDataSource(getSessionFactory())); + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Table table = AnnotationUtils.findAnnotation(User.class, Table.class); return jdbcTemplate.queryForObject( "select password from " + table.name() + " where username=?", String.class, username); Index: data/hibernate/src/main/resources/applicationContext-dao.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- data/hibernate/src/main/resources/applicationContext-dao.xml (revision 3592) +++ data/hibernate/src/main/resources/applicationContext-dao.xml (revision ) @@ -7,10 +7,13 @@ + + - + - + hibernate.dialect=${hibernate.dialect} @@ -24,52 +27,13 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -