Search in sources :

Example 36 with DbRelationship

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);
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) Expression(org.apache.cayenne.exp.Expression) DbRelationship(org.apache.cayenne.map.DbRelationship) DbJoin(org.apache.cayenne.map.DbJoin)

Example 37 with DbRelationship

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);
    }
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) DbJoin(org.apache.cayenne.map.DbJoin) JoinTreeNode(org.apache.cayenne.access.translator.select.JoinTreeNode)

Example 38 with DbRelationship

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);
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) JoinTreeNode(org.apache.cayenne.access.translator.select.JoinTreeNode)

Example 39 with DbRelationship

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;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) Iterator(java.util.Iterator)

Example 40 with DbRelationship

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;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute)

Aggregations

DbRelationship (org.apache.cayenne.map.DbRelationship)106 DbEntity (org.apache.cayenne.map.DbEntity)59 DbAttribute (org.apache.cayenne.map.DbAttribute)35 DbJoin (org.apache.cayenne.map.DbJoin)35 ObjEntity (org.apache.cayenne.map.ObjEntity)30 ObjRelationship (org.apache.cayenne.map.ObjRelationship)28 ObjAttribute (org.apache.cayenne.map.ObjAttribute)20 Test (org.junit.Test)15 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)13 ArrayList (java.util.ArrayList)11 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)10 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)9 DataMap (org.apache.cayenne.map.DataMap)9 Entity (org.apache.cayenne.map.Entity)8 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 HashMap (java.util.HashMap)6 ObjectId (org.apache.cayenne.ObjectId)6