Search in sources :

Example 41 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class ClientExpressionIT method testExpressionFactoryOperators.

@Test
public void testExpressionFactoryOperators() throws Exception {
    createDataSet();
    SelectQuery<ClientMtTable1> table1Query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
    table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
    List<ClientMtTable1> table1List = context.select(table1Query);
    ClientMtTable1 element_7 = table1List.get(6);
    // greater than, ">"
    Expression exp = ExpressionFactory.greaterExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
    SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    List<ClientMtTable2> table2List = context.select(table2Query);
    assertEquals(6, table2List.size());
    // greater than or equal, ">="
    exp = ExpressionFactory.greaterOrEqualExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
    table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    table2List = context.select(table2Query);
    assertEquals(8, table2List.size());
    // less than, "<"
    exp = ExpressionFactory.lessExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
    table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    table2List = context.select(table2Query);
    assertEquals(12, table2List.size());
    // less than or equal, "<="
    exp = ExpressionFactory.lessOrEqualExp(ClientMtTable2.TABLE1_PROPERTY, element_7);
    table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    table2List = context.select(table2Query);
    assertEquals(14, table2List.size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 42 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class ClientChannelServerDiffsIT method testReturnDiffClientArcChanges.

@Test
public void testReturnDiffClientArcChanges() {
    final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler();
    ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false) {

        @Override
        public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
            GraphDiff serverDiff = super.onSync(originatingContext, changes, syncType);
            assertNotNull(serverDiff);
            serverDiff.apply(diffReader);
            return serverDiff;
        }
    };
    CayenneContext context = new CayenneContext(channel);
    ClientMtTable1 o = context.newObject(ClientMtTable1.class);
    ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
    o.addToTable2Array(o2);
    context.commitChanges();
    assertEquals(2, diffReader.size);
    diffReader.reset();
    ClientMtTable2 o3 = context.newObject(ClientMtTable2.class);
    o3.setTable1(o);
    context.commitChanges();
    assertEquals(1, diffReader.size);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectContext(org.apache.cayenne.ObjectContext) CayenneContext(org.apache.cayenne.CayenneContext) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Example 43 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedToOneRelationship.

@Test
public void testPeerObjectUpdatedToOneRelationship() throws Exception {
    ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable1 altA = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable2 p = clientContext.newObject(ClientMtTable2.class);
    p.setTable1(a);
    p.setGlobalAttribute("PPP");
    a.setGlobalAttribute1("X");
    altA.setGlobalAttribute1("Y");
    clientContext.commitChanges();
    ObjectContext peer1 = runtime.newContext(clientContext);
    ClientMtTable2 p1 = peer1.localObject(p);
    ClientMtTable1 altA1 = peer1.localObject(altA);
    ObjectContext peer2 = runtime.newContext(clientContext);
    ClientMtTable2 p2 = peer2.localObject(p);
    ClientMtTable1 altA2 = peer2.localObject(altA);
    ClientMtTable1 a2 = peer2.localObject(a);
    p1.setTable1(altA1);
    assertSame(a2, p2.getTable1());
    peer1.commitChangesToParent();
    assertEquals(altA2, p2.getTable1());
    assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 44 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class RelationshipChangeIT method testChange.

@Test
public void testChange() {
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable2 o2 = clientContext.newObject(ClientMtTable2.class);
    ClientMtTable1 o3 = clientContext.newObject(ClientMtTable1.class);
    o2.setTable1(o1);
    assertEquals(1, o1.getTable2Array().size());
    clientContext.commitChanges();
    o2.setTable1(o3);
    assertEquals(0, o1.getTable2Array().size());
    assertEquals(1, o3.getTable2Array().size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 45 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class RemoteRollbackIT method testRollbackWithMultipleNewObjects.

// Catches a bug where new objects were unregistered within an object iterator, thus
// modifying the
// collection the iterator was iterating over (ConcurrentModificationException)
@Test
public void testRollbackWithMultipleNewObjects() {
    String o1Name = "rollbackTestClientMtTable1";
    String o2Title = "rollbackTestClientMtTable2";
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1(o1Name);
    ClientMtTable2 o2 = clientContext.newObject(ClientMtTable2.class);
    o2.setGlobalAttribute(o2Title);
    o2.setTable1(o1);
    try {
        clientContext.rollbackChanges();
    } catch (Exception e) {
        e.printStackTrace();
        fail("rollbackChanges should not have caused the exception " + e.getMessage());
    }
    assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Aggregations

ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)48 Test (org.junit.Test)48 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)46 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)9 Expression (org.apache.cayenne.exp.Expression)7 SelectQuery (org.apache.cayenne.query.SelectQuery)7 ObjectContext (org.apache.cayenne.ObjectContext)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 Iterator (java.util.Iterator)3 List (java.util.List)3 GraphDiff (org.apache.cayenne.graph.GraphDiff)3 PersistentObjectHolder (org.apache.cayenne.util.PersistentObjectHolder)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)2 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)2 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)2 ROPSerializationService (org.apache.cayenne.rop.ROPSerializationService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CayenneContext (org.apache.cayenne.CayenneContext)1 ValueHolder (org.apache.cayenne.ValueHolder)1