@Override public int compareTo(PasswordTracker passwordTracker) { int value = 0; if (getUserId() < passwordTracker.getUserId()) { value = -1; } else if (getUserId() > passwordTracker.getUserId()) { value = 1; } else { value = 0; } value = value * -1; if (value != 0) { return value; } value = DateUtil.compareTo(getCreateDate(), passwordTracker.getCreateDate()); value = value * -1; if (value != 0) { return value; } return 0; }
@Test public void testFetchByPrimaryKeyExisting() throws Exception { PasswordTracker newPasswordTracker = addPasswordTracker(); PasswordTracker existingPasswordTracker = _persistence.fetchByPrimaryKey(newPasswordTracker.getPrimaryKey()); Assert.assertEquals(existingPasswordTracker, newPasswordTracker); }
@Override public PasswordTracker updateImpl(com.liferay.portal.model.PasswordTracker passwordTracker) throws SystemException { passwordTracker = toUnwrappedModel(passwordTracker); boolean isNew = passwordTracker.isNew(); PasswordTrackerModelImpl passwordTrackerModelImpl = (PasswordTrackerModelImpl) passwordTracker; Session session = null; try { session = openSession(); if (passwordTracker.isNew()) { session.save(passwordTracker); passwordTracker.setNew(false); } else { session.merge(passwordTracker); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (isNew || !PasswordTrackerModelImpl.COLUMN_BITMASK_ENABLED) { FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else { if ((passwordTrackerModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) { Object[] args = new Object[] {passwordTrackerModelImpl.getOriginalUserId()}; FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args); FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID, args); args = new Object[] {passwordTrackerModelImpl.getUserId()}; FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args); FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID, args); } } EntityCacheUtil.putResult( PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED, PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(), passwordTracker); passwordTracker.resetOriginalValues(); return passwordTracker; }
/** * Creates a new password tracker with the primary key. Does not add the password tracker to the * database. * * @param passwordTrackerId the primary key for the new password tracker * @return the new password tracker */ @Override public PasswordTracker create(long passwordTrackerId) { PasswordTracker passwordTracker = new PasswordTrackerImpl(); passwordTracker.setNew(true); passwordTracker.setPrimaryKey(passwordTrackerId); return passwordTracker; }
@Test public void testCreate() throws Exception { long pk = RandomTestUtil.nextLong(); PasswordTracker passwordTracker = _persistence.create(pk); Assert.assertNotNull(passwordTracker); Assert.assertEquals(passwordTracker.getPrimaryKey(), pk); }
/** * Caches the password tracker in the entity cache if it is enabled. * * @param passwordTracker the password tracker */ @Override public void cacheResult(PasswordTracker passwordTracker) { EntityCacheUtil.putResult( PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED, PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(), passwordTracker); passwordTracker.resetOriginalValues(); }
@Test public void testRemove() throws Exception { PasswordTracker newPasswordTracker = addPasswordTracker(); _persistence.remove(newPasswordTracker); PasswordTracker existingPasswordTracker = _persistence.fetchByPrimaryKey(newPasswordTracker.getPrimaryKey()); Assert.assertNull(existingPasswordTracker); }
@Override public void clearCache(List<PasswordTracker> passwordTrackers) { FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (PasswordTracker passwordTracker : passwordTrackers) { EntityCacheUtil.removeResult( PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED, PasswordTrackerImpl.class, passwordTracker.getPrimaryKey()); } }
/** * Caches the password trackers in the entity cache if it is enabled. * * @param passwordTrackers the password trackers */ @Override public void cacheResult(List<PasswordTracker> passwordTrackers) { for (PasswordTracker passwordTracker : passwordTrackers) { if (EntityCacheUtil.getResult( PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED, PasswordTrackerImpl.class, passwordTracker.getPrimaryKey()) == null) { cacheResult(passwordTracker); } else { passwordTracker.resetOriginalValues(); } } }
@Test public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception { PasswordTracker newPasswordTracker = addPasswordTracker(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newPasswordTracker.getPrimaryKey()); Map<Serializable, PasswordTracker> passwordTrackers = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, passwordTrackers.size()); Assert.assertEquals( newPasswordTracker, passwordTrackers.get(newPasswordTracker.getPrimaryKey())); }
@Override protected PasswordTracker removeImpl(PasswordTracker passwordTracker) throws SystemException { passwordTracker = toUnwrappedModel(passwordTracker); Session session = null; try { session = openSession(); if (!session.contains(passwordTracker)) { passwordTracker = (PasswordTracker) session.get(PasswordTrackerImpl.class, passwordTracker.getPrimaryKeyObj()); } if (passwordTracker != null) { session.delete(passwordTracker); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (passwordTracker != null) { clearCache(passwordTracker); } return passwordTracker; }
@Test public void testDynamicQueryByPrimaryKeyExisting() throws Exception { PasswordTracker newPasswordTracker = addPasswordTracker(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(PasswordTracker.class, _dynamicQueryClassLoader); dynamicQuery.add( RestrictionsFactoryUtil.eq("passwordTrackerId", newPasswordTracker.getPasswordTrackerId())); List<PasswordTracker> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); PasswordTracker existingPasswordTracker = result.get(0); Assert.assertEquals(existingPasswordTracker, newPasswordTracker); }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist() throws Exception { PasswordTracker newPasswordTracker = addPasswordTracker(); long pk = RandomTestUtil.nextLong(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newPasswordTracker.getPrimaryKey()); primaryKeys.add(pk); Map<Serializable, PasswordTracker> passwordTrackers = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(1, passwordTrackers.size()); Assert.assertEquals( newPasswordTracker, passwordTrackers.get(newPasswordTracker.getPrimaryKey())); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof PasswordTracker)) { return false; } PasswordTracker passwordTracker = (PasswordTracker) obj; long primaryKey = passwordTracker.getPrimaryKey(); if (getPrimaryKey() == primaryKey) { return true; } else { return false; } }
@Test public void testDynamicQueryByProjectionExisting() throws Exception { PasswordTracker newPasswordTracker = addPasswordTracker(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(PasswordTracker.class, _dynamicQueryClassLoader); dynamicQuery.setProjection(ProjectionFactoryUtil.property("passwordTrackerId")); Object newPasswordTrackerId = newPasswordTracker.getPasswordTrackerId(); dynamicQuery.add( RestrictionsFactoryUtil.in("passwordTrackerId", new Object[] {newPasswordTrackerId})); List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery); Assert.assertEquals(1, result.size()); Object existingPasswordTrackerId = result.get(0); Assert.assertEquals(existingPasswordTrackerId, newPasswordTrackerId); }
protected PasswordTracker toUnwrappedModel(PasswordTracker passwordTracker) { if (passwordTracker instanceof PasswordTrackerImpl) { return passwordTracker; } PasswordTrackerImpl passwordTrackerImpl = new PasswordTrackerImpl(); passwordTrackerImpl.setNew(passwordTracker.isNew()); passwordTrackerImpl.setPrimaryKey(passwordTracker.getPrimaryKey()); passwordTrackerImpl.setPasswordTrackerId(passwordTracker.getPasswordTrackerId()); passwordTrackerImpl.setUserId(passwordTracker.getUserId()); passwordTrackerImpl.setCreateDate(passwordTracker.getCreateDate()); passwordTrackerImpl.setPassword(passwordTracker.getPassword()); return passwordTrackerImpl; }
protected PasswordTracker addPasswordTracker() throws Exception { long pk = RandomTestUtil.nextLong(); PasswordTracker passwordTracker = _persistence.create(pk); passwordTracker.setMvccVersion(RandomTestUtil.nextLong()); passwordTracker.setCompanyId(RandomTestUtil.nextLong()); passwordTracker.setUserId(RandomTestUtil.nextLong()); passwordTracker.setCreateDate(RandomTestUtil.nextDate()); passwordTracker.setPassword(RandomTestUtil.randomString()); _passwordTrackers.add(_persistence.update(passwordTracker)); return passwordTracker; }
@Test public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist() throws Exception { PasswordTracker newPasswordTracker1 = addPasswordTracker(); PasswordTracker newPasswordTracker2 = addPasswordTracker(); Set<Serializable> primaryKeys = new HashSet<Serializable>(); primaryKeys.add(newPasswordTracker1.getPrimaryKey()); primaryKeys.add(newPasswordTracker2.getPrimaryKey()); Map<Serializable, PasswordTracker> passwordTrackers = _persistence.fetchByPrimaryKeys(primaryKeys); Assert.assertEquals(2, passwordTrackers.size()); Assert.assertEquals( newPasswordTracker1, passwordTrackers.get(newPasswordTracker1.getPrimaryKey())); Assert.assertEquals( newPasswordTracker2, passwordTrackers.get(newPasswordTracker2.getPrimaryKey())); }
@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); PasswordTracker newPasswordTracker = _persistence.create(pk); newPasswordTracker.setMvccVersion(RandomTestUtil.nextLong()); newPasswordTracker.setCompanyId(RandomTestUtil.nextLong()); newPasswordTracker.setUserId(RandomTestUtil.nextLong()); newPasswordTracker.setCreateDate(RandomTestUtil.nextDate()); newPasswordTracker.setPassword(RandomTestUtil.randomString()); _passwordTrackers.add(_persistence.update(newPasswordTracker)); PasswordTracker existingPasswordTracker = _persistence.findByPrimaryKey(newPasswordTracker.getPrimaryKey()); Assert.assertEquals( existingPasswordTracker.getMvccVersion(), newPasswordTracker.getMvccVersion()); Assert.assertEquals( existingPasswordTracker.getPasswordTrackerId(), newPasswordTracker.getPasswordTrackerId()); Assert.assertEquals(existingPasswordTracker.getCompanyId(), newPasswordTracker.getCompanyId()); Assert.assertEquals(existingPasswordTracker.getUserId(), newPasswordTracker.getUserId()); Assert.assertEquals( Time.getShortTimestamp(existingPasswordTracker.getCreateDate()), Time.getShortTimestamp(newPasswordTracker.getCreateDate())); Assert.assertEquals(existingPasswordTracker.getPassword(), newPasswordTracker.getPassword()); }
/** * Returns an ordered range of all the password trackers where userId = ?. * * <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 com.liferay.portal.kernel.dao.orm.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 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default * ORDER BY logic from {@link com.liferay.portal.model.impl.PasswordTrackerModelImpl}. 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. * * @param userId the user ID * @param start the lower bound of the range of password trackers * @param end the upper bound of the range of password trackers (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching password trackers * @throws SystemException if a system exception occurred */ @Override public List<PasswordTracker> findByUserId( long userId, int start, int end, OrderByComparator orderByComparator) throws SystemException { 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_BY_USERID; finderArgs = new Object[] {userId}; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID; finderArgs = new Object[] {userId, start, end, orderByComparator}; } List<PasswordTracker> list = (List<PasswordTracker>) FinderCacheUtil.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (PasswordTracker passwordTracker : list) { if ((userId != passwordTracker.getUserId())) { list = null; break; } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE); query.append(_FINDER_COLUMN_USERID_USERID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(userId); if (!pagination) { list = (List<PasswordTracker>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = new UnmodifiableList<PasswordTracker>(list); } else { list = (List<PasswordTracker>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(finderPath, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }