Search in sources :

Example 36 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceImpl method findByUuid_C_PrevAndNext.

/**
 * Returns the bazs before and after the current baz in the ordered set where uuid = ? and companyId = ?.
 *
 * @param bazId the primary key of the current baz
 * @param uuid the uuid
 * @param companyId the company ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next baz
 * @throws NoSuchBazException if a baz with the primary key could not be found
 */
@Override
public Baz[] findByUuid_C_PrevAndNext(long bazId, String uuid, long companyId, OrderByComparator<Baz> orderByComparator) throws NoSuchBazException {
    uuid = Objects.toString(uuid, "");
    Baz baz = findByPrimaryKey(bazId);
    Session session = null;
    try {
        session = openSession();
        Baz[] array = new BazImpl[3];
        array[0] = getByUuid_C_PrevAndNext(session, baz, uuid, companyId, orderByComparator, true);
        array[1] = baz;
        array[2] = getByUuid_C_PrevAndNext(session, baz, uuid, companyId, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : BazImpl(com.liferay.blade.workflow.basic.model.impl.BazImpl) Baz(com.liferay.blade.workflow.basic.model.Baz) NoSuchBazException(com.liferay.blade.workflow.basic.exception.NoSuchBazException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 37 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceImpl method getByUuid_PrevAndNext.

protected Baz getByUuid_PrevAndNext(Session session, Baz baz, String uuid, OrderByComparator<Baz> orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(4 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(3);
    }
    query.append(_SQL_SELECT_BAZ_WHERE);
    boolean bindUuid = false;
    if (uuid.isEmpty()) {
        query.append(_FINDER_COLUMN_UUID_UUID_3);
    } else {
        bindUuid = true;
        query.append(_FINDER_COLUMN_UUID_UUID_2);
    }
    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }
        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);
            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }
        query.append(ORDER_BY_CLAUSE);
        String[] orderByFields = orderByComparator.getOrderByFields();
        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);
            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(BazModelImpl.ORDER_BY_JPQL);
    }
    String sql = query.toString();
    Query q = session.createQuery(sql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    QueryPos qPos = QueryPos.getInstance(q);
    if (bindUuid) {
        qPos.add(uuid);
    }
    if (orderByComparator != null) {
        for (Object orderByConditionValue : orderByComparator.getOrderByConditionValues(baz)) {
            qPos.add(orderByConditionValue);
        }
    }
    List<Baz> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) Baz(com.liferay.blade.workflow.basic.model.Baz) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler)

Example 38 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceImpl method findByUuid_C.

/**
 * Returns an ordered range of all the bazs where uuid = &#63; and companyId = &#63;.
 *
 * <p>
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to <code>QueryUtil#ALL_POS</code> will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not <code>QueryUtil#ALL_POS</code>), then the query will include the default ORDER BY logic from <code>BazModelImpl</code>. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param uuid the uuid
 * @param companyId the company ID
 * @param start the lower bound of the range of bazs
 * @param end the upper bound of the range of bazs (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching bazs
 */
@Override
public List<Baz> findByUuid_C(String uuid, long companyId, int start, int end, OrderByComparator<Baz> orderByComparator, boolean retrieveFromCache) {
    uuid = Objects.toString(uuid, "");
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = _finderPathWithoutPaginationFindByUuid_C;
        finderArgs = new Object[] { uuid, companyId };
    } else {
        finderPath = _finderPathWithPaginationFindByUuid_C;
        finderArgs = new Object[] { uuid, companyId, start, end, orderByComparator };
    }
    List<Baz> list = null;
    if (retrieveFromCache) {
        list = (List<Baz>) finderCache.getResult(finderPath, finderArgs, this);
        if ((list != null) && !list.isEmpty()) {
            for (Baz baz : list) {
                if (!uuid.equals(baz.getUuid()) || (companyId != baz.getCompanyId())) {
                    list = null;
                    break;
                }
            }
        }
    }
    if (list == null) {
        StringBundler query = null;
        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(4);
        }
        query.append(_SQL_SELECT_BAZ_WHERE);
        boolean bindUuid = false;
        if (uuid.isEmpty()) {
            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
        } else {
            bindUuid = true;
            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
        }
        query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(BazModelImpl.ORDER_BY_JPQL);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindUuid) {
                qPos.add(uuid);
            }
            qPos.add(companyId);
            if (!pagination) {
                list = (List<Baz>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Baz>) QueryUtil.list(q, getDialect(), start, end);
            }
            cacheResult(list);
            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) Baz(com.liferay.blade.workflow.basic.model.Baz) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBazException(com.liferay.blade.workflow.basic.exception.NoSuchBazException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 39 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazLocalServiceImpl method deleteBaz.

@Override
public Baz deleteBaz(long bazId) throws PortalException {
    Baz baz = bazPersistence.remove(bazId);
    workflowInstanceLinkLocalService.deleteWorkflowInstanceLinks(baz.getCompanyId(), baz.getGroupId(), Baz.class.getName(), baz.getPrimaryKey());
    return baz;
}
Also used : Baz(com.liferay.blade.workflow.basic.model.Baz)

Aggregations

Baz (com.liferay.blade.workflow.basic.model.Baz)39 Test (org.junit.Test)14 StringBundler (com.liferay.petra.string.StringBundler)13 NoSuchBazException (com.liferay.blade.workflow.basic.exception.NoSuchBazException)12 Session (com.liferay.portal.kernel.dao.orm.Session)7 Query (com.liferay.portal.kernel.dao.orm.Query)6 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)5 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)5 BazImpl (com.liferay.blade.workflow.basic.model.impl.BazImpl)4 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)4 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)3 Serializable (java.io.Serializable)3 HashSet (java.util.HashSet)3 User (com.liferay.portal.kernel.model.User)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 ManifestSummary (com.liferay.exportimport.kernel.lar.ManifestSummary)1 StagedModelDataHandler (com.liferay.exportimport.kernel.lar.StagedModelDataHandler)1