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