本文整理了Java中org.hibernate.ScrollableResults
类的一些代码示例,展示了ScrollableResults
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScrollableResults
类的具体详情如下:
包路径:org.hibernate.ScrollableResults
类名称:ScrollableResults
[英]A result iterator that allows moving around within the results by arbitrary increments. The Query / ScrollableResults pattern is very similar to the JDBC PreparedStatement/ ResultSet pattern and the semantics of methods of this interface are similar to the similarly named methods on ResultSet.
Contrary to JDBC, columns of results are numbered from zero.
[中]一个结果迭代器,允许以任意增量在结果中移动。Query/ScrollableResults模式与JDBC PreparedStatement/ResultSet模式非常相似,该接口的方法的语义与ResultSet上的类似命名方法相似。
与JDBC相反,结果列从零开始编号。
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testIncompleteScrollFirstResult() {
Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
results.next();
Parent p = (Parent) results.get( 0 );
assertResultFromOneUser( p );
s.getTransaction().commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testScrollCriteria() {
Session session = openSession();
Transaction t = session.beginTransaction();
Course course = new Course();
course.setCourseCode("HIB");
course.setDescription("Hibernate Training");
session.persist(course);
session.flush();
session.clear();
ScrollableResults sr = session.createCriteria(Course.class).setReadOnly( true ).scroll();
assertTrue( sr.next() );
course = (Course) sr.get(0);
assertNotNull(course);
assertTrue( session.isReadOnly( course ) );
sr.close();
session.delete(course);
t.commit();
session.close();
}
代码示例来源:origin: hibernate/hibernate-orm
assertTrue( query.getReturnTypes().length==2 );
ScrollableResults iter = query.scroll();
assertTrue( iter.next() );
assertTrue( iter.scroll(1) );
FooProxy f2 = (FooProxy) iter.get()[0];
assertTrue( f2!=null );
assertTrue( iter.scroll(-1) );
Object f1 = iter.get(0);
iter.next();
assertTrue( f1!=null && iter.get(0)==f2 );
iter.getInteger(1);
assertTrue( !iter.scroll(100) );
assertTrue( iter.first() );
assertTrue( iter.scroll(3) );
Object f4 = iter.get(0);
assertTrue( f4!=null );
assertTrue( !iter.next() );
assertTrue( iter.first() );
assertTrue( iter.get(0)==f1 );
assertTrue( iter.last() );
assertTrue( iter.get(0)==f4 );
assertTrue( iter.previous() );
txn.commit();
assertTrue( query.getReturnTypes().length==2 );
iter = query.scroll();
assertTrue( iter.next() );
assertTrue( iter.scroll(1) );
代码示例来源:origin: stackoverflow.com
StatelessSession session = ((Session) entityManager.getDelegate()).getSessionFactory().openStatelessSession();
Query query = session
.createQuery("SELECT a FROM Address a WHERE .... ORDER BY a.id");
query.setFetchSize(Integer.valueOf(1000));
query.setReadOnly(true);
query.setLockMode("a", LockMode.NONE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
while (results.next()) {
Address addr = (Address) results.get(0);
// Do stuff
}
results.close();
session.close();
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testSetParameters() {
final List params = new ArrayList();
params.add( new BigInteger( "2" ) );
params.add( new BigInteger( "3" ) );
try (Session s = openSession()) {
final Query query = s.createNativeQuery( "select e.big from MY_ENTITY e where e.big in (:bigValues)" )
.setParameter( "bigValues", params );
try (ScrollableResults scroll = query.scroll()) {
while ( scroll.next() ) {
assertThat( scroll.get()[0], not( nullValue()) );
}
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
public void testSQLFunctions() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1");
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();
.size()==2
);
t.commit();
t = s.beginTransaction();
assertTrue(
ScrollableResults sr = s.createQuery("from Simple s").scroll();
sr.next();
sr.get(0);
sr.close();
s.delete( other );
s.delete( simple );
s.delete( min );
t.commit();
s.close();
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testQueryReadOnlyScroll() {
Session s = openSession();
s.setCacheMode(CacheMode.IGNORE);
Transaction t = s.beginTransaction();
DataPoint dp = null;
for ( int i=0; i<100; i++ ) {
dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
s.save(dp);
t.commit();
assertFalse( query.isReadOnly() );
s.setDefaultReadOnly( true );
assertTrue( query.isReadOnly() );
s.setDefaultReadOnly( false );
assertFalse( query.isReadOnly() );
while ( sr.next() ) {
assertFalse( s.isDefaultReadOnly() );
dp = (DataPoint) sr.get(0);
if ( dp.getId() == dpLast.getId() ) {
t.commit();
t.commit();
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testQuery() throws Exception {
Session s = openSession();
Transaction txn = s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
Foo foo2 = new Foo();
s.save(foo2);
foo.setFoo(foo2);
ScrollableResults sr = s.createQuery("select new Foo(fo.x) from Foo fo").scroll();
assertTrue( "projection scroll (results)", sr.next() );
assertTrue( "projection scroll (return check)", Foo.class.isAssignableFrom( sr.get(0).getClass() ) );
list = s.createQuery( "select foo.long, foo.component.name, foo, foo.foo from Foo foo" ).list();
Query qu = s.createQuery("from Named n where n.name = :name");
qu.getReturnTypes();
qu.getNamedParameters();
iter = s.createQuery( "from java.lang.Object" ).iterate();
txn.commit();
s.close();
s.delete( foop.getFoo() );
s.delete(foop);
txn.commit();
s.close();
代码示例来源:origin: hibernate/hibernate-orm
assertFalse( results.isFirst() );
assertFalse( results.isLast() );
assertFalse( results.next() );
assertFalse( results.isFirst() );
assertFalse( results.isLast() );
assertFalse( results.previous() );
assertFalse( results.isFirst() );
assertFalse( results.isLast() );
results.beforeFirst();
assertFalse( results.isFirst() );
assertFalse( results.isLast() );
assertFalse( results.next() );
assertFalse( results.first() );
assertFalse( results.isFirst() );
assertFalse( results.isLast() );
assertFalse( results.next() );
results.afterLast();
assertFalse( results.isFirst() );
assertFalse( results.isLast() );
assertFalse( results.next() );
assertFalse( results.last() );
assertFalse( results.isFirst() );
assertFalse( results.isLast() );
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testReadOnlyModeAutoFlushOnQuery() {
clearCounts();
Session s = openSession();
Transaction t = s.beginTransaction();
DataPoint dpFirst = null;
for ( int i=0; i<100; i++ ) {
DataPoint dp = new DataPoint();
dp.setX( new BigDecimal(i * 0.1d).setScale(19, BigDecimal.ROUND_DOWN) );
dp.setY( new BigDecimal( Math.cos( dp.getX().doubleValue() ) ).setScale(19, BigDecimal.ROUND_DOWN) );
s.save(dp);
}
assertInsertCount( 0 );
assertUpdateCount( 0 );
ScrollableResults sr = s.createQuery("from DataPoint dp order by dp.x asc")
.setReadOnly(true)
.scroll(ScrollMode.FORWARD_ONLY);
assertInsertCount( 100 );
assertUpdateCount( 0 );
clearCounts();
while ( sr.next() ) {
DataPoint dp = (DataPoint) sr.get(0);
assertFalse( s.isReadOnly( dp ) );
s.delete( dp );
}
t.commit();
s.close();
assertUpdateCount( 0 );
assertDeleteCount( 100 );
}
代码示例来源:origin: hibernate/hibernate-orm
t.commit();
s.close();
Query query = s.createQuery("from DataPoint dp order by dp.x asc");
s.setDefaultReadOnly( true );
ScrollableResults sr = query.scroll(ScrollMode.FORWARD_ONLY);
s.setDefaultReadOnly( false );
while ( sr.next() ) {
DataPoint dp = (DataPoint) sr.get(0);
if (++i==50) {
s.setReadOnly(dp, false);
t.commit();
s.clear();
t = s.beginTransaction();
assertEquals( 1, single.size() );
s.createQuery("delete from DataPoint").executeUpdate();
t.commit();
s.close();
代码示例来源:origin: org.andromda.samples.animalquiz/animal-quiz-core
final ScrollableResults scrollableResults = queryObject.scroll();
scrollableResults.last();
int totalCount = scrollableResults.getRowNumber();
totalCount = totalCount >= 0 ? totalCount + 1 : 0;
if (pageNumber > 0 && pageSize > 0)
queryObject.setFirstResult(this.calculateFirstResult(pageNumber, pageSize));
queryObject.setMaxResults(pageSize);
代码示例来源:origin: hibernate/hibernate-orm
public void testIncompleteScrollLast() {
Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
results.next();
Parent p = (Parent) results.get( 0 );
assertResultFromOneUser( p );
results.last();
assertSame( pOther, s.get( Parent.class, pOther.getId() ) );
s.getTransaction().commit();
s.close();
代码示例来源:origin: hibernate/hibernate-orm
Transaction tx = s.beginTransaction();
fillDb(s);
tx.commit();
s.close();
tx = s.beginTransaction();
final String continents = "from Continent";
int results = s.createQuery( continents ).list().size();
while ( scrollableResults.next() ) {
scrollableResults.close();
tx.commit();
s.close();
assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() );
tx.commit();
s.close();
assertFalse( s.isOpen() );
代码示例来源:origin: hibernate/hibernate-orm
sessionFactory().getStatistics().clear();
Session s = openSession();
Transaction t = s.beginTransaction();
Item i1 = new Item("foo");
Item i2 = new Item("bar");
s.persist("Item", i1);
s.persist("Item", i2);
t.commit();
s.close();
t = s.beginTransaction();
ScrollableResults sr = s.getNamedQuery("Item.nameDesc").scroll();
assertTrue( sr.next() );
i1 = (Item) sr.get(0);
assertTrue( sr.next() );
i2 = (Item) sr.get(0);
assertTrue( Hibernate.isInitialized(i1) );
assertTrue( Hibernate.isInitialized(i2) );
assertEquals( i1.getName(), "foo" );
assertEquals( i2.getName(), "bar" );
assertFalse( sr.next() );
s.delete(i1);
s.delete(i2);
t.commit();
s.close();
assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 );
代码示例来源:origin: Jasig/uPortal
Function<PortalEvent, Boolean> handler) {
final Session session = this.getEntityManager().unwrap(Session.class);
session.setFlushMode(FlushMode.COMMIT);
final org.hibernate.Query query = session.createQuery(this.selectUnaggregatedQuery);
query.setParameter(this.startTimeParameter.getName(), startTime);
query.setParameter(this.endTimeParameter.getName(), endTime);
if (maxEvents > 0) {
query.setMaxResults(maxEvents);
for (final ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
results.next(); ) {
final PersistentPortalEvent persistentPortalEvent =
(PersistentPortalEvent) results.get(0);
final PortalEvent portalEvent;
try {
session.persist(persistentPortalEvent);
代码示例来源:origin: hibernate/hibernate-orm
Transaction txn = s.beginTransaction();
.createQuery( "from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
.setString( "desc", "root%" )
.scroll();
results.first();
Animal animal = ( Animal ) results.get( 0 );
assertEquals( "first() did not return expected row", data.root1Id, animal.getId() );
results.scroll( 1 );
animal = ( Animal ) results.get( 0 );
assertEquals( "scroll(1) did not return expected row", data.root2Id, animal.getId() );
results.scroll( -1 );
animal = ( Animal ) results.get( 0 );
assertEquals( "scroll(-1) did not return expected row", data.root1Id, animal.getId() );
results.setRowNumber( 1 );
animal = ( Animal ) results.get( 0 );
assertEquals( "setRowNumber(1) did not return expected row", data.root1Id, animal.getId() );
results.setRowNumber( 2 );
animal = ( Animal ) results.get( 0 );
assertEquals( "setRowNumber(2) did not return expected row", data.root2Id, animal.getId() );
txn.commit();
s.close();
代码示例来源:origin: hibernate/hibernate-orm
@Test
@SkipForDialect(value = CUBRIDDialect.class, comment = "As of verion 8.4.1 CUBRID doesn't support temporary tables. This test fails with"
+ "HibernateException: cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables")
@SkipForDialect(value = AbstractHANADialect.class, comment = "HANA only supports forward-only cursors.")
public void testScrollingJoinFetchesReverse() {
TestData data = new TestData();
data.prepare();
Session s = openSession();
Transaction txn = s.beginTransaction();
ScrollableResults results = s
.createQuery(
"from Animal a left join fetch a.offspring where a.description like :desc order by a.id" )
.setString( "desc", "root%" ).scroll();
results.afterLast();
int counter = 0;
while ( results.previous() ) {
counter++;
Animal animal = ( Animal ) results.get( 0 );
checkResult( animal );
}
assertEquals( "unexpected result count", 2, counter );
txn.commit();
s.close();
data.cleanup();
}
代码示例来源:origin: org.compass-project/compass
} else {
Query query = entityInformation.getQueryProvider().createQuery(hibernateSession, entityInformation);
cursor = query.scroll(ScrollMode.FORWARD_ONLY);
while (true) {
try {
if (!cursor.next()) {
break;
continue;
Object item = cursor.get(0);
if (prev != null && item != prev) {
buffer.put(prev);
cursor.close();
hibernateTransaction.commit();
} catch (Exception e) {
log.error(device.buildMessage("Failed to index the database"), e);
if (cursor != null) {
try {
cursor.close();
} catch (Exception e1) {
log.warn(device.buildMessage("Failed to close cursor on error, ignoring"), e1);
代码示例来源:origin: de.tudarmstadt.ukp.uby/de.tudarmstadt.ukp.uby.persistence.transform-asl
Query query = lookupSession.createQuery("FROM " + clazz.getSimpleName()
+ " WHERE lexiconId = '" + lexicon.getId() + "' ORDER BY id");
query.setReadOnly(true);
if (DBConfig.MYSQL.equals(dbConfig.getDBType())) {
query.setFetchSize(Integer.MIN_VALUE); // MIN_VALUE gives hint to JDBC driver to stream results
query.setFetchSize(1000);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
while (results.next()) {
Object[] rows = results.get();
Object row = rows[0];
lookupSession.evict(row);
lookupSession.evict(rows);
rows = null;
row = session.get(row.getClass(), ((IHasID) row).getId());
results.close();
lookupSession.close();
内容来源于网络,如有侵权,请联系作者删除!