use of org.apache.cayenne.project.upgrade.UpgradeService in project cayenne by apache.
the class CompatibilityUpgradeServiceIT method testUpgradeFullProjectDom.
@Test
public void testUpgradeFullProjectDom() throws Exception {
Injector injector = getInjector();
CompatibilityUpgradeService upgradeService = (CompatibilityUpgradeService) injector.getInstance(UpgradeService.class);
DocumentProvider documentProvider = injector.getInstance(DocumentProvider.class);
URL resourceUrl = getClass().getResource("cayenne-project-v6.xml");
Resource resource = new URLResource(resourceUrl);
upgradeService.upgradeProject(resource);
Document domainDocument = documentProvider.getDocument(resourceUrl);
assertNotNull(domainDocument);
assertEquals("10", domainDocument.getDocumentElement().getAttribute("project-version"));
URL dataMapUrl = getClass().getResource("test-map-v6.map.xml");
Document dataMapDocument = documentProvider.getDocument(dataMapUrl);
assertNotNull(dataMapDocument);
assertEquals("10", dataMapDocument.getDocumentElement().getAttribute("project-version"));
assertEquals(1, dataMapDocument.getElementsByTagName("obj-entity").getLength());
assertEquals(1, dataMapDocument.getElementsByTagName("db-entity").getLength());
assertEquals(2, dataMapDocument.getElementsByTagName("db-attribute").getLength());
}
use of org.apache.cayenne.project.upgrade.UpgradeService in project cayenne by apache.
the class OpenProjectAction method openProject.
/**
* Opens specified project file. File must already exist.
*/
public void openProject(File file) {
try {
if (!file.exists()) {
JOptionPane.showMessageDialog(Application.getFrame(), "Can't open project - file \"" + file.getPath() + "\" does not exist", "Can't Open Project", JOptionPane.ERROR_MESSAGE);
return;
}
CayenneModelerController controller = Application.getInstance().getFrameController();
controller.addToLastProjListAction(file);
URL url = file.toURI().toURL();
Resource rootSource = new URLResource(url);
UpgradeService upgradeService = getApplication().getInjector().getInstance(UpgradeService.class);
UpgradeMetaData metaData = upgradeService.getUpgradeType(rootSource);
switch(metaData.getUpgradeType()) {
case INTERMEDIATE_UPGRADE_NEEDED:
String modelerVersion = PROJECT_TO_MODELER_VERSION.get(metaData.getProjectVersion());
if (modelerVersion == null) {
modelerVersion = "";
}
JOptionPane.showMessageDialog(Application.getFrame(), "Open the project in the older Modeler " + modelerVersion + " to do an intermediate upgrade\nbefore you can upgrade to latest version.", "Can't Upgrade Project", JOptionPane.ERROR_MESSAGE);
closeProject(false);
return;
case DOWNGRADE_NEEDED:
JOptionPane.showMessageDialog(Application.getFrame(), "Can't open project - it was created using a newer version of the Modeler", "Can't Open Project", JOptionPane.ERROR_MESSAGE);
closeProject(false);
return;
case UPGRADE_NEEDED:
if (processUpgrades()) {
rootSource = upgradeService.upgradeProject(rootSource);
} else {
closeProject(false);
return;
}
break;
}
openProjectResourse(rootSource, controller);
} catch (Exception ex) {
logObj.warn("Error loading project file.", ex);
ErrorDebugDialog.guiWarning(ex, "Error loading project");
}
}
use of org.apache.cayenne.project.upgrade.UpgradeService in project cayenne by apache.
the class CompatibilityUpgradeServiceIT method testUpgradeStandAloneDataMapDom.
@Test
public void testUpgradeStandAloneDataMapDom() throws Exception {
Injector injector = getInjector();
CompatibilityUpgradeService upgradeService = (CompatibilityUpgradeService) injector.getInstance(UpgradeService.class);
DocumentProvider documentProvider = injector.getInstance(DocumentProvider.class);
URL dataMapUrl = getClass().getResource("test-map-v6.map.xml");
Document dataMapDocument = documentProvider.getDocument(dataMapUrl);
assertNull(dataMapDocument);
Resource resource = new URLResource(dataMapUrl);
upgradeService.upgradeDataMap(resource);
dataMapDocument = documentProvider.getDocument(dataMapUrl);
assertNotNull(dataMapDocument);
assertEquals("10", dataMapDocument.getDocumentElement().getAttribute("project-version"));
}
Aggregations