Search in sources :

Example 16 with DataObject

use of org.apache.cayenne.DataObject 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 17 with DataObject

use of org.apache.cayenne.DataObject 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 18 with DataObject

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

the class DataContextExtrasIT method testPartialObjectFromDataRow.

@Test
public void testPartialObjectFromDataRow() {
    DataRow row = new DataRow(10);
    row.put("ARTIST_ID", 100001);
    row.put("ARTIST_NAME", "ArtistXYZ");
    DataObject obj = context.objectFromDataRow(Artist.class, row);
    assertNotNull(obj);
    assertTrue(context.getGraphManager().registeredNodes().contains(obj));
    assertEquals(PersistenceState.HOLLOW, obj.getPersistenceState());
    assertNull(context.getObjectStore().getCachedSnapshot(obj.getObjectId()));
}
Also used : DataObject(org.apache.cayenne.DataObject) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 19 with DataObject

use of org.apache.cayenne.DataObject 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)

Example 20 with DataObject

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

the class DataContextIT method testInvalidateObjects_Vararg.

@Test
public void testInvalidateObjects_Vararg() 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(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

DataObject (org.apache.cayenne.DataObject)38 Test (org.junit.Test)27 ObjectId (org.apache.cayenne.ObjectId)18 DataRow (org.apache.cayenne.DataRow)15 Persistent (org.apache.cayenne.Persistent)8 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)7 Artist (org.apache.cayenne.testdo.testmap.Artist)7 CayenneDataObject (org.apache.cayenne.CayenneDataObject)6 SelectQuery (org.apache.cayenne.query.SelectQuery)6 Date (java.util.Date)5 HashMap (java.util.HashMap)5 SQLStatement (org.apache.cayenne.access.jdbc.SQLStatement)4 Expression (org.apache.cayenne.exp.Expression)3 ObjEntity (org.apache.cayenne.map.ObjEntity)3 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)3 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)3 Map (java.util.Map)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 MockDataObject (org.apache.cayenne.MockDataObject)2 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)2