Search in sources :

Example 1 with UpgradeService

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());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) UpgradeService(org.apache.cayenne.project.upgrade.UpgradeService) Injector(org.apache.cayenne.di.Injector) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) Document(org.w3c.dom.Document) URL(java.net.URL) Test(org.junit.Test)

Example 2 with UpgradeService

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");
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) UpgradeService(org.apache.cayenne.project.upgrade.UpgradeService) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) UpgradeMetaData(org.apache.cayenne.project.upgrade.UpgradeMetaData) URL(java.net.URL)

Example 3 with UpgradeService

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"));
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) UpgradeService(org.apache.cayenne.project.upgrade.UpgradeService) Injector(org.apache.cayenne.di.Injector) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) Document(org.w3c.dom.Document) URL(java.net.URL) Test(org.junit.Test)

Aggregations

URL (java.net.URL)3 UpgradeService (org.apache.cayenne.project.upgrade.UpgradeService)3 Resource (org.apache.cayenne.resource.Resource)3 URLResource (org.apache.cayenne.resource.URLResource)3 Injector (org.apache.cayenne.di.Injector)2 Test (org.junit.Test)2 Document (org.w3c.dom.Document)2 CayenneModelerController (org.apache.cayenne.modeler.CayenneModelerController)1 UpgradeMetaData (org.apache.cayenne.project.upgrade.UpgradeMetaData)1