use of org.teiid.client.metadata.ParameterInfo in project teiid by teiid.
the class RequestWorkItem method getParameterInfo.
private static List<ParameterInfo> getParameterInfo(StoredProcedure procedure) {
List<ParameterInfo> paramInfos = new ArrayList<ParameterInfo>();
for (SPParameter param : procedure.getParameters()) {
ParameterInfo info = new ParameterInfo(param.getParameterType(), param.getResultSetColumns().size());
paramInfos.add(info);
}
return paramInfos;
}
use of org.teiid.client.metadata.ParameterInfo in project teiid by teiid.
the class TestResultsMessage method example.
public static ResultsMessage example() {
ResultsMessage message = new ResultsMessage();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
message.setColumnNames(new String[] { "A", "B", "C", "D" });
message.setDataTypes(new String[] { DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.BIG_INTEGER });
message.setFinalRow(200);
message.setFirstRow(1);
message.setLastRow(100);
List parameters = new ArrayList();
parameters.add(new ParameterInfo(ParameterInfo.IN, 0));
parameters.add(new ParameterInfo(ParameterInfo.RESULT_SET, 5));
message.setParameters(parameters);
PlanNode planDescs = new PlanNode("test");
// $NON-NLS-1$ //$NON-NLS-2$
planDescs.addProperty("key1", "val1");
// $NON-NLS-1$ //$NON-NLS-2$
planDescs.addProperty("key2", "val2");
// $NON-NLS-1$ //$NON-NLS-2$
planDescs.addProperty("key3", "val3");
// $NON-NLS-1$ //$NON-NLS-2$
planDescs.addProperty("key4", "val4");
message.setPlanDescription(planDescs);
List results = new ArrayList();
// $NON-NLS-1$
results.add(new BigInteger("100"));
// $NON-NLS-1$
results.add(new BigInteger("200"));
// $NON-NLS-1$
results.add(new BigInteger("300"));
// $NON-NLS-1$
results.add(new BigInteger("400"));
message.setResults(new List[] { results });
List warnings = new ArrayList();
// $NON-NLS-1$
warnings.add(new Exception("warning1"));
// $NON-NLS-1$
warnings.add(new Exception("warning2"));
message.setWarnings(warnings);
return message;
}
use of org.teiid.client.metadata.ParameterInfo in project teiid by teiid.
the class TestResultsMessage method testSerialize.
public void testSerialize() throws Exception {
ResultsMessage message = example();
ResultsMessage copy = UnitTestUtil.helpSerialize(message);
assertNotNull(copy.getColumnNames());
assertEquals(4, copy.getColumnNames().length);
// $NON-NLS-1$
assertEquals("A", copy.getColumnNames()[0]);
// $NON-NLS-1$
assertEquals("B", copy.getColumnNames()[1]);
// $NON-NLS-1$
assertEquals("C", copy.getColumnNames()[2]);
// $NON-NLS-1$
assertEquals("D", copy.getColumnNames()[3]);
assertNotNull(copy.getDataTypes());
assertEquals(4, copy.getDataTypes().length);
assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[0]);
assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[1]);
assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[2]);
assertEquals(DataTypeManager.DefaultDataTypes.BIG_INTEGER, copy.getDataTypes()[3]);
assertEquals(200, copy.getFinalRow());
assertEquals(1, copy.getFirstRow());
assertEquals(100, copy.getLastRow());
assertNotNull(copy.getParameters());
assertEquals(2, copy.getParameters().size());
ParameterInfo info1 = (ParameterInfo) copy.getParameters().get(0);
assertEquals(ParameterInfo.IN, info1.getType());
assertEquals(0, info1.getNumColumns());
ParameterInfo info2 = (ParameterInfo) copy.getParameters().get(1);
assertEquals(ParameterInfo.RESULT_SET, info2.getType());
assertEquals(5, info2.getNumColumns());
assertNotNull(copy.getPlanDescription());
assertEquals(4, copy.getPlanDescription().getProperties().size());
List<? extends List<?>> results = copy.getResultsList();
assertNotNull(results);
assertEquals(1, results.size());
assertNotNull(results.get(0));
assertEquals(4, results.get(0).size());
// $NON-NLS-1$
assertEquals(new BigInteger("100"), copy.getResultsList().get(0).get(0));
// $NON-NLS-1$
assertEquals(new BigInteger("200"), copy.getResultsList().get(0).get(1));
// $NON-NLS-1$
assertEquals(new BigInteger("300"), copy.getResultsList().get(0).get(2));
// $NON-NLS-1$
assertEquals(new BigInteger("400"), copy.getResultsList().get(0).get(3));
assertNotNull(copy.getWarnings());
assertEquals(2, copy.getWarnings().size());
assertEquals(Exception.class, copy.getWarnings().get(0).getClass());
// $NON-NLS-1$
assertEquals("warning1", ((Exception) copy.getWarnings().get(0)).getMessage());
assertEquals(Exception.class, copy.getWarnings().get(1).getClass());
// $NON-NLS-1$
assertEquals("warning2", ((Exception) copy.getWarnings().get(1)).getMessage());
}
use of org.teiid.client.metadata.ParameterInfo in project teiid by teiid.
the class StatementImpl method createResultSet.
protected void createResultSet(ResultsMessage resultsMsg) throws SQLException {
// create out/return parameter index map if there is any
List listOfParameters = resultsMsg.getParameters();
if (listOfParameters != null) {
// get the size of result set
int resultSetSize = 0;
Iterator iteratorOfParameters = listOfParameters.iterator();
while (iteratorOfParameters.hasNext()) {
ParameterInfo parameter = (ParameterInfo) iteratorOfParameters.next();
if (parameter.getType() == ParameterInfo.RESULT_SET) {
resultSetSize = parameter.getNumColumns();
// one ResultSet only
break;
}
}
// return needs to be the first
// index in user call - {?=call sp(?)}
int index = 0;
int count = 0;
iteratorOfParameters = listOfParameters.iterator();
while (iteratorOfParameters.hasNext()) {
ParameterInfo parameter = (ParameterInfo) iteratorOfParameters.next();
if (parameter.getType() == ParameterInfo.RETURN_VALUE) {
count++;
index++;
int resultIndex = resultSetSize + count;
outParamIndexMap.put(index, resultIndex);
outParamByName.put(resultsMsg.getColumnNames()[resultIndex - 1].toUpperCase(), resultIndex);
break;
}
}
iteratorOfParameters = listOfParameters.iterator();
while (iteratorOfParameters.hasNext()) {
ParameterInfo parameter = (ParameterInfo) iteratorOfParameters.next();
if (parameter.getType() != ParameterInfo.RETURN_VALUE && parameter.getType() != ParameterInfo.RESULT_SET) {
index++;
if (parameter.getType() == ParameterInfo.OUT || parameter.getType() == ParameterInfo.INOUT) {
count++;
int resultIndex = resultSetSize + count;
outParamIndexMap.put(index, resultIndex);
outParamByName.put(resultsMsg.getColumnNames()[resultIndex - 1].toUpperCase(), resultIndex);
}
}
}
}
ResultSetMetaData metadata = null;
if (updateCounts != null) {
metadata = createResultSetMetaData(createMetadataMap(resultsMsg.getColumnNames(), resultsMsg.getDataTypes()));
}
resultSet = new ResultSetImpl(resultsMsg, this, metadata, outParamIndexMap.size());
resultSet.setMaxFieldSize(this.maxFieldSize);
}
use of org.teiid.client.metadata.ParameterInfo in project teiid by teiid.
the class TestCallableStatement method testGetOutputParameter.
@Test
public void testGetOutputParameter() throws Exception {
CallableStatementImpl mmcs = getCallableStatement();
RequestMessage request = new RequestMessage();
request.setExecutionId(1);
ResultsMessage resultsMsg = new ResultsMessage();
List<?>[] results = new List[] { Arrays.asList(null, null, null), Arrays.asList(null, 1, 2) };
resultsMsg.setResults(results);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
resultsMsg.setColumnNames(new String[] { "IntNum", "Out1", "Out2" });
resultsMsg.setDataTypes(new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
resultsMsg.setFinalRow(results.length);
resultsMsg.setLastRow(results.length);
resultsMsg.setFirstRow(1);
resultsMsg.setParameters(Arrays.asList(new ParameterInfo(ParameterInfo.RESULT_SET, 1), new ParameterInfo(ParameterInfo.OUT, 1), new ParameterInfo(ParameterInfo.OUT, 1)));
mmcs.createResultSet(resultsMsg);
assertEquals(1, mmcs.getInt(1));
assertEquals(2, mmcs.getInt(2));
assertEquals(1, mmcs.getInt("Out1"));
assertEquals(2, mmcs.getInt("Out2"));
}
Aggregations