Search in sources :

Example 31 with Table

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

the class ODataMetadataProcessor method addEntitySetAsTable.

protected Table addEntitySetAsTable(MetadataFactory mf, EdmEntitySet entitySet) throws TranslatorException {
    Table table = buildTable(mf, entitySet);
    table.setProperty(ENTITY_TYPE, entitySet.getType().getFullyQualifiedTypeName());
    // add columns
    for (EdmProperty ep : entitySet.getType().getProperties().toList()) {
        if (ep.getType().isSimple() || (ep.getType() instanceof EdmCollectionType && ((EdmCollectionType) ep.getType()).getItemType().isSimple())) {
            addPropertyAsColumn(mf, table, ep, entitySet);
        } else {
            // this is complex type, i.e treat them as embeddable in the same table add all columns.
            // Have tried adding this as separate table with 1 to 1 mapping to parent table, however
            // that model fails when there are two instances of single complex type as column. This
            // creates verbose columns but safe.
            EdmComplexType embedded = (EdmComplexType) ep.getType();
            for (EdmProperty property : embedded.getProperties().toList()) {
                if (property.getType().isSimple() || (property.getType() instanceof EdmCollectionType && ((EdmCollectionType) property.getType()).getItemType().isSimple())) {
                    Column column = addPropertyAsColumn(mf, table, property, entitySet, ep.getName());
                    // complex type
                    column.setProperty(COMPLEX_TYPE, embedded.getFullyQualifiedTypeName());
                    // name of parent column
                    column.setProperty(COLUMN_GROUP, ep.getName());
                } else {
                    throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17002, entitySet.getName(), ep.getName()));
                }
            }
        }
    }
    // add PK
    // $NON-NLS-1$
    mf.addPrimaryKey("PK", entitySet.getType().getKeys(), table);
    return table;
}
Also used : Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException)

Example 32 with Table

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

the class ODataMetadataProcessor method buildTable.

protected Table buildTable(MetadataFactory mf, EdmEntitySet entitySet) {
    Table table = mf.addTable(entitySet.getName());
    table.setSupportsUpdate(true);
    return table;
}
Also used : Table(org.teiid.metadata.Table)

Example 33 with Table

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

the class TestODataMetadataProcessor method testManytoManyAssosiation.

@Test
public void testManytoManyAssosiation() 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.MANY);
    EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.MANY);
    EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("m_2_m").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();
    EdmEntitySet g2Set = EdmEntitySet.newBuilder().setName("G2").setEntityType(g2Entity).build();
    processor.addEntitySetAsTable(mf, g1Set);
    processor.addEntitySetAsTable(mf, g2Set);
    processor.addNavigationRelations(mf, "G2", g2Entity.build());
    Table g1 = mf.getSchema().getTable("G1");
    Table g2 = mf.getSchema().getTable("G2");
    Table linkTable = mf.getSchema().getTable("m_2_m");
    assertEquals(1, linkTable.getColumns().size());
    assertEquals("e1", linkTable.getColumns().get(0).getName());
    assertNotNull(linkTable);
    assertEquals("G2,G1", linkTable.getProperty(ODataMetadataProcessor.LINK_TABLES, false));
    ForeignKey fk1 = linkTable.getForeignKeys().get(0);
    assertEquals("G2_FK", fk1.getName());
    assertNotNull(fk1.getColumnByName("e1"));
    ForeignKey fk2 = linkTable.getForeignKeys().get(1);
    assertEquals("G1_FK", fk2.getName());
    assertNotNull(fk2.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 34 with Table

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

the class TestODataMetadataProcessor method testManytoManyAssosiationWithReferntialConstraint.

@Test
public void testManytoManyAssosiationWithReferntialConstraint() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    EdmEntityType.Builder g1Entity = entityType("g1");
    g1Entity.addProperties(EdmProperty.newBuilder("g2e2").setType(EdmSimpleType.STRING).setNullable(false));
    EdmEntityType.Builder g2Entity = entityType("g2");
    EdmAssociationEnd.Builder aend1 = EdmAssociationEnd.newBuilder().setRole("source").setType(g1Entity).setMultiplicity(EdmMultiplicity.MANY);
    EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.MANY);
    EdmReferentialConstraint.Builder refContraint = EdmReferentialConstraint.newBuilder().addPrincipalReferences("e1").addDependentReferences("g2e2");
    EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("m_2_m").setEnds(aend2, aend1).setRefConstraint(refContraint);
    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();
    EdmEntitySet g2Set = EdmEntitySet.newBuilder().setName("G2").setEntityType(g2Entity).build();
    processor.addEntitySetAsTable(mf, g1Set);
    processor.addEntitySetAsTable(mf, g2Set);
    processor.addNavigationRelations(mf, "G2", g2Entity.build());
    Table g1 = mf.getSchema().getTable("G1");
    Table g2 = mf.getSchema().getTable("G2");
    Table linkTable = mf.getSchema().getTable("m_2_m");
    assertEquals(2, linkTable.getColumns().size());
    assertEquals("e1", linkTable.getColumns().get(0).getName());
    assertEquals("g2e2", linkTable.getColumns().get(1).getName());
    assertNotNull(linkTable);
    assertEquals("G2,G1", linkTable.getProperty(ODataMetadataProcessor.LINK_TABLES, false));
    ForeignKey fk = linkTable.getForeignKeys().get(0);
    assertEquals("G2_FK", fk.getName());
    assertNotNull(fk.getColumnByName("e1"));
    ForeignKey fk2 = linkTable.getForeignKeys().get(1);
    assertEquals("G1_FK", fk2.getName());
    assertNotNull(fk2.getColumnByName("g2e2"));
}
Also used : EdmAssociationEnd(org.odata4j.edm.EdmAssociationEnd) Table(org.teiid.metadata.Table) EdmReferentialConstraint(org.odata4j.edm.EdmReferentialConstraint) 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 35 with Table

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

the class TestODataMetadataProcessor method testEnititySetWithComplexType.

@Test
public void testEnititySetWithComplexType() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    EdmEntitySet es = EdmEntitySet.newBuilder().setName("Person").setEntityType(buildPersonEntity(buildAddressEntity().build())).build();
    processor.addEntitySetAsTable(mf, es);
    assertEquals(1, mf.getSchema().getTables().size());
    assertNotNull(mf.getSchema().getTable("Person"));
    Table personTable = mf.getSchema().getTable("Person");
    assertEquals(5, personTable.getColumns().size());
    assertNotNull(personTable.getColumnByName("address_street"));
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmEntitySet(org.odata4j.edm.EdmEntitySet) 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