Search in sources :

Example 21 with MetadataFactory

use of org.teiid.metadata.MetadataFactory 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 22 with MetadataFactory

use of org.teiid.metadata.MetadataFactory 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 23 with MetadataFactory

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

the class TestODataMetadataProcessor method testAssosiationWithReferentialContriant.

@Test
public void testAssosiationWithReferentialContriant() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    CsdlEntityType g1Entity = entityType("g1");
    g1Entity.getProperties().add(createProperty("g2e2", EdmPrimitiveTypeKind.String));
    g1Entity.setKey(Arrays.asList(new CsdlPropertyRef().setName("g2e2")));
    CsdlEntityType g2Entity = entityType("g2");
    CsdlNavigationProperty navProperty = new CsdlNavigationProperty();
    navProperty.setName("one_2_one");
    navProperty.setType("namespace.g2");
    navProperty.setNullable(false);
    navProperty.setPartner("PartnerPath");
    navProperty.setReferentialConstraints(Arrays.asList(new CsdlReferentialConstraint().setProperty("g2e2").setReferencedProperty("e2")));
    g1Entity.setNavigationProperties(Arrays.asList(navProperty));
    CsdlEntitySet g1Set = createES("G1", "namespace.g1");
    CsdlEntitySet g2Set = createES("G2", "namespace.g2");
    CsdlNavigationPropertyBinding navBinding = new CsdlNavigationPropertyBinding();
    navBinding.setPath("one_2_one");
    navBinding.setTarget("G2");
    g1Set.setNavigationPropertyBindings(Arrays.asList(navBinding));
    XMLMetadata metadata = buildXmlMetadata(g1Entity, g1Set, g2Entity, g2Set);
    processor.getMetadata(mf, metadata);
    Table g1 = mf.getSchema().getTable("G1");
    Table g2 = mf.getSchema().getTable("G2");
    assertNotNull(g1);
    assertNotNull(g2);
    ForeignKey fk = g1.getForeignKeys().get(0);
    assertEquals("G1_one_2_one", fk.getName());
    assertNotNull(fk.getColumnByName("g2e2"));
    assertEquals("e2", fk.getReferenceColumns().get(0));
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) XMLMetadata(org.apache.olingo.client.api.edm.xml.XMLMetadata) ClientCsdlXMLMetadata(org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata) Properties(java.util.Properties) ForeignKey(org.teiid.metadata.ForeignKey) Test(org.junit.Test)

Example 24 with MetadataFactory

use of org.teiid.metadata.MetadataFactory 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 25 with MetadataFactory

use of org.teiid.metadata.MetadataFactory 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)

Aggregations

MetadataFactory (org.teiid.metadata.MetadataFactory)159 Test (org.junit.Test)116 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)91 Properties (java.util.Properties)74 Table (org.teiid.metadata.Table)59 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 Procedure (org.teiid.metadata.Procedure)30 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)21 Column (org.teiid.metadata.Column)20 Connection (java.sql.Connection)18 FunctionTree (org.teiid.query.function.FunctionTree)15 UDFSource (org.teiid.query.function.UDFSource)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)14 TranslationUtility (org.teiid.cdk.api.TranslationUtility)13 ValidatorReport (org.teiid.query.validator.ValidatorReport)13 XMLMetadata (org.apache.olingo.client.api.edm.xml.XMLMetadata)12 ClientCsdlXMLMetadata (org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata)12 ForeignKey (org.teiid.metadata.ForeignKey)12