Search in sources :

Example 91 with DataRow

use of org.apache.cayenne.DataRow 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 92 with DataRow

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

the class PrefetchProcessorTreeBuilderIT method testBuildTreeNoPrefetches.

@Test
public void testBuildTreeNoPrefetches() {
    final ClassDescriptor descriptor = resolver.getClassDescriptor("Artist");
    List<DataRow> dataRows = new ArrayList<>();
    dataRows.add(new DataRow(4));
    dataRows.add(new DataRow(4));
    QueryMetadata metadata = new MockQueryMetadata() {

        @Override
        public ClassDescriptor getClassDescriptor() {
            return descriptor;
        }

        @Override
        public ObjEntity getObjEntity() {
            return descriptor.getEntity();
        }

        @Override
        public DbEntity getDbEntity() {
            return getObjEntity().getDbEntity();
        }

        @Override
        public DataMap getDataMap() {
            return getObjEntity().getDataMap();
        }

        @Override
        public boolean isRefreshingObjects() {
            return true;
        }

        @Override
        public boolean isResolvingInherited() {
            return true;
        }
    };
    PrefetchTreeNode tree = new PrefetchTreeNode();
    HierarchicalObjectResolver resolver = new HierarchicalObjectResolver(context, metadata);
    PrefetchProcessorTreeBuilder builder = new PrefetchProcessorTreeBuilder(resolver, dataRows, new HashMap<>());
    PrefetchProcessorNode processingTree = builder.buildTree(tree);
    assertTrue(processingTree.getChildren().isEmpty());
    assertFalse(processingTree.isPhantom());
    assertFalse(processingTree.isPartitionedByParent());
    assertTrue(processingTree.isDisjointPrefetch());
    assertSame(dataRows, processingTree.getDataRows());
    assertSame(descriptor.getEntity(), processingTree.getResolver().getEntity());
    assertNull(processingTree.getIncoming());
}
Also used : MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) QueryMetadata(org.apache.cayenne.query.QueryMetadata) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) PrefetchTreeNode(org.apache.cayenne.query.PrefetchTreeNode) ArrayList(java.util.ArrayList) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 93 with DataRow

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

the class SimpleIdIncrementalFaultListDataRowsIT method setUp.

@Before
public void setUp() throws Exception {
    tArtist = new TableHelper(dbHelper, "ARTIST");
    tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
    createArtistsDataSet();
    ObjectSelect<DataRow> q = ObjectSelect.dataRowQuery(Artist.class).pageSize(6).orderBy("db:ARTIST_ID", SortOrder.ASCENDING);
    list = new SimpleIdIncrementalFaultList<>(context, q, 10000);
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) DataRow(org.apache.cayenne.DataRow) Before(org.junit.Before)

Example 94 with DataRow

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

the class SimpleIdIncrementalFaultListDataRowsIT method testIndexOf1.

@Test
public void testIndexOf1() {
    List<DataRow> artists = ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist20")).select(context);
    assertEquals(1, artists.size());
    DataRow row = artists.get(0);
    assertEquals(19, list.indexOf(row));
    DataRow clone = new DataRow(row);
    assertEquals(19, list.indexOf(clone));
    row.remove("ARTIST_ID");
    assertEquals(-1, list.indexOf(row));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 95 with DataRow

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

the class SimpleIdIncrementalFaultListDataRowsIT method testLastIndexOf2.

@Test
public void testLastIndexOf2() {
    List<DataRow> artists = ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist20")).select(context);
    assertEquals(1, artists.size());
    DataRow row = artists.get(0);
    assertEquals(19, list.lastIndexOf(row));
    row.remove("ARTIST_ID");
    assertEquals(-1, list.lastIndexOf(row));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Aggregations

DataRow (org.apache.cayenne.DataRow)152 Test (org.junit.Test)113 Artist (org.apache.cayenne.testdo.testmap.Artist)31 ObjectId (org.apache.cayenne.ObjectId)25 DataObject (org.apache.cayenne.DataObject)20 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)20 SQLTemplate (org.apache.cayenne.query.SQLTemplate)18 Date (java.util.Date)14 HashMap (java.util.HashMap)14 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)14 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)12 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Persistent (org.apache.cayenne.Persistent)8 Painting (org.apache.cayenne.testdo.testmap.Painting)8 Connection (java.sql.Connection)6 Calendar (java.util.Calendar)5 Map (java.util.Map)5 QueryResponse (org.apache.cayenne.QueryResponse)5 DataMap (org.apache.cayenne.map.DataMap)5