use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class JoinStack method appendJoinSubtree.
protected void appendJoinSubtree(StringBuilder out, JoinTreeNode node) {
DbRelationship relationship = node.getRelationship();
DbEntity targetEntity = relationship.getTargetEntity();
String srcAlias = node.getSourceTableAlias();
String targetAlias = node.getTargetTableAlias();
switch(node.getJoinType()) {
case INNER:
out.append(" JOIN");
break;
case LEFT_OUTER:
out.append(" LEFT JOIN");
break;
default:
throw new IllegalArgumentException("Unsupported join type: " + node.getJoinType());
}
out.append(' ');
out.append(quotingStrategy.quotedFullyQualifiedName(targetEntity));
out.append(' ');
out.append(quotingStrategy.quotedIdentifier(targetEntity, targetAlias));
out.append(" ON (");
List<DbJoin> joins = relationship.getJoins();
int len = joins.size();
for (int i = 0; i < len; i++) {
DbJoin join = joins.get(i);
if (i > 0) {
out.append(" AND ");
}
out.append(quotingStrategy.quotedIdentifier(relationship.getSourceEntity(), srcAlias, join.getSourceName()));
out.append(" = ");
out.append(quotingStrategy.quotedIdentifier(targetEntity, targetAlias, join.getTargetName()));
}
/*
* Attaching root Db entity's qualifier
*/
Expression dbQualifier = targetEntity.getQualifier();
if (dbQualifier != null) {
dbQualifier = dbQualifier.transform(new JoinedDbEntityQualifierTransformer(node));
if (len > 0) {
out.append(" AND ");
}
qualifierTranslator.setOut(out);
qualifierTranslator.doAppendPart(dbQualifier);
}
out.append(')');
for (JoinTreeNode child : node.getChildren()) {
appendJoinSubtree(out, child);
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class OpenBaseJoinStack method appendQualifierSubtree.
protected void appendQualifierSubtree(StringBuilder out, JoinTreeNode node) {
DbRelationship relationship = node.getRelationship();
String srcAlias = node.getSourceTableAlias();
String targetAlias = node.getTargetTableAlias();
List<DbJoin> joins = relationship.getJoins();
int len = joins.size();
for (int i = 0; i < len; i++) {
DbJoin join = joins.get(i);
if (i > 0) {
out.append(" AND ");
}
out.append(srcAlias).append('.').append(join.getSourceName());
switch(node.getJoinType()) {
case INNER:
out.append(" = ");
break;
case LEFT_OUTER:
out.append(" * ");
break;
default:
throw new IllegalArgumentException("Unsupported join type: " + node.getJoinType());
}
out.append(targetAlias).append('.').append(join.getTargetName());
}
for (JoinTreeNode child : node.getChildren()) {
out.append(" AND ");
appendQualifierSubtree(out, child);
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class Oracle8JoinStack method appendJoinSubtree.
@Override
protected void appendJoinSubtree(StringBuilder out, JoinTreeNode node) {
DbRelationship relationship = node.getRelationship();
if (relationship == null) {
return;
}
DbEntity targetEntity = relationship.getTargetEntity();
String targetAlias = node.getTargetTableAlias();
out.append(", ").append(targetEntity.getFullyQualifiedName()).append(' ').append(targetAlias);
for (JoinTreeNode child : node.getChildren()) {
appendJoinSubtree(out, child);
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class DbAttributePathComboBoxEditor method createTreeModelForComboBox.
@Override
protected EntityTreeModel createTreeModelForComboBox(int attributeIndexInTable) {
ObjAttribute attribute = model.getAttribute(attributeIndexInTable).getValue();
Entity firstEntity = null;
if (attribute.getDbAttribute() == null) {
if (attribute.getParent() instanceof ObjEntity) {
DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
if (dbEnt != null) {
Collection<DbAttribute> attributes = dbEnt.getAttributes();
Collection<DbRelationship> rel = dbEnt.getRelationships();
if (!attributes.isEmpty()) {
Iterator<DbAttribute> iterator = attributes.iterator();
firstEntity = iterator.next().getEntity();
} else if (!rel.isEmpty()) {
Iterator<DbRelationship> iterator = rel.iterator();
firstEntity = iterator.next().getSourceEntity();
}
}
}
} else {
firstEntity = getFirstEntity(attribute);
}
if (firstEntity != null) {
EntityTreeModel treeModel = new EntityTreeModel(firstEntity);
treeModel.setFilter(new EntityTreeAttributeRelationshipFilter());
return treeModel;
}
return null;
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class DbAttributePathComboBoxEditor method getFirstEntity.
private Entity getFirstEntity(ObjAttribute attribute) {
Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
Entity firstEnt = attribute.getDbAttribute().getEntity();
boolean setEnt = false;
while (it.hasNext()) {
Object ob = it.next();
if (ob instanceof DbRelationship) {
if (!setEnt) {
firstEnt = ((DbRelationship) ob).getSourceEntity();
setEnt = true;
}
} else if (ob instanceof DbAttribute) {
if (!setEnt) {
firstEnt = ((DbAttribute) ob).getEntity();
}
}
}
return firstEnt;
}
Aggregations