org.hibernate.Query.setProperties()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(300)

本文整理了Java中org.hibernate.Query.setProperties方法的一些代码示例,展示了Query.setProperties的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setProperties方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setProperties

Query.setProperties介绍

[英]Bind the property values of the given bean to named parameters of the query, matching property names with parameter names and mapping property types to Hibernate types using heuristics.
[中]

代码示例

代码示例来源:origin: spring-projects/spring-framework

@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();
  }));
}

代码示例来源:origin: spring-projects/spring-framework

@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();
  }));
}

代码示例来源:origin: org.springframework/spring-orm

@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();
  }));
}

代码示例来源:origin: org.springframework/spring-orm

@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();
  }));
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * 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);
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * 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;
}

代码示例来源:origin: hibernate/hibernate-orm

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();
}

代码示例来源:origin: hibernate/hibernate-orm

@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();
}

代码示例来源:origin: hibernate/hibernate-orm

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 );

代码示例来源:origin: hibernate/hibernate-orm

.addEntity( "category", Category.class );
query.setProperties( s );

代码示例来源:origin: riotfamily/riot

@SuppressWarnings("unchecked")
public TypedQuery<T> setProperties(Map bean) throws HibernateException {
  query.setProperties(bean);
  return this;
}

代码示例来源:origin: com.github.cafdataprocessing/corepolicy-hibernate

@Override
public Query setProperties(Object o) {
  return query.setProperties(o);
}

代码示例来源:origin: com.github.cafdataprocessing/corepolicy-hibernate

@Override
public Query setProperties(Map map) {
  return query.setProperties(map);
}

代码示例来源:origin: com.googlecode.the-fascinator/fascinator-config-db

@SuppressWarnings("unchecked")
  @Override
  @Transactional
  public List<T> query(String name, Map<String, Object> properties) {
    return getSession().createQuery(queryMap.get(name)).setProperties(properties).list();
  }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
  public List<?> doInHibernate(Session session) throws HibernateException {
    Query queryObject = session.createQuery(queryString);
    prepareQuery(queryObject);
    queryObject.setProperties(valueBean);
    return queryObject.list();
  }
});

代码示例来源:origin: apache/servicemix-bundles

@Override
  public List<?> doInHibernate(Session session) throws HibernateException {
    Query queryObject = session.createQuery(queryString);
    prepareQuery(queryObject);
    queryObject.setProperties(valueBean);
    return queryObject.list();
  }
});

代码示例来源:origin: hibernate/hibernate

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; 
}

代码示例来源:origin: apache/servicemix-bundles

@Override
  public List<?> doInHibernate(Session session) throws HibernateException {
    Query queryObject = session.getNamedQuery(queryName);
    prepareQuery(queryObject);
    queryObject.setProperties(valueBean);
    return queryObject.list();
  }
});

代码示例来源:origin: apache/servicemix-bundles

@Override
  public List<?> doInHibernate(Session session) throws HibernateException {
    Query queryObject = session.getNamedQuery(queryName);
    prepareQuery(queryObject);
    queryObject.setProperties(valueBean);
    return queryObject.list();
  }
});

代码示例来源:origin: br.org.sesc/entity-validation-hibernate4

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);
  }
}

相关文章