Search in sources :

Example 86 with ObjectId

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

the class DataContextEntityWithMeaningfulPKIT method testChangeKey.

@Test
public void testChangeKey() {
    MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
    obj.setPkAttribute(1000);
    obj.setDescr("aaa-aaa");
    context.commitChanges();
    obj.setPkAttribute(2000);
    context.commitChanges();
    // assert that object id got fixed
    ObjectId id = obj.getObjectId();
    assertEquals(2000, id.getIdSnapshot().get("PK_ATTRIBUTE"));
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 87 with ObjectId

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

the class DataContextEntityWithMeaningfulPKIT method testInsertWithMeaningfulPK.

@Test
public void testInsertWithMeaningfulPK() {
    MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
    obj.setPkAttribute(1000);
    obj.setDescr("aaa-aaa");
    context.commitChanges();
    ObjectId objId = new ObjectId("MeaningfulPKTest1", MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN, 1000);
    ObjectIdQuery q = new ObjectIdQuery(objId, true, ObjectIdQuery.CACHE_REFRESH);
    @SuppressWarnings("unchecked") List<DataRow> result = (List<DataRow>) context.performQuery(q);
    assertEquals(1, result.size());
    assertEquals(1000, result.get(0).get(MeaningfulPKTest1.PK_ATTRIBUTE_PK_COLUMN));
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) ObjectId(org.apache.cayenne.ObjectId) List(java.util.List) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 88 with ObjectId

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

the class DataContextExtrasIT method testManualIdProcessingOnCommit.

@Test
public void testManualIdProcessingOnCommit() throws Exception {
    Artist object = context.newObject(Artist.class);
    object.setArtistName("ABC");
    assertEquals(PersistenceState.NEW, object.getPersistenceState());
    // do a manual ID substitution
    ObjectId manualId = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 77777);
    object.setObjectId(manualId);
    context.commitChanges();
    assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
    assertSame(object, context.getGraphManager().getNode(manualId));
    assertEquals(manualId, object.getObjectId());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 89 with ObjectId

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

the class DataContextIT method testBeforeHollowDeleteShouldChangeStateToCommited.

@Test
public void testBeforeHollowDeleteShouldChangeStateToCommited() throws Exception {
    createSingleArtistDataSet();
    Artist hollow = Cayenne.objectForPK(context, Artist.class, 33001);
    context.invalidateObjects(hollow);
    assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
    // testing this...
    context.deleteObjects(hollow);
    assertSame(hollow, context.getGraphManager().getNode(new ObjectId("Artist", "ARTIST_ID", 33001)));
    assertEquals("artist1", hollow.getArtistName());
    assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ROArtist(org.apache.cayenne.testdo.testmap.ROArtist) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 90 with ObjectId

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

the class DataContextIT method testInvalidateObjects.

@Test
public void testInvalidateObjects() throws Exception {
    DataRow row = new DataRow(10);
    row.put("ARTIST_ID", new Integer(1));
    row.put("ARTIST_NAME", "ArtistXYZ");
    row.put("DATE_OF_BIRTH", new Date());
    DataObject object = context.objectFromDataRow(Artist.class, row);
    ObjectId oid = object.getObjectId();
    // insert object into the ObjectStore
    context.getObjectStore().registerNode(oid, object);
    assertSame(object, context.getObjectStore().getNode(oid));
    assertNotNull(context.getObjectStore().getCachedSnapshot(oid));
    context.invalidateObjects(Collections.singleton(object));
    assertSame(oid, object.getObjectId());
    assertNull(context.getObjectStore().getCachedSnapshot(oid));
    assertSame(object, context.getObjectStore().getNode(oid));
}
Also used : DataObject(org.apache.cayenne.DataObject) ObjectId(org.apache.cayenne.ObjectId) DataRow(org.apache.cayenne.DataRow) Date(java.util.Date) 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