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());
}
}
}
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);
}
}
}
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());
}
}
}
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);
}
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());
}
}
}
Aggregations