@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()));
  }
  @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());
  }
Пример #3
0
  @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;
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    PasswordTracker newPasswordTracker = addPasswordTracker();

    PasswordTracker existingPasswordTracker =
        _persistence.fetchByPrimaryKey(newPasswordTracker.getPrimaryKey());

    Assert.assertEquals(existingPasswordTracker, newPasswordTracker);
  }
Пример #5
0
  /**
   * Clears the cache for the password tracker.
   *
   * <p>The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link
   * com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
   */
  @Override
  public void clearCache(PasswordTracker passwordTracker) {
    EntityCacheUtil.removeResult(
        PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
        PasswordTrackerImpl.class,
        passwordTracker.getPrimaryKey());

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
  }
Пример #6
0
  /**
   * 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 testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    PasswordTracker passwordTracker = _persistence.create(pk);

    Assert.assertNotNull(passwordTracker);

    Assert.assertEquals(passwordTracker.getPrimaryKey(), pk);
  }
  @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()));
  }
  @Test
  public void testRemove() throws Exception {
    PasswordTracker newPasswordTracker = addPasswordTracker();

    _persistence.remove(newPasswordTracker);

    PasswordTracker existingPasswordTracker =
        _persistence.fetchByPrimaryKey(newPasswordTracker.getPrimaryKey());

    Assert.assertNull(existingPasswordTracker);
  }
  @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()));
  }
Пример #11
0
 /**
  * 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();
     }
   }
 }
Пример #12
0
  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;
  }
  @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;
    }
  }