Search in sources :

Example 56 with DbEntity

use of org.apache.cayenne.map.DbEntity in project cayenne by apache.

the class BoxCellRenderer method setUpdatedValueAt.

@Override
public void setUpdatedValueAt(Object value, int row, int col) {
    EmbeddableAttribute attribute = getEmbeddableAttribute(row);
    if (col == DB_ATTRIBUTE) {
        attribute.setDbAttributeName(value != null ? value.toString() : null);
        fireTableCellUpdated(row, col);
        this.isAttributeOverrideChange = true;
        ((ObjAttributeInfoDialogView) ((ObjAttributeInfoDialog) eventSource).getView()).getSaveButton().setEnabled(true);
        if (value != null) {
            DbEntity currentEnt = ((ObjEntity) attr.getEntity()).getDbEntity();
            if (currentEnt != null) {
                DbAttribute dbAttr = (DbAttribute) currentEnt.getAttribute(value.toString());
                if (dbAttr != null) {
                    fireTableCellUpdated(DB_ATTRIBUTE_TYPE, col);
                }
            }
        }
        fireTableRowsUpdated(row, row);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute)

Example 57 with DbEntity

use of org.apache.cayenne.map.DbEntity in project cayenne by apache.

the class AttributeErrorMsg method displayField.

public void displayField(ProjectController mediator, JFrame frame) {
    AttributeDisplayEvent event = new AttributeDisplayEvent(frame, attribute, entity, map, domain);
    // twice
    if (entity instanceof ObjEntity) {
        mediator.fireObjEntityDisplayEvent(event);
        mediator.fireObjAttributeDisplayEvent(event);
    } else if (entity instanceof DbEntity) {
        mediator.fireDbEntityDisplayEvent(event);
        mediator.fireDbAttributeDisplayEvent(event);
    }
}
Also used : AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity)

Example 58 with DbEntity

use of org.apache.cayenne.map.DbEntity in project cayenne by apache.

the class CreateAttributeAction method performAction.

/**
 * Creates ObjAttribute, DbAttribute depending on context.
 */
@Override
public void performAction(ActionEvent e) {
    ProjectController mediator = getProjectController();
    if (getProjectController().getCurrentEmbeddable() != null) {
        Embeddable embeddable = mediator.getCurrentEmbeddable();
        EmbeddableAttribute attr = new EmbeddableAttribute();
        attr.setName(NameBuilder.builder(attr, embeddable).name());
        createEmbAttribute(embeddable, attr);
        application.getUndoManager().addEdit(new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[] { attr }));
    }
    if (getProjectController().getCurrentObjEntity() != null) {
        ObjEntity objEntity = mediator.getCurrentObjEntity();
        ObjAttribute attr = new ObjAttribute();
        attr.setName(NameBuilder.builder(attr, objEntity).name());
        createObjAttribute(mediator.getCurrentDataMap(), objEntity, attr);
        application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), objEntity, attr));
    } else if (getProjectController().getCurrentDbEntity() != null) {
        DbEntity dbEntity = getProjectController().getCurrentDbEntity();
        DbAttribute attr = new DbAttribute();
        attr.setName(NameBuilder.builder(attr, dbEntity).name());
        attr.setType(TypesMapping.NOT_DEFINED);
        attr.setEntity(dbEntity);
        createDbAttribute(mediator.getCurrentDataMap(), dbEntity, attr);
        application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), dbEntity, attr));
    }
}
Also used : CreateEmbAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateEmbAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) CreateAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateAttributeUndoableEdit) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) Embeddable(org.apache.cayenne.map.Embeddable)

Example 59 with DbEntity

use of org.apache.cayenne.map.DbEntity in project cayenne by apache.

the class CreateDbEntityAction method performAction.

/**
 * Creates new DbEntity, adds it to the current DataMap, fires DbEntityEvent and DbEntityDisplayEvent.
 */
public void performAction(ActionEvent e) {
    ProjectController mediator = getProjectController();
    DataMap map = mediator.getCurrentDataMap();
    DbEntity entity = new DbEntity();
    entity.setName(NameBuilder.builder(entity, map).name());
    createEntity(map, entity);
    application.getUndoManager().addEdit(new CreateDbEntityUndoableEdit(map, entity));
}
Also used : CreateDbEntityUndoableEdit(org.apache.cayenne.modeler.undo.CreateDbEntityUndoableEdit) DbEntity(org.apache.cayenne.map.DbEntity) ProjectController(org.apache.cayenne.modeler.ProjectController) DataMap(org.apache.cayenne.map.DataMap)

Example 60 with DbEntity

use of org.apache.cayenne.map.DbEntity in project cayenne by apache.

the class DbEntitySyncAction method syncDbEntity.

protected void syncDbEntity() {
    ProjectController mediator = getProjectController();
    DbEntity dbEntity = mediator.getCurrentDbEntity();
    if (dbEntity != null) {
        Collection<ObjEntity> entities = dbEntity.getDataMap().getMappedEntities(dbEntity);
        if (entities.isEmpty()) {
            return;
        }
        EntityMergeSupport merger = new EntitySyncController(Application.getInstance().getFrameController(), dbEntity).createMerger();
        if (merger == null) {
            return;
        }
        merger.setNameGenerator(new PreserveRelationshipNameGenerator());
        DbEntitySyncUndoableEdit undoableEdit = new DbEntitySyncUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap());
        // filter out inherited entities, as we need to add attributes only to the roots
        filterInheritedEntities(entities);
        for (ObjEntity entity : entities) {
            DbEntitySyncUndoableEdit.EntitySyncUndoableListener listener = undoableEdit.new EntitySyncUndoableListener(entity);
            merger.addEntityMergeListener(listener);
            // we should not be trying to introspect the merger
            if (merger.isRemovingMeaningfulFKs()) {
                undoableEdit.addEdit(undoableEdit.new MeaningfulFKsUndoableEdit(entity, merger.getMeaningfulFKs(entity)));
            }
            if (merger.synchronizeWithDbEntity(entity)) {
                mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
            }
            merger.removeEntityMergeListener(listener);
        }
        application.getUndoManager().addEdit(undoableEdit);
    }
}
Also used : EntityMergeSupport(org.apache.cayenne.dbsync.merge.context.EntityMergeSupport) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbEntitySyncUndoableEdit(org.apache.cayenne.modeler.undo.DbEntitySyncUndoableEdit) ProjectController(org.apache.cayenne.modeler.ProjectController) EntitySyncController(org.apache.cayenne.modeler.dialog.objentity.EntitySyncController)

Aggregations

DbEntity (org.apache.cayenne.map.DbEntity)273 DbAttribute (org.apache.cayenne.map.DbAttribute)106 Test (org.junit.Test)106 ObjEntity (org.apache.cayenne.map.ObjEntity)64 DbRelationship (org.apache.cayenne.map.DbRelationship)55 DataMap (org.apache.cayenne.map.DataMap)47 ObjAttribute (org.apache.cayenne.map.ObjAttribute)26 ArrayList (java.util.ArrayList)25 DbJoin (org.apache.cayenne.map.DbJoin)24 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)20 ObjRelationship (org.apache.cayenne.map.ObjRelationship)19 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)16 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)16 Entity (org.apache.cayenne.map.Entity)16 List (java.util.List)15 DbAdapter (org.apache.cayenne.dba.DbAdapter)15 EntityEvent (org.apache.cayenne.map.event.EntityEvent)14 HashMap (java.util.HashMap)12 SelectQuery (org.apache.cayenne.query.SelectQuery)12 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)11