use of com.sforce.soap.partner.ChildRelationship in project teiid by teiid.
the class SalesForceMetadataProcessor method addRelationships.
private void addRelationships() {
for (Map.Entry<String, ChildRelationship[]> entry : this.relationships.entrySet()) {
for (ChildRelationship relationship : entry.getValue()) {
if (relationship.getRelationshipName() == null) {
// not queryable
continue;
}
if (!isModelAuditFields() && isAuditField(relationship.getField())) {
continue;
}
Table parent = tableMap.get(entry.getKey());
KeyRecord pk = parent.getPrimaryKey();
if (null == pk) {
// $NON-NLS-1$
throw new RuntimeException("ERROR !!primary key column not found!!");
}
Table child = tableMap.get(relationship.getChildSObject());
if (child == null) {
// child must have been excluded
continue;
}
Column col = null;
columns = child.getColumns();
for (Iterator<Column> colIter = columns.iterator(); colIter.hasNext(); ) {
Column column = colIter.next();
if (column.getNameInSource().equals(relationship.getField())) {
col = column;
}
}
if (null == col) {
throw new RuntimeException(// $NON-NLS-1$
"ERROR !!foreign key column not found!! " + child.getName() + relationship.getField());
}
// $NON-NLS-1$ //$NON-NLS-2$
String name = "FK_" + parent.getName() + "_" + col.getName();
ArrayList<String> columnNames = new ArrayList<String>();
columnNames.add(col.getName());
ForeignKey fk = metadataFactory.addForeignKey(name, columnNames, parent.getName(), child);
// TODO: only needed for custom relationships
fk.setNameInSource(relationship.getRelationshipName());
}
}
}
Aggregations