Search in sources :

Example 61 with DbAttribute

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());
        }
    }
}
Also used : RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 62 with DbAttribute

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);
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 63 with DbAttribute

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);
            }
        }
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 64 with DbAttribute

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);
    }
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 65 with DbAttribute

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;
}
Also used : TreePath(javax.swing.tree.TreePath) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute)

Aggregations

DbAttribute (org.apache.cayenne.map.DbAttribute)194 DbEntity (org.apache.cayenne.map.DbEntity)109 Test (org.junit.Test)67 ObjEntity (org.apache.cayenne.map.ObjEntity)36 DbRelationship (org.apache.cayenne.map.DbRelationship)35 ObjAttribute (org.apache.cayenne.map.ObjAttribute)32 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)21 DbJoin (org.apache.cayenne.map.DbJoin)18 HashMap (java.util.HashMap)16 ObjRelationship (org.apache.cayenne.map.ObjRelationship)16 ArrayList (java.util.ArrayList)14 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)12 DataMap (org.apache.cayenne.map.DataMap)11 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)10 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)10 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)10 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)10 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)10 ObjectId (org.apache.cayenne.ObjectId)9 Expression (org.apache.cayenne.exp.Expression)8