Search in sources :

Example 1 with EdmDataServices

use of org.odata4j.edm.EdmDataServices 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)

Example 2 with EdmDataServices

use of org.odata4j.edm.EdmDataServices in project teiid by teiid.

the class TestODataSQLVistor method setUp.

@Before
public void setUp() throws Exception {
    translator = new ODataExecutionFactory();
    translator.start();
    String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
    EdmDataServices eds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes()))));
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    Properties props = new Properties();
    props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
    props.setProperty("entityContainer", "NorthwindEntities");
    MetadataFactory mf = new MetadataFactory("vdb", 1, "nw", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.getMetadata(mf, eds);
    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());
    }
    // TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
    utility = new TranslationUtility(metadata);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) InputStreamReader(java.io.InputStreamReader) TranslationUtility(org.teiid.cdk.api.TranslationUtility) 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) EdmDataServices(org.odata4j.edm.EdmDataServices) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Before(org.junit.Before)

Example 3 with EdmDataServices

use of org.odata4j.edm.EdmDataServices in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    String URI = this.visitor.buildURL();
    Schema schema = visitor.getProcedure().getParent();
    EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
    if (this.visitor.hasCollectionReturn()) {
        if (this.visitor.isReturnComplexType()) {
            // complex return
            this.response = executeWithComplexReturn(this.visitor.getMethod(), URI, null, this.visitor.getReturnEntityTypeName(), edm, null, Status.OK, Status.NO_CONTENT);
        } else {
            // entity type return
            this.response = executeWithReturnEntity(this.visitor.getMethod(), URI, null, this.visitor.getTable().getName(), edm, null, Status.OK, Status.NO_CONTENT);
        }
        if (this.response != null && this.response.hasError()) {
            throw this.response.getError();
        }
    } else {
        try {
            BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), URI, null, getDefaultHeaders());
            if (execution.getResponseCode() != Status.OK.getStatusCode()) {
                throw buildError(execution);
            }
            Blob blob = (Blob) execution.getOutputParameterValues().get(0);
            ODataVersion version = getODataVersion(execution);
            // if the procedure is not void
            if (this.visitor.getReturnType() != null) {
                FormatParser<? extends OObject> parser = FormatParserFactory.getParser(OSimpleObject.class, FormatType.ATOM, new Settings(version, edm, this.visitor.getProcedure().getName(), // entitykey
                null, // isResponse
                true, ODataTypeManager.odataType(this.visitor.getReturnType())));
                OSimpleObject object = (OSimpleObject) parser.parse(new InputStreamReader(blob.getBinaryStream()));
                this.returnValue = this.translator.retrieveValue(object.getValue(), this.visitor.getReturnTypeClass());
            }
        } catch (SQLException e) {
            throw new TranslatorException(e);
        }
    }
}
Also used : Blob(java.sql.Blob) OSimpleObject(org.odata4j.core.OSimpleObject) InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) Schema(org.teiid.metadata.Schema) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ODataVersion(org.odata4j.core.ODataVersion) EdmDataServices(org.odata4j.edm.EdmDataServices) TranslatorException(org.teiid.translator.TranslatorException) Settings(org.odata4j.format.Settings)

Example 4 with EdmDataServices

use of org.odata4j.edm.EdmDataServices in project teiid by teiid.

the class ODataQueryExecution method execute.

@Override
public void execute() throws TranslatorException {
    String URI = this.visitor.buildURL();
    if (this.visitor.isCount()) {
        Map<String, List<String>> headers = new TreeMap<String, List<String>>();
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        headers.put("Accept", Arrays.asList("text/xml", "text/plain"));
        // $NON-NLS-1$
        BinaryWSProcedureExecution execution = executeDirect("GET", URI, null, headers);
        if (execution.getResponseCode() != Status.OK.getStatusCode()) {
            throw buildError(execution);
        }
        Blob blob = (Blob) execution.getOutputParameterValues().get(0);
        try {
            this.countResponse = Integer.parseInt(ObjectConverterUtil.convertToString(blob.getBinaryStream()));
        } catch (IOException e) {
            throw new TranslatorException(e);
        } catch (SQLException e) {
            throw new TranslatorException(e);
        }
    } else {
        Schema schema = visitor.getEnityTable().getParent();
        EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
        // $NON-NLS-1$
        this.response = executeWithReturnEntity("GET", URI, null, visitor.getEnityTable().getName(), edm, null, Status.OK, Status.NO_CONTENT, Status.NOT_FOUND);
        if (this.response != null && this.response.hasError()) {
            throw this.response.getError();
        }
    }
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) Schema(org.teiid.metadata.Schema) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException) EdmDataServices(org.odata4j.edm.EdmDataServices) IOException(java.io.IOException) TreeMap(java.util.TreeMap)

Example 5 with EdmDataServices

use of org.odata4j.edm.EdmDataServices in project teiid by teiid.

the class TestODataUpdateExecution method testArrayUpdate.

@Test
public void testArrayUpdate() 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());
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
    String query = "Update G2 set e3 = (1,2,3) where e1 = 1";
    String expectedURL = "G2(1)";
    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>";
    String payload = helpExecute(query, result, expectedURL, new int[] { 200, 204 }, metadata, 2);
    String expected = "<category term=\"PM1.G2\" " + "scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\">" + "</category>" + "<content type=\"application/xml\">" + "<m:properties><d:e3 m:type=\"Collection(Edm.Int32)\">" + "<d:element>1</d:element>" + "<d:element>2</d:element>" + "<d:element>3</d:element>" + "</d:e3>" + "</m:properties>" + "</content>" + "</entry>";
    assertTrue(expected, payload.endsWith(expected));
}
Also used : 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) EdmDataServices(org.odata4j.edm.EdmDataServices) FileReader(java.io.FileReader) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

EdmDataServices (org.odata4j.edm.EdmDataServices)7 EdmxFormatParser (org.odata4j.format.xml.EdmxFormatParser)4 MetadataFactory (org.teiid.metadata.MetadataFactory)4 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)4 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)4 FileReader (java.io.FileReader)3 Test (org.junit.Test)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 Column (org.teiid.metadata.Column)3 Schema (org.teiid.metadata.Schema)3 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)3 InputStreamReader (java.io.InputStreamReader)2 Blob (java.sql.Blob)2 SQLException (java.sql.SQLException)2 TranslatorException (org.teiid.translator.TranslatorException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 List (java.util.List)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1