Search in sources :

Example 41 with Table

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

the class TestODataMetadataProcessor method testMultikeyPK.

@Test
public void testMultikeyPK() throws Exception {
    MetadataFactory mf = multiplePKMetadata();
    Table g1 = mf.getSchema().getTable("G1");
    assertNotNull(g1.getPrimaryKey().getColumnByName("e1"));
    assertNotNull(g1.getPrimaryKey().getColumnByName("e2"));
    assertNull(g1.getPrimaryKey().getColumnByName("e3"));
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Test(org.junit.Test)

Example 42 with Table

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

the class TestODataMetadataProcessor method testMultipleNavigationProperties.

@Test
public void testMultipleNavigationProperties() throws Exception {
    MetadataFactory mf = multipleNavigationProperties();
    String metadataDDL = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    Table g1 = mf.getSchema().getTable("G1");
    Table g2 = mf.getSchema().getTable("G2");
    ForeignKey fk = g2.getForeignKeys().get(0);
    assertEquals("G1_one_2_many", fk.getName());
    assertNotNull(fk.getColumnByName("e1"));
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ForeignKey(org.teiid.metadata.ForeignKey) Test(org.junit.Test)

Example 43 with Table

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

the class TestODataMetadataProcessor method testMultipleEnititySetWithSameComplexType.

@Test
public void testMultipleEnititySetWithSameComplexType() throws Exception {
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    CsdlComplexType address = complexType("Address");
    XMLMetadata metadata = buildXmlMetadata(createES("Persons", "namespace.Person"), buildPersonEntity(address), address, createES("Corporate", "namespace.Business"), buildBusinessEntity(address));
    processor.getMetadata(mf, metadata);
    assertEquals(5, mf.getSchema().getTables().size());
    assertNotNull(mf.getSchema().getTable("Persons"));
    assertNotNull(mf.getSchema().getTable("Corporate"));
    assertNotNull(mf.getSchema().getTable("Persons_address"));
    assertNotNull(mf.getSchema().getTable("Corporate_address"));
    Table personTable = mf.getSchema().getTable("Persons");
    assertEquals(2, personTable.getColumns().size());
    Table personAddress = mf.getSchema().getTable("Persons_address");
    assertEquals(4, personAddress.getColumns().size());
    ForeignKey fk = personAddress.getForeignKeys().get(0);
    assertNotNull(fk.getColumnByName("Persons_ssn"));
    Table businessTable = mf.getSchema().getTable("Corporate");
    assertEquals(1, businessTable.getColumns().size());
    Table corporateAddress = mf.getSchema().getTable("Corporate_address");
    assertEquals(4, corporateAddress.getColumns().size());
    fk = corporateAddress.getForeignKeys().get(0);
    assertNotNull(fk.getColumnByName("Corporate_name"));
}
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 44 with Table

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

the class ODataUpdateExecution method addAutoGeneretedKeys.

private void addAutoGeneretedKeys() {
    OEntity entity = this.response.getResultsIter().next().getEntity();
    Table table = this.visitor.getEnityTable();
    int cols = table.getPrimaryKey().getColumns().size();
    Class<?>[] columnDataTypes = new Class<?>[cols];
    String[] columnNames = new String[cols];
    // this is typically expected to be an int/long, but we'll be general here.  we may eventual need the type logic off of the metadata importer
    for (int i = 0; i < cols; i++) {
        columnDataTypes[i] = table.getPrimaryKey().getColumns().get(i).getJavaType();
        columnNames[i] = table.getPrimaryKey().getColumns().get(i).getName();
    }
    GeneratedKeys generatedKeys = this.executionContext.getCommandContext().returnGeneratedKeys(columnNames, columnDataTypes);
    List<Object> vals = new ArrayList<Object>(columnDataTypes.length);
    for (int i = 0; i < columnDataTypes.length; i++) {
        OProperty<?> prop = entity.getProperty(columnNames[i]);
        Object value = this.translator.retrieveValue(prop.getValue(), columnDataTypes[i]);
        vals.add(value);
    }
    generatedKeys.addKey(vals);
}
Also used : Table(org.teiid.metadata.Table) ArrayList(java.util.ArrayList) GeneratedKeys(org.teiid.GeneratedKeys) OEntity(org.odata4j.core.OEntity)

Example 45 with Table

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

the class SAPMetadataProcessor method addEntitySetAsTable.

@Override
protected Table addEntitySetAsTable(MetadataFactory mf, EdmEntitySet entitySet) throws TranslatorException {
    Table table = super.addEntitySetAsTable(mf, entitySet);
    KeyRecord accessPattern = this.accessPatterns.get(table);
    if (accessPattern != null) {
        table.getAccessPatterns().add(accessPattern);
    }
    return table;
}
Also used : KeyRecord(org.teiid.metadata.KeyRecord) Table(org.teiid.metadata.Table)

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