Search in sources :

Example 11 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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 12 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestODataUpdateExecution method helpExecute.

private String helpExecute(String query, final String resultXML, String expectedURL, int[] responseCode, TransformationMetadata metadata, int times) throws Exception {
    ODataExecutionFactory translator = new ODataExecutionFactory();
    translator.start();
    TranslationUtility utility = new TranslationUtility(metadata);
    Command cmd = utility.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    WSConnection connection = Mockito.mock(WSConnection.class);
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(MessageContext.HTTP_REQUEST_HEADERS, new HashMap<String, List<String>>());
    headers.put(WSConnection.STATUS_CODE, new Integer(responseCode[0]));
    Dispatch<DataSource> dispatch = Mockito.mock(Dispatch.class);
    Mockito.stub(dispatch.getRequestContext()).toReturn(headers);
    Mockito.stub(dispatch.getResponseContext()).toReturn(headers);
    Mockito.stub(connection.createDispatch(Mockito.eq(HTTPBinding.HTTP_BINDING), Mockito.anyString(), Mockito.eq(DataSource.class), Mockito.eq(Mode.MESSAGE))).toReturn(dispatch);
    DataSource ds = new DataSource() {

        @Override
        public OutputStream getOutputStream() throws IOException {
            return new ByteArrayOutputStream();
        }

        @Override
        public String getName() {
            return "result";
        }

        @Override
        public InputStream getInputStream() throws IOException {
            ByteArrayInputStream in = new ByteArrayInputStream(resultXML.getBytes());
            return in;
        }

        @Override
        public String getContentType() {
            return "application/xml";
        }
    };
    ArgumentCaptor<DataSource> payload = ArgumentCaptor.forClass(DataSource.class);
    Mockito.stub(dispatch.invoke(payload.capture())).toReturn(ds);
    UpdateExecution execution = translator.createUpdateExecution(cmd, context, utility.createRuntimeMetadata(), connection);
    execution.execute();
    ArgumentCaptor<String> endpoint = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> binding = ArgumentCaptor.forClass(String.class);
    Mockito.verify(connection, Mockito.times(times)).createDispatch(binding.capture(), endpoint.capture(), Mockito.eq(DataSource.class), Mockito.eq(Mode.MESSAGE));
    Mockito.verify(dispatch, Mockito.times(times)).invoke(payload.capture());
    assertEquals(expectedURL, URLDecoder.decode(endpoint.getValue(), "utf-8"));
    if (payload.getAllValues() != null) {
        List<DataSource> listDS = payload.getAllValues();
        InputStream in = null;
        if (times > 1) {
            in = listDS.get(1).getInputStream();
        } else {
            in = listDS.get(0).getInputStream();
        }
        return new String(ObjectConverterUtil.convertToByteArray(in));
    }
    return "";
}
Also used : WSConnection(org.teiid.translator.WSConnection) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TranslationUtility(org.teiid.cdk.api.TranslationUtility) UpdateExecution(org.teiid.translator.UpdateExecution) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataSource(javax.activation.DataSource) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List)

Example 13 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestSAPODataMetadataProcessor method testSchema.

@Test
public void testSchema() throws Exception {
    translator = new SAPODataExecutionFactory();
    translator.start();
    String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("sap-metadata.xml"));
    SAPMetadataProcessor processor = new SAPMetadataProcessor();
    Properties props = new Properties();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "flight", 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(), "flight", 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(null, 1, "flight", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    // QueryParser.getQueryParser().parseDDL(mf2, ddl);
    TranslationUtility utility = new TranslationUtility(metadata);
    RuntimeMetadata rm = utility.createRuntimeMetadata();
    Table t = rm.getTable("flight", "SubscriptionCollection");
    assertNotNull(t);
    // check the label name
    assertNotNull(t.getColumnByName("persistNotifications"));
    assertTrue(!t.getColumnByName("ID").isUpdatable());
    assertEquals("Persist Notification", t.getColumnByName("persistNotifications").getAnnotation());
    // check filterable
    assertEquals(SearchType.Unsearchable, t.getColumnByName("persistNotifications").getSearchType());
    // check sortable
    assertEquals(SearchType.Unsearchable, t.getColumnByName("filter").getSearchType());
    // check visible
    assertEquals(false, t.getColumnByName("filter").isSelectable());
    // check required-in-filter
    assertEquals(1, t.getAccessPatterns().size());
    assertEquals(2, t.getAccessPatterns().get(0).getColumns().size());
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) Table(org.teiid.metadata.Table) InputStreamReader(java.io.InputStreamReader) TranslationUtility(org.teiid.cdk.api.TranslationUtility) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Properties(java.util.Properties) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Test(org.junit.Test)

Example 14 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestHotrodExecution method setup.

@BeforeClass
public static void setup() throws Exception {
    TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-5"));
    SERVER = new HotRodTestServer(PORT);
    MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
    EF = new InfinispanExecutionFactory();
    TransformationMetadata tm = TestProtobufMetadataProcessor.getTransformationMetadata(mf, EF);
    // String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    // System.out.println(ddl);
    METADATA = new RuntimeMetadataImpl(tm);
    UTILITY = new TranslationUtility(tm);
    InfinispanConnection connection = SERVER.getConnection();
    // only use G2 & G4 as cache only support single id
    connection.registerProtobufFile(new ProtobufResource("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
    EC = Mockito.mock(ExecutionContext.class);
    Mockito.stub(EC.getBatchSize()).toReturn(512);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) ExecutionContext(org.teiid.translator.ExecutionContext) MetadataFactory(org.teiid.metadata.MetadataFactory) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) HotRodTestServer(org.teiid.infinispan.api.HotRodTestServer) TranslationUtility(org.teiid.cdk.api.TranslationUtility) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) BeforeClass(org.junit.BeforeClass)

Example 15 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestIckleConversionVisitor method helpExecute.

private IckleConversionVisitor helpExecute(MetadataFactory mf, String query, String expected) throws Exception {
    InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
    TransformationMetadata metadata = TestProtobufMetadataProcessor.getTransformationMetadata(mf, ef);
    TranslationUtility utility = new TranslationUtility(metadata);
    Select cmd = (Select) utility.parseCommand(query);
    IckleConversionVisitor visitor = new IckleConversionVisitor(new RuntimeMetadataImpl(metadata), false);
    visitor.visitNode(cmd);
    if (!visitor.exceptions.isEmpty()) {
        throw visitor.exceptions.get(0);
    }
    String actual = visitor.getQuery();
    assertEquals(expected, actual);
    return visitor;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Select(org.teiid.language.Select)

Aggregations

TranslationUtility (org.teiid.cdk.api.TranslationUtility)76 Command (org.teiid.language.Command)52 Test (org.junit.Test)45 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 ExecutionContext (org.teiid.translator.ExecutionContext)33 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)26 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 MetadataFactory (org.teiid.metadata.MetadataFactory)13 FunctionTree (org.teiid.query.function.FunctionTree)11 UDFSource (org.teiid.query.function.UDFSource)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 Before (org.junit.Before)10 LdapContext (javax.naming.ldap.LdapContext)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 List (java.util.List)7 ResultSetExecution (org.teiid.translator.ResultSetExecution)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataSource (javax.activation.DataSource)6 WSConnection (org.teiid.translator.WSConnection)6