Search in sources :

Example 1 with FullQualifiedName

use of org.apache.olingo.commons.api.edm.FullQualifiedName in project teiid by teiid.

the class ODataSchemaBuilder method buildReverseNavigation.

private static CsdlNavigationProperty buildReverseNavigation(Table table, ForeignKey fk) {
    String refSchemaName = table.getParent().getName();
    CsdlNavigationProperty navigaton = new CsdlNavigationProperty();
    navigaton.setName(table.getName() + "_" + fk.getName()).setType(new FullQualifiedName(refSchemaName, table.getName()));
    ArrayList<CsdlReferentialConstraint> constrainsts = new ArrayList<CsdlReferentialConstraint>();
    for (int i = 0; i < fk.getColumns().size(); i++) {
        Column c = fk.getColumns().get(i);
        String refColumn = fk.getReferenceColumns().get(i);
        CsdlReferentialConstraint constraint = new CsdlReferentialConstraint();
        constraint.setProperty(refColumn);
        constraint.setReferencedProperty(c.getName());
    }
    navigaton.setReferentialConstraints(constrainsts);
    return navigaton;
}
Also used : Column(org.teiid.metadata.Column) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) ArrayList(java.util.ArrayList)

Example 2 with FullQualifiedName

use of org.apache.olingo.commons.api.edm.FullQualifiedName in project teiid by teiid.

the class ODataSchemaBuilder method buildEntityTypes.

static void buildEntityTypes(String namespace, org.teiid.metadata.Schema schema, CsdlSchema csdlSchema) {
    Map<String, CsdlEntitySet> entitySets = new LinkedHashMap<String, CsdlEntitySet>();
    Map<String, CsdlEntityType> entityTypes = new LinkedHashMap<String, CsdlEntityType>();
    String fullSchemaName = namespace + "." + schema.getName();
    for (Table table : schema.getTables().values()) {
        // skip if the table does not have the PK or unique
        KeyRecord primaryKey = getIdentifier(table);
        if (primaryKey == null) {
            LogManager.logDetail(LogConstants.CTX_ODATA, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16017, table.getFullName()));
            continue;
        }
        String entityTypeName = table.getName();
        CsdlEntityType entityType = new CsdlEntityType().setName(entityTypeName);
        // adding properties
        List<CsdlProperty> properties = new ArrayList<CsdlProperty>();
        for (Column c : table.getColumns()) {
            boolean nullable = c.getNullType() == NullType.Nullable;
            CsdlProperty property = buildProperty(c, isPartOfPrimaryKey(table, c.getName()) ? false : nullable);
            addColumnAnnotations(c, property, csdlSchema);
            properties.add(property);
        }
        entityType.setProperties(properties);
        if (hasStream(properties)) {
            entityType.setHasStream(true);
        }
        // set keys
        ArrayList<CsdlPropertyRef> keyProps = new ArrayList<CsdlPropertyRef>();
        for (Column c : primaryKey.getColumns()) {
            keyProps.add(new CsdlPropertyRef().setName(c.getName()));
        }
        entityType.setKey(keyProps);
        addTableAnnotations(table, entityType, csdlSchema);
        // entity set one for one entity type
        CsdlEntitySet entitySet = new CsdlEntitySet().setName(table.getName()).setType(new FullQualifiedName(fullSchemaName, table.getName())).setIncludeInServiceDocument(true);
        // add entity types for entity schema
        entityTypes.put(entityTypeName, entityType);
        entitySets.put(entityTypeName, entitySet);
    }
    buildNavigationProperties(schema, entityTypes, entitySets);
    // entity container is holder entity sets, association sets, function
    // imports
    CsdlEntityContainer entityContainer = new CsdlEntityContainer().setName(schema.getName()).setEntitySets(new ArrayList<CsdlEntitySet>(entitySets.values()));
    // build entity schema
    csdlSchema.setEntityTypes(new ArrayList<CsdlEntityType>(entityTypes.values())).setEntityContainer(entityContainer);
}
Also used : Table(org.teiid.metadata.Table) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column)

Example 3 with FullQualifiedName

use of org.apache.olingo.commons.api.edm.FullQualifiedName in project teiid by teiid.

the class ODataSchemaBuilder method buildNavigation.

private static CsdlNavigationProperty buildNavigation(ForeignKey fk) {
    String refSchemaName = fk.getReferenceKey().getParent().getParent().getName();
    CsdlNavigationProperty navigaton = new CsdlNavigationProperty();
    navigaton.setName(fk.getName()).setType(new FullQualifiedName(refSchemaName, fk.getReferenceTableName()));
    ArrayList<CsdlReferentialConstraint> constrainsts = new ArrayList<CsdlReferentialConstraint>();
    for (int i = 0; i < fk.getColumns().size(); i++) {
        Column c = fk.getColumns().get(i);
        String refColumn = fk.getReferenceColumns().get(i);
        CsdlReferentialConstraint constraint = new CsdlReferentialConstraint();
        constraint.setProperty(c.getName());
        constraint.setReferencedProperty(refColumn);
    }
    navigaton.setReferentialConstraints(constrainsts);
    return navigaton;
}
Also used : Column(org.teiid.metadata.Column) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) ArrayList(java.util.ArrayList)

Example 4 with FullQualifiedName

use of org.apache.olingo.commons.api.edm.FullQualifiedName in project teiid by teiid.

the class ComplexDocumentNode method buildComplexDocumentNode.

public static ComplexDocumentNode buildComplexDocumentNode(EdmOperation edmOperation, MetadataStore metadata, OData odata, UniqueNameGenerator nameGenerator, boolean useAlias, UriInfo uriInfo, URLParseService parseService) throws TeiidProcessingException {
    ComplexDocumentNode resource = new ComplexDocumentNode();
    FullQualifiedName fqn = edmOperation.getFullQualifiedName();
    String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.') + 1);
    Schema schema = metadata.getSchema(withoutVDB);
    Procedure procedure = schema.getProcedure(edmOperation.getName());
    StoredProcedure storedQuery = new StoredProcedure();
    // $NON-NLS-1$
    storedQuery.setProcedureName(procedure.getFullName());
    for (int i = 0; i < procedure.getParameters().size(); i++) {
        storedQuery.setParameter(new SPParameter(i + 1, new Reference(i)));
    }
    String group = nameGenerator.getNextGroup();
    // $NON-NLS-1$
    SubqueryFromClause sfc = new SubqueryFromClause(group, storedQuery);
    resource.setGroupSymbol(new GroupSymbol(group));
    resource.setFromClause(sfc);
    resource.procedure = procedure;
    return resource;
}
Also used : StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) SPParameter(org.teiid.query.sql.lang.SPParameter) Reference(org.teiid.query.sql.symbol.Reference) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) Schema(org.teiid.metadata.Schema) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Procedure(org.teiid.metadata.Procedure) SubqueryFromClause(org.teiid.query.sql.lang.SubqueryFromClause)

Example 5 with FullQualifiedName

use of org.apache.olingo.commons.api.edm.FullQualifiedName in project teiid by teiid.

the class TestODataMetadataProcessor method createES.

static CsdlEntitySet createES(String name, String entityType) {
    CsdlEntitySet es = new CsdlEntitySet();
    es.setName(name);
    es.setType(new FullQualifiedName(entityType));
    return es;
}
Also used : FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName)

Aggregations

FullQualifiedName (org.apache.olingo.commons.api.edm.FullQualifiedName)10 ArrayList (java.util.ArrayList)5 Column (org.teiid.metadata.Column)3 Procedure (org.teiid.metadata.Procedure)3 Properties (java.util.Properties)2 XMLMetadata (org.apache.olingo.client.api.edm.xml.XMLMetadata)2 ClientCsdlXMLMetadata (org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata)2 EdmPrimitiveTypeKind (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)2 MetadataFactory (org.teiid.metadata.MetadataFactory)2 ProcedureParameter (org.teiid.metadata.ProcedureParameter)2 Schema (org.teiid.metadata.Schema)2 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)2 LinkedHashMap (java.util.LinkedHashMap)1 KeyRecord (org.teiid.metadata.KeyRecord)1 Table (org.teiid.metadata.Table)1 SPParameter (org.teiid.query.sql.lang.SPParameter)1 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)1 SubqueryFromClause (org.teiid.query.sql.lang.SubqueryFromClause)1 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)1 Reference (org.teiid.query.sql.symbol.Reference)1