Search in sources :

Example 1 with NVPair

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);
}
Also used : VerboseMock(org.eclipse.scout.rt.server.jdbc.fixture.VerboseMock) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) Test(org.junit.Test)

Example 2 with NVPair

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);
}
Also used : VerboseMock(org.eclipse.scout.rt.server.jdbc.fixture.VerboseMock) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) Test(org.junit.Test)

Example 3 with NVPair

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);
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with NVPair

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]);
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) Test(org.junit.Test)

Example 5 with NVPair

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));
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) BeanArrayHolder(org.eclipse.scout.rt.platform.holders.BeanArrayHolder) ITableBeanHolder(org.eclipse.scout.rt.platform.holders.ITableBeanHolder) Holder(org.eclipse.scout.rt.platform.holders.Holder) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) List(java.util.List) Test(org.junit.Test)

Aggregations

NVPair (org.eclipse.scout.rt.platform.holders.NVPair)25 Test (org.junit.Test)19 SqlServiceMock (org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock)12 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)5 ITableBeanHolder (org.eclipse.scout.rt.platform.holders.ITableBeanHolder)4 List (java.util.List)3 BeanArrayHolder (org.eclipse.scout.rt.platform.holders.BeanArrayHolder)3 IntegerHolder (org.eclipse.scout.rt.platform.holders.IntegerHolder)3 AbstractSqlService (org.eclipse.scout.rt.server.jdbc.AbstractSqlService)3 TableFieldBeanData (org.eclipse.scout.rt.server.jdbc.fixture.TableFieldBeanData)3 VerboseMock (org.eclipse.scout.rt.server.jdbc.fixture.VerboseMock)3 Method (java.lang.reflect.Method)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 IBeanArrayHolder (org.eclipse.scout.rt.platform.holders.IBeanArrayHolder)2 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)2 LongHolder (org.eclipse.scout.rt.platform.holders.LongHolder)2 TableBeanHolderFilter (org.eclipse.scout.rt.platform.holders.TableBeanHolderFilter)2 FastPropertyDescriptor (org.eclipse.scout.rt.platform.reflect.FastPropertyDescriptor)2