Search in sources :

Example 6 with Project

use of org.apache.cayenne.project.Project in project cayenne by apache.

the class OpenProjectAction method openProjectResourse.

private Project openProjectResourse(Resource resource, CayenneModelerController controller) {
    Project project = getApplication().getInjector().getInstance(ProjectLoader.class).loadProject(resource);
    controller.projectOpenedAction(project);
    return project;
}
Also used : Project(org.apache.cayenne.project.Project) ProjectLoader(org.apache.cayenne.project.ProjectLoader)

Example 7 with Project

use of org.apache.cayenne.project.Project in project cayenne by apache.

the class DefaultDbImportActionTest method testNewDataMapImport.

@Test
public void testNewDataMapImport() throws Exception {
    DbImportConfiguration config = mock(DbImportConfiguration.class);
    when(config.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
    when(config.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration());
    when(config.getTargetDataMap()).thenReturn(new File("xyz.map.xml"));
    when(config.createNameGenerator()).thenReturn(new DefaultObjectNameGenerator(NoStemStemmer.getInstance()));
    when(config.createMeaningfulPKFilter()).thenReturn(NamePatternMatcher.EXCLUDE_ALL);
    DbLoader dbLoader = new DbLoader(mockAdapter, mockConnection, config.getDbLoaderConfig(), mockDelegate, mockNameGenerator) {

        @Override
        public DataMap load() throws SQLException {
            DataMap map = new DataMap();
            new DataMapBuilder(map).withDbEntities(2).build();
            return map;
        }
    };
    final boolean[] haveWeTriedToSave = { false };
    DefaultDbImportAction action = buildDbImportAction(new FileProjectSaver(Collections.emptyList()) {

        @Override
        public void save(Project project) {
            haveWeTriedToSave[0] = true;
            // Validation phase
            assertTrue(project.getRootNode() instanceof DataMap);
        }
    }, null, dbLoader);
    action.execute(config);
    assertTrue("We should try to save.", haveWeTriedToSave[0]);
}
Also used : FileProjectSaver(org.apache.cayenne.project.FileProjectSaver) DefaultModelMergeDelegate(org.apache.cayenne.dbsync.reverse.dbload.DefaultModelMergeDelegate) DbLoaderConfiguration(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration) DataMap(org.apache.cayenne.map.DataMap) DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) Project(org.apache.cayenne.project.Project) DataMapBuilder(org.apache.cayenne.dbsync.merge.builders.DataMapBuilder) File(java.io.File) DbLoader(org.apache.cayenne.dbsync.reverse.dbload.DbLoader) Test(org.junit.Test)

Example 8 with Project

use of org.apache.cayenne.project.Project in project cayenne by apache.

the class DefaultUpgradeService method saveModel.

protected void saveModel(ConfigurationTree<DataChannelDescriptor> configurationTree) {
    // Save project once again via project saver, this will normalize XML to minimize final diff
    Project project = new Project(configurationTree);
    projectSaver.save(project);
}
Also used : Project(org.apache.cayenne.project.Project)

Example 9 with Project

use of org.apache.cayenne.project.Project in project cayenne by apache.

the class TableSelectorController method updateTables.

/**
 * Performs validation of DbEntities in the current DataMap. Returns a collection of
 * ValidationInfo objects describing the problems.
 */
public void updateTables(Collection<DataMap> dataMaps) {
    this.tables = new ArrayList<DbEntity>();
    for (DataMap dataMap : dataMaps) {
        this.tables.addAll(dataMap.getDbEntities());
    }
    excludedTables.clear();
    validationMessages.clear();
    // if there were errors, filter out those related to
    // non-derived DbEntities...
    // TODO: this is inefficient.. we need targeted validation
    // instead of doing it on the whole project
    Project project = getApplication().getProject();
    ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
    ValidationResult validationResult = projectValidator.validate(project.getRootNode());
    if (validationResult.getFailures().size() > 0) {
        for (ValidationFailure nextProblem : validationResult.getFailures()) {
            DbEntity failedEntity = null;
            if (nextProblem.getSource() instanceof DbAttribute) {
                DbAttribute failedAttribute = (DbAttribute) nextProblem.getSource();
                failedEntity = (DbEntity) failedAttribute.getEntity();
            } else if (nextProblem.getSource() instanceof DbRelationship) {
                DbRelationship failedRelationship = (DbRelationship) nextProblem.getSource();
                failedEntity = (DbEntity) failedRelationship.getSourceEntity();
            } else if (nextProblem.getSource() instanceof DbEntity) {
                failedEntity = (DbEntity) nextProblem.getSource();
            }
            if (failedEntity == null) {
                continue;
            }
            excludedTables.put(failedEntity.getName(), failedEntity);
            validationMessages.put(failedEntity.getName(), nextProblem.getDescription());
        }
    }
    // Find selectable tables
    permanentlyExcludedCount = excludedTables.size();
    selectableTablesList.clear();
    for (DbEntity table : tables) {
        if (false == excludedTables.containsKey(table.getName())) {
            selectableTablesList.add(table);
        }
    }
    tableBinding.updateView();
    tableSelectedAction();
}
Also used : Project(org.apache.cayenne.project.Project) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) ProjectValidator(org.apache.cayenne.project.validation.ProjectValidator) ValidationResult(org.apache.cayenne.validation.ValidationResult) DataMap(org.apache.cayenne.map.DataMap) ValidationFailure(org.apache.cayenne.validation.ValidationFailure)

Example 10 with Project

use of org.apache.cayenne.project.Project in project cayenne by apache.

the class MergerOptions method notifyProjectModified.

private void notifyProjectModified(boolean modelChanged) {
    if (!modelChanged) {
        return;
    }
    // mark the model as unsaved
    Project project = getApplication().getProject();
    project.setModified(true);
    ProjectController projectController = getProjectController();
    projectController.setDirty(true);
    projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.REMOVE));
    projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.ADD));
}
Also used : Project(org.apache.cayenne.project.Project) ProjectController(org.apache.cayenne.modeler.ProjectController) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent)

Aggregations

Project (org.apache.cayenne.project.Project)14 DataMap (org.apache.cayenne.map.DataMap)7 File (java.io.File)4 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 URLResource (org.apache.cayenne.resource.URLResource)3 DataMapBuilder (org.apache.cayenne.dbsync.merge.builders.DataMapBuilder)2 DefaultObjectNameGenerator (org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator)2 DbLoader (org.apache.cayenne.dbsync.reverse.dbload.DbLoader)2 DbLoaderConfiguration (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration)2 DefaultModelMergeDelegate (org.apache.cayenne.dbsync.reverse.dbload.DefaultModelMergeDelegate)2 DbEntity (org.apache.cayenne.map.DbEntity)2 CayenneModelerController (org.apache.cayenne.modeler.CayenneModelerController)2 FileProjectSaver (org.apache.cayenne.project.FileProjectSaver)2 ProjectSaver (org.apache.cayenne.project.ProjectSaver)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 Preferences (java.util.prefs.Preferences)1 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DataMapLoader (org.apache.cayenne.configuration.DataMapLoader)1