@Deprecated @Override @SuppressWarnings({"rawtypes", "unchecked", "deprecation"}) public List<?> findByNamedQueryAndValueBean(final String queryName, final Object valueBean) throws DataAccessException { return nonNull(executeWithNativeSession((HibernateCallback<List<?>>) session -> { org.hibernate.Query queryObject = queryObject( ReflectionUtils.invokeMethod(getNamedQueryMethod, session, queryName)); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); })); }
@Deprecated @Override @SuppressWarnings({"rawtypes", "unchecked", "deprecation"}) public List<?> findByValueBean(final String queryString, final Object valueBean) throws DataAccessException { return nonNull(executeWithNativeSession((HibernateCallback<List<?>>) session -> { org.hibernate.Query queryObject = queryObject( ReflectionUtils.invokeMethod(createQueryMethod, session, queryString)); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); })); }
@Deprecated @Override @SuppressWarnings({"rawtypes", "unchecked", "deprecation"}) public List<?> findByNamedQueryAndValueBean(final String queryName, final Object valueBean) throws DataAccessException { return nonNull(executeWithNativeSession((HibernateCallback<List<?>>) session -> { org.hibernate.Query queryObject = queryObject( ReflectionUtils.invokeMethod(getNamedQueryMethod, session, queryName)); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); })); }
@Deprecated @Override @SuppressWarnings({"rawtypes", "unchecked", "deprecation"}) public List<?> findByValueBean(final String queryString, final Object valueBean) throws DataAccessException { return nonNull(executeWithNativeSession((HibernateCallback<List<?>>) session -> { org.hibernate.Query queryObject = queryObject( ReflectionUtils.invokeMethod(createQueryMethod, session, queryString)); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); })); }
/** * Get a cursor over all of the results, with the forward-only flag set. * * @param fetchSize the fetch size to use retrieving the results * @param parameterValues the parameter values to use (or null if none). * * @return a forward-only {@link ScrollableResults} */ public ScrollableResults getForwardOnlyCursor(int fetchSize, Map<String, Object> parameterValues) { Query query = createQuery(); if (parameterValues != null) { query.setProperties(parameterValues); } return query.setFetchSize(fetchSize).scroll(ScrollMode.FORWARD_ONLY); }
/** * Read a page of data, clearing the existing session (if necessary) first, * and creating a new session before executing the query. * * @param page the page to read (starting at 0) * @param pageSize the size of the page or maximum number of items to read * @param fetchSize the fetch size to use * @param parameterValues the parameter values to use (if any, otherwise * null) * @return a collection of items */ public Collection<? extends T> readPage(int page, int pageSize, int fetchSize, Map<String, Object> parameterValues) { clear(); Query query = createQuery(); if (parameterValues != null) { query.setProperties(parameterValues); } @SuppressWarnings("unchecked") List<T> result = query.setFetchSize(fetchSize).setFirstResult(page * pageSize).setMaxResults(pageSize).list(); return result; }
public void testSetProperties() throws Exception { Session s = openSession(); Transaction t = s.beginTransaction(); Simple simple = new Simple( Long.valueOf( 10 ) ); simple.setName("Simple 1"); s.save( simple ); Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); q.setProperties(simple); assertTrue( q.list().get(0)==simple ); //misuse of "Single" as a propertyobject, but it was the first testclass i found with a collection ;) Single single = new Single() { // trivial hack to test properties with arrays. @SuppressWarnings( {"unchecked"}) String[] getStuff() { return (String[]) getSeveral().toArray(new String[getSeveral().size()]); } }; List l = new ArrayList(); l.add("Simple 1"); l.add("Slimeball"); single.setSeveral(l); q = s.createQuery("from Simple s where s.name in (:several)"); q.setProperties(single); assertTrue( q.list().get(0)==simple ); q = s.createQuery("from Simple s where s.name in (:stuff)"); q.setProperties(single); assertTrue( q.list().get(0)==simple ); s.delete(simple); t.commit(); s.close(); }
@Test public void testSetPropertiesMap() throws Exception { Session s = openSession(); Transaction t = s.beginTransaction(); Simple simple = new Simple( Long.valueOf(10) ); simple.setName("Simple 1"); s.save( simple ); Map<String,Object> parameters = new HashMap<>(); parameters.put( "name", simple.getName() ); parameters.put( "count", simple.getCount() ); Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); q.setProperties((parameters)); assertTrue( q.list().get(0)==simple ); List<String> l = new ArrayList<>(); l.add("Simple 1"); l.add("Slimeball"); parameters.put("several", l); q = s.createQuery("from Simple s where s.name in (:several)"); q.setProperties(parameters); assertTrue( q.list().get(0)==simple ); parameters.put("stuff", l.toArray(new String[0])); q = s.createQuery("from Simple s where s.name in (:stuff)"); q.setProperties(parameters); assertTrue( q.list().get(0)==simple ); s.delete(simple); t.commit(); s.close(); }
s.save( simple ); Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); q.setProperties(simple); assertTrue( q.list().get(0)==simple ); single.setSeveral(l); q = s.createQuery("from Simple s where s.name in (:several)"); q.setProperties(single); assertTrue( q.list().get(0)==simple ); q.setProperties(single); assertTrue( q.list().get(0)==simple ); q.setProperties(single); assertTrue( q.list().get(0)==simple ); q.setProperties(single); assertTrue( q.list().get(0)==simple );
.addEntity( "category", Category.class ); query.setProperties( s );
@SuppressWarnings("unchecked") public TypedQuery<T> setProperties(Map bean) throws HibernateException { query.setProperties(bean); return this; }
@Override public Query setProperties(Object o) { return query.setProperties(o); }
@Override public Query setProperties(Map map) { return query.setProperties(map); }
@SuppressWarnings("unchecked") @Override @Transactional public List<T> query(String name, Map<String, Object> properties) { return getSession().createQuery(queryMap.get(name)).setProperties(properties).list(); } }
@Override public List<?> doInHibernate(Session session) throws HibernateException { Query queryObject = session.createQuery(queryString); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); } });
@Override public List<?> doInHibernate(Session session) throws HibernateException { Query queryObject = session.createQuery(queryString); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); } });
private List getList() { if (list==null) { if ( log.isDebugEnabled() ) { log.debug("loading query-list using named query: " + queryName); } list = session.getNamedQuery(queryName) .setProperties(owner) .setFlushMode(FlushMode.NEVER) //TODO: should this really override the setting in the query definition? .list(); } return list; }
@Override public List<?> doInHibernate(Session session) throws HibernateException { Query queryObject = session.getNamedQuery(queryName); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); } });
@Override public List<?> doInHibernate(Session session) throws HibernateException { Query queryObject = session.getNamedQuery(queryName); prepareQuery(queryObject); queryObject.setProperties(valueBean); return queryObject.list(); } });
private Long count(Serializable id, String name, Class<? extends ParameterResolver> classResolver) { ParameterResolver resolver; try { resolver = classResolver.newInstance(); Session session = applicationContext.getBean(SessionFactory.class).getCurrentSession(); return (Long) session.getNamedQuery(name).setProperties(resolver.getParameters(id)).uniqueResult(); } catch (Exception e) { throw new DeleteInterceptorException(e); } }