Search in sources :

Example 41 with ClientMtTable1

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

the class ClientExpressionIT method testPersistentValueInExpression.

@Test
public void testPersistentValueInExpression() throws Exception {
    ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
    ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
    context.commitChanges();
    Expression scalar = ExpressionFactory.matchExp(null, t1);
    Expression list = ExpressionFactory.matchAllExp("|", Arrays.asList(t1, t2));
    assertEquals(t1.getObjectId(), scalar.getOperand(1));
    assertEquals(t1.getObjectId(), ((ASTEqual) list.getOperand(0)).getOperand(1));
    assertEquals(t2.getObjectId(), ((ASTEqual) list.getOperand(1)).getOperand(1));
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 42 with ClientMtTable1

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

the class ClientExpressionIT method testParams.

@Test
public void testParams() 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_5 = table1List.get(4);
    Expression exp = ExpressionFactory.exp("table1 = $attr");
    exp = exp.params(Collections.singletonMap("attr", element_1));
    SelectQuery<ClientMtTable2> table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    List<ClientMtTable2> table2List = context.select(table2Query);
    assertEquals(2, table2List.size());
    exp = exp.andExp(ExpressionFactory.exp("table1 = $attr")).params(Collections.singletonMap("attr", element_5));
    table2Query = new SelectQuery<ClientMtTable2>(ClientMtTable2.class, exp);
    table2List = context.select(table2Query);
    assertEquals(0, 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 43 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 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 44 with ClientMtTable1

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

the class ClientObjectSelectIT method testPageSelect.

@Test
public void testPageSelect() throws Exception {
    final ObjectSelect<ClientMtTable1> objectSelect = ObjectSelect.query(ClientMtTable1.class).pageSize(5);
    final List<ClientMtTable1> list = objectSelect.select(context);
    assertNotNull(list);
    assertEquals(RemoteIncrementalFaultList.class, list.getClass());
    int count = serverCaseDataChannelInterceptor.runWithQueryCounter(new UnitTestClosure() {

        @Override
        public void execute() {
            assertNotNull(list.get(0));
            assertNotNull(list.get(4));
            assertNotNull(list.get(5));
            assertNotNull(list.get(6));
        }
    });
    assertEquals(1, count);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 45 with ClientMtTable1

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

the class ClientChannelServerDiffsIT method testReturnDiffInPrePersist.

@Test
public void testReturnDiffInPrePersist() {
    final List<GenericDiff> diffs = new ArrayList<GenericDiff>();
    final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler() {

        @Override
        public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
            super.nodePropertyChanged(nodeId, property, oldValue, newValue);
            diffs.add(new GenericDiff((ObjectId) nodeId, property, oldValue, newValue));
        }
    };
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
        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);
        ObjectId tempId = o.getObjectId();
        o.setServerAttribute1("YY");
        context.commitChanges();
        assertEquals(2, diffReader.size);
        assertEquals(1, diffs.size());
        assertEquals(tempId, diffs.get(0).sourceId);
        assertEquals(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, diffs.get(0).property);
        assertNull(diffs.get(0).oldValue);
        assertEquals("XXX", diffs.get(0).newValue);
    } finally {
        callbackRegistry.clear();
    }
}
Also used : ObjectId(org.apache.cayenne.ObjectId) GraphDiff(org.apache.cayenne.graph.GraphDiff) ArrayList(java.util.ArrayList) CayenneContext(org.apache.cayenne.CayenneContext) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectContext(org.apache.cayenne.ObjectContext) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Aggregations

ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)112 Test (org.junit.Test)112 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)46 SelectQuery (org.apache.cayenne.query.SelectQuery)26 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)19 ObjectContext (org.apache.cayenne.ObjectContext)12 Expression (org.apache.cayenne.exp.Expression)12 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)11 List (java.util.List)8 ObjectId (org.apache.cayenne.ObjectId)7 EntityResolver (org.apache.cayenne.map.EntityResolver)7 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)7 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)6 GraphDiff (org.apache.cayenne.graph.GraphDiff)5 MockEventManager (org.apache.cayenne.event.MockEventManager)4 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)3 MtTable1 (org.apache.cayenne.testdo.mt.MtTable1)3