use of org.teiid.util.FullyQualifiedName in project teiid by teiid.
the class ODataMetadataProcessor method addComplexPropertyAsTable.
private void addComplexPropertyAsTable(MetadataFactory mf, CsdlProperty parentProperty, CsdlComplexType complexType, XMLMetadata metadata, Table parentTable) throws TranslatorException {
String tableName = parentTable.getName() + NAME_SEPARATOR + parentProperty.getName();
Table childTable = buildTable(mf, tableName);
String parent = parentTable.getProperty(FQN, false);
// $NON-NLS-1$
childTable.setProperty(FQN, parent + FullyQualifiedName.SEPARATOR + new FullyQualifiedName("complex property", parentProperty.getName()).toString());
// complex type
childTable.setProperty(NAME_IN_SCHEMA, parentProperty.getType());
childTable.setProperty(ODATA_TYPE, parentProperty.isCollection() ? ODataType.COMPLEX_COLLECTION.name() : // complex type
ODataType.COMPLEX.name());
// add a primary key to complex table
KeyRecord pk = parentTable.getPrimaryKey();
List<Column> pkColumns = new ArrayList<Column>();
for (Column c : pk.getColumns()) {
String colName = parentTable.getName() + NAME_SEPARATOR + c.getName();
// if the parent is already a complex, just copy the its PK
if (isComplexType(parentTable)) {
colName = c.getName();
}
Column col = addColumn(mf, childTable, c, colName);
pkColumns.add(col);
col.setProperty(PSEUDO, String.valueOf(Boolean.TRUE));
}
mf.addPrimaryKey("PK0", getColumnNames(pkColumns), childTable);
mf.addForeignKey("FK0", getColumnNames(pkColumns), getColumnNames(pk.getColumns()), parentTable.getFullName(), childTable);
if (isComplexType(parentTable)) {
childTable.setNameInSource(parentTable.getNameInSource() + "/" + parentProperty.getName());
} else {
childTable.setNameInSource(parentProperty.getName());
}
List<CsdlProperty> complexTypes = new ArrayList<CsdlProperty>();
for (CsdlProperty property : complexType.getProperties()) {
if (!addProperty(mf, metadata, childTable, property)) {
complexTypes.add(property);
}
}
// add properties from base type; if any to flatten the model
String baseType = complexType.getBaseType();
while (baseType != null) {
CsdlComplexType baseComplexType = getComplexType(metadata, baseType);
for (CsdlProperty property : baseComplexType.getProperties()) {
if (!addProperty(mf, metadata, childTable, property)) {
complexTypes.add(property);
}
}
baseType = baseComplexType.getBaseType();
}
for (CsdlProperty property : complexTypes) {
addComplexPropertyAsTable(mf, property, getComplexType(metadata, property.getType()), metadata, childTable);
}
}
use of org.teiid.util.FullyQualifiedName in project teiid by teiid.
the class JDBCMetadataProcessor method addTable.
/**
* @param metadataFactory
* @param tableCatalog
* @param tableSchema
* @param tableName
* @param remarks
* @param fullName
* @return
*/
protected Table addTable(MetadataFactory metadataFactory, String tableCatalog, String tableSchema, String tableName, String remarks, String fullName) {
Table table = metadataFactory.addTable(useFullSchemaName ? fullName : tableName);
table.setNameInSource(getFullyQualifiedName(tableCatalog, tableSchema, tableName, true));
// create a fqn for the table
FullyQualifiedName fqn = new FullyQualifiedName();
if (tableCatalog != null && !tableCatalog.isEmpty()) {
fqn.append(getCatalogTerm(), tableCatalog);
}
if (tableSchema != null && !tableSchema.isEmpty()) {
fqn.append(getSchemaTerm(), tableSchema);
}
fqn.append(getTableTerm(), tableName);
table.setProperty(FQN, fqn.toString());
table.setSupportsUpdate(true);
table.setAnnotation(remarks);
return table;
}
use of org.teiid.util.FullyQualifiedName in project teiid by teiid.
the class MongoDBMetadataProcessor method addTable.
private Table addTable(MetadataFactory metadataFactory, String tableName, BasicDBObject row, Table parent) {
Table table = null;
if (metadataFactory.getSchema().getTable(tableName) != null) {
table = metadataFactory.getSchema().getTable(tableName);
}
Set<String> keys = row.keySet();
if (keys != null && !keys.isEmpty()) {
if (table == null) {
table = metadataFactory.addTable(tableName);
table.setSupportsUpdate(true);
if (parent != null) {
// $NON-NLS-1$
FullyQualifiedName rn = new FullyQualifiedName("embedded", tableName);
String parentfqn = parent.getProperty(FQN, false);
table.setProperty(FQN, parentfqn + FullyQualifiedName.SEPARATOR + rn.toString());
} else {
// $NON-NLS-1$
FullyQualifiedName fqn = new FullyQualifiedName("collection", tableName);
table.setProperty(FQN, fqn.toString());
}
}
for (String columnKey : keys) {
Object value = row.get(columnKey);
Column column = addColumn(metadataFactory, table, columnKey, value);
if (column != null) {
column.setUpdatable(true);
}
}
return table;
}
return null;
}
use of org.teiid.util.FullyQualifiedName in project teiid by teiid.
the class ODataMetadataProcessor method getMetadata.
void getMetadata(MetadataFactory mf, XMLMetadata metadata) throws TranslatorException {
CsdlSchema csdlSchema = getDefaultSchema(metadata);
CsdlEntityContainer container = csdlSchema.getEntityContainer();
if (container == null) {
throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17035, csdlSchema.getNamespace()));
}
// add entity sets as tables
for (CsdlEntitySet entitySet : container.getEntitySets()) {
Table t = addTable(mf, entitySet.getName(), entitySet.getType(), ODataType.ENTITY_COLLECTION, metadata);
// $NON-NLS-1$ //$NON-NLS-2$
FullyQualifiedName fqn = new FullyQualifiedName("entity container", container.getName() == null ? "default" : container.getName());
// $NON-NLS-1$
fqn.append("entity set", entitySet.getName());
t.setProperty(FQN, fqn.toString());
}
// add singletons sets as tables
for (CsdlSingleton singleton : container.getSingletons()) {
Table t = addTable(mf, singleton.getName(), singleton.getType(), ODataType.ENTITY_COLLECTION, metadata);
// $NON-NLS-1$ //$NON-NLS-2$
FullyQualifiedName fqn = new FullyQualifiedName("entity container", container.getName() == null ? "default" : container.getName());
// $NON-NLS-1$
fqn.append("singleton", singleton.getName());
t.setProperty(FQN, fqn.toString());
}
// build relationships among tables
for (CsdlEntitySet entitySet : container.getEntitySets()) {
addNavigationProperties(mf, entitySet.getName(), entitySet, metadata, container);
}
for (CsdlSingleton singleton : container.getSingletons()) {
addNavigationProperties(mf, singleton.getName(), singleton, metadata, container);
}
// add functions
for (CsdlFunctionImport function : container.getFunctionImports()) {
addFunctionImportAsProcedure(mf, function, ODataType.FUNCTION, metadata);
}
// add actions
for (CsdlActionImport action : container.getActionImports()) {
addActionImportAsProcedure(mf, action, ODataType.ACTION, metadata);
}
}
use of org.teiid.util.FullyQualifiedName in project teiid by teiid.
the class SalesForceMetadataProcessor method addTable.
private void addTable(DescribeGlobalSObjectResult objectMetadata) {
String name = objectMetadata.getName();
if (normalizeNames) {
name = NameUtil.normalizeName(name);
}
if (!allowedToAdd(name)) {
return;
}
Table table = metadataFactory.addTable(name);
// $NON-NLS-1$
FullyQualifiedName fqn = new FullyQualifiedName("sobject", objectMetadata.getName());
table.setProperty(FQN, fqn.toString());
table.setNameInSource(objectMetadata.getName());
tableMap.put(objectMetadata.getName(), table);
table.setProperty(TABLE_CUSTOM, String.valueOf(objectMetadata.isCustom()));
table.setProperty(TABLE_SUPPORTS_CREATE, String.valueOf(objectMetadata.isCreateable()));
table.setProperty(TABLE_SUPPORTS_DELETE, String.valueOf(objectMetadata.isDeletable()));
table.setProperty(TABLE_SUPPORTS_MERGE, String.valueOf(objectMetadata.isMergeable()));
table.setProperty(TABLE_SUPPORTS_QUERY, String.valueOf(objectMetadata.isQueryable()));
table.setProperty(TABLE_SUPPORTS_REPLICATE, String.valueOf(objectMetadata.isReplicateable()));
table.setProperty(TABLE_SUPPORTS_RETRIEVE, String.valueOf(objectMetadata.isRetrieveable()));
table.setProperty(TABLE_SUPPORTS_SEARCH, String.valueOf(objectMetadata.isSearchable()));
}
Aggregations