Search in sources :

Example 1 with CreateObjEntityUndoableEdit

use of org.apache.cayenne.modeler.undo.CreateObjEntityUndoableEdit 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)1 DefaultObjectNameGenerator (org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator)1 DataMap (org.apache.cayenne.map.DataMap)1 DbEntity (org.apache.cayenne.map.DbEntity)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 CreateObjEntityUndoableEdit (org.apache.cayenne.modeler.undo.CreateObjEntityUndoableEdit)1