Search in sources :

Example 26 with MetadataFactory

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

the class TestODataMetadataProcessor method multipleNavigationProperties.

static MetadataFactory multipleNavigationProperties() throws TranslatorException {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    CsdlEntityType g1Entity = entityType("g1");
    CsdlEntityType g2Entity = entityType("g2");
    CsdlEntityType g3Entity = entityType("g3");
    CsdlNavigationProperty navProperty = new CsdlNavigationProperty();
    navProperty.setName("one_2_many");
    navProperty.setType("Collection(namespace.g2)");
    navProperty.setNullable(false);
    navProperty.setPartner("PartnerPath");
    navProperty.setCollection(true);
    CsdlNavigationProperty navProperty2 = new CsdlNavigationProperty();
    navProperty2.setName("one_2_g3");
    navProperty2.setType("namespace.g3");
    navProperty2.setNullable(true);
    g1Entity.setNavigationProperties(Arrays.asList(navProperty, navProperty2));
    CsdlEntitySet g1Set = createES("G1", "namespace.g1");
    CsdlEntitySet g2Set = createES("G2", "namespace.g2");
    CsdlEntitySet g3Set = createES("G3", "namespace.g3");
    CsdlNavigationPropertyBinding navBinding = new CsdlNavigationPropertyBinding();
    navBinding.setPath("one_2_many");
    navBinding.setTarget("G2");
    CsdlNavigationPropertyBinding navBinding2 = new CsdlNavigationPropertyBinding();
    navBinding2.setPath("one_2_g3");
    navBinding2.setTarget("G3");
    g1Set.setNavigationPropertyBindings(Arrays.asList(navBinding, navBinding2));
    XMLMetadata metadata = buildXmlMetadata(g1Entity, g1Set, g2Entity, g2Set, g3Entity, g3Set);
    processor.getMetadata(mf, metadata);
    return mf;
}
Also used : 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)

Example 27 with MetadataFactory

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

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

the class TestODataMetadataProcessor method testEnititySetWithComplexType.

@Test
public void testEnititySetWithComplexType() throws Exception {
    MetadataFactory mf = getEntityWithComplexProperty();
    assertEquals(3, mf.getSchema().getTables().size());
    assertNotNull(mf.getSchema().getTable("Persons"));
    assertNotNull(mf.getSchema().getTable("Persons_address"));
    assertNotNull(mf.getSchema().getTable("Persons_secondaddress"));
    Table personTable = mf.getSchema().getTable("Persons");
    assertEquals(2, personTable.getColumns().size());
    assertNotNull(personTable.getPrimaryKey());
    Table addressTable = mf.getSchema().getTable("Persons_address");
    assertEquals(4, addressTable.getColumns().size());
    assertNotNull(addressTable.getColumnByName("Persons_ssn"));
    assertTrue(ODataMetadataProcessor.isPseudo(addressTable.getColumnByName("Persons_ssn")));
    assertTrue(addressTable.getColumnByName("Persons_ssn").isSelectable());
    assertEquals(1, addressTable.getForeignKeys().size());
    assertEquals("northwind.Persons", addressTable.getForeignKeys().get(0).getReferenceTableName());
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Test(org.junit.Test)

Example 29 with MetadataFactory

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

the class TestODataMetadataProcessor method createMetadata.

private static MetadataFactory createMetadata(final String file, final String schema, final String schemaNamespace) throws TranslatorException {
    ODataMetadataProcessor processor = new ODataMetadataProcessor() {

        protected XMLMetadata getSchema(WSConnection conn) throws TranslatorException {
            try {
                ClientODataDeserializerImpl deserializer = new ClientODataDeserializerImpl(false, ContentType.APPLICATION_XML);
                XMLMetadata metadata = deserializer.toMetadata(new FileInputStream(UnitTestUtil.getTestDataFile(file)));
                return metadata;
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    };
    Properties props = new Properties();
    props.setProperty("schemaNamespace", schemaNamespace);
    processor.setSchemaNamespace(schemaNamespace);
    MetadataFactory mf = new MetadataFactory("vdb", 1, schema, SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.process(mf, null);
    return mf;
}
Also used : WSConnection(org.teiid.translator.WSConnection) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) FileNotFoundException(java.io.FileNotFoundException) ClientODataDeserializerImpl(org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl) XMLMetadata(org.apache.olingo.client.api.edm.xml.XMLMetadata) ClientCsdlXMLMetadata(org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 30 with MetadataFactory

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

the class TestODataMetadataProcessor method testSelfJoin.

@Test
public void testSelfJoin() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    CsdlEntityType g1Entity = entityType("g1");
    CsdlNavigationProperty navProperty = new CsdlNavigationProperty();
    navProperty.setName("self");
    navProperty.setType("Collection(namespace.g1)");
    navProperty.setNullable(false);
    navProperty.setPartner("PartnerPath");
    navProperty.setCollection(true);
    g1Entity.setNavigationProperties(Arrays.asList(navProperty));
    CsdlEntitySet g1Set = createES("G1", "namespace.g1");
    CsdlNavigationPropertyBinding navBinding = new CsdlNavigationPropertyBinding();
    navBinding.setPath("self");
    navBinding.setTarget("G1");
    g1Set.setNavigationPropertyBindings(Arrays.asList(navBinding));
    XMLMetadata metadata = buildXmlMetadata(g1Entity, g1Set);
    processor.getMetadata(mf, metadata);
    Table g1 = mf.getSchema().getTable("G1_self");
    assertNotNull(g1);
    assertEquals("FK0", g1.getForeignKeys().get(0).getName());
    assertNotNull(g1.getForeignKeys().get(0).getColumnByName("G1_e1"));
    assertEquals("self", g1.getNameInSource());
}
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) 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