Search in sources :

Example 21 with RosterMember

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

the class RosterMemberPersistenceImpl method getByUuid_PrevAndNext.

protected RosterMember getByUuid_PrevAndNext(Session session, RosterMember rosterMember, String uuid, 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);
    boolean bindUuid = false;
    if (uuid == null) {
        query.append(_FINDER_COLUMN_UUID_UUID_1);
    } else if (uuid.equals(StringPool.BLANK)) {
        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(RosterMemberModelImpl.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) {
        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 22 with RosterMember

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

the class RosterMemberPersistenceImpl method create.

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

Example 23 with RosterMember

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

the class RosterMemberPersistenceImpl method fetchByPrimaryKey.

/**
 * Returns the roster member with the primary key or returns <code>null</code> if it could not be found.
 *
 * @param primaryKey the primary key of the roster member
 * @return the roster member, or <code>null</code> if a roster member with the primary key could not be found
 */
@Override
public RosterMember fetchByPrimaryKey(Serializable primaryKey) {
    RosterMember rosterMember = (RosterMember) entityCache.getResult(RosterMemberModelImpl.ENTITY_CACHE_ENABLED, RosterMemberImpl.class, primaryKey);
    if (rosterMember == _nullRosterMember) {
        return null;
    }
    if (rosterMember == null) {
        Session session = null;
        try {
            session = openSession();
            rosterMember = (RosterMember) session.get(RosterMemberImpl.class, primaryKey);
            if (rosterMember != null) {
                cacheResult(rosterMember);
            } else {
                entityCache.putResult(RosterMemberModelImpl.ENTITY_CACHE_ENABLED, RosterMemberImpl.class, primaryKey, _nullRosterMember);
            }
        } catch (Exception e) {
            entityCache.removeResult(RosterMemberModelImpl.ENTITY_CACHE_ENABLED, RosterMemberImpl.class, primaryKey);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return rosterMember;
}
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)

Example 24 with RosterMember

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

the class RosterMemberPersistenceImpl method remove.

/**
 * Removes the roster member with the primary key from the database. Also notifies the appropriate model listeners.
 *
 * @param primaryKey the primary key of the roster member
 * @return the roster member that was removed
 * @throws NoSuchRosterMemberException if a roster member with the primary key could not be found
 */
@Override
public RosterMember remove(Serializable primaryKey) throws NoSuchRosterMemberException {
    Session session = null;
    try {
        session = openSession();
        RosterMember rosterMember = (RosterMember) session.get(RosterMemberImpl.class, primaryKey);
        if (rosterMember == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }
            throw new NoSuchRosterMemberException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
        }
        return remove(rosterMember);
    } catch (NoSuchRosterMemberException nsee) {
        throw nsee;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) NoSuchRosterMemberException(com.liferay.roster.exception.NoSuchRosterMemberException) RosterMemberImpl(com.liferay.roster.model.impl.RosterMemberImpl) NoSuchRosterMemberException(com.liferay.roster.exception.NoSuchRosterMemberException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 25 with RosterMember

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

the class RosterMemberPersistenceTest method testFindByPrimaryKeyExisting.

@Test
public void testFindByPrimaryKeyExisting() throws Exception {
    RosterMember newRosterMember = addRosterMember();
    RosterMember existingRosterMember = _persistence.findByPrimaryKey(newRosterMember.getPrimaryKey());
    Assert.assertEquals(existingRosterMember, newRosterMember);
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) Test(org.junit.Test)

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