Search in sources :

Example 21 with NVPair

use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.

the class SelectIntoArrayTest method testSelectIntoBeanArray.

@Test
public void testSelectIntoBeanArray() throws Exception {
    SqlServiceMock sql = createSqlServiceMock(DATA);
    // 
    BeanArrayHolder<MyBean> h = new BeanArrayHolder<SelectIntoArrayTest.MyBean>(MyBean.class);
    sql.selectInto("SELECT A,B,C FROM T WHERE D=0 INTO :{h.active},:{h.state},:{h.name}", new NVPair("h", h));
    MyBean[] a = h.getBeans();
    assertNotNull(a);
    assertEquals(4, a.length);
    for (int i = 0; i < a.length; i++) {
        a[i].assertValues(DATA[i]);
    }
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) BeanArrayHolder(org.eclipse.scout.rt.platform.holders.BeanArrayHolder) Test(org.junit.Test)

Example 22 with NVPair

use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.

the class StatementProcessorTest method testDuplicateBindNames.

@Test
public void testDuplicateBindNames() {
    final String bind1Name = "bind1";
    final String bind2Name = "bind2";
    final String bindSessionName = "userId";
    final String stmtWithInBinds = "select :" + bind1Name + ", :" + bind2Name + " from dual";
    final String stmtWithOutBinds = "select 1, 2 from dual into :" + bind1Name + ", :" + bind2Name;
    final String stmtWithSessionProperty = "select :" + bindSessionName + ", :" + bind1Name + " from dual";
    // test in binds
    assertArrayEquals(new String[] {}, exec(true, stmtWithInBinds, new NVPair(bind1Name, null), new NVPair(bind2Name, null)));
    assertArrayEquals(new String[] { bind1Name }, exec(true, stmtWithInBinds, new NVPair(bind1Name, null), new NVPair(bind2Name, null), new NVPair(bind1Name, null)));
    // test out binds
    assertArrayEquals(new String[] {}, exec(true, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()), new NVPair(bind2Name, new IntegerHolder())));
    assertArrayEquals(new String[] { bind1Name }, exec(true, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()), new NVPair(bind2Name, new IntegerHolder()), new NVPair(bind1Name, new IntegerHolder())));
    // test duplicate with property from session
    assertArrayEquals(new String[] { bindSessionName }, exec(true, stmtWithSessionProperty, new NVPair(bindSessionName, null), new NVPair(bind1Name, null)));
    // test with duplicate check disabled
    assertArrayEquals(new String[] {}, exec(false, stmtWithInBinds, new NVPair(bind1Name, null), new NVPair(bind2Name, null), new NVPair(bind1Name, null)));
    assertArrayEquals(new String[] {}, exec(false, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()), new NVPair(bind2Name, new IntegerHolder()), new NVPair(bind1Name, new IntegerHolder())));
    // missing input with duplicate checking
    try {
        exec(true, stmtWithInBinds, new NVPair(bind1Name, null));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
    // missing output with duplicate checking
    try {
        exec(true, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
    // missing input without duplicate checking
    try {
        exec(false, stmtWithInBinds, new NVPair(bind1Name, null));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
    // missing output without duplicate checking
    try {
        exec(false, stmtWithOutBinds, new NVPair(bind1Name, new IntegerHolder()));
        fail();
    } catch (ProcessingException e) {
        assertNotNull(e);
    }
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 23 with NVPair

use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.

the class StatementProcessorTest method testSelectLike.

@Test
public void testSelectLike() throws Exception {
    AbstractSqlService sqlService = new AbstractSqlService() {
    };
    BeanInstanceUtil.initializeBeanInstance(sqlService);
    StatementProcessor sp = new StatementProcessor(sqlService, "SELECT BP_NR FROM FLM_BP WHERE BP_NO LIKE :bpNo INTO :bpNr", new Object[] { new NVPair("bpNo", "12"), new NVPair("bpNr", new LongHolder()) });
    sp.simulate();
    String sqlPlainTextDump = sp.createSqlDump(false, true);
    assertFalse(sqlPlainTextDump.contains("UNPARSED"));
}
Also used : LongHolder(org.eclipse.scout.rt.platform.holders.LongHolder) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) Test(org.junit.Test)

Example 24 with NVPair

use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.

the class StatementProcessorTest method testFormData.

@Test
public void testFormData() throws Exception {
    IntegerHolder countConcurrent = new IntegerHolder();
    PersonFormData formData = new PersonFormData();
    formData.getAddressTable().addRow();
    formData.getAddressTable().addRow();
    // 
    AbstractSqlService sqlService = new AbstractSqlService() {
    };
    BeanInstanceUtil.initializeBeanInstance(sqlService);
    StatementProcessor sp = new StatementProcessor(sqlService, "SELECT COUNT(*) " + "FROM PERSON P " + "WHERE NVL(:birthdate,TO_DATE('1.1.3000','dd.mm.yyyy')) >= SYSDATE " + "AND :name like '%Me%' " + "AND :{addressTable.street} like '%Park%' " + "INTO :countConcurrent ", new Object[] { formData, new NVPair("countConcurrent", countConcurrent) });
    sp.simulate();
    String sqlPlainTextDump = sp.createSqlDump(false, true);
    assertFalse(sqlPlainTextDump.contains("UNPARSED"));
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) AbstractSqlService(org.eclipse.scout.rt.server.jdbc.AbstractSqlService) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) Test(org.junit.Test)

Example 25 with NVPair

use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.

the class StatementProcessorCreateSqlDumpTest method runDump.

private void runDump(String expected, StatementType type, String statement) {
    ISqlStyle style = Mockito.mock(ISqlStyle.class);
    Mockito.when(style.buildBindFor(23, null)).thenReturn(new SqlBind(4, 23));
    Mockito.when(style.toPlainText(23)).thenReturn("23");
    Mockito.when(style.buildBindFor("lorem", null)).thenReturn(new SqlBind(1, "lorem"));
    Mockito.when(style.toPlainText("lorem")).thenReturn("'lorem'");
    ISqlService callerService = Mockito.mock(ISqlService.class);
    Mockito.when(callerService.getSqlStyle()).thenReturn(style);
    Object[] bindBases = new Object[] { new NVPair("myKey", 23), new NVPair("myText", "lorem") };
    P_StatementProcessor_UnderTest statementProcessor = new P_StatementProcessor_UnderTest(callerService, statement, bindBases);
    String dump = statementProcessor.getDump(type);
    assertEquals(type.name() + " dump", expected, dump);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) ISqlStyle(org.eclipse.scout.rt.server.jdbc.style.ISqlStyle) ISqlService(org.eclipse.scout.rt.server.jdbc.ISqlService) NVPair(org.eclipse.scout.rt.platform.holders.NVPair)

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