assertEquals("[4, mrrrrh]", Arrays.toString(physicalRow));
assertEquals(String.class, physicalRow[0].getClass());
}
public void testScenario() throws Exception {
UpdateableDataContext dc = new MockUpdateableDataContext();
List<Object[]> physicalValuesList = ((MockUpdateableDataContext) dc).getValues();
assertEquals(3, physicalValuesList.size());
for (Object[] physicalValues : physicalValuesList) {
assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
}
final Table table = dc.getDefaultSchema().getTables()[0];
Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(dc, table, 1000);
assertEquals(1, converters.size());
dc = Converters.addTypeConverters(dc, converters);
final Query q = dc.query().from(table).select("foo").toQuery();
assertEquals("SELECT table.foo FROM schema.table", q.toSql());
DataSet ds = dc.executeQuery(q);
assertTrue(ds.next());
assertEquals(1, ds.getRow().getValue(0));
assertTrue(ds.next());
assertEquals(2, ds.getRow().getValue(0));
assertTrue(ds.next());
assertEquals(3, ds.getRow().getValue(0));
assertFalse(ds.next());
dc.executeUpdate(new UpdateScript() {
@Override
public void run(UpdateCallback callback) {
callback.insertInto(table).value("foo", 4).value("bar", "heidiho!").execute();
}
});
ds = dc.executeQuery(q);
assertTrue(ds.next());
assertEquals(1, ds.getRow().getValue(0));
assertTrue(ds.next());
assertEquals(2, ds.getRow().getValue(0));
assertTrue(ds.next());
assertEquals(3, ds.getRow().getValue(0));
assertTrue(ds.next());
assertEquals(4, ds.getRow().getValue(0));
assertFalse(ds.next());
assertEquals(4, physicalValuesList.size());
for (Object[] physicalValues : physicalValuesList) {
assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
}
dc.executeUpdate(new UpdateScript() {
@Override
public void run(UpdateCallback callback) {
callback.insertInto(table).value("foo", 5).value("bar", "hejsa...").execute();
callback.update(table).where("foo").lessThan(3).value("foo", 100).execute();
}
});
ds = dc.executeQuery(q);
assertTrue(ds.next());
assertEquals(3, ds.getRow().getValue(0));
assertTrue(ds.next());
assertEquals(4, ds.getRow().getValue(0));
assertTrue(ds.next());