Search in sources :

Example 31 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class CommitLogFilter_FilteredIT method testPostCommit_IgnoreAttributes.

@Test
public void testPostCommit_IgnoreAttributes() throws SQLException {
    auditable3.insert(1, "31", "32");
    final Auditable3 a3 = SelectById.query(Auditable3.class, 1).selectOne(context);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            assertSame(context, invocation.getArguments()[0]);
            ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
            assertNull(changes.getChanges().get(new ObjectId("Auditable3", Auditable3.ID_PK_COLUMN, 1)));
            return null;
        }
    }).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
    a3.setCharProperty1("33");
    a3.setCharProperty2("34");
    context.commitChanges();
    verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
Also used : ChangeMap(org.apache.cayenne.commitlog.model.ChangeMap) ObjectId(org.apache.cayenne.ObjectId) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Auditable3(org.apache.cayenne.commitlog.db.Auditable3) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 32 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class CommitLogFilter_FilteredIT method testPostCommit_Delete.

@Test
public void testPostCommit_Delete() throws SQLException {
    auditable2.insert(1, "P1_1", "P2_1");
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            assertSame(context, invocation.getArguments()[0]);
            ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
            assertNotNull(changes);
            assertEquals(1, changes.getUniqueChanges().size());
            ObjectChange c = changes.getChanges().get(new ObjectId("Auditable2", Auditable2.ID_PK_COLUMN, 1));
            assertNotNull(c);
            assertEquals(ObjectChangeType.DELETE, c.getType());
            assertEquals(1, c.getAttributeChanges().size());
            assertEquals(Confidential.getInstance(), c.getAttributeChanges().get(Auditable2.CHAR_PROPERTY2.getName()).getOldValue());
            return null;
        }
    }).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
    Auditable2 a1 = SelectById.query(Auditable2.class, 1).selectOne(context);
    context.deleteObject(a1);
    context.commitChanges();
    verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
Also used : ChangeMap(org.apache.cayenne.commitlog.model.ChangeMap) ObjectChange(org.apache.cayenne.commitlog.model.ObjectChange) ObjectId(org.apache.cayenne.ObjectId) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Auditable2(org.apache.cayenne.commitlog.db.Auditable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 33 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class CommitLogFilter_FilteredIT method testPostCommit_IgnoreToOne.

@Test
public void testPostCommit_IgnoreToOne() throws SQLException {
    auditable3.insert(1, "31", "32");
    auditable3.insert(2, "33", "34");
    auditable4.insert(11, "41", "41", 1);
    final Auditable3 a32 = SelectById.query(Auditable3.class, 2).selectOne(context);
    final Auditable4 a4 = SelectById.query(Auditable4.class, 11).selectOne(context);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            assertSame(context, invocation.getArguments()[0]);
            ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
            assertNull(changes.getChanges().get(new ObjectId("Auditable4", Auditable4.ID_PK_COLUMN, 11)));
            return null;
        }
    }).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
    a4.setAuditable3(a32);
    context.commitChanges();
    verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
Also used : ChangeMap(org.apache.cayenne.commitlog.model.ChangeMap) ObjectId(org.apache.cayenne.ObjectId) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Auditable4(org.apache.cayenne.commitlog.db.Auditable4) Auditable3(org.apache.cayenne.commitlog.db.Auditable3) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 34 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class ClientServerChannelIT method testPerformQueryObjectIDInjection.

@Test
public void testPerformQueryObjectIDInjection() throws Exception {
    tMtTable1.insert(55, "g1", "s1");
    Query query = new SelectQuery("MtTable1");
    QueryResponse response = clientServerChannel.onQuery(null, query);
    assertNotNull(response);
    List<?> results = response.firstList();
    assertNotNull(results);
    assertEquals(1, results.size());
    Object result = results.get(0);
    assertTrue(result instanceof ClientMtTable1);
    ClientMtTable1 clientObject = (ClientMtTable1) result;
    assertNotNull(clientObject.getObjectId());
    assertEquals(new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 55), clientObject.getObjectId());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) SelectQuery(org.apache.cayenne.query.SelectQuery) MockQuery(org.apache.cayenne.query.MockQuery) Query(org.apache.cayenne.query.Query) ObjectId(org.apache.cayenne.ObjectId) QueryResponse(org.apache.cayenne.QueryResponse) Test(org.junit.Test)

Example 35 with ObjectId

use of org.apache.cayenne.ObjectId in project cayenne by apache.

the class ClientExpressionIT method testArrayInASTList.

@Test
public void testArrayInASTList() throws Exception {
    ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
    ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
    ClientMtTable1 t3 = context.newObject(ClientMtTable1.class);
    context.commitChanges();
    Object[] tArray = new Object[3];
    tArray[0] = t1;
    tArray[1] = t2;
    // send array in expression factory
    Expression list = ExpressionFactory.inExp(ClientMtTable2.TABLE1_PROPERTY, tArray);
    tArray[2] = t3;
    Object[] values = (Object[]) ((ASTList) list.getOperand(1)).getOperand(0);
    assertEquals(tArray.length, values.length);
    assertNotSame(tArray[2], values[2]);
    assertEquals(t1.getObjectId(), values[0]);
    assertEquals(t2.getObjectId(), values[1]);
    ObjectId t1Id = new ObjectId("MtTable1", "TABLE1_ID", 1);
    ObjectId t2Id = new ObjectId("MtTable1", "TABLE1_ID", 2);
    t1.setObjectId(t1Id);
    t2.setObjectId(t2Id);
    // Expression and client have different arrays
    assertNotSame(t1.getObjectId(), values[0]);
    assertNotSame(t2.getObjectId(), values[1]);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Expression(org.apache.cayenne.exp.Expression) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Aggregations

ObjectId (org.apache.cayenne.ObjectId)156 Test (org.junit.Test)104 Persistent (org.apache.cayenne.Persistent)38 DataObject (org.apache.cayenne.DataObject)20 DataRow (org.apache.cayenne.DataRow)20 ObjectContext (org.apache.cayenne.ObjectContext)20 ObjEntity (org.apache.cayenne.map.ObjEntity)20 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)18 HashMap (java.util.HashMap)17 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)16 ArrayList (java.util.ArrayList)14 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)14 Artist (org.apache.cayenne.testdo.testmap.Artist)14 Map (java.util.Map)13 EntityResolver (org.apache.cayenne.map.EntityResolver)13 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 ChangeMap (org.apache.cayenne.commitlog.model.ChangeMap)12 ObjRelationship (org.apache.cayenne.map.ObjRelationship)10 SelectQuery (org.apache.cayenne.query.SelectQuery)10 ObjectChange (org.apache.cayenne.commitlog.model.ObjectChange)9