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