コード例 #1
0
  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());
  }
コード例 #2
0
  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;
  }
コード例 #3
0
  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);
  }
コード例 #4
0
  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);
  }