use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class BindValueTest method testNullBindWithLong.
@Test
public void testNullBindWithLong() throws Exception {
m_sqlService.clearProtocol();
// actual behaviour
m_sqlService.select("SELECT A FROM T WHERE A = :a", new NVPair("a", null));
String actual = m_sqlService.getProtocol().toString();
// expected behaviour
VerboseMock m = new VerboseMock(new StringBuffer());
m.log(Connection.class, "prepareStatement", "SELECT A FROM T WHERE A = ?");
m.log(PreparedStatement.class, "setNull", 1, Types.NULL);
m.log(PreparedStatement.class, "executeQuery");
m.log(ResultSet.class, "getFetchSize");
m.log(ResultSet.class, "next");
m.log(ResultSet.class, "close");
String expected = m.getProtocol().toString();
// check
assertEquals(expected, actual);
}
use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class BindValueTest method testNullBindWithLongAndNullType.
@Test
public void testNullBindWithLongAndNullType() throws Exception {
m_sqlService.clearProtocol();
// actual behaviour
m_sqlService.select("SELECT A FROM T WHERE A = :a", new NVPair("a", null, Long.class));
String actual = m_sqlService.getProtocol().toString();
// expected behaviour
VerboseMock m = new VerboseMock(new StringBuffer());
m.log(Connection.class, "prepareStatement", "SELECT A FROM T WHERE A = ?");
m.log(PreparedStatement.class, "setObject", 1, null, Types.BIGINT);
m.log(PreparedStatement.class, "executeQuery");
m.log(ResultSet.class, "getFetchSize");
m.log(ResultSet.class, "next");
m.log(ResultSet.class, "close");
String expected = m.getProtocol().toString();
// check
assertEquals(expected, actual);
}
use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class SelectInputBindTest method testBatchUpdateFromSet.
/**
* Direct batch update from a set.
*/
@Test
public void testBatchUpdateFromSet() throws Exception {
SqlServiceMock sql = createSqlServiceMock();
Long person = 9L;
Set<Long> roles = new HashSet<Long>();
roles.add(5L);
roles.add(6L);
sql.update("UDPATE this_table SET v = :value where r = :{roles} and p = :personNr", new NVPair("personNr", person), new NVPair("roles", roles), new NVPair("value", "lorem"));
assertExpectedProtocol2(sql);
}
use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class SelectIntoArrayTest method testSelectFromFormDataArray.
@Test
public void testSelectFromFormDataArray() throws Exception {
SqlServiceMock sql = new SqlServiceMock();
Object[][] expectedData = new Object[][] { new Object[] { true, 1, "abc" } };
sql.setResultData(expectedData);
//
MyFormData f1 = new MyFormData();
f1.getActive().setValue(true);
f1.getState().setValue(1);
f1.getName().setValue("abc");
MyFormData f2 = new MyFormData();
f2.getActive().setValue(null);
f2.getState().setValue(null);
f2.getName().setValue(null);
//
MyFormData[] h = new MyFormData[] { f1, f2 };
Object[][] data = sql.select("SELECT A,B,C FROM T WHERE A=:{h.active} AND B=:{h.state} AND C=:{h.name}", new NVPair("h", h));
assertNotNull(data);
assertEquals(2, data.length);
assertArrayEquals(new Object[] { true, 1, "abc" }, data[0]);
assertArrayEquals(new Object[] { true, 1, "abc" }, data[1]);
}
use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class SelectIntoArrayTest method testSelectIntoListInHolder.
@Test
public void testSelectIntoListInHolder() throws Exception {
SqlServiceMock sql = createSqlServiceMock(ROLES_DATA);
//
Holder<List> rolesHolder = new Holder<List>(List.class);
sql.selectInto("SELECT ROLE_NR FROM USER_ROLE WHERE USER_NR = :personNr INTO :{roles}", new NVPair("personNr", 63L), new NVPair("roles", rolesHolder));
List r = rolesHolder.getValue();
assertNotNull(r);
assertEquals(3, r.size());
assertEquals("first role", 3L, r.get(0));
assertEquals("second role", 5L, r.get(1));
assertEquals("third role", 7L, r.get(2));
}
Aggregations