use of org.apache.cayenne.map.DbAttribute 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.DbAttribute in project cayenne by apache.
the class RemoveAttributeAction method removeDbAttributes.
public void removeDbAttributes(DataMap dataMap, DbEntity entity, DbAttribute[] attribs) {
ProjectController mediator = getProjectController();
for (DbAttribute attrib : attribs) {
entity.removeAttribute(attrib.getName());
AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
mediator.fireDbAttributeEvent(e);
}
ProjectUtil.cleanObjMappings(dataMap);
}
use of org.apache.cayenne.map.DbAttribute 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.DbAttribute in project cayenne by apache.
the class InferRelationshipsControllerBase method createJoins.
protected void createJoins() {
Iterator<InferredRelationship> it = inferredRelationships.iterator();
while (it.hasNext()) {
InferredRelationship inferred = it.next();
DbAttribute src = getJoinAttribute(inferred.getSource(), inferred.getTarget());
if (src == null) {
// TODO: andrus 03/28/2010 this is pretty inefficient I guess... We should
// check for this condition earlier. See CAY-1405 for the map that caused
// this issue
it.remove();
continue;
}
DbAttribute target = getJoinAttribute(inferred.getTarget(), inferred.getSource());
if (target == null) {
// TODO: andrus 03/28/2010 this is pretty inefficient I guess... We should
// check for this condition earlier. See CAY-1405 for the map that caused
// this issue
it.remove();
continue;
}
inferred.setJoinSource(src);
if (src.isPrimaryKey()) {
inferred.setToMany(true);
}
inferred.setJoinTarget(target);
}
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class ObjAttributeInfoDialog method setPath.
public boolean setPath(boolean isChange) {
if (isChange()) {
attributeSaved.setType(view.getTypeComboBox().getSelectedItem().toString());
attributeSaved.setName(view.getAttributeName().getText());
}
if (!(attributeSaved instanceof EmbeddedAttribute) || isRegistredType(attributeSaved.getType())) {
StringBuilder attributePath = new StringBuilder();
StringBuilder pathStr = new StringBuilder();
if (attribute.getEntity().getDbEntity() != null) {
TreePath path = view.getPathBrowser().getSelectionPath();
if (path.getLastPathComponent() instanceof DbAttribute) {
Object[] pathComponents = path.getPath();
for (int i = 0; i < pathComponents.length; i++) {
boolean attrOrRel = true;
if (pathComponents[i] instanceof DbAttribute) {
pathStr.append(((DbAttribute) pathComponents[i]).getName());
attributePath.append(((DbAttribute) pathComponents[i]).getName());
} else if (pathComponents[i] instanceof DbRelationship) {
pathStr.append(((DbRelationship) pathComponents[i]).getName());
attributePath.append(((DbRelationship) pathComponents[i]).getName());
} else {
attrOrRel = false;
}
if (i != pathComponents.length - 1 && attrOrRel) {
pathStr.append(" -> ");
attributePath.append(".");
}
}
}
} else {
view.getCurrentPathLabel().setText("");
}
view.getCurrentPathLabel().setText(pathStr.toString());
if (attribute.getDbAttributePath() != null && !embeddableNames.contains(view.getTypeComboBox().getSelectedItem().toString())) {
if (!attribute.getDbAttributePath().equals(attributePath.toString())) {
attributeSaved.setDbAttributePath(attributePath.toString());
if (!attribute.getDbAttributePath().equals(attributePath.toString()) && isChange) {
model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
}
return true;
}
} else {
if (attributePath.length() > 0 || (attribute instanceof EmbeddedAttribute && !(attributeSaved instanceof EmbeddedAttribute))) {
attributeSaved.setDbAttributePath(attributePath.toString());
if (attributePath.length() == 0) {
model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
return false;
}
return true;
}
}
}
return false;
}
Aggregations