Search in sources :

Example 11 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestODataMetadataProcessor method testAction.

@Test
public void testAction() throws Exception {
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    MetadataFactory mf = actionMetadata("invoke", returnType, null);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(3, p.getParameters().size());
    assertNull(p.getResultSet());
    assertNotNull(getReturnParameter(p));
    ProcedureParameter pp = getReturnParameter(p);
    assertEquals("string", pp.getRuntimeType());
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.ACTION, type);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 12 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestODataMetadataProcessor method testFunctionReturnComplexCollection.

@Test
public void testFunctionReturnComplexCollection() throws Exception {
    CsdlComplexType complex = complexType("Address");
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("namespace.Address");
    returnType.setCollection(true);
    MetadataFactory mf = functionMetadata("invoke", returnType, complex);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(2, p.getParameters().size());
    assertNotNull(p.getResultSet());
    assertNull(getReturnParameter(p));
    ColumnSet<Procedure> table = p.getResultSet();
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.FUNCTION, type);
    type = ODataType.valueOf(table.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.COMPLEX_COLLECTION, type);
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 13 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestODataMetadataProcessor method testSchema.

@Test
public void testSchema() throws Exception {
    translator = new ODataExecutionFactory();
    translator.start();
    MetadataFactory mf = tripPinMetadata();
    TransformationMetadata metadata = getTransformationMetadata(mf, this.translator);
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    // System.out.println(ddl);
    MetadataFactory mf2 = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    QueryParser.getQueryParser().parseDDL(mf2, ddl);
    Procedure p = mf.getSchema().getProcedure("ResetDataSource");
    assertNotNull(p);
    assertEquals(0, p.getParameters().size());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestODataMetadataProcessor method testFunctionReturnPrimitiveCollection.

@Test
public void testFunctionReturnPrimitiveCollection() throws Exception {
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    returnType.setCollection(true);
    MetadataFactory mf = functionMetadata("invoke", returnType, null);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(3, p.getParameters().size());
    assertNull(p.getResultSet());
    assertNotNull(getReturnParameter(p));
    ProcedureParameter pp = getReturnParameter(p);
    assertEquals("string[]", pp.getRuntimeType());
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.FUNCTION, type);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 15 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    try {
        String parameters = getQueryParameters(this.command);
        InputStream response = null;
        Procedure procedure = this.command.getMetadataObject();
        if (isFunction(procedure)) {
            String URI = buildFunctionURL(this.command, parameters);
            response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        } else {
            String URI = this.command.getProcedureName();
            response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        }
    } catch (ODataDeserializerException e) {
        throw new TranslatorException(e);
    } catch (EdmPrimitiveTypeException e) {
        throw new TranslatorException(e);
    }
}
Also used : InputStream(java.io.InputStream) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException) ODataDeserializerException(org.apache.olingo.client.api.serialization.ODataDeserializerException) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)

Aggregations

Procedure (org.teiid.metadata.Procedure)82 ProcedureParameter (org.teiid.metadata.ProcedureParameter)36 Test (org.junit.Test)35 MetadataFactory (org.teiid.metadata.MetadataFactory)30 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)27 Schema (org.teiid.metadata.Schema)16 Column (org.teiid.metadata.Column)14 MetadataStore (org.teiid.metadata.MetadataStore)11 Properties (java.util.Properties)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 Table (org.teiid.metadata.Table)9 QueryNode (org.teiid.query.mapping.relational.QueryNode)8 List (java.util.List)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)5 TranslatorException (org.teiid.translator.TranslatorException)5 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)5 ArrayList (java.util.ArrayList)4 Call (org.teiid.language.Call)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3