Search in sources :

Example 6 with ClientMtTable2

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

the class CayenneContextValidationIT method testValidate.

@Test
public void testValidate() throws Exception {
    ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1("G1");
    o1.resetValidation(false);
    // this one is not validating
    ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
    o2.setTable1(o1);
    context.commitChanges();
    assertTrue(o1.isValidatedForInsert());
    assertFalse(o1.isValidatedForDelete());
    assertFalse(o1.isValidatedForUpdate());
    o1.resetValidation(false);
    o1.setGlobalAttribute1("G2");
    context.commitChanges();
    assertFalse(o1.isValidatedForInsert());
    assertFalse(o1.isValidatedForDelete());
    assertTrue(o1.isValidatedForUpdate());
    o1.resetValidation(false);
    context.deleteObjects(o1);
    context.deleteObjects(o2);
    context.commitChanges();
    assertFalse(o1.isValidatedForInsert());
    assertTrue(o1.isValidatedForDelete());
    assertFalse(o1.isValidatedForUpdate());
    ClientMtTable1 o11 = context.newObject(ClientMtTable1.class);
    o11.setGlobalAttribute1("G1");
    o11.resetValidation(true);
    try {
        context.commitChanges();
        fail("Validation failure must have prevented commit");
    } catch (ValidationException e) {
    // expected
    }
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ValidationException(org.apache.cayenne.validation.ValidationException) Test(org.junit.Test)

Example 7 with ClientMtTable2

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

the class CayenneContextWithDataContextIT method testPrefetchingToMany.

@Test
public void testPrefetchingToMany() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class);
    q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
    final List<ClientMtTable1> results = clientContext.performQuery(q);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            ClientMtTable1 o1 = results.get(0);
            assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
            assertSame(clientContext, o1.getObjectContext());
            List<?> children1 = o1.getTable2Array();
            assertEquals(2, children1.size());
            Iterator<?> it = children1.iterator();
            while (it.hasNext()) {
                ClientMtTable2 o = (ClientMtTable2) it.next();
                assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
                assertSame(clientContext, o.getObjectContext());
            // TODO: fixme... reverse relationship is not connected and will
            // cause a fetch
            // assertEquals(o1, o.getTable1());
            }
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Iterator(java.util.Iterator) RemoteIncrementalFaultList(org.apache.cayenne.remote.RemoteIncrementalFaultList) List(java.util.List) Test(org.junit.Test)

Example 8 with ClientMtTable2

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

the class CayenneContextWithDataContextIT method testSetValueHolder.

@Test
public void testSetValueHolder() throws Exception {
    ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
    t2.setTable1(t1);
    assertEquals(1, t1.getTable2Array().size());
    assertSame(t1, t2.getTable1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 9 with ClientMtTable2

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

the class CayenneContextWithDataContextIT method testAddToList.

@Test
public void testAddToList() throws Exception {
    ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
    t1.addToTable2Array(t2);
    assertEquals(1, t1.getTable2Array().size());
    assertSame(t1, t2.getTable1());
    // do it again to make sure action can handle series of changes
    ClientMtTable1 t3 = clientContext.newObject(ClientMtTable1.class);
    ClientMtTable2 t4 = clientContext.newObject(ClientMtTable2.class);
    t3.addToTable2Array(t4);
    assertEquals(1, t3.getTable2Array().size());
    assertSame(t3, t4.getTable1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 10 with ClientMtTable2

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

the class CayenneContextWithDataContextIT method testPrefetchingToOneNull.

@Test
public void testPrefetchingToOneNull() throws Exception {
    tMtTable2.insert(15, null, "g3");
    SelectQuery q = new SelectQuery(ClientMtTable2.class);
    q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
    final List<ClientMtTable2> results = clientContext.performQuery(q);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, results.size());
            ClientMtTable2 o = results.get(0);
            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
            assertSame(clientContext, o.getObjectContext());
            assertNull(o.getTable1());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) 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