Search in sources :

Example 41 with DbJoin

use of org.apache.cayenne.map.DbJoin in project cayenne by apache.

the class EJBQLPathAnaliserTranslator method processFlattenedRelationShip.

private String processFlattenedRelationShip(String subqueryRootAlias, ObjRelationship relationship) {
    QuotingStrategy quoter = context.getQuotingStrategy();
    List<DbRelationship> dbRelationships = relationship.getDbRelationships();
    // relation
    for (int i = dbRelationships.size() - 1; i > 0; i--) {
        DbRelationship dbRelationship = dbRelationships.get(i);
        String subqueryTargetTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship.getTargetEntity());
        String subqueryTargetAlias;
        if (i == dbRelationships.size() - 1) {
            subqueryTargetAlias = subqueryRootAlias;
            context.append(subqueryTargetTableName).append(' ').append(subqueryTargetAlias);
        } else {
            subqueryTargetAlias = context.getTableAlias(subqueryTargetTableName, subqueryTargetTableName);
        }
        context.append(" JOIN ");
        String subquerySourceTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship.getSourceEntity());
        String subquerySourceAlias = context.getTableAlias(subquerySourceTableName, subquerySourceTableName);
        context.append(subquerySourceTableName).append(' ').append(subquerySourceAlias);
        context.append(" ON (");
        List<DbJoin> joins = dbRelationship.getJoins();
        Iterator<DbJoin> it = joins.iterator();
        while (it.hasNext()) {
            DbJoin join = it.next();
            context.append(' ').append(subqueryTargetAlias).append('.').append(join.getTargetName()).append(" = ");
            context.append(subquerySourceAlias).append('.').append(join.getSourceName());
            if (it.hasNext()) {
                context.append(" AND");
            }
        }
        context.append(" )");
        subqueryRootAlias = subquerySourceAlias;
    }
    return subqueryRootAlias;
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) DbJoin(org.apache.cayenne.map.DbJoin) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 42 with DbJoin

use of org.apache.cayenne.map.DbJoin in project cayenne by apache.

the class EJBQLJoinAppender method generateJoiningExpression.

private void generateJoiningExpression(DbRelationship incomingDB, String sourceAlias, String targetAlias) {
    context.append(" ON (");
    QuotingStrategy quoter = context.getQuotingStrategy();
    Iterator<DbJoin> it = incomingDB.getJoins().iterator();
    if (it.hasNext()) {
        DbJoin dbJoin = it.next();
        context.append(sourceAlias).append('.').append(quoter.quotedSourceName(dbJoin)).append(" = ").append(targetAlias).append('.').append(quoter.quotedTargetName(dbJoin));
    }
    while (it.hasNext()) {
        context.append(" AND ");
        DbJoin dbJoin = it.next();
        context.append(sourceAlias).append('.').append(quoter.quotedSourceName(dbJoin)).append(" = ").append(targetAlias).append('.').append(quoter.quotedTargetName(dbJoin));
    }
    context.append(")");
}
Also used : DbJoin(org.apache.cayenne.map.DbJoin) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 43 with DbJoin

use of org.apache.cayenne.map.DbJoin in project cayenne by apache.

the class DataObjectMatchTranslator method setRelationship.

/**
 * Initializes itself to do translation of the match ending with a
 * DbRelationship.
 *
 * @since 3.0
 */
public void setRelationship(DbRelationship rel, String joinSplitAlias) {
    this.relationship = rel;
    this.joinSplitAlias = joinSplitAlias;
    attributes = new HashMap<>(rel.getJoins().size() * 2);
    if (rel.isToMany() || !rel.isToPK()) {
        // match on target PK
        DbEntity ent = rel.getTargetEntity();
        // index by name
        for (DbAttribute pkAttr : ent.getPrimaryKeys()) {
            attributes.put(pkAttr.getName(), pkAttr);
        }
    } else {
        // match on this FK
        for (DbJoin join : rel.getJoins()) {
            // index by target name
            attributes.put(join.getTargetName(), join.getSource());
        }
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) DbJoin(org.apache.cayenne.map.DbJoin)

Example 44 with DbJoin

use of org.apache.cayenne.map.DbJoin in project cayenne by apache.

the class InferRelationshipsControllerBase method createNames.

protected void createNames() {
    for (InferredRelationship myir : inferredRelationships) {
        DbRelationship localRelationship = new DbRelationship();
        localRelationship.setToMany(myir.isToMany());
        if (myir.getJoinSource().isPrimaryKey()) {
            localRelationship.addJoin(new DbJoin(localRelationship, myir.getJoinSource().getName(), myir.getJoinTarget().getName()));
            localRelationship.setSourceEntity(myir.getSource());
            localRelationship.setTargetEntityName(myir.getTarget().getName());
        } else {
            localRelationship.addJoin(new DbJoin(localRelationship, myir.getJoinTarget().getName(), myir.getJoinSource().getName()));
            localRelationship.setSourceEntity(myir.getTarget());
            localRelationship.setTargetEntityName(myir.getSource().getName());
        }
        myir.setName(strategy.relationshipName(localRelationship));
    }
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) DbJoin(org.apache.cayenne.map.DbJoin)

Example 45 with DbJoin

use of org.apache.cayenne.map.DbJoin in project cayenne by apache.

the class DbJoinTableModel method setUpdatedValueAt.

public void setUpdatedValueAt(Object aValue, int row, int column) {
    DbJoin join = getJoin(row);
    if (join == null) {
        return;
    }
    String value = (String) aValue;
    if (column == SOURCE) {
        if (source == null || source.getAttribute(value) == null) {
            value = null;
        }
        join.setSourceName(value);
    } else if (column == TARGET) {
        if (target == null || target.getAttribute(value) == null) {
            value = null;
        }
        join.setTargetName(value);
    }
    fireTableRowsUpdated(row, row);
}
Also used : DbJoin(org.apache.cayenne.map.DbJoin)

Aggregations

DbJoin (org.apache.cayenne.map.DbJoin)49 DbRelationship (org.apache.cayenne.map.DbRelationship)35 DbEntity (org.apache.cayenne.map.DbEntity)24 DbAttribute (org.apache.cayenne.map.DbAttribute)18 ObjRelationship (org.apache.cayenne.map.ObjRelationship)14 ObjAttribute (org.apache.cayenne.map.ObjAttribute)12 ObjEntity (org.apache.cayenne.map.ObjEntity)11 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)9 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)8 ArrayList (java.util.ArrayList)7 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)7 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)7 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)7 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)5 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)5 HashSet (java.util.HashSet)4 List (java.util.List)3