use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestProcedureProcessor method addProc.
private void addProc(TransformationMetadata metadata, String name, String query, String[] rsCols, String[] rsTypes, String[] params, String[] paramTypes) {
// $NON-NLS-1$
Schema pm1 = metadata.getMetadataStore().getSchema("PM1");
pm1.getProcedures().remove(name.toUpperCase());
ColumnSet<Procedure> rs2 = RealMetadataFactory.createResultSet("rs1", rsCols, rsTypes);
// $NON-NLS-1$
QueryNode sq2n1 = new QueryNode(query);
ArrayList<ProcedureParameter> procParams = new ArrayList<ProcedureParameter>(params.length);
for (int i = 0; i < params.length; i++) {
procParams.add(RealMetadataFactory.createParameter(params[i], SPParameter.IN, paramTypes[i]));
}
// $NON-NLS-1$
Procedure sq1 = RealMetadataFactory.createVirtualProcedure(name, pm1, procParams, sq2n1);
sq1.setResultSet(rs2);
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestProcedureRelational method testIssue119.
/*
* The following are tests that were removed from the validator. We are no longer trying to validate a priori whether
* procedure input criteria is valid. This can be addressed later more generally when we do up front validation of
* access patterns and access patterns have a wider range of semantics.
*
@Test public void testProcInVirtualGroupDefect14609_1() throws Exception{
helpValidate("select ve3 from vm1.vgvp1 where ve1=1.1 and ve2='a'", new String[] {"ve1 = 1.1"}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testProcInVirtualGroupDefect14609_2() throws Exception{
helpValidate("select ve3 from vm1.vgvp1 where convert(ve1, integer)=1 and ve2='a'", new String[] {"convert(ve1, integer) = 1" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testProcInVirtualGroupDefect14609_3() throws Exception{
helpValidate("select ve3 from vm1.vgvp1 where 1.1=ve1 and ve2='a'", new String[] {"1.1 = ve1" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testProcInVirtualGroupDefect14609_4() throws Exception{
helpValidate("select ve3 from vm1.vgvp1 where 1=convert(ve1, integer) and ve2='a'", new String[] {"1 = convert(ve1, integer)" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testDefect15861() throws Exception{
helpValidate("select ve3 from vm1.vgvp1 where (ve1=1 or ve1=2) and ve2='a'", new String[] {"(ve1 = 1) OR (ve1 = 2)", "ve1 = 2"}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
@Test public void testProcInVirtualGroup1_Defect20164() {
helpFailProcedure("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') or ve3='c'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
}
@Test public void testProcInVirtualGroup2_Defect20164() {
helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 or ve2='a'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
}
@Test public void testProcInVirtualGroup3_Defect20164() {
helpFailProcedure("select ve3 from vm1.vgvp2, pm1.g1 where ve1=pm1.g1.e2 and ve2='a'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
}
@Test public void testProcInVirtualGroup4_Defect20164() {
helpValidate("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') and (ve3='a' OR ve3='c')", new String[0], RealMetadataFactory.example1Cached()); //$NON-NLS-1$
}
@Test public void testProcInVirtualGroup5_Defect20164() {
helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and NOT(ve2='a')", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
}
@Test public void testProcInVirtualGroup6_Defect20164() {
helpValidate("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is null", new String[0], RealMetadataFactory.example1Cached()); //$NON-NLS-1$
}
@Test public void testProcInVirtualGroup7_Defect20164() {
helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is not null", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
}*/
/**
* Ensures that dependent procedures are processed 1 at a time so that projected input values
* are set correctly.
*/
@Test
public void testIssue119() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
ProcedureParameter in = RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.vp1.rs1", new String[] { "e1", "e2", "e3", "e4", "e5" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
// $NON-NLS-1$
QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN SELECT vp1.in1 e1, x.in1 e2, x.e1 e3, y.in1 e4, y.e1 e5 FROM pm1.sp119 x, pm1.sp119 y where x.in1 = vp1.in1 and y.in1 = x.e1; END");
// $NON-NLS-1$
Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, Arrays.asList(in), n1);
vt1.setResultSet(rs1);
// $NON-NLS-1$
ProcedureParameter in1 = RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$ //$NON-NLS-2$
ColumnSet<Procedure> rs3 = RealMetadataFactory.createResultSet("pm1.sp119.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
// $NON-NLS-1$
Procedure sp1 = RealMetadataFactory.createStoredProcedure("sp119", pm1, Arrays.asList(in1));
sp1.setResultSet(rs3);
// $NON-NLS-1$
String sql = "select * from (exec v1.vp1(1)) foo order by e4, e5";
List<?>[] expected = new List[] { Arrays.asList(1, 1, 3, 3, 5), Arrays.asList(1, 1, 3, 3, 8), Arrays.asList(1, 1, 6, 6, 8), Arrays.asList(1, 1, 6, 6, 11) };
QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
// Construct data manager with data
// Plan query
ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);
// Run query
HardcodedDataManager dataManager = new HardcodedDataManager() {
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (command instanceof StoredProcedure) {
StoredProcedure proc = (StoredProcedure) command;
List<SPParameter> params = proc.getInputParameters();
assertEquals(1, params.size());
int value = (Integer) ((Constant) params.get(0).getExpression()).getValue();
return new FakeTupleSource(command.getProjectedSymbols(), new List[] { Arrays.asList(value + 2), Arrays.asList(value + 5) });
}
return super.registerRequest(context, command, modelName, parameterObject);
}
};
TestProcedureProcessor.helpTestProcess(plan, expected, dataManager, metadata);
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class WSDLMetadataProcessor method buildSoapOperation.
private void buildSoapOperation(MetadataFactory mf, BindingOperation bindingOperation) {
Operation operation = bindingOperation.getOperation();
// add input
String inputXML = null;
Input input = operation.getInput();
if (input != null) {
Message message = input.getMessage();
if (message != null) {
inputXML = message.getQName().getLocalPart();
}
}
// add output
String outXML = null;
Output output = operation.getOutput();
if (output != null) {
Message message = output.getMessage();
if (message != null) {
outXML = message.getQName().getLocalPart();
}
}
// $NON-NLS-1$
ExtensibilityElement operationExtension = getExtensibilityElement(bindingOperation.getExtensibilityElements(), "operation");
if (!(operationExtension instanceof SOAPOperation) && !(operationExtension instanceof SOAP12Operation)) {
return;
}
if (operationExtension instanceof SOAPOperation) {
// soap:operation
SOAPOperation soapOperation = (SOAPOperation) operationExtension;
String style = soapOperation.getStyle();
if (style.equalsIgnoreCase("rpc")) {
// $NON-NLS-1$
LogManager.logInfo(LogConstants.CTX_CONNECTOR, WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15004, operation.getName()));
return;
}
} else if (operationExtension instanceof SOAP12Operation) {
// soap:operation
SOAP12Operation soapOperation = (SOAP12Operation) operationExtension;
String style = soapOperation.getStyle();
if (style.equalsIgnoreCase("rpc")) {
// $NON-NLS-1$
LogManager.logInfo(LogConstants.CTX_CONNECTOR, WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15004, operation.getName()));
return;
}
}
Procedure procedure = mf.addProcedure(operation.getName());
procedure.setVirtual(false);
procedure.setNameInSource(operation.getName());
mf.addProcedureParameter(inputXML, TypeFacility.RUNTIME_NAMES.XML, Type.In, procedure);
// $NON-NLS-1$
ProcedureParameter param = mf.addProcedureParameter("stream", TypeFacility.RUNTIME_NAMES.BOOLEAN, Type.In, procedure);
// $NON-NLS-1$
param.setAnnotation("If the result should be streamed.");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param.setDefaultValue("false");
mf.addProcedureParameter(outXML, TypeFacility.RUNTIME_NAMES.XML, Type.ReturnValue, procedure);
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class WSExecutionFactory method getMetadata.
@Override
public void getMetadata(MetadataFactory metadataFactory, WSConnection conn) throws TranslatorException {
Procedure p = metadataFactory.addProcedure(INVOKE);
// $NON-NLS-1$
p.setAnnotation("Invokes a webservice that returns an XML result");
// $NON-NLS-1$
metadataFactory.addProcedureParameter("result", TypeFacility.RUNTIME_NAMES.XML, Type.ReturnValue, p);
// $NON-NLS-1$
ProcedureParameter param = metadataFactory.addProcedureParameter("binding", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("The invocation binding (HTTP, SOAP11, SOAP12). May be set or allowed to default to null to use the default binding.");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("action", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("With a SOAP invocation, action sets the SOAPAction. With HTTP it sets the HTTP Method (GET, POST - default, etc.).");
param.setNullType(NullType.Nullable);
// can be one of string, xml, clob
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.XML, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("The XML document or root element that represents the request. If the ExecutionFactory is configured in with a DefaultServiceMode of MESSAGE, then the SOAP request must contain the entire SOAP message.");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("endpoint", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("The relative or abolute endpoint to use. May be set or allowed to default to null to use the default endpoint address.");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("stream", TypeFacility.RUNTIME_NAMES.BOOLEAN, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("If the result should be streamed.");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param.setDefaultValue("false");
p = metadataFactory.addProcedure(INVOKE_HTTP);
// $NON-NLS-1$
p.setAnnotation("Invokes a webservice that returns an binary result");
// $NON-NLS-1$
metadataFactory.addProcedureParameter("result", TypeFacility.RUNTIME_NAMES.BLOB, Type.ReturnValue, p);
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("action", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("Sets the HTTP Method (GET, POST - default, etc.).");
param.setNullType(NullType.Nullable);
// can be one of string, xml, clob
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.OBJECT, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("The String, XML, BLOB, or CLOB value containing a payload (only for POST).");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("endpoint", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("The relative or abolute endpoint to use. May be set or allowed to default to null to use the default endpoint address.");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("stream", TypeFacility.RUNTIME_NAMES.BOOLEAN, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("If the result should be streamed.");
param.setNullType(NullType.Nullable);
// $NON-NLS-1$
param.setDefaultValue("false");
// $NON-NLS-1$
metadataFactory.addProcedureParameter("contentType", TypeFacility.RUNTIME_NAMES.STRING, Type.Out, p);
// $NON-NLS-1$
param = metadataFactory.addProcedureParameter("headers", TypeFacility.RUNTIME_NAMES.CLOB, Type.In, p);
// $NON-NLS-1$
param.setAnnotation("Headers to send");
param.setNullType(NullType.Nullable);
WSDLMetadataProcessor metadataProcessor = new WSDLMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
metadataProcessor.process(metadataFactory, conn);
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestWSTranslator method testStreaming.
@Test
public void testStreaming() throws Exception {
WSExecutionFactory ef = new WSExecutionFactory();
WSConnection mockConnection = Mockito.mock(WSConnection.class);
MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
ef.getMetadata(mf, mockConnection);
Procedure p = mf.getSchema().getProcedure(WSExecutionFactory.INVOKE_HTTP);
assertEquals(7, p.getParameters().size());
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
Dispatch<Object> mockDispatch = mockDispatch();
DataSource mock = Mockito.mock(DataSource.class);
ByteArrayInputStream baos = new ByteArrayInputStream(new byte[100]);
Mockito.stub(mock.getInputStream()).toReturn(baos);
Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(mock);
Mockito.stub(mockConnection.createDispatch(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
CommandBuilder cb = new CommandBuilder(tm);
Call call = (Call) cb.getCommand("call invokeHttp('GET', null, null, true)");
BinaryWSProcedureExecution pe = new BinaryWSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
pe.execute();
List<?> result = pe.getOutputParameterValues();
Blob b = (Blob) result.get(0);
assertEquals(100, ObjectConverterUtil.convertToByteArray(b.getBinaryStream()).length);
try {
ObjectConverterUtil.convertToByteArray(b.getBinaryStream());
fail();
} catch (SQLException e) {
// should only be able to read once
}
}
Aggregations