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

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

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

Query.iterate介绍

[英]Return the query results as an Iterator. If the query contains multiple results per row, the results are returned in an instance of Object[].

Entities returned as results are initialized on demand. The first SQL query returns identifiers only.
[中]以迭代器的形式返回查询结果。如果查询每行包含多个结果,则结果将在对象[]的实例中返回。
作为结果返回的实体按需初始化。第一个SQL查询只返回标识符。

代码示例

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

@Deprecated
@Override
@SuppressWarnings({"rawtypes", "deprecation"})
public Iterator<?> iterate(final String queryString, @Nullable final Object... values) throws DataAccessException {
  return nonNull(executeWithNativeSession((HibernateCallback<Iterator<?>>) session -> {
    org.hibernate.Query queryObject = queryObject(
        ReflectionUtils.invokeMethod(createQueryMethod, session, queryString));
    prepareQuery(queryObject);
    if (values != null) {
      for (int i = 0; i < values.length; i++) {
        queryObject.setParameter(i, values[i]);
      }
    }
    return queryObject.iterate();
  }));
}

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

@Deprecated
@Override
@SuppressWarnings({"rawtypes", "deprecation"})
public Iterator<?> iterate(final String queryString, @Nullable final Object... values) throws DataAccessException {
  return nonNull(executeWithNativeSession((HibernateCallback<Iterator<?>>) session -> {
    org.hibernate.Query queryObject = queryObject(
        ReflectionUtils.invokeMethod(createQueryMethod, session, queryString));
    prepareQuery(queryObject);
    if (values != null) {
      for (int i = 0; i < values.length; i++) {
        queryObject.setParameter(i, values[i]);
      }
    }
    return queryObject.iterate();
  }));
}

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

public SyntaxChecker checkIterate() {
    Session s = openSession();
    s.beginTransaction();
    Query query = s.createQuery( hql );
    preparer.prepare( query );
    query.iterate();
    s.getTransaction().commit();
    s.close();
    return this;
  }
}

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

Query query = s.createQuery("from DataPoint dp order by dp.x asc");
s.setDefaultReadOnly( true );
Iterator it = query.iterate();
s.setDefaultReadOnly( false );
while ( it.hasNext() ) {

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

q.setString( 0, "Simple 1" );
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );
q = s.createQuery("from Simple s where s.name = :foo and upper(s.name) = :bar or s.count=:count or s.count=:count + 1");
q.setParameter( "bar", "SIMPLE 1" );
q.setInteger("count", 69);
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );
q = s.createQuery("select s.id from Simple s");
q.setFirstResult(1);
q.setMaxResults( 2 );
iter = q.iterate();
int i=0;
while ( iter.hasNext() ) {

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

assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );
zoo = (Zoo) q
  .iterate().next();
assertEquals( zoo.getMammals().size(), 1 );
assertEquals( zoo.getAnimals().size(), 1 );

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

q.setString(0, "Simple 1");
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );
q = s.createQuery("from Simple s where s.name = :foo and upper(s.name) = :bar or s.count=:count or s.count=:count + 1");
q.setParameter("bar", "SIMPLE 1");
q.setInteger("count", 69);
q.setFirstResult(0);
assertTrue( q.iterate().hasNext() );
q = s.createQuery("select s.id from Simple s");
q.setFirstResult(1);
q.setMaxResults(2);
iter = q.iterate();
int i=0;
while ( iter.hasNext() ) {

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

assertTrue( q.iterate().hasNext() );
assertTrue( s.createFilter( master.getIncoming(), "where this.id > -1 and this.name is not null" ).list().size()==0 );
assertTrue( s.createFilter( master.getDetails(), "select max(this.i)" ).iterate().next() instanceof Integer );
assertTrue( s.createFilter( master.getDetails(), "select max(this.i) group by this.id" ).iterate().next() instanceof Integer );
assertTrue( s.createFilter( master.getDetails(), "select count(*)" ).iterate().next() instanceof Long );
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) );
coll.add( new Integer(0) );
f.setParameterList("list", coll);
assertEquals( f.iterate().next(), new Integer(12) );
assertEquals( f.iterate().next(), new Integer(12) );

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

getSelectNewQuery( session ).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).iterate();
fail("'select new' together with a resulttransformer should result in error!");

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

s.setDefaultReadOnly( false );
assertFalse( s.isDefaultReadOnly() );
Iterator it = query.iterate();
assertTrue( query.isReadOnly() );
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );

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

s.setDefaultReadOnly( true );
assertTrue( s.isDefaultReadOnly() );
Iterator it = query.iterate();
assertFalse( query.isReadOnly() );
DataPoint dpLast = ( DataPoint ) s.get( DataPoint.class, dp.getId() );

代码示例来源:origin: hazelcast/hazelcast-code-samples

@Override
  public Iterator<T> iterator() {
    return new CloseableIterator<T>((HibernateIterator) query.iterate());
  }
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core

public Iterator<Interaction> getInteractionsForExperimentWithAcIterator( String ac ) {
  Query query = getSession().createQuery("from InteractionImpl as interaction left join interaction.experiments as exp where exp.ac = :ac");
  query.setParameter("ac", ac);
  return query.iterate();
}

代码示例来源:origin: org.n52.sensorweb/52n-sps-hibernate

public long getCount(String procedure) {
  LOGGER.debug("getCount({})", procedure);
  Session currentSession = getCurrentSession();
  Query query = currentSession.createQuery("select count(*) from SensorConfiguration");
  return ((Long) query.iterate().next()).longValue();
}

代码示例来源:origin: sakaiproject/sakai

public boolean isEmpty(final String courseSetEid) {
  HibernateCallback hc = session -> {
    Query q = session.getNamedQuery("findNonEmptyCourseSet");
    q.setParameter("eid", courseSetEid);
    return Boolean.valueOf( ! q.iterate().hasNext());
  };
  return ((Boolean)getHibernateTemplate().execute(hc)).booleanValue();
}

代码示例来源:origin: sakaiproject/sakai

public boolean isEnrolled(final String userId, final Set<String> enrollmentSetEids) {
  HibernateCallback hc = session -> {
    Query q = session.getNamedQuery("countEnrollments");
    q.setParameter("userId", userId);
    q.setParameterList("enrollmentSetEids", enrollmentSetEids);
    return q.iterate().next();
  };
  int i = ((Number)getHibernateTemplate().execute(hc)).intValue();
  if(log.isDebugEnabled()) log.debug(userId + " is enrolled in " + i + " of these " + enrollmentSetEids.size() + " EnrollmentSets" );
  return i > 0;
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core

@Transactional(propagation = Propagation.MANDATORY)
public Iterator<T> getByShortLabelLikeIterator(String value, boolean ignoreCase) {
  Query query;
  if (ignoreCase) {
    query = getEntityManager().createQuery("from " + getEntityClass().getSimpleName() + " where lower(shortlabel) = lower(:label)");
  } else {
    query = getEntityManager().createQuery("from " + getEntityClass().getSimpleName() + " where shortlabel = :label");
  }
  query.setParameter("label", value);
  return ((HibernateQuery) query).getHibernateQuery().iterate();
}

代码示例来源:origin: org.ow2.bonita/bonita-server

@Override
public List<LabelImpl> getUserCustomLabels(final String ownerName) {
 final List<LabelImpl> result = new ArrayList<LabelImpl>();
 final Query query = getSession().getNamedQuery("getUserCustomLabels");
 query.setString("ownerName", ownerName);
 CollectionUtils.addAll(result, query.iterate());
 return result;
}

代码示例来源:origin: org.ow2.bonita/bonita-server

@Override
public Set<TaskInstance> getUserTasks(final String userId, final Collection<ActivityState> taskStates) {
 final Query query = getSession().getNamedQuery("getUserTasksWithStates");
 query.setString("userId", userId);
 query.setParameterList("states", taskStates, ACTIVITY_STATE_USER_TYPE);
 final Set<TaskInstance> result = new HashSet<TaskInstance>();
 CollectionUtils.addAll(result, query.iterate());
 return result;
}

代码示例来源:origin: org.ow2.bonita/bonita-server

@Override
public Set<IncomingEventInstance> getIncomingEvents(final ActivityInstanceUUID activityUUID) {
 final Set<IncomingEventInstance> result = new HashSet<IncomingEventInstance>();
 final Query query = getSession().getNamedQuery("getActivityInstanceIncomingEvents");
 query.setString("activityUUID", activityUUID.getValue());
 CollectionUtils.addAll(result, query.iterate());
 return result;
}

相关文章