@Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    MBBan newMBBan = addMBBan();

    MBBan existingMBBan = _persistence.fetchByPrimaryKey(newMBBan.getPrimaryKey());

    Assert.assertEquals(existingMBBan, newMBBan);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBBan mbBan = _persistence.create(pk);

    Assert.assertNotNull(mbBan);

    Assert.assertEquals(mbBan.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    MBBan newMBBan = addMBBan();

    _persistence.remove(newMBBan);

    MBBan existingMBBan = _persistence.fetchByPrimaryKey(newMBBan.getPrimaryKey());

    Assert.assertNull(existingMBBan);
  }
  protected MBBan addMBBan() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBBan mbBan = _persistence.create(pk);

    mbBan.setUuid(RandomTestUtil.randomString());

    mbBan.setGroupId(RandomTestUtil.nextLong());

    mbBan.setCompanyId(RandomTestUtil.nextLong());

    mbBan.setUserId(RandomTestUtil.nextLong());

    mbBan.setUserName(RandomTestUtil.randomString());

    mbBan.setCreateDate(RandomTestUtil.nextDate());

    mbBan.setModifiedDate(RandomTestUtil.nextDate());

    mbBan.setBanUserId(RandomTestUtil.nextLong());

    _mbBans.add(_persistence.update(mbBan));

    return mbBan;
  }
Exemple #5
0
  @Override
  protected void validateImport(
      StagedModel stagedModel, Map<String, List<StagedModel>> dependentStagedModelsMap, Group group)
      throws Exception {

    super.validateImport(stagedModel, dependentStagedModelsMap, group);

    MBBan ban = (MBBan) stagedModel;
    MBBan importBan = (MBBan) getStagedModel(stagedModel.getUuid(), group);

    Assert.assertEquals(ban.getBanUserUuid(), importBan.getBanUserUuid());
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    MBBan newMBBan = addMBBan();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newMBBan.getPrimaryKey());

    Map<Serializable, MBBan> mbBans = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, mbBans.size());
    Assert.assertEquals(newMBBan, mbBans.get(newMBBan.getPrimaryKey()));
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    MBBan newMBBan = addMBBan();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBBan.class, MBBan.class.getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("banId", newMBBan.getBanId()));

    List<MBBan> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    MBBan existingMBBan = result.get(0);

    Assert.assertEquals(existingMBBan, newMBBan);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    MBBan newMBBan = addMBBan();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newMBBan.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, MBBan> mbBans = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, mbBans.size());
    Assert.assertEquals(newMBBan, mbBans.get(newMBBan.getPrimaryKey()));
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static MBBan toModel(MBBanSoap soapModel) {
    MBBan model = new MBBanImpl();

    model.setBanId(soapModel.getBanId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setBanUserId(soapModel.getBanUserId());

    return model;
  }
Exemple #10
0
  public static Date getUnbanDate(MBBan ban, int expireInterval) {
    Date banDate = ban.getCreateDate();

    Calendar cal = Calendar.getInstance();

    cal.setTime(banDate);

    cal.add(Calendar.DATE, expireInterval);

    return cal.getTime();
  }
  public int compareTo(MBBan mbBan) {
    long pk = mbBan.getPrimaryKey();

    if (getPrimaryKey() < pk) {
      return -1;
    } else if (getPrimaryKey() > pk) {
      return 1;
    } else {
      return 0;
    }
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    MBBan newMBBan = addMBBan();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBBan.class, MBBan.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("banId"));

    Object newBanId = newMBBan.getBanId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("banId", new Object[] {newBanId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingBanId = result.get(0);

    Assert.assertEquals(existingBanId, newBanId);
  }
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    MBBan mbBan = null;

    try {
      mbBan = (MBBan) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long pk = mbBan.getPrimaryKey();

    if (getPrimaryKey() == pk) {
      return true;
    } else {
      return false;
    }
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    MBBan newMBBan = addMBBan();

    _persistence.clearCache();

    MBBanModelImpl existingMBBanModelImpl =
        (MBBanModelImpl) _persistence.findByPrimaryKey(newMBBan.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingMBBanModelImpl.getUuid(), existingMBBanModelImpl.getOriginalUuid()));
    Assert.assertEquals(
        existingMBBanModelImpl.getGroupId(), existingMBBanModelImpl.getOriginalGroupId());

    Assert.assertEquals(
        existingMBBanModelImpl.getGroupId(), existingMBBanModelImpl.getOriginalGroupId());
    Assert.assertEquals(
        existingMBBanModelImpl.getBanUserId(), existingMBBanModelImpl.getOriginalBanUserId());
  }
  /**
   * Adds the message boards ban to the database. Also notifies the appropriate model listeners.
   *
   * @param mbBan the message boards ban
   * @return the message boards ban that was added
   * @throws SystemException if a system exception occurred
   */
  public MBBan addMBBan(MBBan mbBan) throws SystemException {
    mbBan.setNew(true);

    mbBan = mbBanPersistence.update(mbBan, false);

    Indexer indexer = IndexerRegistryUtil.getIndexer(getModelClassName());

    if (indexer != null) {
      try {
        indexer.reindex(mbBan);
      } catch (SearchException se) {
        if (_log.isWarnEnabled()) {
          _log.warn(se, se);
        }
      }
    }

    return mbBan;
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    MBBan newMBBan1 = addMBBan();
    MBBan newMBBan2 = addMBBan();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newMBBan1.getPrimaryKey());
    primaryKeys.add(newMBBan2.getPrimaryKey());

    Map<Serializable, MBBan> mbBans = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, mbBans.size());
    Assert.assertEquals(newMBBan1, mbBans.get(newMBBan1.getPrimaryKey()));
    Assert.assertEquals(newMBBan2, mbBans.get(newMBBan2.getPrimaryKey()));
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBBan newMBBan = _persistence.create(pk);

    newMBBan.setUuid(RandomTestUtil.randomString());

    newMBBan.setGroupId(RandomTestUtil.nextLong());

    newMBBan.setCompanyId(RandomTestUtil.nextLong());

    newMBBan.setUserId(RandomTestUtil.nextLong());

    newMBBan.setUserName(RandomTestUtil.randomString());

    newMBBan.setCreateDate(RandomTestUtil.nextDate());

    newMBBan.setModifiedDate(RandomTestUtil.nextDate());

    newMBBan.setBanUserId(RandomTestUtil.nextLong());

    _mbBans.add(_persistence.update(newMBBan));

    MBBan existingMBBan = _persistence.findByPrimaryKey(newMBBan.getPrimaryKey());

    Assert.assertEquals(existingMBBan.getUuid(), newMBBan.getUuid());
    Assert.assertEquals(existingMBBan.getBanId(), newMBBan.getBanId());
    Assert.assertEquals(existingMBBan.getGroupId(), newMBBan.getGroupId());
    Assert.assertEquals(existingMBBan.getCompanyId(), newMBBan.getCompanyId());
    Assert.assertEquals(existingMBBan.getUserId(), newMBBan.getUserId());
    Assert.assertEquals(existingMBBan.getUserName(), newMBBan.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBBan.getCreateDate()),
        Time.getShortTimestamp(newMBBan.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBBan.getModifiedDate()),
        Time.getShortTimestamp(newMBBan.getModifiedDate()));
    Assert.assertEquals(existingMBBan.getBanUserId(), newMBBan.getBanUserId());
  }
  /**
   * Updates the message boards ban in the database. Also notifies the appropriate model listeners.
   *
   * @param mbBan the message boards ban to update
   * @param merge whether to merge the message boards ban with the current session. See {@link
   *     com.liferay.portal.service.persistence.BatchSession#update(com.liferay.portal.kernel.dao.orm.Session,
   *     com.liferay.portal.model.BaseModel, boolean)} for an explanation.
   * @return the message boards ban that was updated
   * @throws SystemException if a system exception occurred
   */
  public MBBan updateMBBan(MBBan mbBan, boolean merge) throws SystemException {
    mbBan.setNew(false);

    return mbBanPersistence.update(mbBan, merge);
  }
  /**
   * Adds the message boards ban to the database. Also notifies the appropriate model listeners.
   *
   * @param mbBan the message boards ban to add
   * @return the message boards ban that was added
   * @throws SystemException if a system exception occurred
   */
  public MBBan addMBBan(MBBan mbBan) throws SystemException {
    mbBan.setNew(true);

    return mbBanPersistence.update(mbBan, false);
  }