Search in sources :

Example 21 with KeyRecord

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

the class ODataSchemaBuilder method addTableAnnotations.

private static void addTableAnnotations(Table table, CsdlEntityType entityType, CsdlSchema csdlSchema) {
    if (table.getAnnotation() != null) {
        addStringAnnotation(entityType, "core.Description", table.getAnnotation());
    }
    if (table.getCardinality() != -1) {
        addIntAnnotation(entityType, "teiid.CARDINALITY", table.getCardinality());
    }
    if (table.isMaterialized()) {
        if (table.getMaterializedTable() != null) {
            addStringAnnotation(entityType, "teiid.MATERIALIZED_TABLE", table.getMaterializedTable().getFullName());
        }
        if (table.getMaterializedStageTable() != null) {
            addStringAnnotation(entityType, "teiid.MATERIALIZED_STAGE_TABLE", table.getMaterializedStageTable().getFullName());
        }
    }
    if (table.getNameInSource() != null) {
        addStringAnnotation(entityType, "teiid.NAMEINSOURCE", table.getNameInSource());
    }
    if (table.getAccessPatterns() != null && !table.getAccessPatterns().isEmpty()) {
        ArrayList<String> values = new ArrayList<String>();
        for (KeyRecord record : table.getAccessPatterns()) {
            StringBuilder sb = new StringBuilder();
            for (Column c : record.getColumns()) {
                if (sb.length() > 0) {
                    sb.append(",");
                }
                sb.append(c.getName());
            }
            values.add(sb.toString());
        }
        addStringCollectionAnnotation(entityType, "teiid.ACCESS_PATTERNS", values);
    }
    if (table.supportsUpdate()) {
        addBooleanAnnotation(entityType, "teiid.UPDATABLE", table.supportsUpdate());
    }
    // add all custom properties
    for (String property : table.getProperties().keySet()) {
        addTerm(normalizeTermName(property), new String[] { "EntityType" }, csdlSchema);
        addStringAnnotation(entityType, csdlSchema.getAlias() + "." + normalizeTermName(property), table.getProperties().get(property));
    }
}
Also used : KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList)

Example 22 with KeyRecord

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

the class DocumentNode method addDefaultOrderBy.

OrderBy addDefaultOrderBy() {
    if (this.table == null) {
        return null;
    }
    OrderBy orderBy = new OrderBy();
    // provide implicit ordering for cursor logic
    KeyRecord record = this.table.getPrimaryKey();
    if (record == null) {
        // if PK is not available there MUST at least one unique key
        record = this.table.getUniqueKeys().get(0);
    }
    // provide implicit ordering for cursor logic
    for (Column column : record.getColumns()) {
        ElementSymbol expr = new ElementSymbol(column.getName(), this.groupSymbol);
        orderBy.addVariable(expr);
        addProjectedColumn(column.getName(), expr);
    }
    return orderBy;
}
Also used : KeyRecord(org.teiid.metadata.KeyRecord) ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ProjectedColumn(org.teiid.olingo.ProjectedColumn) Column(org.teiid.metadata.Column)

Aggregations

KeyRecord (org.teiid.metadata.KeyRecord)22 Column (org.teiid.metadata.Column)18 Table (org.teiid.metadata.Table)14 ArrayList (java.util.ArrayList)11 LinkedHashMap (java.util.LinkedHashMap)3 Test (org.junit.Test)3 ForeignKey (org.teiid.metadata.ForeignKey)3 MetadataStore (org.teiid.metadata.MetadataStore)3 Schema (org.teiid.metadata.Schema)3 QueryNode (org.teiid.query.mapping.relational.QueryNode)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 TranslatorException (org.teiid.translator.TranslatorException)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Properties (java.util.Properties)2 EntityType (javax.persistence.metamodel.EntityType)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 ChildRelationship (com.sforce.soap.partner.ChildRelationship)1 BatchUpdateException (java.sql.BatchUpdateException)1