use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestConnectorWorkItem method testProcedureBatching.
@Test
public void testProcedureBatching() throws Exception {
ProcedureExecution exec = new FakeProcedureExecution(2, 1);
// this has two result set columns and 1 out parameter
int total_columns = 3;
// $NON-NLS-1$
StoredProcedure command = (StoredProcedure) helpGetCommand("{call pm2.spTest8(?)}", EXAMPLE_BQT);
command.getInputParameters().get(0).setExpression(new Constant(1));
Call proc = new LanguageBridgeFactory(EXAMPLE_BQT).translate(command);
ProcedureBatchHandler pbh = new ProcedureBatchHandler(proc, exec);
assertEquals(total_columns, pbh.padRow(Arrays.asList(null, null)).size());
List params = pbh.getParameterRow();
assertEquals(total_columns, params.size());
// check the parameter value
assertEquals(Integer.valueOf(0), params.get(2));
try {
pbh.padRow(Arrays.asList(1));
// $NON-NLS-1$
fail("Expected exception from resultset mismatch");
} catch (TranslatorException err) {
assertEquals("TEIID30479 Could not process stored procedure results for EXEC spTest8(1). Expected 2 result set columns, but was 1. Please update your models to allow for stored procedure results batching.", // $NON-NLS-1$
err.getMessage());
}
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestODataQueryExecution method testActionReturnsComplexCollection.
@Test
public void testActionReturnsComplexCollection() throws Exception {
String query = "exec invoke(1, 'foo')";
String expectedURL = "invoke";
String response = "{\"value\":[{\n" + " \"street\":\"United States\",\n" + " \"city\":\"Boise\",\n" + " \"state\":\"ID\"\n" + " }," + " {" + " \"street\":\"China\",\n" + " \"city\":\"Newyork\",\n" + " \"state\":\"NY\"\n" + " }]}";
CsdlComplexType complex = TestODataMetadataProcessor.complexType("Address");
CsdlReturnType returnType = new CsdlReturnType();
returnType.setType("namespace.Address");
MetadataFactory mf = TestODataMetadataProcessor.actionMetadata("invoke", returnType, complex);
ProcedureExecution excution = helpProcedureExecute(mf, query, response, expectedURL, 200);
assertArrayEquals(new Object[] { "United States", "Boise", "ID" }, excution.next().toArray(new Object[3]));
assertArrayEquals(new Object[] { "China", "Newyork", "NY" }, excution.next().toArray(new Object[3]));
assertNull(excution.next());
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class FileExecutionFactory method createProcedureExecution.
// @Override
public ProcedureExecution createProcedureExecution(final Call command, final ExecutionContext executionContext, final RuntimeMetadata metadata, final Connection conn) throws TranslatorException {
if (conn instanceof VirtualFileConnection) {
return new VirtualFileProcedureExecution(command, (VirtualFileConnection) conn);
}
final FileConnection fc = (FileConnection) conn;
if (command.getProcedureName().equalsIgnoreCase(SAVEFILE)) {
return new ProcedureExecution() {
@Override
public void execute() throws TranslatorException {
String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
Object file = command.getArguments().get(1).getArgumentValue().getValue();
if (file == null || filePath == null) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("non_null"));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Saving", filePath);
InputStream is = null;
try {
if (file instanceof SQLXML) {
is = ((SQLXML) file).getBinaryStream();
} else if (file instanceof Clob) {
is = new ReaderInputStream(((Clob) file).getCharacterStream(), encoding);
} else if (file instanceof Blob) {
is = ((Blob) file).getBinaryStream();
} else {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("unknown_type"));
}
ObjectConverterUtil.write(is, fc.getFile(filePath));
} catch (IOException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
} catch (SQLException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
} catch (ResourceException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
}
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
return null;
}
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
return Collections.emptyList();
}
};
} else if (command.getProcedureName().equalsIgnoreCase(DELETEFILE)) {
return new ProcedureExecution() {
@Override
public void execute() throws TranslatorException {
String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
if (filePath == null) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("non_null"));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Deleting", filePath);
try {
File f = fc.getFile(filePath);
if (!f.exists()) {
if (exceptionIfFileNotFound) {
// $NON-NLS-1$
throw new TranslatorException(DataPlugin.Util.gs("file_not_found", filePath));
}
} else if (!f.delete()) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("error_deleting"));
}
} catch (ResourceException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_deleting"));
}
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
return null;
}
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
return Collections.emptyList();
}
};
}
return new FileProcedureExecution(command, fc);
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestOlapTranslator method testCannedProcedure.
@Test
public void testCannedProcedure() throws Exception {
String ddl = "create foreign procedure proc(arg integer, arg1 date) returns table (x string) options (\"teiid_rel:native-query\" '$2 $1 something')";
String query = "exec proc(2, {d'1970-01-01'})";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "phy");
CommandBuilder commandBuilder = new CommandBuilder(tm);
Command obj = commandBuilder.getCommand(query);
OlapExecutionFactory oef = new OlapExecutionFactory();
Connection mock = Mockito.mock(java.sql.Connection.class);
OlapWrapper mock2 = Mockito.mock(OlapWrapper.class);
OlapConnection mock3 = Mockito.mock(OlapConnection.class);
OlapStatement mock4 = Mockito.mock(OlapStatement.class);
Mockito.stub(mock4.executeOlapQuery(Mockito.anyString())).toThrow(new TeiidRuntimeException());
Mockito.stub(mock3.createStatement()).toReturn(mock4);
Mockito.stub(mock2.unwrap(OlapConnection.class)).toReturn(mock3);
Mockito.stub(mock.unwrap(OlapWrapper.class)).toReturn(mock2);
ProcedureExecution pe = oef.createProcedureExecution((Call) obj, Mockito.mock(ExecutionContext.class), new RuntimeMetadataImpl(tm), mock);
try {
pe.execute();
fail();
} catch (TeiidRuntimeException e) {
Mockito.verify(mock4).executeOlapQuery("'1970-01-01' 2 something");
}
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestSwaggerQueryExecution method testParameterInPath.
@Test
public void testParameterInPath() throws Exception {
String query = "exec getPetById(petId=>687789);";
String expectedURL = "http://petstore.swagger.io/v2/pet/687789";
String response = "{\n" + " \"id\": 687789,\n" + " \"category\": {\n" + " \"id\": 0,\n" + " \"name\": \"Lions\"\n" + " },\n" + " \"name\": \"nikky\",\n" + " \"photoUrls\": [\n" + " \"url1\"\n" + " ],\n" + " \"tags\": [\n" + " {\n" + " \"id\": 1,\n" + " \"name\": \"tag1\"\n" + " }\n" + " ],\n" + " \"status\": \"sold\"\n" + "}";
ProcedureExecution excution = helpProcedureExecute(query, response, expectedURL, 200, true, "GET", null, getHeaders());
assertArrayEquals(new Object[] { 687789L, 0L, "Lions", "nikky", new String[] { "url1" }, 1L, "tag1", "sold" }, excution.next().toArray(new Object[8]));
assertNull(excution.next());
}
Aggregations