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;
}
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]);
}
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);
}
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();
}
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));
}
Aggregations