Search in sources :

Example 6 with EntityMergeSupport

use of org.apache.cayenne.dbsync.merge.context.EntityMergeSupport in project cayenne by apache.

the class CreateObjEntityAction method createObjEntity.

protected void createObjEntity() {
    ProjectController mediator = getProjectController();
    DataMap dataMap = mediator.getCurrentDataMap();
    ObjEntity entity = new ObjEntity();
    entity.setName(NameBuilder.builder(entity, dataMap).name());
    // init defaults
    entity.setSuperClassName(dataMap.getDefaultSuperclass());
    entity.setDeclaredLockType(dataMap.getDefaultLockType());
    DbEntity dbEntity = mediator.getCurrentDbEntity();
    if (dbEntity != null) {
        entity.setDbEntity(dbEntity);
        // TODO: use injectable name generator
        String baseName = new DefaultObjectNameGenerator(NoStemStemmer.getInstance()).objEntityName(dbEntity);
        entity.setName(NameBuilder.builder(entity, dbEntity.getDataMap()).baseName(baseName).name());
    }
    entity.setClassName(dataMap.getNameWithDefaultPackage(entity.getName()));
    if (dataMap.isClientSupported()) {
        entity.setClientClassName(dataMap.getNameWithDefaultClientPackage(entity.getName()));
        entity.setClientSuperClassName(dataMap.getDefaultClientSuperclass());
    }
    dataMap.addObjEntity(entity);
    // TODO: Modeler-controlled defaults for all the hardcoded boolean flags here.
    EntityMergeSupport merger = new EntityMergeSupport(new DefaultObjectNameGenerator(NoStemStemmer.getInstance()), NamePatternMatcher.EXCLUDE_ALL, true, true, false);
    merger.setNameGenerator(new DbEntitySyncAction.PreserveRelationshipNameGenerator());
    merger.addEntityMergeListener(DeleteRuleUpdater.getEntityMergeListener());
    merger.synchronizeWithDbEntity(entity);
    fireObjEntityEvent(this, mediator, dataMap, entity);
    application.getUndoManager().addEdit(new CreateObjEntityUndoableEdit(dataMap, entity));
}
Also used : DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) EntityMergeSupport(org.apache.cayenne.dbsync.merge.context.EntityMergeSupport) ObjEntity(org.apache.cayenne.map.ObjEntity) CreateObjEntityUndoableEdit(org.apache.cayenne.modeler.undo.CreateObjEntityUndoableEdit) DbEntity(org.apache.cayenne.map.DbEntity) ProjectController(org.apache.cayenne.modeler.ProjectController) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)6 ObjEntity (org.apache.cayenne.map.ObjEntity)5 DbEntity (org.apache.cayenne.map.DbEntity)3 ProjectController (org.apache.cayenne.modeler.ProjectController)3 DefaultObjectNameGenerator (org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator)2 EntityEvent (org.apache.cayenne.map.event.EntityEvent)2 EntitySyncController (org.apache.cayenne.modeler.dialog.objentity.EntitySyncController)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 ObjectNameGenerator (org.apache.cayenne.dbsync.naming.ObjectNameGenerator)1 DataMap (org.apache.cayenne.map.DataMap)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbJoin (org.apache.cayenne.map.DbJoin)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)1 CreateObjEntityUndoableEdit (org.apache.cayenne.modeler.undo.CreateObjEntityUndoableEdit)1 DbEntitySyncUndoableEdit (org.apache.cayenne.modeler.undo.DbEntitySyncUndoableEdit)1 Test (org.junit.Test)1