Search in sources :

Example 6 with Procedure

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

the class DirectQueryMetadataRepository method loadMetadata.

@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory) throws TranslatorException {
    if (executionFactory != null && executionFactory.supportsDirectQueryProcedure() && factory.getSchema().getProcedure(executionFactory.getDirectQueryProcedureName()) == null) {
        Procedure p = factory.addProcedure(executionFactory.getDirectQueryProcedureName());
        // $NON-NLS-1$
        p.setAnnotation("Invokes translator with a native query that returns results in an array of values");
        // $NON-NLS-1$
        ProcedureParameter param = factory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
        // $NON-NLS-1$
        param.setAnnotation("The native query to execute");
        param.setNullType(NullType.No_Nulls);
        // $NON-NLS-1$
        param = factory.addProcedureParameter("variable", TypeFacility.RUNTIME_NAMES.OBJECT, Type.In, p);
        // $NON-NLS-1$
        param.setAnnotation("Any number of varaibles; usage will vary by translator");
        param.setNullType(NullType.Nullable);
        param.setVarArg(true);
        // $NON-NLS-1$
        factory.addProcedureResultSetColumn("tuple", DataTypeManager.getDataTypeName(DataTypeManager.getArrayType(TypeFacility.RUNTIME_TYPES.OBJECT)), p);
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure)

Example 7 with Procedure

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

the class ComplexDocumentNode method buildComplexDocumentNode.

public static ComplexDocumentNode buildComplexDocumentNode(EdmOperation edmOperation, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidProcessingException {
    ComplexDocumentNode resource = new ComplexDocumentNode();
    FullQualifiedName fqn = edmOperation.getFullQualifiedName();
    String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.') + 1);
    Schema schema = metadata.getSchema(withoutVDB);
    Procedure procedure = schema.getProcedure(edmOperation.getName());
    StoredProcedure storedQuery = new StoredProcedure();
    // $NON-NLS-1$
    storedQuery.setProcedureName(procedure.getFullName());
    for (int i = 0; i < procedure.getParameters().size(); i++) {
        storedQuery.setParameter(new SPParameter(i + 1, new Reference(i)));
    }
    String group = nameGenerator.getNextGroup();
    // $NON-NLS-1$
    SubqueryFromClause sfc = new SubqueryFromClause(group, storedQuery);
    resource.setGroupSymbol(new GroupSymbol(group));
    resource.setFromClause(sfc);
    resource.procedure = procedure;
    return resource;
}
Also used : StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) SPParameter(org.teiid.query.sql.lang.SPParameter) Reference(org.teiid.query.sql.symbol.Reference) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) Schema(org.teiid.metadata.Schema) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Procedure(org.teiid.metadata.Procedure) SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Example 8 with Procedure

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

the class ODataMetadataProcessor method addFunctionImportAsProcedure.

void addFunctionImportAsProcedure(MetadataFactory mf, EdmFunctionImport function) throws TranslatorException {
    Procedure procedure = mf.addProcedure(function.getName());
    procedure.setProperty(HTTP_METHOD, function.getHttpMethod());
    // add parameters
    for (EdmFunctionParameter fp : function.getParameters()) {
        ProcedureParameter.Type type = ProcedureParameter.Type.In;
        if (fp.getMode().equals(EdmFunctionParameter.Mode.InOut)) {
            type = ProcedureParameter.Type.InOut;
        } else if (fp.getMode().equals(EdmFunctionParameter.Mode.Out)) {
            type = ProcedureParameter.Type.Out;
        }
        mf.addProcedureParameter(fp.getName(), ODataTypeManager.teiidType(fp.getType().getFullyQualifiedTypeName()), type, procedure);
    }
    // add return type
    EdmType returnType = function.getReturnType();
    if (returnType != null) {
        if (returnType.isSimple()) {
            // $NON-NLS-1$
            mf.addProcedureParameter("return", ODataTypeManager.teiidType(((EdmSimpleType) returnType).getFullyQualifiedTypeName()), ProcedureParameter.Type.ReturnValue, procedure);
        } else if (returnType instanceof EdmComplexType) {
            procedure.setProperty(ENTITY_TYPE, function.getReturnType().getFullyQualifiedTypeName());
            addProcedureTableReturn(mf, procedure, returnType);
        } else if (returnType instanceof EdmEntityType) {
            procedure.setProperty(ENTITY_TYPE, function.getReturnType().getFullyQualifiedTypeName());
            addProcedureTableReturn(mf, procedure, returnType);
        } else if (returnType instanceof EdmCollectionType) {
            procedure.setProperty(ENTITY_TYPE, ((EdmCollectionType) returnType).getItemType().getFullyQualifiedTypeName());
            addProcedureTableReturn(mf, procedure, ((EdmCollectionType) returnType).getItemType());
        } else {
            throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17005, function.getName(), returnType.getFullyQualifiedTypeName()));
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException)

Example 9 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();
    String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    Properties props = new Properties();
    props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
    props.setProperty("entityContainer", "NorthwindEntities");
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.getMetadata(mf, new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes())))));
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "northwind", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    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("executeVoid");
    assertNotNull(p);
    assertEquals(1, p.getParameters().size());
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) InputStreamReader(java.io.InputStreamReader) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Properties(java.util.Properties) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) Procedure(org.teiid.metadata.Procedure) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Test(org.junit.Test)

Example 10 with Procedure

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

the class TestODataQueryExecution method testArrayType.

@Test
public void testArrayType() throws Exception {
    ModelMetaData model = new ModelMetaData();
    model.setName("nw");
    model.setModelType(Type.PHYSICAL);
    MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
    EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("arraytest.xml"))));
    ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
    metadataProcessor.getMetadata(mf, edm);
    Column c = mf.getSchema().getTable("G2").getColumnByName("e3");
    assertEquals("integer[]", c.getRuntimeType());
    Procedure p = mf.getSchema().getProcedure("ARRAYITERATE");
    assertEquals("varbinary[]", p.getParameters().get(0).getRuntimeType());
    assertEquals("varbinary", p.getResultSet().getColumns().get(0).getRuntimeType());
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
    String query = "SELECT * FROM G2";
    String expectedURL = "G2?$select=e1,e3";
    String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" xml:base=\"http://localhost:8080/odata/loopy/\">\n" + "   <title type=\"text\">VM1.x</title>\n" + "   <id>http://localhost:8080/odata/loopy/VM1.x</id>\n" + "   <updated>2015-10-14T19:36:58Z</updated>\n" + "   <link rel=\"self\" title=\"VM1.x\" href=\"VM1.x\" />\n" + "   <entry>\n" + "      <id>http://localhost:8080/odata/loopy/VM1.x('x')</id>\n" + "      <title type=\"text\" />\n" + "      <updated>2015-10-14T19:36:58Z</updated>\n" + "      <author>\n" + "         <name />\n" + "      </author>\n" + "      <link rel=\"edit\" title=\"x\" href=\"VM1.x('x')\" />\n" + "      <category term=\"PM1.G2\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" />\n" + "      <content type=\"application/xml\">\n" + "         <m:properties>\n" + "            <d:e1>32</d:e1>\n" + "            <d:e3 m:type=\"Collection(Edm.Int32)\">\n" + "               <d:element>1</d:element>\n" + "               <d:element>2</d:element>\n" + "               <d:element>3</d:element>\n" + "            </d:e3>\n" + "         </m:properties>\n" + "      </content>\n" + "   </entry>\n" + "</feed>";
    ResultSetExecution excution = helpExecute(query, result, expectedURL, 200, metadata);
    assertArrayEquals(new Object[] { 32, new Integer[] { 1, 2, 3 } }, excution.next().toArray(new Object[2]));
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Procedure(org.teiid.metadata.Procedure) EdmDataServices(org.odata4j.edm.EdmDataServices) FileReader(java.io.FileReader) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

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