use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class RemoveAction method removeLastPathComponent.
/**
* Removes an object, depending on its type
*/
private UndoableEdit removeLastPathComponent(ConfigurationNode object, ConfigurationNode parentObject) {
UndoableEdit undo = null;
if (object instanceof DataMap) {
if (parentObject != null && parentObject instanceof DataNodeDescriptor) {
undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) parentObject, (DataMap) object);
removeDataMapFromDataNode((DataNodeDescriptor) parentObject, (DataMap) object);
} else {
// Not under Data Node, remove completely
undo = new RemoveUndoableEdit(application, (DataMap) object);
removeDataMap((DataMap) object);
}
} else if (object instanceof DataNodeDescriptor) {
undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) object);
removeDataNode((DataNodeDescriptor) object);
} else if (object instanceof DbEntity) {
undo = new RemoveUndoableEdit(((DbEntity) object).getDataMap(), (DbEntity) object);
removeDbEntity(((DbEntity) object).getDataMap(), (DbEntity) object);
} else if (object instanceof ObjEntity) {
undo = new RemoveUndoableEdit(((ObjEntity) object).getDataMap(), (ObjEntity) object);
removeObjEntity(((ObjEntity) object).getDataMap(), (ObjEntity) object);
} else if (object instanceof QueryDescriptor) {
undo = new RemoveUndoableEdit(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
removeQuery(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
} else if (object instanceof Procedure) {
undo = new RemoveUndoableEdit(((Procedure) object).getDataMap(), (Procedure) object);
removeProcedure(((Procedure) object).getDataMap(), (Procedure) object);
} else if (object instanceof Embeddable) {
undo = new RemoveUndoableEdit(((Embeddable) object).getDataMap(), (Embeddable) object);
removeEmbeddable(((Embeddable) object).getDataMap(), (Embeddable) object);
}
return undo;
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class RemoveAction method removeDbAttributes.
private void removeDbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, DbAttribute[] dbAttrs) {
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));
for (DbAttribute attrib : dbAttrs) {
entity.removeAttribute(attrib.getName());
AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
mediator.fireDbAttributeEvent(e);
}
ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
}
}
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class RemoveRelationshipAction method performAction.
@Override
public void performAction(ActionEvent e, boolean allowAsking) {
ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
ProjectController mediator = getProjectController();
ObjRelationship[] rels = getProjectController().getCurrentObjRelationships();
if (rels != null && rels.length > 0) {
if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
ObjEntity entity = mediator.getCurrentObjEntity();
removeObjRelationships(entity, rels);
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
}
} else {
DbRelationship[] dbRels = getProjectController().getCurrentDbRelationships();
if (dbRels != null && dbRels.length > 0) {
if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName())) || (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
DbEntity entity = mediator.getCurrentDbEntity();
removeDbRelationships(entity, dbRels);
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
}
}
}
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class InferRelationshipsControllerBase method createRelationships.
protected void createRelationships(DbEntity entity) {
for (DbAttribute attribute : entity.getAttributes()) {
String name = attribute.getName();
if (name.length() < 4) {
continue;
}
if (!name.substring(name.length() - 3, name.length()).equalsIgnoreCase("_ID")) {
continue;
}
String baseName = name.substring(0, name.length() - 3);
for (DbEntity targetEntity : entities) {
// TODO: should we handle relationships to self??
if (targetEntity == entity) {
continue;
}
if (baseName.equalsIgnoreCase(targetEntity.getName()) && !attribute.isPrimaryKey() && !targetEntity.getAttributes().isEmpty()) {
if (!attribute.isForeignKey()) {
InferredRelationship myir = new InferredRelationship();
myir.setSource(entity);
myir.setTarget(targetEntity);
inferredRelationships.add(myir);
}
createReversRelationship(targetEntity, entity);
}
}
}
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class InferRelationshipsControllerBase method setRelationships.
public void setRelationships() {
inferredRelationships = new ArrayList<>();
for (DbEntity entity : entities) {
createRelationships(entity);
}
createJoins();
createNames();
}
Aggregations