Search in sources :

Example 21 with Roster

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

the class RosterPersistenceImpl method findByClubId_PrevAndNext.

/**
 * Returns the rosters before and after the current roster in the ordered set where clubId = ?.
 *
 * @param rosterId the primary key of the current roster
 * @param clubId the club ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next roster
 * @throws NoSuchRosterException if a roster with the primary key could not be found
 */
@Override
public Roster[] findByClubId_PrevAndNext(long rosterId, long clubId, OrderByComparator<Roster> orderByComparator) throws NoSuchRosterException {
    Roster roster = findByPrimaryKey(rosterId);
    Session session = null;
    try {
        session = openSession();
        Roster[] array = new RosterImpl[3];
        array[0] = getByClubId_PrevAndNext(session, roster, clubId, orderByComparator, true);
        array[1] = roster;
        array[2] = getByClubId_PrevAndNext(session, roster, clubId, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Roster(com.liferay.roster.model.Roster) RosterImpl(com.liferay.roster.model.impl.RosterImpl) NoSuchRosterException(com.liferay.roster.exception.NoSuchRosterException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 22 with Roster

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

the class RosterPersistenceImpl method fetchByPrimaryKeys.

@Override
public Map<Serializable, Roster> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Serializable, Roster> map = new HashMap<Serializable, Roster>();
    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();
        Serializable primaryKey = iterator.next();
        Roster roster = fetchByPrimaryKey(primaryKey);
        if (roster != null) {
            map.put(primaryKey, roster);
        }
        return map;
    }
    Set<Serializable> uncachedPrimaryKeys = null;
    for (Serializable primaryKey : primaryKeys) {
        Roster roster = (Roster) entityCache.getResult(RosterModelImpl.ENTITY_CACHE_ENABLED, RosterImpl.class, primaryKey);
        if (roster == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }
            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, roster);
        }
    }
    if (uncachedPrimaryKeys == null) {
        return map;
    }
    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);
    query.append(_SQL_SELECT_ROSTER_WHERE_PKS_IN);
    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append(String.valueOf(primaryKey));
        query.append(StringPool.COMMA);
    }
    query.setIndex(query.index() - 1);
    query.append(StringPool.CLOSE_PARENTHESIS);
    String sql = query.toString();
    Session session = null;
    try {
        session = openSession();
        Query q = session.createQuery(sql);
        for (Roster roster : (List<Roster>) q.list()) {
            map.put(roster.getPrimaryKeyObj(), roster);
            cacheResult(roster);
            uncachedPrimaryKeys.remove(roster.getPrimaryKeyObj());
        }
        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(RosterModelImpl.ENTITY_CACHE_ENABLED, RosterImpl.class, primaryKey, _nullRoster);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
    return map;
}
Also used : Serializable(java.io.Serializable) RosterImpl(com.liferay.roster.model.impl.RosterImpl) Query(com.liferay.portal.kernel.dao.orm.Query) HashMap(java.util.HashMap) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchRosterException(com.liferay.roster.exception.NoSuchRosterException) Roster(com.liferay.roster.model.Roster) List(java.util.List) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 23 with Roster

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

the class RosterPersistenceImpl method findByUuid_Last.

/**
 * Returns the last roster in the ordered set where uuid = &#63;.
 *
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching roster
 * @throws NoSuchRosterException if a matching roster could not be found
 */
@Override
public Roster findByUuid_Last(String uuid, OrderByComparator<Roster> orderByComparator) throws NoSuchRosterException {
    Roster roster = fetchByUuid_Last(uuid, orderByComparator);
    if (roster != null) {
        return roster;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("uuid=");
    msg.append(uuid);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchRosterException(msg.toString());
}
Also used : Roster(com.liferay.roster.model.Roster) NoSuchRosterException(com.liferay.roster.exception.NoSuchRosterException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 24 with Roster

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

the class RosterPersistenceImpl method getByClubId_PrevAndNext.

protected Roster getByClubId_PrevAndNext(Session session, Roster roster, long clubId, OrderByComparator<Roster> 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_ROSTER_WHERE);
    query.append(_FINDER_COLUMN_CLUBID_CLUBID_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(RosterModelImpl.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(clubId);
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(roster);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<Roster> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) Roster(com.liferay.roster.model.Roster) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 25 with Roster

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

the class RosterPersistenceTest method addRoster.

protected Roster addRoster() throws Exception {
    long pk = RandomTestUtil.nextLong();
    Roster roster = _persistence.create(pk);
    roster.setUuid(RandomTestUtil.randomString());
    roster.setCreateDate(RandomTestUtil.nextDate());
    roster.setModifiedDate(RandomTestUtil.nextDate());
    roster.setClubId(RandomTestUtil.nextLong());
    roster.setName(RandomTestUtil.randomString());
    _rosters.add(_persistence.update(roster));
    return roster;
}
Also used : Roster(com.liferay.roster.model.Roster)

Aggregations

Roster (com.liferay.roster.model.Roster)34 Test (org.junit.Test)13 NoSuchRosterException (com.liferay.roster.exception.NoSuchRosterException)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 RosterImpl (com.liferay.roster.model.impl.RosterImpl)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