Search in sources :

Example 16 with RosterMember

use of com.liferay.roster.model.RosterMember in project liferay-ide by liferay.

the class RosterMemberPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the roster members.
 *
 * <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 {@link QueryUtil#ALL_POS} 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 {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RosterMemberModelImpl}. 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 start the lower bound of the range of roster members
 * @param end the upper bound of the range of roster members (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 roster members
 */
@Override
public List<RosterMember> findAll(int start, int end, OrderByComparator<RosterMember> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }
    List<RosterMember> list = null;
    if (retrieveFromCache) {
        list = (List<RosterMember>) finderCache.getResult(finderPath, finderArgs, this);
    }
    if (list == null) {
        StringBundler query = null;
        String sql = null;
        if (orderByComparator != null) {
            query = new StringBundler(2 + (orderByComparator.getOrderByFields().length * 2));
            query.append(_SQL_SELECT_ROSTERMEMBER);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_ROSTERMEMBER;
            if (pagination) {
                sql = sql.concat(RosterMemberModelImpl.ORDER_BY_JPQL);
            }
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            if (!pagination) {
                list = (List<RosterMember>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = Collections.unmodifiableList(list);
            } else {
                list = (List<RosterMember>) 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 : RosterMember(com.liferay.roster.model.RosterMember) Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchRosterMemberException(com.liferay.roster.exception.NoSuchRosterMemberException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 17 with RosterMember

use of com.liferay.roster.model.RosterMember in project liferay-ide by liferay.

the class RosterMemberPersistenceImpl method getByRosterId_PrevAndNext.

protected RosterMember getByRosterId_PrevAndNext(Session session, RosterMember rosterMember, long rosterId, OrderByComparator<RosterMember> 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_ROSTERMEMBER_WHERE);
    query.append(_FINDER_COLUMN_ROSTERID_ROSTERID_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(RosterMemberModelImpl.ORDER_BY_JPQL);
    }
    String sql = query.toString();
    Query q = session.createQuery(sql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    QueryPos qPos = QueryPos.getInstance(q);
    qPos.add(rosterId);
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(rosterMember);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<RosterMember> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) Query(com.liferay.portal.kernel.dao.orm.Query) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 18 with RosterMember

use of com.liferay.roster.model.RosterMember in project liferay-ide by liferay.

the class RosterMemberPersistenceImpl method clearCache.

@Override
public void clearCache(List<RosterMember> rosterMembers) {
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    for (RosterMember rosterMember : rosterMembers) {
        entityCache.removeResult(RosterMemberModelImpl.ENTITY_CACHE_ENABLED, RosterMemberImpl.class, rosterMember.getPrimaryKey());
    }
}
Also used : RosterMember(com.liferay.roster.model.RosterMember)

Example 19 with RosterMember

use of com.liferay.roster.model.RosterMember in project liferay-ide by liferay.

the class RosterMemberPersistenceImpl method findByRosterId_First.

/**
 * Returns the first roster member in the ordered set where rosterId = &#63;.
 *
 * @param rosterId the roster ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the first matching roster member
 * @throws NoSuchRosterMemberException if a matching roster member could not be found
 */
@Override
public RosterMember findByRosterId_First(long rosterId, OrderByComparator<RosterMember> orderByComparator) throws NoSuchRosterMemberException {
    RosterMember rosterMember = fetchByRosterId_First(rosterId, orderByComparator);
    if (rosterMember != null) {
        return rosterMember;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("rosterId=");
    msg.append(rosterId);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchRosterMemberException(msg.toString());
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) NoSuchRosterMemberException(com.liferay.roster.exception.NoSuchRosterMemberException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 20 with RosterMember

use of com.liferay.roster.model.RosterMember in project liferay-ide by liferay.

the class RosterMemberPersistenceImpl method findByUuid_PrevAndNext.

/**
 * Returns the roster members before and after the current roster member in the ordered set where uuid = &#63;.
 *
 * @param rosterMemberId the primary key of the current roster member
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next roster member
 * @throws NoSuchRosterMemberException if a roster member with the primary key could not be found
 */
@Override
public RosterMember[] findByUuid_PrevAndNext(long rosterMemberId, String uuid, OrderByComparator<RosterMember> orderByComparator) throws NoSuchRosterMemberException {
    RosterMember rosterMember = findByPrimaryKey(rosterMemberId);
    Session session = null;
    try {
        session = openSession();
        RosterMember[] array = new RosterMemberImpl[3];
        array[0] = getByUuid_PrevAndNext(session, rosterMember, uuid, orderByComparator, true);
        array[1] = rosterMember;
        array[2] = getByUuid_PrevAndNext(session, rosterMember, uuid, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) RosterMemberImpl(com.liferay.roster.model.impl.RosterMemberImpl) NoSuchRosterMemberException(com.liferay.roster.exception.NoSuchRosterMemberException) Session(com.liferay.portal.kernel.dao.orm.Session)

Aggregations

RosterMember (com.liferay.roster.model.RosterMember)32 Test (org.junit.Test)13 NoSuchRosterMemberException (com.liferay.roster.exception.NoSuchRosterMemberException)12 StringBundler (com.liferay.portal.kernel.util.StringBundler)10 Session (com.liferay.portal.kernel.dao.orm.Session)8 Query (com.liferay.portal.kernel.dao.orm.Query)6 RosterMemberImpl (com.liferay.roster.model.impl.RosterMemberImpl)6 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)4 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)4 Serializable (java.io.Serializable)4 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)3 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)3 HashSet (java.util.HashSet)3 IntegerWrapper (com.liferay.portal.kernel.util.IntegerWrapper)1 HashMap (java.util.HashMap)1 List (java.util.List)1