當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.scroll方法代碼示例

本文整理匯總了Java中org.hibernate.Query.scroll方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.scroll方法的具體用法?Java Query.scroll怎麽用?Java Query.scroll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.Query的用法示例。


在下文中一共展示了Query.scroll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeDataMigration

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
protected void executeDataMigration(HibernateMigrationHelper helper, MigrationResult result, Session session)
{
	Query query = session
		.createQuery("select i.id, i.moderation.id from Item i where moderating = true or status = 'rejected'");
	ScrollableResults results = query.scroll();
	while( results.next() )
	{
		Query upQuery = session
			.createQuery("update ModerationStatus m set lastAction = "
				+ "(select max(h.date) from Item i join i.history h where i.id = ? and h.type in ('approved','rejected', 'comment') group by i.id) "
				+ "where m.id = ?");
		upQuery.setParameter(0, results.get(0));
		upQuery.setParameter(1, results.get(1));
		upQuery.executeUpdate();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:AddLastActionDate.java

示例2: executeDataMigration

import org.hibernate.Query; //導入方法依賴的package包/類
@Override
protected void executeDataMigration(HibernateMigrationHelper helper, MigrationResult result, Session session)
{
	Date convertDate = new Date();
	Query query = session.createSQLQuery("SELECT i.uuid, i.version, i.institution_id,"
		+ " un.element FROM item_users_notified un INNER JOIN item i ON i.id = un.item_id");
	ScrollableResults results = query.scroll();
	while( results.next() )
	{
		Object[] oldnote = results.get();

		ItemId itemId = new ItemId((String) oldnote[0], ((Number) oldnote[1]).intValue());

		Institution inst = new Institution();
		inst.setDatabaseId(((Number) oldnote[2]).longValue());

		FakeNotification notification = new FakeNotification();
		notification.reason = FakeNotification.REASON_WENTLIVE;
		notification.date = convertDate;
		notification.itemid = itemId.toString();
		notification.institution = inst;
		notification.userTo = (String) oldnote[3];

		session.save(notification);
		session.flush();
		session.clear();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:29,代碼來源:MigrateNotifications.java

示例3: withSession

import org.hibernate.Query; //導入方法依賴的package包/類
public final int withSession(Session session)
{
	final String idFinderHql = buildIdFinderHql();
	final String dmlHql = buildDmlHql();

	int total = 0;

	long startId = -1;
	long endId = -1;
	while( true )
	{
		// Find the next start and end ID
		startId = endId + 1;

		Query idFinder = session.createQuery(idFinderHql);
		idFinder.setMaxResults(MAX_BATCH_SIZE);
		idFinder.setParameter("startId", startId);
		setWhereParams(idFinder);
		ScrollableResults sr = idFinder.scroll();
		try
		{
			if( sr.last() )
			{
				endId = sr.getLong(0);
			}
			else
			{
				// Nothing more to process
				return total;
			}
		}
		finally
		{
			sr.close();
		}

		// Process rows in our ID range
		Query dml = session.createQuery(dmlHql);
		dml.setParameter("startId", startId);
		dml.setParameter("endId", endId);
		setWhereParams(dml);
		setDmlParams(dml);

		total += dml.executeUpdate();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:47,代碼來源:DMLPartitioner.java

示例4: withSession

import org.hibernate.Query; //導入方法依賴的package包/類
private final int withSession(Session session) {
	log.debug("inside withSession() method");
	final String idFinderHql = buildIdFinderHql();
	final String dmlHql = buildDeleteAuditLogDmlHql();

	int total = 0;

	long startId = -1;
	long endId = -1;
	while( true )
	{
		// Find the next start and end ID
		startId = endId + 1;
		Query idFinder = session.createQuery(idFinderHql);
		idFinder.setMaxResults(MAX_BATCH_SIZE);
		idFinder.setParameter("startId", startId);		
		idFinder.setParameter("date", daysBeforeRemoval);
		idFinder.setParameter("institution", institution);
		ScrollableResults sr = idFinder.scroll();
		try
		{
			if( sr.last() )
			{				
				endId = sr.getLong(0);
			}
			else
			{
				// Nothing more to process
				log.debug("Total Audit Log Deleted Records :: "+total);
				return total;
			}
		}
		finally
		{
			sr.close();
		}
		
		Query dml = session.createQuery(dmlHql);
		dml.setParameter("startId", startId);
		dml.setParameter("endId", endId);
		dml.setParameter("date", daysBeforeRemoval);
		dml.setParameter("institution", institution);			
		total += dml.executeUpdate();
		log.debug("Start Id:: "+startId+" End Id:: "+endId+" Total Deleted Records ::"+total);
	}		
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:47,代碼來源:AuditLogDMLPartitioner.java


注:本文中的org.hibernate.Query.scroll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。