Search in sources :

Example 6 with Roster

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

the class RosterPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the rosters.
 *
 * <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 RosterModelImpl}. 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 rosters
 * @param end the upper bound of the range of rosters (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 rosters
 */
@Override
public List<Roster> findAll(int start, int end, OrderByComparator<Roster> 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<Roster> list = null;
    if (retrieveFromCache) {
        list = (List<Roster>) 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_ROSTER);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_ROSTER;
            if (pagination) {
                sql = sql.concat(RosterModelImpl.ORDER_BY_JPQL);
            }
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            if (!pagination) {
                list = (List<Roster>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Roster>) 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 : Roster(com.liferay.roster.model.Roster) Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchRosterException(com.liferay.roster.exception.NoSuchRosterException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 7 with Roster

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

the class RosterPersistenceImpl method create.

/**
 * Creates a new roster with the primary key. Does not add the roster to the database.
 *
 * @param rosterId the primary key for the new roster
 * @return the new roster
 */
@Override
public Roster create(long rosterId) {
    Roster roster = new RosterImpl();
    roster.setNew(true);
    roster.setPrimaryKey(rosterId);
    String uuid = PortalUUIDUtil.generate();
    roster.setUuid(uuid);
    return roster;
}
Also used : Roster(com.liferay.roster.model.Roster) RosterImpl(com.liferay.roster.model.impl.RosterImpl)

Example 8 with Roster

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

the class RosterPersistenceTest method testFindByPrimaryKeyExisting.

@Test
public void testFindByPrimaryKeyExisting() throws Exception {
    Roster newRoster = addRoster();
    Roster existingRoster = _persistence.findByPrimaryKey(newRoster.getPrimaryKey());
    Assert.assertEquals(existingRoster, newRoster);
}
Also used : Roster(com.liferay.roster.model.Roster) Test(org.junit.Test)

Example 9 with Roster

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

the class RosterPersistenceTest method testFetchByPrimaryKeysWithOnePrimaryKey.

@Test
public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    Roster newRoster = addRoster();
    Set<Serializable> primaryKeys = new HashSet<Serializable>();
    primaryKeys.add(newRoster.getPrimaryKey());
    Map<Serializable, Roster> rosters = _persistence.fetchByPrimaryKeys(primaryKeys);
    Assert.assertEquals(1, rosters.size());
    Assert.assertEquals(newRoster, rosters.get(newRoster.getPrimaryKey()));
}
Also used : Serializable(java.io.Serializable) Roster(com.liferay.roster.model.Roster) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Roster

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

the class RosterPersistenceTest method testCreate.

@Test
public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();
    Roster roster = _persistence.create(pk);
    Assert.assertNotNull(roster);
    Assert.assertEquals(roster.getPrimaryKey(), pk);
}
Also used : Roster(com.liferay.roster.model.Roster) Test(org.junit.Test)

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