use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class StatementProcessor method createInput.
private IBindInput createInput(IToken bindToken, Object[] bindBases) {
if (bindToken instanceof ValueInputToken) {
final ValueInputToken valueInputToken = (ValueInputToken) bindToken;
final String[] path = REGEX_DOT.split(valueInputToken.getName());
IBindInput result = null;
for (final Object bindBase : bindBases) {
Class nullType = null;
if (bindBase instanceof NVPair) {
nullType = ((NVPair) bindBase).getNullType();
}
final IBindInput in = createInputRec(valueInputToken, path, bindBase, nullType);
if (in != null) {
// bind found
if (isBindDuplicateCheckEnabled()) {
if (result == null) {
// first match found for the bind -> remember
result = in;
} else {
// second match found
onDuplicateBind(valueInputToken);
return result;
}
} else {
// no duplicate check necessary: directly return the first match
return in;
}
}
}
if (result == null) {
throw new ProcessingException("Cannot find input for '{}' in bind bases.", valueInputToken);
}
return result;
} else if (bindToken instanceof FunctionInputToken) {
return new FunctionInput(m_callerService, m_bindBases, (FunctionInputToken) bindToken);
}
throw new ProcessingException("Cannot find input for {}", bindToken.getClass());
}
use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class CsvSqlAdapter method exportData.
/**
* Export sql data into a file
*
* @param params
*/
public void exportData(CsvSettings params) {
final CsvHelper h = new CsvHelper(params.getContentLocale(), params.getColSeparator(), params.getTextDelimiter(), "\n");
if (params.getCsvColumnTypes() != null) {
h.setColumnTypes(params.getCsvColumnTypes());
}
if (params.getCsvColumnNames() != null) {
h.setColumnNames(params.getCsvColumnNames());
}
Collection<String> cols = new ArrayList<String>();
cols.addAll(params.getCsvColumnNames());
// prepare select statement
String sqlText;
Object[] base = null;
if (params.getSqlSelect() != null) {
sqlText = params.getSqlSelect();
base = params.getBindBase();
} else {
StringBuilder buf = new StringBuilder();
buf.append("SELECT ");
for (Iterator<String> it = cols.iterator(); it.hasNext(); ) {
String colName = it.next();
buf.append(colName);
if (it.hasNext()) {
buf.append(",");
}
}
buf.append(" FROM ");
buf.append(params.getTableName());
if (params.getGroupKeyValue() != null) {
buf.append(" WHERE ");
buf.append(params.getGroupKeyColumnName());
buf.append("=:groupKeyColumnValue");
}
if (params.getLineNumberColumnName() != null) {
buf.append(" ORDER BY ");
buf.append(params.getLineNumberColumnName());
}
sqlText = buf.toString();
if (params.getGroupKeyValue() != null) {
base = new Object[1];
base[0] = new NVPair("groupKeyColumnValue", params.getGroupKeyValue());
}
}
try (FileOutputStream out = new FileOutputStream(params.getFile());
Writer w = new OutputStreamWriter(out, params.getEncoding())) {
h.exportHeaderRows(w, params.getWriteColumnNames(), params.getWriteColumnTypes());
ISelectStreamHandler handler = new ISelectStreamHandler() {
@Override
public void handleRow(Connection con, PreparedStatement stm, ResultSet rs, int rowIndex, List<SqlBind> values) {
Object[] row = new Object[values.size()];
for (int i = 0; i < row.length; i++) {
row[i] = values.get(i).getValue();
}
h.exportDataRow(row, w, false);
}
@Override
public void finished(Connection con, PreparedStatement stm, ResultSet rs, int rowCount) {
// do nothing
}
};
m_sqlService.selectStreaming(sqlText, handler, base);
} catch (IOException e) {
throw new ProcessingException(e.getMessage(), e);
}
}
use of org.eclipse.scout.rt.platform.holders.NVPair in project scout.rt by eclipse.
the class BindValueTest method testNullBindWithLongHolder.
@Test
public void testNullBindWithLongHolder() throws Exception {
m_sqlService.clearProtocol();
// actual behaviour
m_sqlService.select("SELECT A FROM T WHERE A = :a", new NVPair("a", new LongHolder()));
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 testBatchUpdateFromArray.
/**
* Batch update from an array.
*/
@Test
public void testBatchUpdateFromArray() throws Exception {
SqlServiceMock sql = createSqlServiceMock();
Long person = 9L;
Long[] roles = new Long[] { 5L, 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 SelectInputBindTest method testBatchUpdateFromTableFieldBeanDataInNVPair.
/**
* {@link TableFieldBeanData} is from type {@link ITableBeanHolder} (introduced with Luna). TableData for batch update
* is in NVPair bind.
*/
@Test
public void testBatchUpdateFromTableFieldBeanDataInNVPair() throws Exception {
SqlServiceMock sql = createSqlServiceMock();
TableFieldBeanData tableData = createTableFieldBeanData(false);
sql.update("UDPATE my_table SET a=:{table.active}, s=:{table.state} where n=:{table.name} ", new NVPair("table", tableData));
assertExpectedProtocol(sql);
}
Aggregations