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

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

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

Query.setInteger介绍

[英]Bind a positional int-valued parameter.
[中]绑定位置int值参数。

代码示例

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

Session s = openSession();
try {
  Query q = s.createQuery("select bar from Bar as bar where bar.x > :myX");
  q.list();
  fail("Should throw QueryException for missing myX");
  Query q = s.createQuery("select bar from Bar as bar where bar.x > ?");
  q.list();
  fail("Should throw QueryException for missing ?");
  Query q = s.createQuery("select bar from Bar as bar where bar.x > ? or bar.short = 1 or bar.string = 'ff ? bb'");
  q.setInteger(0, 1);
  q.list();

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

assertEquals( session.createFilter( customer.getOrders(), "" ).list().size(), 1 );
assertEquals( session.createFilter( order.getLineItems(), "" ).list().size(), 1 );
assertEquals( session.createFilter( order.getLineItems(), "where this.quantity > :quantity" ).setInteger( "quantity", 5 ).list().size(), 0 );

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.PatientDAO#getAllergy(Integer)
 */
  @Override
public Allergy getAllergy(Integer allergyId) {
  return (Allergy) sessionFactory.getCurrentSession().createQuery("from Allergy a where a.allergyId = :allergyId")
      .setInteger("allergyId", allergyId).uniqueResult();
}

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

s.save( bar2 );
List list = s.createQuery(
    "from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar %'"
).list();
assertTrue( row instanceof Object[] && ( (Object[]) row ).length==3 );
Query q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar%'");
list = q.list();
if ( !(getDialect() instanceof SAPDBDialect) ) assertTrue( list.size()==2 );
q = s.createQuery("select bar, b from Bar bar left join bar.baz baz left join baz.cascadingBars b where ( bar.name in (:nameList) or bar.name in (:nameList) ) and bar.string = :stringVal");
HashSet nameList = new HashSet();
nameList.add( "bar" );
q.setParameterList( "nameList", nameList );
q.setParameter( "stringVal", "a string" );
list = q.list();
if ( !(getDialect() instanceof SAPDBDialect) ) assertTrue( list.size()==2 );
q = s.createQuery("select bar from Bar bar order by ((bar.x - :valueX)*(bar.x - :valueX))");
q.setInteger( "valueX", bar.getX() + 1 );
list = q.list();
assertTrue( ((Bar) list.get( 0 )).getX() == bar.getX() );
q.setInteger( "valueX", bar2.getX() + 1 );
list = q.list();
assertTrue( ((Bar)list.get(0)).getX() == bar2.getX());

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.api.db.PersonDAO#getLosingPersonMergeLogs(org.openmrs.Person)
 */
@Override
public PersonMergeLog getLosingPersonMergeLogs(Person person) throws DAOException {
  return (PersonMergeLog) sessionFactory.getCurrentSession().createQuery(
    "from PersonMergeLog p where p.loser.id = :loserId").setInteger("loserId", person.getId()).uniqueResult();
}

代码示例来源:origin: denimgroup/threadfix

@Override
public boolean hasMappings(int id) {
   Object result = sessionFactory.getCurrentSession().createQuery(
         "from VulnerabilityMap map where map.channelVulnerability = :channelVuln")
       .setInteger("channelVuln", id).list();
      return result == null;
}

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

s.save(simple );
s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
s.createQuery( "from Simple s where repeat( lower(s.name), (3 + (1-1)) / 2) = 'foofoofoo'" ).list();
Query q = s.createQuery("from Simple s");
q.setMaxResults( 10 );
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" );
q.setParameter( "bar", "SIMPLE 1" );
q.setString( "foo", "Simple 1" );
q.setInteger("count", 69);
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );

代码示例来源:origin: openmrs/openmrs-core

.createQuery(
      "select count(*) from User u where (u.username = :uname1 or u.systemId = :uname2 or u.username = :sysid1 or u.systemId = :sysid2 or u.systemId = :uname3) and u.userId <> :uid");
query.setString("uname1", username);
query.setString("sysid2", systemId);
query.setString("uname3", usernameWithCheckDigit);
query.setInteger("uid", userId);

代码示例来源:origin: stackoverflow.com

String[] tags = {"ADMIN", "EMPLOYEE"};
String hql = "select u from User u " +
        "join u.roles r " +
        "where r.name in (:tags)" +
        "group by u " +
        "having count(r)=:tag_count";
Query query = session.createQuery(hql);
query.setParameterList("tags", tags);
query.setInteger("tag_count", tags.length);
List<User> Users = query.list();

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

s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
  s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
  s.createQuery( "from Simple s where repeat( lower(s.name), 3 + (1-1) / 2) = 'foofoofoo'" ).list();
Query q = s.createQuery("from Simple s");
q.setMaxResults(10);
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");
q.setParameter("bar", "SIMPLE 1");
q.setString("foo", "Simple 1");
q.setInteger("count", 69);
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );

代码示例来源:origin: openmrs/openmrs-core

Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setString("identifier", patientIdentifier.getIdentifier());
query.setInteger("idType", patientIdentifier.getIdentifierType().getPatientIdentifierTypeId());
if (checkPatient) {
  query.setInteger("ptId", patientIdentifier.getPatient().getPatientId());
  query.setInteger("locationId", patientIdentifier.getLocation().getLocationId());

代码示例来源:origin: denimgroup/threadfix

@SuppressWarnings("unchecked")
@Override
public List<WafRule> retrieveByWafAndDirective(Waf waf,
    WafRuleDirective directive) {
  return sessionFactory
    .getCurrentSession()
    .createQuery( "from WafRule wafRule where wafRule.waf = :wafId " +
      "and wafRule.wafRuleDirective = :directiveId")
    .setInteger("wafId", waf.getId())
    .setInteger("directiveId", directive.getId()).list();
}

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

assertTrue( s.createQuery( "select elements(master.details) from Master master" ).list().size()==2 );
t.commit();
s.close();
List list = s.createQuery( "from Master m left join fetch m.details" ).list();
Master m = (Master) list.get(0);
assertTrue( Hibernate.isInitialized( m.getDetails() ) );
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.setInteger("id2", 99999999);
assertTrue( q.list().size()==2 );
q.setInteger("id2", -1);
assertTrue( q.list().size()==0 );
f.setInteger("top", 100);
f.setInteger("bottom", 0);
assertEquals( f.iterate().next(), new Integer(12) );
f.setInteger("top", 2);
assertEquals( f.iterate().next(), new Integer(0) );

代码示例来源:origin: denimgroup/threadfix

@Override
public void delete(Integer reportId) {
  Session session = sessionFactory.getCurrentSession();
  String hql;
  hql = "delete from Report where id = :id";
  session.createQuery(hql).setInteger("id", reportId).executeUpdate();
}

代码示例来源:origin: denimgroup/threadfix

@SuppressWarnings("unchecked")
public List<Vulnerability> getVulns(Application app) {
  return (List<Vulnerability>) sessionFactory.getCurrentSession()
      .createQuery("from Vulnerability vuln where vuln.application = :appId")
      .setInteger("appId", app.getId()).list();
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * Gets primary diagnoses for a given encounter
 *
 * @param encounter the specific encounter to get the primary diagnoses for.
 * @return list of primary diagnoses for an encounter
 */
@Override
public List<Diagnosis> getPrimaryDiagnoses(Encounter encounter) {
  Query query = sessionFactory.getCurrentSession().createQuery(
    "from Diagnosis d where d.encounter.encounterId = :encounterId and d.rank = :rankId order by dateCreated desc");
  query.setInteger("encounterId", encounter.getId());
  query.setInteger("rankId", PRIMARY_RANK);
  return query.list();
}

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

public ItemData findByItemEventCrfOrdinal(Integer itemId, Integer eventCrfId, Integer ordinal) {
  String query = "from " + getDomainClassName()
      + " item_data where item_data.item.itemId = :itemid and item_data.eventCrf.eventCrfId = :eventcrfid and item_data.ordinal = :ordinal "
      + "and deleted=false";
  org.hibernate.Query q = getCurrentSession().createQuery(query);
  q.setInteger("itemid", itemId);
  q.setInteger("eventcrfid", eventCrfId);
  q.setInteger("ordinal", ordinal);
  return (ItemData) q.uniqueResult();
}

代码示例来源:origin: denimgroup/threadfix

@Override
@SuppressWarnings("unchecked")
public List<ChannelSeverity> retrieveByChannel(ChannelType channelType) {
  return sessionFactory
      .getCurrentSession()
      .createQuery(
          "from ChannelSeverity cs where cs.channelType = :channelTypeId order by cs.numericValue desc")
      .setInteger("channelTypeId", channelType.getId()).list();
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see org.openmrs.api.db.PersonDAO#getWinningPersonMergeLogs(org.openmrs.Person)
 */
@Override
@SuppressWarnings("unchecked")
public List<PersonMergeLog> getWinningPersonMergeLogs(Person person) throws DAOException {
  return (List<PersonMergeLog>) sessionFactory.getCurrentSession().createQuery(
    "from PersonMergeLog p where p.winner.id = :winnerId").setInteger("winnerId", person.getId()).list();
}

代码示例来源:origin: OpenNMS/opennms

private OnmsNode getNode(Integer nodeId, Session session) {
  if (nodeId != null) {
    Query q = session.createQuery("from OnmsNode as n where n.id = :nodeId");
    q.setInteger("nodeId",  nodeId);
    return (OnmsNode)q.uniqueResult();
  }
  return null;
}

相关文章