Search in sources :

Example 36 with Table

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

the class TestODataMetadataProcessor method testOneToOneAssosiation.

@Test
public void testOneToOneAssosiation() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    EdmEntityType.Builder g1Entity = entityType("g1");
    EdmEntityType.Builder g2Entity = entityType("g2");
    EdmAssociationEnd.Builder aend1 = EdmAssociationEnd.newBuilder().setRole("source").setType(g1Entity).setMultiplicity(EdmMultiplicity.ONE);
    EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.ONE);
    EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("one_2_one").setEnds(aend2, aend1);
    EdmNavigationProperty.Builder navigation = EdmNavigationProperty.newBuilder("g1").setFromTo(aend2, aend1).setFromToName("source", "target").setRelationship(assocition);
    g2Entity.addNavigationProperties(navigation);
    EdmEntitySet g1Set = EdmEntitySet.newBuilder().setName("G1").setEntityType(g1Entity).build();
    processor.addEntitySetAsTable(mf, g1Set);
    EdmEntitySet g2Set = EdmEntitySet.newBuilder().setName("G2").setEntityType(g2Entity).build();
    processor.addEntitySetAsTable(mf, g2Set);
    processor.addNavigationRelations(mf, "G2", g2Entity.build());
    Table g1 = mf.getSchema().getTable("G1");
    Table g2 = mf.getSchema().getTable("G2");
    ForeignKey fk = g1.getForeignKeys().get(0);
    assertEquals("one_2_one", fk.getName());
    assertNotNull(fk.getColumnByName("e1"));
}
Also used : EdmAssociationEnd(org.odata4j.edm.EdmAssociationEnd) Table(org.teiid.metadata.Table) EdmEntityType(org.odata4j.edm.EdmEntityType) EdmNavigationProperty(org.odata4j.edm.EdmNavigationProperty) Properties(java.util.Properties) ForeignKey(org.teiid.metadata.ForeignKey) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmAssociation(org.odata4j.edm.EdmAssociation) EdmEntitySet(org.odata4j.edm.EdmEntitySet) Test(org.junit.Test)

Example 37 with Table

use of org.teiid.metadata.Table 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 38 with Table

use of org.teiid.metadata.Table 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 39 with Table

use of org.teiid.metadata.Table 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 40 with Table

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

Table (org.teiid.metadata.Table)239 Test (org.junit.Test)82 Column (org.teiid.metadata.Column)72 MetadataFactory (org.teiid.metadata.MetadataFactory)59 Properties (java.util.Properties)45 MetadataStore (org.teiid.metadata.MetadataStore)37 Schema (org.teiid.metadata.Schema)35 TranslatorException (org.teiid.translator.TranslatorException)30 ArrayList (java.util.ArrayList)27 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)27 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)23 List (java.util.List)22 ForeignKey (org.teiid.metadata.ForeignKey)22 Connection (java.sql.Connection)15 QueryNode (org.teiid.query.mapping.relational.QueryNode)15 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)15 KeyRecord (org.teiid.metadata.KeyRecord)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)13 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)13