org.hibernate.ScrollableResults.getString()

Here are the examples of the java api org.hibernate.ScrollableResults.getString() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : BadUrlsToReferencedUrlsMigration.java
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();
}