Search in sources :

Example 21 with ClientMtTable2

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

the class ClientExpressionIT method testExpressionFactoryMatchAny.

@Test
public void testExpressionFactoryMatchAny() throws Exception {
    createDataSet();
    SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class);
    table2Query.addOrdering(new Ordering("db:TABLE2_ID", SortOrder.ASCENDING));
    List<ClientMtTable2> table2List = context.select(table2Query);
    ClientMtTable2 element_1 = table2List.get(0);
    ClientMtTable2 element_2 = table2List.get(10);
    Expression exp = ExpressionFactory.matchAnyExp(element_1, element_2);
    table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    table2List = context.select(table2Query);
    assertEquals(2, table2List.size());
}
Also used : ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 22 with ClientMtTable2

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

the class ClientExpressionIT method testExpressionFactoryBetween.

@Test
public void testExpressionFactoryBetween() 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_1 = table1List.get(0);
    ClientMtTable1 element_7 = table1List.get(6);
    // between
    Expression exp = ExpressionFactory.betweenExp(ClientMtTable2.TABLE1_PROPERTY, element_1, element_7);
    SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    List<ClientMtTable2> table2List = context.select(table2Query);
    assertEquals(14, table2List.size());
    // not between
    exp = ExpressionFactory.notBetweenExp(ClientMtTable2.TABLE1_PROPERTY, element_1, element_7);
    table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    table2List = context.select(table2Query);
    assertEquals(6, 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 23 with ClientMtTable2

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

the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedToManyRelationship.

@Test
public void testPeerObjectUpdatedToManyRelationship() throws Exception {
    ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
    a.setGlobalAttribute1("X");
    ClientMtTable2 px = clientContext.newObject(ClientMtTable2.class);
    px.setTable1(a);
    px.setGlobalAttribute("PX");
    ClientMtTable2 py = clientContext.newObject(ClientMtTable2.class);
    py.setGlobalAttribute("PY");
    clientContext.commitChanges();
    ObjectContext peer1 = runtime.newContext(clientContext);
    ClientMtTable2 py1 = peer1.localObject(py);
    ClientMtTable1 a1 = peer1.localObject(a);
    ObjectContext peer2 = runtime.newContext(clientContext);
    ClientMtTable2 py2 = peer2.localObject(py);
    ClientMtTable1 a2 = peer2.localObject(a);
    a1.addToTable2Array(py1);
    assertEquals(1, a2.getTable2Array().size());
    assertFalse(a2.getTable2Array().contains(py2));
    peer1.commitChangesToParent();
    assertEquals(2, a2.getTable2Array().size());
    assertTrue(a2.getTable2Array().contains(py2));
    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 24 with ClientMtTable2

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

the class RelationshipChangeIT method testNullify.

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

Example 25 with ClientMtTable2

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

the class RemoteRollbackIT method testRollbackRelationshipModification.

@Test
public void testRollbackRelationshipModification() {
    String o1Name = "relationshipModClientMtTable1";
    String o2Title = "relationshipTestClientMtTable2";
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1(o1Name);
    ClientMtTable2 o2 = clientContext.newObject(ClientMtTable2.class);
    o2.setGlobalAttribute(o2Title);
    o2.setTable1(o1);
    assertEquals(1, o1.getTable2Array().size());
    clientContext.commitChanges();
    assertEquals(1, o1.getTable2Array().size());
    o2.setTable1(null);
    assertEquals(0, o1.getTable2Array().size());
    clientContext.rollbackChanges();
    assertEquals(1, o1.getTable2Array().size());
    assertEquals(o1, o2.getTable1());
}
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