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());
}
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());
}
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"));
}
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"));
}
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"));
}
});
}
Aggregations