@Test
  public void testCommitLog() throws SQLException {
    Auditable2 a1 = context.newObject(Auditable2.class);
    a1.setCharProperty1("yy");
    a1.setCharProperty2("zz");

    Auditable2 a2 = context.newObject(Auditable2.class);
    a2.setCharProperty1("yy");
    a2.setCharProperty2("zz");
    context.commitChanges();

    List<Object[]> logs = auditLog.selectAll();
    assertEquals(2, logs.size());
  }
Esempio n. 2
0
  public final void validate(T object) {
    ObjectContext workDc = object.getObjectContext(); // .createChildDataContext();
    T obj = (T) workDc.localObject(object.getObjectId(), object);

    Set<DataObject> toDelete = new HashSet<DataObject>();
    try {
      if (!fakes.isEmpty()) {
        // Simulation des fakes
        for (String prop : fakes.keySet()) {
          if (obj.readProperty(prop) != null) continue;
          DataObject value = (DataObject) workDc.newObject(fakes.get(prop));
          obj.setToOneTarget(prop, value, false);
          toDelete.add(value);
        }
      }
      // Validation
      validateImpl(obj);
    } finally {
      // Annulation des modifs
      if (!fakes.isEmpty()) {
        // Suppression des fakes
        for (String prop : fakes.keySet()) {
          DataObject value = (DataObject) obj.readProperty(prop);
          if (!toDelete.contains(value)) continue;
          workDc.deleteObject(value);
        }
      }
    }
    // childDc.rollbackChangesLocally();
  }
Esempio n. 3
0
  public static void main(String[] args) {
    ServerRuntime cayenneRuntime =
        new ServerRuntime("cayenne-CESDomain.xml", new CayenneExtrasModule());
    //        ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-CESDomain.xml");
    ObjectContext context = cayenneRuntime.getContext();

    LineItem li = context.newObject(LineItem.class);
    Item i = context.newObject(Item.class);
    CostElement ce1 = context.newObject(CostElement.class);
    CostElement ce2 = context.newObject(CostElement.class);
    CostElement ce3 = context.newObject(CostElement.class);
    BudgetYear by1 = context.newObject(BudgetYear.class);
    BudgetYear by2 = context.newObject(BudgetYear.class);
    BudgetYear by3 = context.newObject(BudgetYear.class);

    li.addToItems(i);
    i.addToCostElements(ce1);
    ce1.addToCostElements(ce2);
    ce2.addToCostElements(ce3);
    ce3.setQuantity(by1);
    ce3.setTotalCost(by2);
    ce3.setUnitCost(by3);
    by1.setLineItem(li);
    by2.setLineItem(li);
    by3.setLineItem(li);

    //        ce2.setItem(i);
    //        ce3.setItem(i);

    context.commitChanges();

    context.deleteObject(li);

    context.commitChanges();
  }
  /**
   * Create a new {@link EntryType} instance using the specified {@link ObjectContext}.
   *
   * @param context
   * @return Instance of EntryType attached to a valid {@link ObjectContext}
   */
  private EntryType create(ObjectContext context) {

    EntryType entryType = context.newObject(EntryType.class);
    return entryType;
  }