Search in sources :

Example 81 with ObjectId

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

the class NumericTypesIT method testDecimalPK.

@Test
public void testDecimalPK() throws Exception {
    // populate (testing insert as well)
    DecimalPKTestEntity object = context.newObject(DecimalPKTestEntity.class);
    object.setName("o1");
    object.setDecimalPK(new BigDecimal("1.25"));
    context.commitChanges();
    ObjectId syntheticId = new ObjectId("DecimalPKTestEntity", "DECIMAL_PK", new BigDecimal("1.25"));
    assertSame(object, context.getGraphManager().getNode(syntheticId));
    context.deleteObjects(object);
    context.commitChanges();
}
Also used : ObjectId(org.apache.cayenne.ObjectId) DecimalPKTestEntity(org.apache.cayenne.testdo.numeric_types.DecimalPKTestEntity) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 82 with ObjectId

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

the class ObjectStoreIT method testObjectsUnregistered.

@Test
public void testObjectsUnregistered() 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.getObjectStore().objectsUnregistered(Collections.singletonList(object));
    assertEquals(oid, object.getObjectId());
    assertNull(context.getObjectStore().getNode(oid));
    // in the future this may not be the case
    assertNull(context.getObjectStore().getCachedSnapshot(oid));
}
Also used : MockDataObject(org.apache.cayenne.MockDataObject) DataObject(org.apache.cayenne.DataObject) ObjectId(org.apache.cayenne.ObjectId) DataRow(org.apache.cayenne.DataRow) Date(java.util.Date) Test(org.junit.Test)

Example 83 with ObjectId

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

the class ObjectStoreIT method testRegisteredObjectsCount.

@Test
public void testRegisteredObjectsCount() throws Exception {
    assertEquals(0, context.getObjectStore().registeredObjectsCount());
    DataObject o1 = new MockDataObject();
    o1.setObjectId(new ObjectId("T", "key1", "v1"));
    context.getObjectStore().registerNode(o1.getObjectId(), o1);
    assertEquals(1, context.getObjectStore().registeredObjectsCount());
    // test object with same id
    DataObject o2 = new MockDataObject();
    o2.setObjectId(new ObjectId("T", "key1", "v1"));
    context.getObjectStore().registerNode(o2.getObjectId(), o2);
    assertEquals(1, context.getObjectStore().registeredObjectsCount());
    // test new object
    DataObject o3 = new MockDataObject();
    o3.setObjectId(new ObjectId("T", "key3", "v3"));
    context.getObjectStore().registerNode(o3.getObjectId(), o3);
    assertEquals(2, context.getObjectStore().registeredObjectsCount());
}
Also used : MockDataObject(org.apache.cayenne.MockDataObject) DataObject(org.apache.cayenne.DataObject) ObjectId(org.apache.cayenne.ObjectId) MockDataObject(org.apache.cayenne.MockDataObject) Test(org.junit.Test)

Example 84 with ObjectId

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

the class ObjectStoreTest method testRegisterNode.

@Test
public void testRegisterNode() {
    ObjectId id = new ObjectId("E1", "ID", 500);
    Persistent object = mock(Persistent.class);
    objectStore.registerNode(id, object);
    assertSame(object, objectStore.getNode(id));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 85 with ObjectId

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

the class ObjectStoreTest method testUnregisterNode.

@Test
public void testUnregisterNode() {
    ObjectId id = new ObjectId("E1", "ID", 500);
    Persistent object = mock(Persistent.class);
    objectStore.registerNode(id, object);
    Object unregistered = objectStore.unregisterNode(id);
    assertSame(object, unregistered);
    verify(object, times(0)).setObjectId(null);
    verify(object).setObjectContext(null);
    verify(object).setPersistenceState(PersistenceState.TRANSIENT);
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Persistent(org.apache.cayenne.Persistent) 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