Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.DbJoin


                    table.getFullyQualifiedName());

            List<DbJoin> joins = relationship.getJoins();

            if (joins.size() == 1) {
                DbJoin join = joins.get(0);
                context.append(' ');
                if (isUsingAliases()) {
                    context.append(alias).append('.');
                }
                context.append(join.getSourceName());
            }
            else {
                Map<String, String> multiColumnMatch = new HashMap<String, String>(joins
                        .size() + 2);

                for (DbJoin join : joins) {
                    String column = isUsingAliases()
                            ? alias + "." + join.getSourceName()
                            : join.getSourceName();

                    multiColumnMatch.put(join.getTargetName(), column);
                }

                appendMultiColumnPath(EJBQLMultiColumnOperand.getPathOperand(
                        context,
                        multiColumnMatch));
View Full Code Here


                    attribute.setType(pkAttribute.getType());
                    attribute.setMaxLength(pkAttribute.getMaxLength());
                    attribute.setAttributePrecision(pkAttribute.getAttributePrecision());
                    cayenneSecondaryTable.addAttribute(attribute);

                    DbJoin join = new DbJoin(dbRelationship, column
                            .getReferencedColumnName(), column.getName());
                    dbRelationship.addJoin(join);
                }

                dbRelationship.setToDependentPK(true);
View Full Code Here

            Entity srcEntity = dbRelationship.getSourceEntity();
            srcEntity.addAttribute(src);

            // add join
            DbJoin join = new DbJoin(dbRelationship, src.getName(), jpaTargetId
                    .getColumn()
                    .getName());
            dbRelationship.addJoin(join);

            return false;
View Full Code Here

                            .getTargetEntity()
                            .getRelationship(relationship.getMappedBy());

                    if (owner != null) {
                        for (DbJoin join : owner.getJoins()) {
                            DbJoin reverse = join.createReverseJoin();
                            reverse.setRelationship(relationship);
                            relationship.addJoin(reverse);
                        }
                    }
                }
            }
View Full Code Here

                        logObj.info("no attribute for declared foreign key: "
                                + fkName);
                        continue;
                    }

                    forwardRelationship.addJoin(new DbJoin(
                            forwardRelationship,
                            pkName,
                            fkName));
                    reverseRelationship.addJoin(new DbJoin(
                            reverseRelationship,
                            fkName,
                            pkName));
                }
            } while (rs.next());
View Full Code Here

        boolean toPK = true;
        List joins = relationship.getJoins();

        Iterator joinsIt = joins.iterator();
        while (joinsIt.hasNext()) {
            DbJoin join = (DbJoin) joinsIt.next();
            if (!join.getTarget().isPrimaryKey()) {
                toPK = false;
                break;
            }

        }
View Full Code Here

                DbRelationship dbRel = rel.getDbRelationships().get(0);

                List joins = dbRel.getJoins();
                int len = joins.size();
                for (int i = 0; i < len; i++) {
                    DbJoin join = (DbJoin) joins.get(i);
                    DbAttribute src = join.getSource();
                    appendColumn(columns, null, src, attributes, null);
                }
            }
        };

        if (query.isResolvingInherited()) {
            descriptor.visitAllProperties(visitor);
        }
        else {
            descriptor.visitProperties(visitor);
        }

        // add remaining needed attrs from DbEntity
        DbEntity table = getRootDbEntity();
        for (final DbAttribute dba : table.getPrimaryKeys()) {
            appendColumn(columns, null, dba, attributes, null);
        }

        // special handling of a disjoint query...

        // TODO, Andrus 11/17/2005 - resultPath mechanism is generic and should probably
        // be moved in the superclass (SelectQuery), replacing customDbAttributes.

        if (query instanceof PrefetchSelectQuery) {

            Iterator extraPaths = ((PrefetchSelectQuery) query)
                    .getResultPaths()
                    .iterator();

            // for each relationship path add closest FK or PK, for each attribute path,
            // add specified column
            while (extraPaths.hasNext()) {

                String path = (String) extraPaths.next();
                Expression pathExp = oe.translateToDbPath(Expression.fromString(path));

                Iterator<CayenneMapEntry> it = table.resolvePathComponents(pathExp);

                // add joins and find terminating element
                CayenneMapEntry pathComponent = null;
                while (it.hasNext()) {
                    pathComponent = it.next();

                    // do not add join for the last DB Rel
                    if (it.hasNext() && pathComponent instanceof DbRelationship) {
                        dbRelationshipAdded((DbRelationship) pathComponent);
                    }
                }

                String labelPrefix = pathExp.toString().substring("db:".length());

                // process terminating element
                if (pathComponent instanceof DbAttribute) {

                    // label prefix already includes relationship name
                    appendColumn(
                            columns,
                            null,
                            (DbAttribute) pathComponent,
                            attributes,
                            labelPrefix);
                }
                else if (pathComponent instanceof DbRelationship) {
                    DbRelationship relationship = (DbRelationship) pathComponent;

                    // add last join
                    if (relationship.isToMany()) {
                        dbRelationshipAdded(relationship);
                    }

                    for (DbJoin j : relationship.getJoins()) {

                        DbAttribute attribute = relationship.isToMany()
                                ? j.getTarget()
                                : j.getSource();

                        // note that we my select a source attribute, but label it as
                        // target for simplified snapshot processing
                        appendColumn(columns, null, attribute, attributes, labelPrefix
                                + '.'
                                + j.getTargetName());
                    }
                }
            }
        }

        // handle joint prefetches directly attached to this query...
        if (query.getPrefetchTree() != null) {

            for (PrefetchTreeNode prefetch : query.getPrefetchTree().adjacentJointNodes()) {

                // for each prefetch add all joins plus columns from the target entity
                Expression prefetchExp = Expression.fromString(prefetch.getPath());
                Expression dbPrefetch = oe.translateToDbPath(prefetchExp);

                Iterator it = table.resolvePathComponents(dbPrefetch);

                DbRelationship r = null;
                while (it.hasNext()) {
                    r = (DbRelationship) it.next();
                    dbRelationshipAdded(r);
                }

                if (r == null) {
                    throw new CayenneRuntimeException("Invalid joint prefetch '"
                            + prefetch
                            + "' for entity: "
                            + oe.getName());
                }

                // add columns from the target entity, skipping those that are an FK to
                // source entity

                Collection skipColumns = Collections.EMPTY_LIST;
                if (r.getSourceEntity() == table) {
                    skipColumns = new ArrayList(2);
                    Iterator joins = r.getJoins().iterator();
                    while (joins.hasNext()) {
                        DbJoin join = (DbJoin) joins.next();
                        if (attributes.contains(join.getSource())) {
                            skipColumns.add(join.getTarget());
                        }
                    }
                }

                // go via target OE to make sure that Java types are mapped correctly...
View Full Code Here

        boolean andFlag = false;

        List joins = rel.getJoins();
        int len = joins.size();
        for (int i = 0; i < len; i++) {
            DbJoin join = (DbJoin) joins.get(i);

            if (andFlag) {
                queryBuf.append(" AND ");
            }
            else {
                andFlag = true;
            }

            queryBuf.append(srcAlias).append('.').append(join.getSourceName()).append(
                    " = ").append(targetAlias).append('.').append(join.getTargetName());
        }
    }
View Full Code Here

                    List joins = (List) relMap.get("joins");
                    Iterator jIt = joins.iterator();
                    while (jIt.hasNext()) {
                        Map joinMap = (Map) jIt.next();

                        DbJoin join = new DbJoin(dbRel);

                        // find source attribute dictionary and extract the column name
                        String sourceAttributeName = (String) joinMap
                                .get("sourceAttribute");
                        join.setSourceName(columnName(attributes, sourceAttributeName));

                        String targetAttributeName = (String) joinMap
                                .get("destinationAttribute");

                        join.setTargetName(columnName(
                                targetAttributes,
                                targetAttributeName));
                        dbRel.addJoin(join);
                    }
                }
View Full Code Here

        }

        if (relationship != null) {
            // Can't properly handle multiple joins....
            if (relationship.getJoins().size() == 1) {
                DbJoin join = relationship.getJoins().get(0);
                return join.getSource();
            }
        }

        return null;
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.map.DbJoin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.