Search in sources :

Example 1 with Relationship

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

the class EJBQLPathTranslator method resolveJoin.

protected void resolveJoin() {
    EJBQLJoinAppender joinAppender = context.getTranslatorFactory().getJoinAppender(context);
    String newPath = idPath + '.' + lastPathComponent;
    String oldPath = joinAppender.registerReusableJoin(idPath, lastPathComponent, newPath);
    this.fullPath = fullPath + '.' + lastPathComponent;
    if (oldPath != null) {
        this.idPath = oldPath;
        Relationship lastRelationship = currentEntity.getRelationship(lastPathComponent);
        if (lastRelationship != null) {
            ObjEntity targetEntity = (ObjEntity) lastRelationship.getTargetEntity();
            this.lastAlias = context.getTableAlias(fullPath, context.getQuotingStrategy().quotedFullyQualifiedName(targetEntity.getDbEntity()));
        } else {
            String tableName = context.getQuotingStrategy().quotedFullyQualifiedName(currentEntity.getDbEntity());
            this.lastAlias = context.getTableAlias(oldPath, tableName);
        }
    } else {
        Relationship lastRelationship = currentEntity.getRelationship(lastPathComponent);
        ObjEntity targetEntity = null;
        if (lastRelationship != null) {
            targetEntity = (ObjEntity) lastRelationship.getTargetEntity();
        } else {
            targetEntity = currentEntity;
        }
        // register join
        if (innerJoin) {
            joinAppender.appendInnerJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath));
        } else {
            joinAppender.appendOuterJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath));
        }
        this.lastAlias = context.getTableAlias(fullPath, context.getQuotingStrategy().quotedFullyQualifiedName(targetEntity.getDbEntity()));
        this.idPath = newPath;
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Relationship(org.apache.cayenne.map.Relationship) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbRelationship(org.apache.cayenne.map.DbRelationship)

Example 2 with Relationship

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

the class ManyToManyCandidateEntityTest method testOptimisationForManyToManyEntity.

@Test
public void testOptimisationForManyToManyEntity() {
    ObjEntity manyToManyEntity = map.getObjEntity("Table1Table2");
    ManyToManyCandidateEntity.build(manyToManyEntity).optimizeRelationships(new DefaultObjectNameGenerator(NoStemStemmer.getInstance()));
    ObjEntity table1Entity = map.getObjEntity("Table1");
    ObjEntity table2Entity = map.getObjEntity("Table2");
    assertEquals(1, table1Entity.getRelationships().size());
    assertEquals(table2Entity, new ArrayList<Relationship>(table1Entity.getRelationships()).get(0).getTargetEntity());
    assertEquals(1, table2Entity.getRelationships().size());
    assertEquals(table1Entity, new ArrayList<Relationship>(table2Entity.getRelationships()).get(0).getTargetEntity());
}
Also used : DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) ObjEntity(org.apache.cayenne.map.ObjEntity) Relationship(org.apache.cayenne.map.Relationship) Test(org.junit.Test)

Example 3 with Relationship

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

the class SQLTemplatePrefetchTab method createBrowserModel.

protected TreeModel createBrowserModel(Entity entity) {
    EntityTreeModel treeModel = new EntityTreeModel(entity);
    treeModel.setFilter(new EntityTreeFilter() {

        public boolean attributeMatch(Object node, Attribute attr) {
            return false;
        }

        public boolean relationshipMatch(Object node, Relationship rel) {
            return true;
        }
    });
    return treeModel;
}
Also used : EntityTreeFilter(org.apache.cayenne.modeler.util.EntityTreeFilter) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) Attribute(org.apache.cayenne.map.Attribute) Relationship(org.apache.cayenne.map.Relationship)

Example 4 with Relationship

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

the class SelectQueryPrefetchTab method createBrowserModel.

protected TreeModel createBrowserModel(Entity entity) {
    EntityTreeModel treeModel = new EntityTreeModel(entity);
    treeModel.setFilter(new EntityTreeFilter() {

        public boolean attributeMatch(Object node, Attribute attr) {
            return false;
        }

        public boolean relationshipMatch(Object node, Relationship rel) {
            return true;
        }
    });
    return treeModel;
}
Also used : EntityTreeFilter(org.apache.cayenne.modeler.util.EntityTreeFilter) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) Attribute(org.apache.cayenne.map.Attribute) Relationship(org.apache.cayenne.map.Relationship)

Example 5 with Relationship

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

the class BaseGraphBuilder method createRelationshipCell.

protected DefaultEdge createRelationshipCell(Relationship rel) {
    if (!relCells.containsKey(getQualifiedName(rel))) {
        Relationship reverse = rel.getReverseRelationship();
        DefaultEdge edge = new DefaultEdge();
        // GraphConstants.setLineStyle(edge.getAttributes(),
        // GraphConstants.STYLE_ORTHOGONAL);
        // GraphConstants.setRouting(edge.getAttributes(),
        // GraphConstants.ROUTING_SIMPLE);
        GraphConstants.setEditable(edge.getAttributes(), false);
        GraphConstants.setLabelAlongEdge(edge.getAttributes(), true);
        GraphConstants.setSelectable(edge.getAttributes(), false);
        GraphConstants.setFont(edge.getAttributes(), EDGE_FONT);
        updateRelationshipLabels(edge, rel, reverse);
        relCells.put(getQualifiedName(rel), edge);
        if (reverse != null) {
            relCells.put(getQualifiedName(reverse), edge);
        }
        return edge;
    }
    return null;
}
Also used : Relationship(org.apache.cayenne.map.Relationship) DefaultEdge(org.jgraph.graph.DefaultEdge)

Aggregations

Relationship (org.apache.cayenne.map.Relationship)16 ObjEntity (org.apache.cayenne.map.ObjEntity)9 DbRelationship (org.apache.cayenne.map.DbRelationship)7 DbEntity (org.apache.cayenne.map.DbEntity)6 Attribute (org.apache.cayenne.map.Attribute)5 Entity (org.apache.cayenne.map.Entity)5 ObjRelationship (org.apache.cayenne.map.ObjRelationship)5 ArrayList (java.util.ArrayList)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 DataMap (org.apache.cayenne.map.DataMap)3 Test (org.junit.Test)3 DefaultObjectNameGenerator (org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DetectedDbEntity (org.apache.cayenne.map.DetectedDbEntity)2 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 RelationshipDisplayEvent (org.apache.cayenne.modeler.event.RelationshipDisplayEvent)2 EntityTreeFilter (org.apache.cayenne.modeler.util.EntityTreeFilter)2 EntityTreeModel (org.apache.cayenne.modeler.util.EntityTreeModel)2 URL (java.net.URL)1