Search in sources :

Example 76 with ObjAttribute

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

the class RemoveAction method removeObjAttributes.

private void removeObjAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, ObjAttribute[] objAttrs) {
    if (objAttrs != null && objAttrs.length > 0) {
        if ((objAttrs.length == 1 && dialog.shouldDelete("DbAttribute", objAttrs[0].getName())) || (objAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
            for (ObjAttribute attrib : objAttrs) {
                entity.removeAttribute(attrib.getName());
                AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
                mediator.fireObjAttributeEvent(e);
            }
            ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
        }
    }
}
Also used : RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 77 with ObjAttribute

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

the class RemoveAttributeAction method performAction.

@Override
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    ProjectController mediator = getProjectController();
    EmbeddableAttribute[] embAttrs = getProjectController().getCurrentEmbAttributes();
    ObjAttribute[] objAttrs = getProjectController().getCurrentObjAttributes();
    DbAttribute[] dbAttrs = getProjectController().getCurrentDbAttributes();
    if (embAttrs != null && embAttrs.length > 0) {
        if ((embAttrs.length == 1 && dialog.shouldDelete("Embeddable Attribute", embAttrs[0].getName())) || (embAttrs.length > 1 && dialog.shouldDelete("selected EmbAttributes"))) {
            Embeddable embeddable = mediator.getCurrentEmbeddable();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(embeddable, embAttrs));
            removeEmbeddableAttributes(embeddable, embAttrs);
        }
    } else if (objAttrs != null && objAttrs.length > 0) {
        if ((objAttrs.length == 1 && dialog.shouldDelete("ObjAttribute", objAttrs[0].getName())) || (objAttrs.length > 1 && dialog.shouldDelete("selected ObjAttributes"))) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
            removeObjAttributes(entity, objAttrs);
        }
    } else if (dbAttrs != null && dbAttrs.length > 0) {
        if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName())) || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
            DbEntity entity = mediator.getCurrentDbEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
            removeDbAttributes(mediator.getCurrentDataMap(), entity, dbAttrs);
        }
    }
}
Also used : RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog) Embeddable(org.apache.cayenne.map.Embeddable)

Example 78 with ObjAttribute

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

the class RemoveAttributeAction method removeObjAttributes.

public void removeObjAttributes(ObjEntity entity, ObjAttribute[] attribs) {
    ProjectController mediator = getProjectController();
    for (ObjAttribute attrib : attribs) {
        entity.removeAttribute(attrib.getName());
        AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
        mediator.fireObjAttributeEvent(e);
        Collection<ObjEntity> objEntities = ProjectUtil.getCollectionOfChildren((ObjEntity) e.getEntity());
        for (ObjEntity objEntity : objEntities) {
            objEntity.removeAttributeOverride(e.getAttribute().getName());
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 79 with ObjAttribute

use of org.apache.cayenne.map.ObjAttribute 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 80 with ObjAttribute

use of org.apache.cayenne.map.ObjAttribute 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

ObjAttribute (org.apache.cayenne.map.ObjAttribute)81 ObjEntity (org.apache.cayenne.map.ObjEntity)57 DbAttribute (org.apache.cayenne.map.DbAttribute)31 ObjRelationship (org.apache.cayenne.map.ObjRelationship)27 DbEntity (org.apache.cayenne.map.DbEntity)26 Test (org.junit.Test)26 DbRelationship (org.apache.cayenne.map.DbRelationship)19 DbJoin (org.apache.cayenne.map.DbJoin)12 DataMap (org.apache.cayenne.map.DataMap)9 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)9 HashMap (java.util.HashMap)8 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)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 ArrayList (java.util.ArrayList)7 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)7 HashSet (java.util.HashSet)6 Expression (org.apache.cayenne.exp.Expression)6