Search in sources :

Example 16 with Club

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

the class ClubPersistenceImpl method findByUuid_PrevAndNext.

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

Example 17 with Club

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

the class ClubPersistenceImpl method fetchByPrimaryKeys.

@Override
public Map<Serializable, Club> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Serializable, Club> map = new HashMap<Serializable, Club>();
    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();
        Serializable primaryKey = iterator.next();
        Club club = fetchByPrimaryKey(primaryKey);
        if (club != null) {
            map.put(primaryKey, club);
        }
        return map;
    }
    Set<Serializable> uncachedPrimaryKeys = null;
    for (Serializable primaryKey : primaryKeys) {
        Club club = (Club) entityCache.getResult(ClubModelImpl.ENTITY_CACHE_ENABLED, ClubImpl.class, primaryKey);
        if (club == null) {
            if (uncachedPrimaryKeys == null) {
                uncachedPrimaryKeys = new HashSet<Serializable>();
            }
            uncachedPrimaryKeys.add(primaryKey);
        } else {
            map.put(primaryKey, club);
        }
    }
    if (uncachedPrimaryKeys == null) {
        return map;
    }
    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);
    query.append(_SQL_SELECT_CLUB_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 (Club club : (List<Club>) q.list()) {
            map.put(club.getPrimaryKeyObj(), club);
            cacheResult(club);
            uncachedPrimaryKeys.remove(club.getPrimaryKeyObj());
        }
        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(ClubModelImpl.ENTITY_CACHE_ENABLED, ClubImpl.class, primaryKey, _nullClub);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
    return map;
}
Also used : Serializable(java.io.Serializable) Query(com.liferay.portal.kernel.dao.orm.Query) HashMap(java.util.HashMap) ClubImpl(com.liferay.roster.model.impl.ClubImpl) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchClubException(com.liferay.roster.exception.NoSuchClubException) Club(com.liferay.roster.model.Club) List(java.util.List) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 18 with Club

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

the class ClubPersistenceImpl method clearCache.

@Override
public void clearCache(List<Club> clubs) {
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    for (Club club : clubs) {
        entityCache.removeResult(ClubModelImpl.ENTITY_CACHE_ENABLED, ClubImpl.class, club.getPrimaryKey());
    }
}
Also used : Club(com.liferay.roster.model.Club)

Example 19 with Club

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

the class ClubPersistenceTest method testFetchByPrimaryKeyExisting.

@Test
public void testFetchByPrimaryKeyExisting() throws Exception {
    Club newClub = addClub();
    Club existingClub = _persistence.fetchByPrimaryKey(newClub.getPrimaryKey());
    Assert.assertEquals(existingClub, newClub);
}
Also used : Club(com.liferay.roster.model.Club) Test(org.junit.Test)

Example 20 with Club

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

the class ClubPersistenceTest method testDynamicQueryByProjectionExisting.

@Test
public void testDynamicQueryByProjectionExisting() throws Exception {
    Club newClub = addClub();
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Club.class, _dynamicQueryClassLoader);
    dynamicQuery.setProjection(ProjectionFactoryUtil.property("clubId"));
    Object newClubId = newClub.getClubId();
    dynamicQuery.add(RestrictionsFactoryUtil.in("clubId", new Object[] { newClubId }));
    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
    Assert.assertEquals(1, result.size());
    Object existingClubId = result.get(0);
    Assert.assertEquals(existingClubId, newClubId);
}
Also used : Club(com.liferay.roster.model.Club) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) Test(org.junit.Test)

Aggregations

Club (com.liferay.roster.model.Club)27 Test (org.junit.Test)13 NoSuchClubException (com.liferay.roster.exception.NoSuchClubException)8 Session (com.liferay.portal.kernel.dao.orm.Session)6 StringBundler (com.liferay.portal.kernel.util.StringBundler)6 ClubImpl (com.liferay.roster.model.impl.ClubImpl)5 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)4 Query (com.liferay.portal.kernel.dao.orm.Query)4 Serializable (java.io.Serializable)4 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)3 HashSet (java.util.HashSet)3 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)2 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)2 IntegerWrapper (com.liferay.portal.kernel.util.IntegerWrapper)1 HashMap (java.util.HashMap)1 List (java.util.List)1