Search in sources :

Example 6 with EmbeddableAttribute

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

the class NameBuilderTest method testName_EmbeddableContext.

@Test
public void testName_EmbeddableContext() {
    Embeddable embeddable = new Embeddable();
    EmbeddableAttribute ea0 = new EmbeddableAttribute();
    ea0.setName(NameBuilder.builder(ea0).in(embeddable).name());
    assertEquals("untitledAttr", ea0.getName());
    embeddable.addAttribute(ea0);
    EmbeddableAttribute ea1 = new EmbeddableAttribute();
    ea1.setName(NameBuilder.builder(ea1).in(embeddable).name());
    assertEquals("untitledAttr1", ea1.getName());
    embeddable.addAttribute(ea1);
}
Also used : EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Embeddable(org.apache.cayenne.map.Embeddable) Test(org.junit.Test)

Example 7 with EmbeddableAttribute

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

the class ObjAttributeValidator method validateEmbeddable.

private void validateEmbeddable(EmbeddedAttribute attribute, ValidationResult validationResult) {
    Embeddable embeddable = attribute.getEmbeddable();
    if (embeddable == null) {
        String msg = attribute.getType() == null ? "EmbeddedAttribute '%s' has no Embeddable" : "EmbeddedAttribute '%s' has incorrect Embeddable";
        addFailure(validationResult, attribute, msg, attribute.getName());
        return;
    }
    Map<String, String> attrOverrides = attribute.getAttributeOverrides();
    for (EmbeddableAttribute embeddableAttribute : embeddable.getAttributes()) {
        String dbAttributeName;
        if (!attrOverrides.isEmpty() && attrOverrides.containsKey(embeddableAttribute.getName())) {
            dbAttributeName = attrOverrides.get(embeddableAttribute.getName());
        } else {
            dbAttributeName = embeddableAttribute.getDbAttributeName();
        }
        if (Util.isEmptyString(dbAttributeName)) {
            addFailure(validationResult, attribute, "EmbeddedAttribute '%s' has no DbAttribute mapping", attribute.getName());
        } else if (attribute.getEntity().getDbEntity().getAttribute(dbAttributeName) == null) {
            addFailure(validationResult, attribute, "EmbeddedAttribute '%s' has incorrect DbAttribute mapping", attribute.getName());
        }
    }
}
Also used : EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Embeddable(org.apache.cayenne.map.Embeddable)

Example 8 with EmbeddableAttribute

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

the class ObjAttributeInfoDialog method getCurrentOverrideAttribute.

public Map<String, String> getCurrentOverrideAttribute() {
    Map<String, String> currentEmbeddableOverrite = new HashMap<>();
    Collection<EmbeddableAttribute> embList = embeddableModel.getEmbeddableList();
    Embeddable emb = stringToEmbeddables.get(attributeSaved.getType());
    for (EmbeddableAttribute e : embList) {
        if ((emb.getAttribute(e.getName()).getDbAttributeName() == null && e.getDbAttributeName() != null) || (emb.getAttribute(e.getName()).getDbAttributeName() != null && !emb.getAttribute(e.getName()).getDbAttributeName().equals(e.getDbAttributeName()))) {
            currentEmbeddableOverrite.put(e.getName(), e.getDbAttributeName());
        }
    }
    return currentEmbeddableOverrite;
}
Also used : HashMap(java.util.HashMap) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Embeddable(org.apache.cayenne.map.Embeddable)

Example 9 with EmbeddableAttribute

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

the class BoxCellRenderer method setComboBoxes.

public void setComboBoxes(Collection<String> nameAttr, int column) {
    int count = getRowCount();
    for (int i = 0; i < count; i++) {
        EmbeddableAttribute embAt = getEmbeddableAttribute(i);
        if (!nameAttr.contains(embAt.getDbAttributeName()) && embAt.getDbAttributeName() != null) {
            Collection<String> attributeComboForRow = new ArrayList<String>();
            attributeComboForRow.addAll(nameAttr);
            attributeComboForRow.add(embAt.getDbAttributeName());
            JComboBox comboBoxForRow = Application.getWidgetFactory().createComboBox(attributeComboForRow, true);
            cellEditor.setEditorAt(new Integer(i), new DefaultCellEditor(comboBoxForRow));
            BoxCellRenderer renderer = new BoxCellRenderer();
            renderer.setNotActiveColumn(attributeComboForRow.size() - 1);
            comboBoxForRow.setRenderer(renderer);
        }
    }
    table.getColumnModel().getColumn(column).setCellEditor(cellEditor);
}
Also used : JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 10 with EmbeddableAttribute

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

the class PasteUndoableEdit method undo.

@Override
public void undo() throws CannotUndoException {
    RemoveAttributeAction rAttributeAction = actionManager.getAction(RemoveAttributeAction.class);
    RemoveAction rAction = actionManager.getAction(RemoveAction.class);
    RemoveRelationshipAction rRelationShipAction = actionManager.getAction(RemoveRelationshipAction.class);
    RemoveCallbackMethodAction rCallbackMethodAction = actionManager.getAction(RemoveCallbackMethodAction.class);
    RemoveProcedureParameterAction rProcedureParamAction = actionManager.getAction(RemoveProcedureParameterAction.class);
    if (content instanceof DataMap) {
        if (where instanceof DataChannelDescriptor) {
            rAction.removeDataMap((DataMap) content);
        } else if (where instanceof DataNodeDescriptor) {
            rAction.removeDataMapFromDataNode((DataNodeDescriptor) where, (DataMap) content);
        }
    } else if (where instanceof DataMap) {
        if (content instanceof DbEntity) {
            rAction.removeDbEntity(map, (DbEntity) content);
        } else if (content instanceof ObjEntity) {
            rAction.removeObjEntity(map, (ObjEntity) content);
        } else if (content instanceof Embeddable) {
            rAction.removeEmbeddable(map, (Embeddable) content);
        } else if (content instanceof QueryDescriptor) {
            rAction.removeQuery(map, (QueryDescriptor) content);
        } else if (content instanceof Procedure) {
            rAction.removeProcedure(map, (Procedure) content);
        }
    } else if (where instanceof DbEntity) {
        if (content instanceof DbEntity) {
            rAction.removeDbEntity(map, (DbEntity) content);
        } else if (content instanceof DbAttribute) {
            rAttributeAction.removeDbAttributes(map, (DbEntity) where, new DbAttribute[] { (DbAttribute) content });
        } else if (content instanceof DbRelationship) {
            rRelationShipAction.removeDbRelationships((DbEntity) where, new DbRelationship[] { (DbRelationship) content });
        }
    } else if (where instanceof ObjEntity) {
        if (content instanceof ObjEntity) {
            rAction.removeObjEntity(map, (ObjEntity) content);
        } else if (content instanceof ObjAttribute) {
            rAttributeAction.removeObjAttributes((ObjEntity) where, new ObjAttribute[] { (ObjAttribute) content });
        } else if (content instanceof ObjRelationship) {
            rRelationShipAction.removeObjRelationships((ObjEntity) where, new ObjRelationship[] { (ObjRelationship) content });
        } else if (content instanceof ObjCallbackMethod) {
            ObjCallbackMethod[] methods = new ObjCallbackMethod[] { (ObjCallbackMethod) content };
            for (ObjCallbackMethod callbackMethod : methods) {
                rCallbackMethodAction.removeCallbackMethod(methods[0].getCallbackType(), callbackMethod.getName());
            }
        }
    } else if (where instanceof Procedure) {
        final Procedure procedure = (Procedure) where;
        if (content instanceof ProcedureParameter) {
            rProcedureParamAction.removeProcedureParameters(procedure, new ProcedureParameter[] { (ProcedureParameter) content });
        }
    } else if (where instanceof Embeddable) {
        if (content instanceof Embeddable) {
            rAction.removeEmbeddable(map, (Embeddable) content);
        } else if (content instanceof EmbeddableAttribute) {
            rAttributeAction.removeEmbeddableAttributes((Embeddable) where, new EmbeddableAttribute[] { (EmbeddableAttribute) content });
        }
    }
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbAttribute(org.apache.cayenne.map.DbAttribute) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable) RemoveProcedureParameterAction(org.apache.cayenne.modeler.action.RemoveProcedureParameterAction) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveCallbackMethodAction(org.apache.cayenne.modeler.action.RemoveCallbackMethodAction) Procedure(org.apache.cayenne.map.Procedure) RemoveRelationshipAction(org.apache.cayenne.modeler.action.RemoveRelationshipAction) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) RemoveAction(org.apache.cayenne.modeler.action.RemoveAction) ObjCallbackMethod(org.apache.cayenne.modeler.editor.ObjCallbackMethod) RemoveAttributeAction(org.apache.cayenne.modeler.action.RemoveAttributeAction)

Aggregations

EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)18 Embeddable (org.apache.cayenne.map.Embeddable)10 DbAttribute (org.apache.cayenne.map.DbAttribute)6 DbEntity (org.apache.cayenne.map.DbEntity)6 ObjEntity (org.apache.cayenne.map.ObjEntity)6 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 ProjectController (org.apache.cayenne.modeler.ProjectController)4 DataMap (org.apache.cayenne.map.DataMap)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)3 EmbeddableAttributeEvent (org.apache.cayenne.map.event.EmbeddableAttributeEvent)3 EmbeddableAttributeDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)2 Procedure (org.apache.cayenne.map.Procedure)2 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)2 ObjCallbackMethod (org.apache.cayenne.modeler.editor.ObjCallbackMethod)2