Here are the examples of the java api org.hibernate.ScrollableResults.close() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
10 Examples
19
Source : JRHibernateQueryExecuter.java
with GNU Lesser General Public License v3.0
from TIBCOSoftware
with GNU Lesser General Public License v3.0
from TIBCOSoftware
/**
* Closes the scrollable results of the query.
*/
public void closeScrollableResults() {
if (scrollableResults != null) {
try {
scrollableResults.close();
} finally {
scrollableResults = null;
}
}
}
18
Source : AbstractHibernateDAO.java
with GNU Affero General Public License v3.0
from KnowageLabs
with GNU Affero General Public License v3.0
from KnowageLabs
protected int getTotalNumber(Criteria criteria) {
ScrollableResults results = criteria.scroll();
results.last();
int total = results.getRowNumber() + 1;
results.close();
return total;
}
17
Source : DefaultStreamer.java
with Apache License 2.0
from IBM
with Apache License 2.0
from IBM
private void closeResources(StatelessSession session, ScrollableResults results) {
if (results != null) {
results.close();
}
if (session != null) {
session.close();
}
}
17
Source : QueryConverterTestCase.java
with Apache License 2.0
from HongZhaoHua
with Apache License 2.0
from HongZhaoHua
@Test
public void testHql() throws Exception {
Map<String, Clreplaced<?>> qualityDifinitions = new HashMap<>();
Map<String, Clreplaced<?>> quanreplacedyDifinitions = new HashMap<>();
qualityDifinitions.put("user", int.clreplaced);
qualityDifinitions.put("item", int.clreplaced);
quanreplacedyDifinitions.put("score", float.clreplaced);
DataSpace space = new DataSpace(qualityDifinitions, quanreplacedyDifinitions);
TreeMap<Integer, String> configuration = new TreeMap<>();
configuration.put(2, "user");
configuration.put(4, "item");
configuration.put(5, "score");
QueryConverter converter = new QueryConverter(space.getQualityAttributes(), space.getQuanreplacedyAttributes());
{
DataModule dense = space.makeDenseModule("dense", configuration, 1000);
List<MockData> datas = new ArrayList<>(5);
for (int index = 1; index <= 5; index++) {
MockData data = new MockData(index, 1, 2, 3, 4, index / 10F);
datas.add(data);
}
Session session = sessionFactory.openSession();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.save(data);
}
transaction.commit();
}
Query query = session.createQuery(selectDataHql);
ScrollableResults iterator = query.scroll();
int count = converter.convert(dense, iterator);
replacedert.replacedertEquals(5, count);
iterator.close();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.delete(data);
}
transaction.commit();
}
session.close();
}
{
DataModule sparse = space.makeSparseModule("sparse", configuration, 1000);
List<MockData> datas = new ArrayList<>(5);
datas.add(new MockData(1, 1, null, null, null, null));
datas.add(new MockData(2, 1, 2, null, null, null));
datas.add(new MockData(3, 1, 2, 3, null, null));
datas.add(new MockData(4, 1, 2, 3, 4, null));
datas.add(new MockData(5, 1, 2, 3, 4, 0.5F));
Session session = sessionFactory.openSession();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.save(data);
}
transaction.commit();
}
Query query = session.createQuery(selectDataHql);
ScrollableResults iterator = query.scroll();
int count = converter.convert(sparse, iterator);
replacedert.replacedertEquals(5, count);
iterator.close();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.delete(data);
}
transaction.commit();
}
session.close();
}
}
17
Source : QueryConverterTestCase.java
with Apache License 2.0
from HongZhaoHua
with Apache License 2.0
from HongZhaoHua
@Test
public void testSql() throws Exception {
Map<String, Clreplaced<?>> qualityDifinitions = new HashMap<>();
Map<String, Clreplaced<?>> quanreplacedyDifinitions = new HashMap<>();
qualityDifinitions.put("user", int.clreplaced);
qualityDifinitions.put("item", int.clreplaced);
quanreplacedyDifinitions.put("score", float.clreplaced);
DataSpace space = new DataSpace(qualityDifinitions, quanreplacedyDifinitions);
TreeMap<Integer, String> configuration = new TreeMap<>();
configuration.put(2, "user");
configuration.put(4, "item");
configuration.put(5, "score");
QueryConverter converter = new QueryConverter(space.getQualityAttributes(), space.getQuanreplacedyAttributes());
{
DataModule dense = space.makeDenseModule("dense", configuration, 1000);
List<MockData> datas = new ArrayList<>(5);
for (int index = 1; index <= 5; index++) {
MockData data = new MockData(index, 1, 2, 3, 4, index / 10F);
datas.add(data);
}
Session session = sessionFactory.openSession();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.save(data);
}
transaction.commit();
}
Query query = session.createSQLQuery(selectDataSql);
ScrollableResults iterator = query.scroll();
int count = converter.convert(dense, iterator);
replacedert.replacedertEquals(5, count);
iterator.close();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.delete(data);
}
transaction.commit();
}
session.close();
}
{
DataModule sparse = space.makeSparseModule("sparse", configuration, 1000);
List<MockData> datas = new ArrayList<>(5);
datas.add(new MockData(1, 1, null, null, null, null));
datas.add(new MockData(2, 1, 2, null, null, null));
datas.add(new MockData(3, 1, 2, 3, null, null));
datas.add(new MockData(4, 1, 2, 3, 4, null));
datas.add(new MockData(5, 1, 2, 3, 4, 0.5F));
Session session = sessionFactory.openSession();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.save(data);
}
transaction.commit();
}
Query query = session.createSQLQuery(selectDataSql);
ScrollableResults iterator = query.scroll();
int count = converter.convert(sparse, iterator);
replacedert.replacedertEquals(5, count);
iterator.close();
{
Transaction transaction = session.beginTransaction();
for (MockData data : datas) {
session.delete(data);
}
transaction.commit();
}
session.close();
}
}
16
Source : IndexHelper.java
with GNU General Public License v2.0
from openkm
with GNU General Public License v2.0
from openkm
protected int doRebuildIndex() throws Exception {
FullTextSession fullTextSession = (FullTextSession) enreplacedyManager.getDelegate();
fullTextSession.setFlushMode(org.hibernate.FlushMode.MANUAL);
fullTextSession.setCacheMode(org.hibernate.CacheMode.IGNORE);
fullTextSession.purgeAll(NodeDoreplacedentVersion.clreplaced);
fullTextSession.getSearchFactory().optimize(NodeDoreplacedentVersion.clreplaced);
String query = "select ndv from NodeDoreplacedentVersion ndv";
ScrollableResults cursor = fullTextSession.createQuery(query).scroll();
cursor.last();
int count = cursor.getRowNumber() + 1;
log.warn("Re-building Wine index for " + count + " objects.");
if (count > 0) {
int batchSize = 300;
// Reset to first result row
cursor.first();
int i = 0;
while (true) {
fullTextSession.index(cursor.get(0));
if (++i % batchSize == 0) {
fullTextSession.flushToIndexes();
// Clear persistence context for each batch
fullTextSession.clear();
log.info("Flushed index update " + i + " from Thread " + Thread.currentThread().getName());
}
if (cursor.isLast()) {
break;
}
cursor.next();
}
}
cursor.close();
fullTextSession.flushToIndexes();
// Clear persistence context for each batch
fullTextSession.clear();
fullTextSession.getSearchFactory().optimize(NodeDoreplacedentVersion.clreplaced);
return count;
}
15
Source : DMLPartitioner.java
with Apache License 2.0
from openequella
with Apache License 2.0
from openequella
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();
}
}
15
Source : BadUrlsToReferencedUrlsMigration.java
with Apache License 2.0
from openequella
with Apache License 2.0
from openequella
/**
* Oracle can't cope with SELECT DISTINCT(my_lob_column), so we retrieve all URLs from the table
* and enforce uniqueness post-fact via the hashes.
*/
@Override
protected void executeDataMigration(HibernateMigrationHelper helper, MigrationResult result, Session session) {
// Start by collecting a list of unique Bad URLs. We're not going to
// have the good URLs until items have been re-saved at some point in
// the future.
Date epoch = new Date(0);
Set<String> hashes = Sets.newHashSet();
ScrollableResults sr = session.createQuery("SELECT url FROM BadURL WHERE url is NOT NULL").setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
result.incrementStatus();
try {
while (sr.next()) {
String url = sr.getString(0);
String hash = DigestUtils.md5Hex(url);
boolean notPresent = hashes.add(hash);
if (notPresent) {
FakeReferencedURL fru = new FakeReferencedURL();
fru.url = url;
fru.urlHash = hash;
fru.success = false;
fru.lastChecked = epoch;
fru.lastIndexed = epoch;
session.save(fru);
result.incrementStatus();
}
}
} finally {
sr.close();
}
session.flush();
// Copy the mappings from BadURLs to ReferencedURLs for each item
sr = session.createQuery("FROM Item WHERE badUrls.size > 0").setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
try {
while (sr.next()) {
FakeItem i = (FakeItem) sr.get(0);
for (FakeBadURL fbu : i.badUrls) {
if (fbu != null && fbu.url != null) {
String hashedCompareValue = DigestUtils.md5Hex(fbu.url);
Query query = session.createQuery("FROM ReferencedURL WHERE urlHash = :hashedurl");
i.referencedUrls.add((FakeReferencedURL) query.setString("hashedurl", hashedCompareValue).uniqueResult());
}
}
session.update(i);
}
} finally {
sr.close();
}
session.flush();
// Remove old configuration values
session.createQuery("DELETE FROM ConfigurationProperty WHERE property like 'urlchecker.%'").executeUpdate();
// Remove old ACLs
session.createQuery("DELETE FROM AccessEntry a WHERE a.targetObject = 'C:urlchecking'").executeUpdate();
}
14
Source : AuditLogDMLPartitioner.java
with Apache License 2.0
from openequella
with Apache License 2.0
from openequella
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("insreplacedution", insreplacedution);
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("insreplacedution", insreplacedution);
total += dml.executeUpdate();
log.debug("Start Id:: " + startId + " End Id:: " + endId + " Total Deleted Records ::" + total);
}
}
10
Source : XmlExportCreator.java
with European Union Public License 1.1
from EUSurvey
with European Union Public License 1.1
from EUSurvey
@Transactional
public void simulateExportContent(boolean sync, Export export) throws Exception {
exportedUniqueCodes.clear();
Session session;
session = sessionFactory.getCurrentSession();
if (export != null) {
session.evict(export.getSurvey());
}
exportedNow = new Date();
List<List<String>> answersets = reportingService.getAnswerSets(form.getSurvey(), export == null ? null : export.getResultFilter(), null, false, true, true, true, true);
if (answersets != null) {
for (List<String> row : answersets) {
int answerSetId = ConversionTools.getValue(row.get(1));
String answerSetUniqueCode = row.get(0);
if (!exportedUniqueCodes.containsKey(answerSetId)) {
exportedUniqueCodes.put(answerSetId, answerSetUniqueCode);
}
}
} else {
HashMap<String, Object> values = new HashMap<>();
String sql = "select ans.ANSWER_SET_ID, a.QUESTION_ID, a.QUESTION_UID, a.VALUE, a.ANSWER_COL, a.ANSWER_ID, a.ANSWER_ROW, a.PA_ID, a.PA_UID, ans.UNIQUECODE, ans.ANSWER_SET_DATE, ans.ANSWER_SET_UPDATE, ans.ANSWER_SET_INVID, ans.RESPONDER_EMAIL, ans.ANSWER_SET_LANG FROM ANSWERS a RIGHT JOIN ANSWERS_SET ans ON a.AS_ID = ans.ANSWER_SET_ID where ans.ANSWER_SET_ID IN (" + answerService.getSql(null, form.getSurvey().getId(), export == null ? null : export.getResultFilter(), values, true) + ") ORDER BY ans.ANSWER_SET_ID";
SQLQuery query = session.createSQLQuery(sql);
query.setReadOnly(true);
for (Entry<String, Object> entry : values.entrySet()) {
Object value = entry.getValue();
if (value instanceof String) {
query.setString(entry.getKey(), (String) value);
} else if (value instanceof Integer) {
query.setInteger(entry.getKey(), (Integer) value);
} else if (value instanceof Date) {
query.setTimestamp(entry.getKey(), (Date) value);
}
}
query.setFetchSize(Integer.MIN_VALUE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
while (results.next()) {
Object[] a = results.get();
if (!exportedUniqueCodes.containsKey(ConversionTools.getValue(a[0]))) {
exportedUniqueCodes.put(ConversionTools.getValue(a[0]), (String) a[9]);
}
}
results.close();
}
}