Search in sources :

Example 11 with DataRow

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

the class DateTimeTypesIT method testSQLTemplateTime.

@Test
public void testSQLTemplateTime() {
    DateTestEntity test = (DateTestEntity) context.newObject("DateTestEntity");
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(2003, Calendar.FEBRUARY, 1, 1, 20, 30);
    // most databases fail millisecond accuracy
    // cal.set(Calendar.MILLISECOND, 55);
    Time now = new Time(cal.getTime().getTime());
    test.setTimeColumn(now);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectDateTest")).get(0);
    Date columnValue = (Date) testRead.get("TIME_COLUMN");
    assertNotNull(testRead.toString(), columnValue);
    assertNotNull(columnValue);
    assertEquals(now.toString(), new Time(columnValue.getTime()).toString());
}
Also used : Calendar(java.util.Calendar) Time(java.sql.Time) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) DataRow(org.apache.cayenne.DataRow) Date(java.util.Date) Test(org.junit.Test)

Example 12 with DataRow

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

the class DateTimeTypesIT method testSQLTemplateDate.

@Test
public void testSQLTemplateDate() {
    DateTestEntity test = (DateTestEntity) context.newObject("DateTestEntity");
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(2003, Calendar.FEBRUARY, 1, 1, 20, 30);
    // most databases fail millisecond accuracy
    // cal.set(Calendar.MILLISECOND, 55);
    java.sql.Date now = new java.sql.Date(cal.getTime().getTime());
    test.setDateColumn(now);
    context.commitChanges();
    DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectDateTest")).get(0);
    Date columnValue = (Date) testRead.get("DATE_COLUMN");
    assertNotNull(columnValue);
    assertEquals(now.toString(), new java.sql.Date(columnValue.getTime()).toString());
}
Also used : Calendar(java.util.Calendar) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) DataRow(org.apache.cayenne.DataRow) Date(java.util.Date) Test(org.junit.Test)

Example 13 with DataRow

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

the class EmbeddingIT method testUpdateEmbedded.

@Test
public void testUpdateEmbedded() throws Exception {
    createUpdateDataSet();
    List<EmbedEntity1> results = ObjectSelect.query(EmbedEntity1.class).orderBy(EmbedEntity1.NAME.asc()).select(context);
    EmbedEntity1 o1 = results.get(0);
    Embeddable1 e11 = new Embeddable1();
    e11.setEmbedded10("x1");
    e11.setEmbedded20("x2");
    o1.setEmbedded1(e11);
    assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
    context.commitChanges();
    DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
    assertNotNull(row);
    assertEquals("x1", row.get("EMBEDDED10"));
}
Also used : Embeddable1(org.apache.cayenne.testdo.embeddable.Embeddable1) DataRow(org.apache.cayenne.DataRow) EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Example 14 with DataRow

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

the class EmbeddingIT method testUpdateEmbeddedProperties.

@Test
public void testUpdateEmbeddedProperties() throws Exception {
    createUpdateDataSet();
    List<EmbedEntity1> results = ObjectSelect.query(EmbedEntity1.class).orderBy(EmbedEntity1.NAME.asc()).select(context);
    EmbedEntity1 o1 = results.get(0);
    Embeddable1 e11 = o1.getEmbedded1();
    e11.setEmbedded10("x1");
    assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
    context.commitChanges();
    DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
    assertNotNull(row);
    assertEquals("x1", row.get("EMBEDDED10"));
}
Also used : Embeddable1(org.apache.cayenne.testdo.embeddable.Embeddable1) DataRow(org.apache.cayenne.DataRow) EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Example 15 with DataRow

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

the class JointPrefetchIT method testJointPrefetchDataRows.

@Test
public void testJointPrefetchDataRows() throws Exception {
    createJointPrefetchDataSet();
    // query with to-many joint prefetches
    final List<DataRow> rows = ObjectSelect.dataRowQuery(Painting.class).orderBy("db:PAINTING_ID", SortOrder.ASCENDING).prefetch(Painting.TO_ARTIST.joint()).select(context);
    queryInterceptor.runWithQueriesBlocked(() -> {
        assertEquals(3, rows.size());
        // row should contain columns from both entities minus those duplicated in a join...
        int rowWidth = context.getEntityResolver().getDbEntity("ARTIST").getAttributes().size() + context.getEntityResolver().getDbEntity("PAINTING").getAttributes().size();
        for (DataRow row : rows) {
            assertEquals("" + row, rowWidth, row.size());
            // assert columns presence
            assertTrue(row + "", row.containsKey("PAINTING_ID"));
            assertTrue(row + "", row.containsKey("ARTIST_ID"));
            assertTrue(row + "", row.containsKey("GALLERY_ID"));
            assertTrue(row + "", row.containsKey("PAINTING_TITLE"));
            assertTrue(row + "", row.containsKey("ESTIMATED_PRICE"));
            assertTrue(row + "", row.containsKey("toArtist.ARTIST_NAME"));
            assertTrue(row + "", row.containsKey("toArtist.DATE_OF_BIRTH"));
        }
    });
}
Also used : DataRow(org.apache.cayenne.DataRow) Painting(org.apache.cayenne.testdo.testmap.Painting) 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