Example usage for org.hibernate ScrollMode SCROLL_SENSITIVE

List of usage examples for org.hibernate ScrollMode SCROLL_SENSITIVE

Introduction

In this page you can find the example usage for org.hibernate ScrollMode SCROLL_SENSITIVE.

Prototype

ScrollMode SCROLL_SENSITIVE

To view the source code for org.hibernate ScrollMode SCROLL_SENSITIVE.

Click Source Link

Document

Requests a scrollable result which is sensitive to changes in the underlying data.

Usage

From source file:org.dcm4chee.archive.query.impl.AbstractQuery.java

License:LGPL

@Override
public void executeQuery() {
    results = query.scroll(ScrollMode.SCROLL_SENSITIVE, select());
    hasMoreMatches = results.next();
}

From source file:org.openbravo.advpaymentmngt.utility.FIN_BankStatementImport.java

License:Open Source License

private BusinessPartner matchBusinessPartnerByNameTokens(String partnername, Organization organization) {
    if (partnername == null || "".equals(partnername.trim())) {
        return null;
    }/*w  w  w . j av a2 s.  c  o m*/
    String parsedPartnername = partnername.toLowerCase();
    // Remove exceptions
    for (String eliminate : stringExceptions) {
        parsedPartnername = parsedPartnername.replaceAll(eliminate.toLowerCase(), "");
    }
    StringTokenizer st = new StringTokenizer(parsedPartnername);
    List<String> list = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (token.length() > 3) {
            list.add(token);
        }
    }
    if (list.isEmpty()) {
        return null;
    }
    final StringBuilder whereClause = new StringBuilder();
    OBContext.setAdminMode();
    ScrollableResults businessPartnersScroll = null;
    try {
        whereClause.append("select b.id as id, b.name as name from ");
        whereClause.append(" BusinessPartner b ");
        whereClause.append(" where (");
        for (String token : list) {
            whereClause.append(
                    " lower(b." + BusinessPartner.PROPERTY_NAME + ") like lower('%" + token + "%') or ");
        }
        whereClause.delete(whereClause.length() - 3, whereClause.length()).append(")");
        whereClause.append(" and b." + BusinessPartner.PROPERTY_ORGANIZATION + ".id in (");
        whereClause.append(
                Utility.getInStrSet(new OrganizationStructureProvider().getNaturalTree(organization.getId()))
                        + ") ");
        final Query bl = OBDal.getInstance().getSession().createQuery(whereClause.toString());
        businessPartnersScroll = bl.scroll(ScrollMode.SCROLL_SENSITIVE);

        if (!businessPartnersScroll.next()) {
            return null;
        }

        else {
            final Object[] resultObject = (Object[]) businessPartnersScroll.get(0);
            if (!businessPartnersScroll.next()) {
                String strParnterId = "";
                if (resultObject.getClass().isArray()) {
                    final Object[] values = resultObject;
                    strParnterId = (String) values[0];
                }
                BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, strParnterId);
                return bp;
            }

            else {
                String closestId = closest(businessPartnersScroll, partnername);
                BusinessPartner closest = OBDal.getInstance().get(BusinessPartner.class, closestId);
                return closest;
            }
        }

    } finally {
        businessPartnersScroll.close();
        OBContext.restorePreviousMode();
    }
}