List of usage examples for org.hibernate Query setProperties
Query<R> setProperties(Map bean);
From source file:org.springframework.orm.hibernate3.StatelessHibernateTemplate.java
License:Apache License
public List findByNamedQueryAndValueBean(final String queryName, final Object valueBean) throws DataAccessException { return (List) execute(new CombinedHibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { return executeQuery(session.getNamedQuery(queryName)); }/*w w w. j ava 2s. c o m*/ public Object doInHibernate(StatelessSession session) throws HibernateException { return executeQuery(session.getNamedQuery(queryName)); } private List executeQuery(Query queryObject) { prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); } }, true); }
From source file:org.springframework.orm.hibernate4.HibernateTemplateTests.java
License:Apache License
@Test public void testFindByValueBean() { Query query = mock(Query.class); TestBean tb = new TestBean(); List list = new ArrayList(); given(session.createQuery("some query string")).willReturn(query); given(query.setProperties(tb)).willReturn(query); given(query.list()).willReturn(list); List result = hibernateTemplate.findByValueBean("some query string", tb); assertTrue("Correct list", result == list); verify(query).setProperties(tb);//from www . jav a 2 s . c o m }
From source file:org.springframework.orm.hibernate4.HibernateTemplateTests.java
License:Apache License
@Test public void testFindByNamedQueryAndValueBean() { Query query = mock(Query.class); TestBean tb = new TestBean(); List list = new ArrayList(); given(session.getNamedQuery("some query name")).willReturn(query); given(query.setProperties(tb)).willReturn(query); given(query.list()).willReturn(list); List result = hibernateTemplate.findByNamedQueryAndValueBean("some query name", tb); assertTrue("Correct list", result == list); verify(query).setProperties(tb);/*ww w. j a v a 2 s .com*/ }
From source file:org.springframework.orm.hibernate5.HibernateTemplate.java
License:Apache License
@Override public List<?> findByValueBean(final String queryString, final Object valueBean) throws DataAccessException { return executeWithNativeSession(new HibernateCallback<List<?>>() { @Override//w w w. ja v a 2 s .c o m public List<?> doInHibernate(Session session) throws HibernateException { Query queryObject = session.createQuery(queryString); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); } }); }
From source file:org.springframework.orm.hibernate5.HibernateTemplate.java
License:Apache License
@Override public List<?> findByNamedQueryAndValueBean(final String queryName, final Object valueBean) throws DataAccessException { return executeWithNativeSession(new HibernateCallback<List<?>>() { @Override/*from ww w . j a v a2s. c om*/ public List<?> doInHibernate(Session session) throws HibernateException { Query queryObject = session.getNamedQuery(queryName); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); } }); }
From source file:org.squale.jraf.provider.persistence.hibernate.AbstractDAOImpl.java
License:Open Source License
public java.util.List find(ISession session, String lRequete, Object bean) throws JrafDaoException { SessionImpl sessionHibernate = (SessionImpl) session; List liste = null;//from ww w. j a v a2 s . c om try { Query query = sessionHibernate.getSession().createQuery(lRequete); query.setProperties(bean); liste = query.list(); } catch (Exception e) { throwDAOException(e, "find"); } return liste; }
From source file:org.squale.jraf.provider.persistence.hibernate.AbstractDAOImpl.java
License:Open Source License
public java.util.List findWhere(ISession session, String whereClause, Object bean) throws JrafDaoException { SessionImpl sessionHibernate = (SessionImpl) session; List liste = null;/*from www . j a va 2s.co m*/ try { Query query = sessionHibernate.getSession().createQuery(getRequete() + whereClause); query.setProperties(bean); liste = query.list(); } catch (Exception e) { throwDAOException(e, "findWhere"); } return liste; }
From source file:org.squale.jraf.provider.persistence.hibernate.AbstractDAOImpl.java
License:Open Source License
public int removeWhere(ISession session, String whereClause, Object bean) throws JrafDaoException { SessionImpl sessionHibernate = (SessionImpl) session; String req = "delete " + getClassName(getBusinessClass()) + " " + getAlias() + " "; int nbInstanceSupprime = 0; try {//from ww w . j a v a 2 s .co m Query query = sessionHibernate.getSession().createQuery(req + whereClause); query.setProperties(bean); nbInstanceSupprime = query.executeUpdate(); } catch (Exception e) { throwDAOException(e, "removeAll"); } return nbInstanceSupprime; }
From source file:org.xwiki.mail.internal.DatabaseMailStatusStore.java
License:Open Source License
@Override public List<MailStatus> load(final Map<String, Object> filterMap, final int offset, final int count, String sortField, boolean sortAscending) throws MailStoreException { XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore; final XWikiContext xwikiContext = this.contextProvider.get(); // Load from the main wiki String currentWiki = xwikiContext.getWikiId(); xwikiContext.setWikiId(xwikiContext.getMainXWiki()); // Compute the Query string based on the passed filter map final String queryString = computeSelectQueryString(filterMap, sortField, sortAscending); try {/*www. ja v a 2 s . co m*/ return store.executeRead(xwikiContext, new XWikiHibernateBaseStore.HibernateCallback<List<MailStatus>>() { @Override public List<MailStatus> doInHibernate(Session session) throws HibernateException, XWikiException { Query query = session.createQuery(queryString); if (offset > 0) { query.setFirstResult(offset); } if (count > 0) { query.setMaxResults(count); } query.setProperties(filterMap); List<MailStatus> queryResult = (List<MailStatus>) query.list(); return queryResult; } }); } catch (Exception e) { throw new MailStoreException(String.format( "Failed to load mail statuses matching the filter [%s] from the database.", filterMap), e); } finally { xwikiContext.setWikiId(currentWiki); } }
From source file:org.xwiki.mail.internal.DatabaseMailStatusStore.java
License:Open Source License
@Override public long count(final Map<String, Object> filterMap) throws MailStoreException { XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStore; final XWikiContext xwikiContext = this.contextProvider.get(); // Count in the main wiki String currentWiki = xwikiContext.getWikiId(); xwikiContext.setWikiId(xwikiContext.getMainXWiki()); // Compute the Query string based on the passed filter map final String queryString = computeCountQueryString(filterMap); try {/*from w w w.j a v a 2 s . c o m*/ Long count = store.executeRead(xwikiContext, new XWikiHibernateBaseStore.HibernateCallback<Long>() { @Override public Long doInHibernate(Session session) throws HibernateException, XWikiException { Query query = session.createQuery(queryString); query.setProperties(filterMap); return (Long) query.uniqueResult(); } }); return count; } catch (Exception e) { throw new MailStoreException(String.format( "Failed to count mail statuses matching the filter [%s] from the database.", filterMap), e); } finally { xwikiContext.setWikiId(currentWiki); } }