当前位置: 首页>>代码示例>>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;未经允许,请勿转载。