Search in sources :

Example 81 with ObjRelationship

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

the class RemoveRelationshipAction method removeObjRelationships.

public void removeObjRelationships(ObjEntity entity, ObjRelationship[] rels) {
    ProjectController mediator = getProjectController();
    for (ObjRelationship rel : rels) {
        entity.removeRelationship(rel.getName());
        RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
        mediator.fireObjRelationshipEvent(e);
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) ProjectController(org.apache.cayenne.modeler.ProjectController) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 82 with ObjRelationship

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

the class CreateRelationshipAction method performAction.

/**
 * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
 */
@Override
public void performAction(ActionEvent e) {
    ObjEntity objEnt = getProjectController().getCurrentObjEntity();
    if (objEnt != null) {
        ObjRelationship rel = new ObjRelationship();
        rel.setName(NameBuilder.builder(rel, objEnt).name());
        createObjRelationship(objEnt, rel);
        application.getUndoManager().addEdit(new CreateRelationshipUndoableEdit(objEnt, new ObjRelationship[] { rel }));
    } else {
        DbEntity dbEnt = getProjectController().getCurrentDbEntity();
        if (dbEnt != null) {
            DbRelationship rel = new DbRelationship();
            rel.setName(NameBuilder.builder(rel, dbEnt).name());
            createDbRelationship(dbEnt, rel);
            application.getUndoManager().addEdit(new CreateRelationshipUndoableEdit(dbEnt, new DbRelationship[] { rel }));
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) CreateRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit)

Example 83 with ObjRelationship

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

the class ProjectUtil method clearDbMapping.

/**
 * Clears all the mapping between this obj entity and its current db entity. Clears
 * mapping between entities, attributes and relationships.
 */
public static void clearDbMapping(ObjEntity entity) {
    DbEntity db_entity = entity.getDbEntity();
    if (db_entity == null) {
        return;
    }
    for (ObjAttribute objAttr : entity.getAttributeMap().values()) {
        DbAttribute dbAttr = objAttr.getDbAttribute();
        if (null != dbAttr) {
            objAttr.setDbAttributePath(null);
        }
    }
    for (ObjRelationship obj_rel : entity.getRelationships()) {
        obj_rel.clearDbRelationships();
    }
    entity.setDbEntity(null);
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 84 with ObjRelationship

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

the class EOQuery method initBindings.

private void initBindings(Map bindings, Entity entity, Map qualifier) {
    if (qualifier == null) {
        return;
    }
    if ("EOKeyValueQualifier".equals(qualifier.get("class"))) {
        String key = (String) qualifier.get("key");
        if (key == null) {
            return;
        }
        Object value = qualifier.get("value");
        if (!(value instanceof Map)) {
            return;
        }
        Map valueMap = (Map) value;
        if (!"EOQualifierVariable".equals(valueMap.get("class")) || !valueMap.containsKey("_key")) {
            return;
        }
        String name = (String) valueMap.get("_key");
        String className = null;
        // so we will use Object type for all DB path...
        try {
            Object lastObject = new ASTObjPath(key).evaluate(entity);
            if (lastObject instanceof ObjAttribute) {
                className = ((ObjAttribute) lastObject).getType();
            } else if (lastObject instanceof ObjRelationship) {
                ObjEntity target = ((ObjRelationship) lastObject).getTargetEntity();
                if (target != null) {
                    className = target.getClassName();
                }
            }
        } catch (ExpressionException ex) {
            className = "java.lang.Object";
        }
        if (className == null) {
            className = "java.lang.Object";
        }
        bindings.put(name, className);
        return;
    }
    List children = (List) qualifier.get("qualifiers");
    if (children != null) {
        Iterator it = children.iterator();
        while (it.hasNext()) {
            initBindings(bindings, entity, (Map) it.next());
        }
    }
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ExpressionException(org.apache.cayenne.exp.ExpressionException)

Aggregations

ObjRelationship (org.apache.cayenne.map.ObjRelationship)84 ObjEntity (org.apache.cayenne.map.ObjEntity)48 ObjAttribute (org.apache.cayenne.map.ObjAttribute)27 DbRelationship (org.apache.cayenne.map.DbRelationship)26 Test (org.junit.Test)24 DbEntity (org.apache.cayenne.map.DbEntity)18 DbAttribute (org.apache.cayenne.map.DbAttribute)15 DbJoin (org.apache.cayenne.map.DbJoin)14 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)12 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)12 ObjectId (org.apache.cayenne.ObjectId)10 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)9 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)9 ArrayList (java.util.ArrayList)8 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 List (java.util.List)7 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)7 DataMap (org.apache.cayenne.map.DataMap)7 HashMap (java.util.HashMap)6