public void testUpdateExisting() throws Exception {
    String pk = randomString();

    Counter newCounter = _persistence.create(pk);

    newCounter.setCurrentId(nextLong());

    _persistence.update(newCounter, false);

    Counter existingCounter = _persistence.findByPrimaryKey(newCounter.getPrimaryKey());

    assertEquals(existingCounter.getName(), newCounter.getName());
    assertEquals(existingCounter.getCurrentId(), newCounter.getCurrentId());
  }
  protected Counter toUnwrappedModel(Counter counter) {
    if (counter instanceof CounterImpl) {
      return counter;
    }

    CounterImpl counterImpl = new CounterImpl();

    counterImpl.setNew(counter.isNew());
    counterImpl.setPrimaryKey(counter.getPrimaryKey());

    counterImpl.setName(counter.getName());
    counterImpl.setCurrentId(counter.getCurrentId());

    return counterImpl;
  }
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Counter newCounter = addCounter();

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

    dynamicQuery.add(RestrictionsFactoryUtil.eq("name", newCounter.getName()));

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

    assertEquals(1, result.size());

    Counter existingCounter = result.get(0);

    assertEquals(existingCounter, newCounter);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Counter newCounter = addCounter();

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

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

    Object newName = newCounter.getName();

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

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

    assertEquals(1, result.size());

    Object existingName = result.get(0);

    assertEquals(existingName, newName);
  }