Search in sources :

Example 11 with RosterMember

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

the class RosterMemberPersistenceTest method testCreate.

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

Example 12 with RosterMember

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

the class RosterMemberPersistenceTest method testUpdateExisting.

@Test
public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();
    RosterMember newRosterMember = _persistence.create(pk);
    newRosterMember.setUuid(RandomTestUtil.randomString());
    newRosterMember.setCreateDate(RandomTestUtil.nextDate());
    newRosterMember.setModifiedDate(RandomTestUtil.nextDate());
    newRosterMember.setRosterId(RandomTestUtil.nextLong());
    newRosterMember.setContactId(RandomTestUtil.nextLong());
    _rosterMembers.add(_persistence.update(newRosterMember));
    RosterMember existingRosterMember = _persistence.findByPrimaryKey(newRosterMember.getPrimaryKey());
    Assert.assertEquals(existingRosterMember.getUuid(), newRosterMember.getUuid());
    Assert.assertEquals(existingRosterMember.getRosterMemberId(), newRosterMember.getRosterMemberId());
    Assert.assertEquals(Time.getShortTimestamp(existingRosterMember.getCreateDate()), Time.getShortTimestamp(newRosterMember.getCreateDate()));
    Assert.assertEquals(Time.getShortTimestamp(existingRosterMember.getModifiedDate()), Time.getShortTimestamp(newRosterMember.getModifiedDate()));
    Assert.assertEquals(existingRosterMember.getRosterId(), newRosterMember.getRosterId());
    Assert.assertEquals(existingRosterMember.getContactId(), newRosterMember.getContactId());
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) Test(org.junit.Test)

Example 13 with RosterMember

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

the class RosterMemberPersistenceTest method testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist.

@Test
public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist() throws Exception {
    RosterMember newRosterMember = addRosterMember();
    long pk = RandomTestUtil.nextLong();
    Set<Serializable> primaryKeys = new HashSet<Serializable>();
    primaryKeys.add(newRosterMember.getPrimaryKey());
    primaryKeys.add(pk);
    Map<Serializable, RosterMember> rosterMembers = _persistence.fetchByPrimaryKeys(primaryKeys);
    Assert.assertEquals(1, rosterMembers.size());
    Assert.assertEquals(newRosterMember, rosterMembers.get(newRosterMember.getPrimaryKey()));
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with RosterMember

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

the class RosterMemberPersistenceTest method testActionableDynamicQuery.

@Test
public void testActionableDynamicQuery() throws Exception {
    final IntegerWrapper count = new IntegerWrapper();
    ActionableDynamicQuery actionableDynamicQuery = RosterMemberLocalServiceUtil.getActionableDynamicQuery();
    actionableDynamicQuery.setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<RosterMember>() {

        @Override
        public void performAction(RosterMember rosterMember) {
            Assert.assertNotNull(rosterMember);
            count.increment();
        }
    });
    actionableDynamicQuery.performActions();
    Assert.assertEquals(count.getValue(), _persistence.countAll());
}
Also used : RosterMember(com.liferay.roster.model.RosterMember) IntegerWrapper(com.liferay.portal.kernel.util.IntegerWrapper) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) Test(org.junit.Test)

Example 15 with RosterMember

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

the class RosterMemberPersistenceImpl method fetchByPrimaryKeys.

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