Example usage for com.liferay.portal.kernel.dao.orm SQLQuery iterateNext

List of usage examples for com.liferay.portal.kernel.dao.orm SQLQuery iterateNext

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.orm SQLQuery iterateNext.

Prototype

public Object iterateNext() throws ORMException;

Source Link

Usage

From source file:com.liferay.dynamic.data.lists.service.persistence.impl.DDLRecordFinderImpl.java

License:Open Source License

@Override
public Long[] findByC_S_S_MinAndMax(long companyId, int status, int scope) {
    Session session = null;//from www . j a va 2s .  co m

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(getClass(), COUNT_BY_C_S_S);

        sql = StringUtil.replace(sql, "COUNT(DISTINCT DDLRecord.recordId) AS COUNT_VALUE",
                "MIN(DDLRecord.recordId) AS minRecordId, " + "MAX(DDLRecord.recordId) AS maxRecordId");

        if (status == WorkflowConstants.STATUS_ANY) {
            sql = StringUtil.replace(sql, "(DDLRecordVersion.status = ?) AND", StringPool.BLANK);
        }

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar("minRecordId", Type.LONG);
        q.addScalar("maxRecordId", Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        if (status != WorkflowConstants.STATUS_ANY) {
            qPos.add(status);
        }

        qPos.add(scope);
        qPos.add(companyId);

        Object[] array = (Object[]) q.iterateNext();

        if (array == null) {
            return null;
        }

        return ArrayUtil.toLongArray(array);
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}