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

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

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

Query.iterate介绍

[英]Return the query results as an Iterator. If the query contains multiple results pre 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.
[中]以迭代器的形式返回查询结果。如果查询包含多个结果,则结果将在Object[]的实例中返回。
作为结果返回的实体按需初始化。第一个SQL查询只返回标识符。

代码示例

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

@Test
public void testCollectionQuery() throws Exception {
  Session s = openSession();
  Transaction t = s.beginTransaction();
  if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect) ) {
    s.createQuery( "FROM Master m WHERE NOT EXISTS ( FROM m.details d WHERE NOT d.i=5 )" ).iterate();
    s.createQuery( "FROM Master m WHERE NOT 5 IN ( SELECT d.i FROM m.details AS d )" ).iterate();
  }
  s.createQuery( "SELECT m FROM Master m JOIN m.details d WHERE d.i=5" ).iterate();
  s.createQuery( "SELECT m FROM Master m JOIN m.details d WHERE d.i=5" ).list();
  s.createQuery( "SELECT m.id FROM Master AS m JOIN m.details AS d WHERE d.i=5" ).list();
  t.commit();
  s.close();
}

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

private void checkCounts(String hql, int expected, String testCondition) {
  Session s = openSession();
  s.beginTransaction();
  int count = determineCount( s.createQuery( hql ).list().iterator() );
  assertEquals( "list() [" + testCondition + "]", expected, count );
  count = determineCount( s.createQuery( hql ).iterate() );
  assertEquals( "iterate() [" + testCondition + "]", expected, count );
  s.getTransaction().commit();
  s.close();
}

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

@Test
public void testCascadeSave() throws Exception {
  Session s = openSession();
  Transaction t = s.beginTransaction();
  Baz baz = new Baz();
  List list = new ArrayList();
  list.add( new Fee() );
  list.add( new Fee() );
  baz.setFees( list );
  s.save(baz);
  t.commit();
  s.close();
  s = openSession();
  t = s.beginTransaction();
  baz = (Baz) s.load( Baz.class, baz.getCode() );
  assertTrue( baz.getFees().size() == 2 );
  s.delete(baz);
  assertTrue( !s.createQuery( "from Fee fee" ).iterate().hasNext() );
  t.commit();
  s.close();
}

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

@Test
public void testSelfManyToOne() throws Exception {
  Session s = openSession();
  Transaction t = s.beginTransaction();
  Master m = new Master();
  m.setOtherMaster(m);
  s.save(m);
  t.commit();
  s.close();
  s = openSession();
  t = s.beginTransaction();
  Iterator i = s.createQuery( "from Master" ).iterate();
  m = (Master) i.next();
  assertTrue( m.getOtherMaster()==m );
  if ( getDialect() instanceof HSQLDialect || getDialect() instanceof MySQLDialect ) {
    m.setOtherMaster(null);
    s.flush();
  }
  s.delete(m);
  t.commit();
  s.close();
}

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

s.beginTransaction();
Parent p = null;
for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
  if ( p != null) { s.evict(p); }
  p = (Parent) it.next();

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

@Test
public void testComplicatedQuery() throws Exception {
  Session s = openSession();
  Transaction txn = s.beginTransaction();
  Foo foo = new Foo();
  Serializable id = s.save(foo);
  assertTrue( id != null );
  Qux q = new Qux("q");
  foo.getDependent().setQux(q);
  s.save( q );
  q.getFoo().setString( "foo2" );
  //s.flush();
  //s.connection().commit();
  assertTrue(
      s.createQuery( "from Foo foo where foo.dependent.qux.foo.string = 'foo2'" ).iterate().hasNext()
  );
  s.delete( foo );
  txn.commit();
  s.close();
}

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

for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
  Parent p = (Parent) it.next();
  assertEquals( 1, p.getChildren().size() );

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

s.beginTransaction();
int i = 0;
for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
  Parent p = (Parent) it.next();
  assertEquals( 1, p.getChildren().size() );

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

s.beginTransaction();
int i = 0;
for ( Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
  i++;
  if (i % 2 == 0) {

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

Iterator itr = s.createQuery( "select e.heresAnotherCrazyIdFieldName from MoreCrazyIdFieldNameStuffEntity e" ).iterate();
assertTrue( itr.hasNext() ); itr.next(); assertFalse( itr.hasNext() );

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

@Test
public void testLimitZero() throws Exception {
  TransactionUtil.doInHibernate( this::sessionFactory, s -> {
    Iterator iter = s.createQuery( "from Person p" )
        .setMaxResults( 0 )
        .iterate();
    int count = 0;
    while ( iter.hasNext() ) {
      iter.next();
      count++;
    }
    assertEquals( 0, count );
    final List list = s.createQuery( "select p from Person p" )
        .setMaxResults( 0 )
        .setFirstResult( 2 )
        .list();
    assertTrue( list.isEmpty() );
  } );
}

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

Iterator iter = s.createQuery( "from Qux q where q.stuff is null" ).iterate();
int count=0;
while ( iter.hasNext() ) {
iter = s.createQuery( "from Qux q" ).iterate();
assertTrue( "empty iterator", !iter.hasNext() );
s.getTransaction().commit();

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

Iterator it = s.createQuery("from DataPoint dp order by dp.x asc")
    .setReadOnly( false )
    .iterate();
while ( it.hasNext() ) {
  DataPoint dp = (DataPoint) it.next();

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

int i = 0;
Iterator it = s.createQuery("from DataPoint dp order by dp.x asc")
    .iterate();
s.setDefaultReadOnly( false );
while ( it.hasNext() ) {

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

int count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).list().iterator() );
assertEquals( 1, count ); // thing two would be removed from the result due to the inner join
count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).iterate() );
assertEquals( 1, count );
s.getTransaction().commit();

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

Iterator it = s.createQuery("from DataPoint dp order by dp.x asc")
    .setReadOnly( true )
    .iterate();
while ( it.hasNext() ) {
  DataPoint dp = (DataPoint) it.next();

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

.setMaxResults(4)
  .setFirstResult(2)
  .iterate();
int count=0;
while ( iter.hasNext() ) {

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

assertTrue("deferred load test",g.getProxyArray()[1].getProxyArray()[2]==g );
assertTrue( "set of proxies", g.getProxySet().size()==2 );
Iterator iter = s.createQuery( "from Glarch g" ).iterate();
while ( iter.hasNext() ) {
  iter.next();

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

Iterator iter = s.getNamedQuery("Item.nameDesc").iterate();
i1 = (Item) iter.next();
i2 = (Item) iter.next();

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

Iterator<Person> iterator = session.createQuery( "from Person p", Person.class ).iterate();
assertTrue( iterator.hasNext() );
Person p = iterator.next();

相关文章