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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations