本文整理了Java中org.hibernate.Query.setParameterList
方法的一些代码示例,展示了Query.setParameterList
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setParameterList
方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setParameterList
[英]Bind multiple values to a named query parameter. The Hibernate type of the parameter is first detected via the usage/position in the query and if not sufficient secondly guessed from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).
[中]将多个值绑定到命名查询参数。参数的Hibernate类型首先通过查询中的用法/位置进行检测,如果不够,则从集合中第一个对象的类中进行二次猜测。这对于将值列表绑定到表达式(如foo)非常有用。输入条(:值_列表)。
代码示例来源:origin: hibernate/hibernate-orm
@Test
@RequiresDialectFeature(
value = DialectChecks.SupportsEmptyInListCheck.class,
comment = "Dialect does not support SQL empty in list [x in ()]"
)
public void testEmptyInListQuery() {
Session s = openSession();
s.beginTransaction();
Query q = s.createQuery( "select bar from Bar as bar where bar.name in (:nameList)" );
q.setParameterList( "nameList", Collections.EMPTY_LIST );
assertEquals( 0, q.list().size() );
s.getTransaction().commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testMultipleSelect() {
final String name = "Name";
final String lastName = "LastName";
final List<Integer> ids = new ArrayList<Integer>();
final int quantity = 10;
final List<DestinationEntity> destinations = new ArrayList<DestinationEntity>();
for ( int i = 0; i < quantity; i++ ) {
DestinationEntity createDestination = createDestination( createFrom( name + i, lastName + i ), name + i
+ lastName + i );
ids.add( createDestination.id );
destinations.add( createDestination );
}
Session session = openSession();
Query select = session.getNamedQuery( "DestinationEntity.selectIds" );
select.setParameterList( "ids", ids );
List list = select.list();
session.close();
assertEquals( quantity, list.size() );
for ( int i = 0; i < list.size(); i++ ) {
Object[] object = (Object[]) list.get( i );
DestinationEntity destination = destinations.get( i );
// Compare the Strings, not the actual IDs. Can come back as, for ex,
// a BigDecimal in Oracle.
assertEquals( destination.id + "", object[0] + "" );
assertEquals( destination.from.id + "", object[1] + "" );
assertEquals( destination.fullNameFrom, object[2] );
}
}
代码示例来源:origin: hibernate/hibernate-orm
list.add( new Id( "123456789", order.getId().getOrderNumber(), "4321" ) );
list.add( new Id( "123456789", order.getId().getOrderNumber(), "1234" ) );
query.setParameterList( "idList", list );
assertEquals( 2, query.list().size() );
query.setParameterList( "idList", list );
assertEquals( 2, query.list().size() );
代码示例来源:origin: hibernate/hibernate-orm
list = q.list();
if ( !(getDialect() instanceof SAPDBDialect) ) assertTrue( list.size()==2 );
nameList.add( "Bar" );
nameList.add( "Bar Two" );
q.setParameterList( "nameList", nameList );
q.setParameter( "stringVal", "a string" );
list = q.list();
if ( !(getDialect() instanceof SAPDBDialect) ) assertTrue( list.size()==2 );
q.setParameterList("nameList", (Collection)null);
fail("Should throw a QueryException when passing a null!");
q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like :name and b.name like :name");
q.setString( "name", "Bar%" );
list = q.list();
assertTrue( list.size()==1 );
代码示例来源:origin: hibernate/hibernate-orm
query.list();
query.setParameterList( "names", str );
query.uniqueResult();
query.setParameterList("names", str);
query.uniqueResult();
.addEntity( "category", Category.class );
str = new String[] { "WannaBeFound" };
query.setParameterList( "names", str );
query.uniqueResult();
query.setParameterList( "names", str );
query.uniqueResult();
代码示例来源:origin: hibernate/hibernate-orm
List result = session.createQuery( "FROM Zoo z WHERE z.name IN (?1) and z.address.city IN (?2)" )
.setParameterList( 1, namesArray )
.setParameterList( 2, citiesArray )
.list();
assertEquals( 1, result.size() );
session.getTransaction().commit();
代码示例来源:origin: hibernate/hibernate-orm
assertTrue( q.list().size()==3 );
q = s.createQuery("from Simple s");
q.setMaxResults( 1 );
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s");
assertTrue( q.list().size() == 3 );
q = s.createQuery("from Simple s where s.name = ?");
q.setString( 0, "Simple 1" );
set.add("Simple 1");
set.add("foo");
q.setParameterList( "name_list", set );
q.setParameter("count", new Integer(-1) );
assertTrue( q.list().size()==1 );
代码示例来源:origin: hibernate/hibernate-orm
assertTrue( q.list().size()==3 );
q = s.createQuery("from Simple s");
q.setMaxResults(1);
assertTrue( q.list().size()==1 );
q = s.createQuery("from Simple s");
assertTrue( q.list().size()==3 );
q = s.createQuery("from Simple s where s.name = ?");
q.setString(0, "Simple 1");
HashSet set = new HashSet();
set.add("Simple 1"); set.add("foo");
q.setParameterList( "name_list", set );
q.setParameter("count", Integer.valueOf( -1 ) );
assertTrue( q.list().size()==1 );
代码示例来源:origin: hibernate/hibernate-orm
master = dd.getMaster();
assertTrue( "detail-master", master.getDetails().contains(dd) );
assertTrue( s.createFilter( master.getDetails(), "order by this.i desc" ).list().size()==2 );
assertTrue( s.createFilter( master.getDetails(), "select this where this.id > -1" ).list().size()==2 );
Query q = s.createFilter( master.getDetails(), "where this.id > :id" );
q.setInteger("id", -1);
assertTrue( q.list().size()==2 );
q = s.createFilter( master.getDetails(), "where this.id > :id1 and this.id < :id2" );
q.setInteger("id1", -1);
q.setParameterList("ids", list);
assertTrue( q.list().size()==1 );
q.setParameterList("ids", list);
assertTrue( q.iterate().hasNext() );
coll.add( new Integer(22) );
coll.add( new Integer(0) );
f.setParameterList("list", coll);
assertEquals( f.iterate().next(), new Integer(12) );
f.setParameterList("list", coll);
f.setParameter( "listy2", master.getName() );
assertEquals( f.iterate().next(), new Integer(12) );
代码示例来源:origin: bill1012/AdminEAP
@SuppressWarnings("unchecked")
public <T> List<T> find(String hql, Map<String, Object> params) {
Query query = this.getCurrentSession().createQuery(hql);
if (params != null && !params.isEmpty()) {
for (String key : params.keySet()) {
Object obj = params.get(key);
if (obj instanceof Collection<?>) {
query.setParameterList(key, (Collection<?>) obj);
} else if (obj instanceof Object[]) {
query.setParameterList(key, (Object[]) obj);
} else {
query.setParameter(key, obj);
}
}
}
return query.list();
}
代码示例来源:origin: openmrs/openmrs-core
Query query = sessionFactory.getCurrentSession().createQuery(hql);
if (cohort != null) {
query.setParameterList("patientIds", cohort.getMemberIds());
query.setParameterList("programs", programs);
return query.list();
代码示例来源:origin: openmrs/openmrs-core
/**
* @param attributes attributes on a Person or Patient object. similar to: [gender, givenName,
* middleName, familyName]
* @return list of patients that match other patients
* @see org.openmrs.api.db.PatientDAO#getDuplicatePatientsByAttributes(java.util.List)
*/
@SuppressWarnings("unchecked")
@Override
public List<Patient> getDuplicatePatientsByAttributes(List<String> attributes) {
List<Patient> patients = new ArrayList<>();
List<Integer> patientIds = new ArrayList<>();
if (!attributes.isEmpty()) {
String sqlString = getDuplicatePatientsSQLString(attributes);
if(sqlString != null) {
SQLQuery sqlquery = sessionFactory.getCurrentSession().createSQLQuery(sqlString);
patientIds = sqlquery.list();
if (!patientIds.isEmpty()) {
Query query = sessionFactory.getCurrentSession().createQuery(
"from Patient p1 where p1.patientId in (:ids)");
query.setParameterList("ids", patientIds);
patients = query.list();
}
}
}
sortDuplicatePatients(patients, patientIds);
return patients;
}
代码示例来源:origin: OpenNMS/opennms
@Override
public List<OnmsEvent> doInHibernate(Session session) throws HibernateException, SQLException {
return session.createQuery(hql)
.setParameterList("eventUei", ueiList)
.setParameter("eventTime", date)
.list();
}
});
代码示例来源:origin: stackoverflow.com
String hql = "select * from myTable where isActive IN (:isActive)";
Query query = session.createQuery(hql);
List<String> isActiveList = new ArrayList<>();
isActiveList.add("Y");
isActiveList.add("N");
query.setParameterList("isActive", isActiveList);
return query.list();
代码示例来源:origin: denimgroup/threadfix
@Override
@SuppressWarnings("unchecked")
public List<Organization> retrieveAllActiveFilter(Set<Integer> authenticatedTeamIds) {
return sessionFactory.getCurrentSession()
.createQuery("from Organization org where org.active = 1 and org.id in (:teams) order by org.name")
.setParameterList("teams", authenticatedTeamIds).list();
}
代码示例来源:origin: denimgroup/threadfix
@SuppressWarnings("unchecked")
@Override
public List<String> getTeamNames(List<Integer> appIds) {
return (List<String>) sessionFactory.getCurrentSession()
.createQuery("select distinct organization.name from Application application " +
"where id in (:idList)")
.setParameterList("idList", appIds).list();
}
代码示例来源:origin: apache/ctakes
private void updateNames(String queryName, List<String> subList,
Map<String, String> names) {
Query q = sessionFactory.getCurrentSession().getNamedQuery(queryName);
q.setParameterList("cuis", subList);
@SuppressWarnings("unchecked")
List<Object[]> listCuiName = q.list();
for (Object[] cuiName : listCuiName) {
names.put((String) cuiName[0], (String) cuiName[1]);
}
}
代码示例来源:origin: org.ow2.bonita/bonita-server
@Override
@SuppressWarnings("unchecked")
public Set<Category> getCategories(final Collection<String> categoryNames) {
final Query query = getSession().getNamedQuery("getCategoriesByName");
query.setParameterList("names", categoryNames);
final List<Category> results = query.list();
if (results != null) {
return new HashSet<Category>(results);
} else {
return Collections.emptySet();
}
}
代码示例来源:origin: denimgroup/threadfix
@SuppressWarnings("unchecked")
@Override
public List<Vulnerability> retrieveByApplicationIdList(List<Integer> applicationIdList) {
if (applicationIdList == null || applicationIdList.isEmpty()) {
return list();
}
return sessionFactory.getCurrentSession()
.createQuery("from Vulnerability vulnerability " +
"where vulnerability.hidden = false and vulnerability.application.id in (:idList)")
.setParameterList("idList", applicationIdList).list();
}
代码示例来源:origin: sakaiproject/sakai
public List<QuestionPoolData> getAllPoolsForTransfer(final List<Long> selectedPoolIds) {
final HibernateCallback<List> hcb = session -> {
Query q = session.createQuery("FROM QuestionPoolData a WHERE a.questionPoolId IN (:ids)");
q. setParameterList("ids", selectedPoolIds);
return q.list();
};
return getHibernateTemplate().execute(hcb);
}
内容来源于网络,如有侵权,请联系作者删除!