@Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

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

    primaryKeys.add(newDDLRecordVersion.getPrimaryKey());

    Map<Serializable, DDLRecordVersion> ddlRecordVersions =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, ddlRecordVersions.size());
    Assert.assertEquals(
        newDDLRecordVersion, ddlRecordVersions.get(newDDLRecordVersion.getPrimaryKey()));
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.fetchByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

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

    DDLRecordVersion ddlRecordVersion = _persistence.create(pk);

    Assert.assertNotNull(ddlRecordVersion);

    Assert.assertEquals(ddlRecordVersion.getPrimaryKey(), pk);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    long pk = RandomTestUtil.nextLong();

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

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

    Map<Serializable, DDLRecordVersion> ddlRecordVersions =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, ddlRecordVersions.size());
    Assert.assertEquals(
        newDDLRecordVersion, ddlRecordVersions.get(newDDLRecordVersion.getPrimaryKey()));
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    DDLRecordVersion newDDLRecordVersion1 = addDDLRecordVersion();
    DDLRecordVersion newDDLRecordVersion2 = addDDLRecordVersion();

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

    primaryKeys.add(newDDLRecordVersion1.getPrimaryKey());
    primaryKeys.add(newDDLRecordVersion2.getPrimaryKey());

    Map<Serializable, DDLRecordVersion> ddlRecordVersions =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, ddlRecordVersions.size());
    Assert.assertEquals(
        newDDLRecordVersion1, ddlRecordVersions.get(newDDLRecordVersion1.getPrimaryKey()));
    Assert.assertEquals(
        newDDLRecordVersion2, ddlRecordVersions.get(newDDLRecordVersion2.getPrimaryKey()));
  }
  @Test
  public void testRemove() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    _persistence.remove(newDDLRecordVersion);

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.fetchByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

    Assert.assertNull(existingDDLRecordVersion);
  }
  @Override
  public int compareTo(DDLRecordVersion ddlRecordVersion) {
    long primaryKey = ddlRecordVersion.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    _persistence.clearCache();

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.findByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

    Assert.assertEquals(
        Long.valueOf(existingDDLRecordVersion.getRecordId()),
        ReflectionTestUtil.<Long>invoke(
            existingDDLRecordVersion, "getOriginalRecordId", new Class<?>[0]));
    Assert.assertTrue(
        Validator.equals(
            existingDDLRecordVersion.getVersion(),
            ReflectionTestUtil.invoke(
                existingDDLRecordVersion, "getOriginalVersion", new Class<?>[0])));
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof DDLRecordVersion)) {
      return false;
    }

    DDLRecordVersion ddlRecordVersion = (DDLRecordVersion) obj;

    long primaryKey = ddlRecordVersion.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    DDLRecordVersion newDDLRecordVersion = _persistence.create(pk);

    newDDLRecordVersion.setGroupId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setCompanyId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setUserId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setUserName(RandomTestUtil.randomString());

    newDDLRecordVersion.setCreateDate(RandomTestUtil.nextDate());

    newDDLRecordVersion.setDDMStorageId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setRecordSetId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setRecordId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setVersion(RandomTestUtil.randomString());

    newDDLRecordVersion.setDisplayIndex(RandomTestUtil.nextInt());

    newDDLRecordVersion.setStatus(RandomTestUtil.nextInt());

    newDDLRecordVersion.setStatusByUserId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setStatusByUserName(RandomTestUtil.randomString());

    newDDLRecordVersion.setStatusDate(RandomTestUtil.nextDate());

    _ddlRecordVersions.add(_persistence.update(newDDLRecordVersion));

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.findByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

    Assert.assertEquals(
        existingDDLRecordVersion.getRecordVersionId(), newDDLRecordVersion.getRecordVersionId());
    Assert.assertEquals(existingDDLRecordVersion.getGroupId(), newDDLRecordVersion.getGroupId());
    Assert.assertEquals(
        existingDDLRecordVersion.getCompanyId(), newDDLRecordVersion.getCompanyId());
    Assert.assertEquals(existingDDLRecordVersion.getUserId(), newDDLRecordVersion.getUserId());
    Assert.assertEquals(existingDDLRecordVersion.getUserName(), newDDLRecordVersion.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDDLRecordVersion.getCreateDate()),
        Time.getShortTimestamp(newDDLRecordVersion.getCreateDate()));
    Assert.assertEquals(
        existingDDLRecordVersion.getDDMStorageId(), newDDLRecordVersion.getDDMStorageId());
    Assert.assertEquals(
        existingDDLRecordVersion.getRecordSetId(), newDDLRecordVersion.getRecordSetId());
    Assert.assertEquals(existingDDLRecordVersion.getRecordId(), newDDLRecordVersion.getRecordId());
    Assert.assertEquals(existingDDLRecordVersion.getVersion(), newDDLRecordVersion.getVersion());
    Assert.assertEquals(
        existingDDLRecordVersion.getDisplayIndex(), newDDLRecordVersion.getDisplayIndex());
    Assert.assertEquals(existingDDLRecordVersion.getStatus(), newDDLRecordVersion.getStatus());
    Assert.assertEquals(
        existingDDLRecordVersion.getStatusByUserId(), newDDLRecordVersion.getStatusByUserId());
    Assert.assertEquals(
        existingDDLRecordVersion.getStatusByUserName(), newDDLRecordVersion.getStatusByUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDDLRecordVersion.getStatusDate()),
        Time.getShortTimestamp(newDDLRecordVersion.getStatusDate()));
  }