Search in sources :

Example 1 with UpgradeHandler

use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.

the class CompatibilityUpgradeService method upgradeDataMap.

public Resource upgradeDataMap(Resource resource) {
    List<UpgradeHandler> handlerList = getHandlersForVersion(loadProjectVersion(resource));
    Document document = Util.readDocument(resource.getURL());
    UpgradeUnit upgradeUnit = new UpgradeUnit(resource, document);
    for (UpgradeHandler handler : handlerList) {
        handler.processDataMapDom(upgradeUnit);
    }
    documentProvider.putDocument(upgradeUnit.getResource().getURL(), upgradeUnit.getDocument());
    return upgradeUnit.getResource();
}
Also used : UpgradeUnit(org.apache.cayenne.project.upgrade.UpgradeUnit) Document(org.w3c.dom.Document) UpgradeHandler(org.apache.cayenne.project.upgrade.handlers.UpgradeHandler)

Example 2 with UpgradeHandler

use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.

the class DefaultUpgradeService method upgradeDOM.

protected List<UpgradeUnit> upgradeDOM(Resource resource, List<UpgradeHandler> handlerList) {
    List<UpgradeUnit> allUnits = new ArrayList<>();
    // Load DOM for all resources
    Document projectDocument = Util.readDocument(resource.getURL());
    UpgradeUnit projectUnit = new UpgradeUnit(resource, projectDocument);
    allUnits.add(projectUnit);
    List<Resource> dataMapResources = getAdditionalDatamapResources(projectUnit);
    List<UpgradeUnit> dataMapUnits = new ArrayList<>(dataMapResources.size());
    for (Resource dataMapResource : dataMapResources) {
        dataMapUnits.add(new UpgradeUnit(dataMapResource, Util.readDocument(dataMapResource.getURL())));
    }
    allUnits.addAll(dataMapUnits);
    // Update DOM
    for (UpgradeHandler handler : handlerList) {
        handler.processProjectDom(projectUnit);
        for (UpgradeUnit dataMapUnit : dataMapUnits) {
            handler.processDataMapDom(dataMapUnit);
        }
    }
    return allUnits;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.cayenne.resource.Resource) Document(org.w3c.dom.Document) UpgradeHandler(org.apache.cayenne.project.upgrade.handlers.UpgradeHandler)

Example 3 with UpgradeHandler

use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.

the class DefaultUpgradeServiceTest method upgradeDOM.

@Test
public void upgradeDOM() throws Exception {
    Resource resource = new URLResource(getClass().getResource("../cayenne-PROJECT1.xml"));
    // Mock service so it will use actual reading but skip actual saving part
    upgradeService = mock(DefaultUpgradeService.class);
    when(upgradeService.upgradeDOM(any(Resource.class), ArgumentMatchers.<UpgradeHandler>anyList())).thenCallRealMethod();
    when(upgradeService.getAdditionalDatamapResources(any(UpgradeUnit.class))).thenCallRealMethod();
    upgradeService.upgradeDOM(resource, handlers);
    // verify(upgradeService, times(3)).saveDocument(any(UpgradeUnit.class));
    for (UpgradeHandler handler : handlers) {
        verify(handler).getVersion();
        verify(handler).processProjectDom(any(UpgradeUnit.class));
        // two data maps
        verify(handler, times(2)).processDataMapDom(any(UpgradeUnit.class));
        verifyNoMoreInteractions(handler);
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) UpgradeHandler(org.apache.cayenne.project.upgrade.handlers.UpgradeHandler) Test(org.junit.Test)

Example 4 with UpgradeHandler

use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.

the class DefaultUpgradeServiceTest method createHandler.

private UpgradeHandler createHandler(String version) {
    UpgradeHandler handler = mock(UpgradeHandler.class);
    when(handler.getVersion()).thenReturn(version);
    return handler;
}
Also used : UpgradeHandler(org.apache.cayenne.project.upgrade.handlers.UpgradeHandler)

Example 5 with UpgradeHandler

use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.

the class CompatibilityUpgradeService method upgradeProject.

@Override
public Resource upgradeProject(Resource resource) {
    List<UpgradeHandler> handlerList = getHandlersForVersion(loadProjectVersion(resource));
    List<UpgradeUnit> upgradeUnits = upgradeDOM(resource, handlerList);
    for (UpgradeUnit unit : upgradeUnits) {
        documentProvider.putDocument(unit.getResource().getURL(), unit.getDocument());
    }
    return resource;
}
Also used : UpgradeUnit(org.apache.cayenne.project.upgrade.UpgradeUnit) UpgradeHandler(org.apache.cayenne.project.upgrade.handlers.UpgradeHandler)

Aggregations

UpgradeHandler (org.apache.cayenne.project.upgrade.handlers.UpgradeHandler)5 UpgradeUnit (org.apache.cayenne.project.upgrade.UpgradeUnit)2 Resource (org.apache.cayenne.resource.Resource)2 Document (org.w3c.dom.Document)2 ArrayList (java.util.ArrayList)1 URLResource (org.apache.cayenne.resource.URLResource)1 Test (org.junit.Test)1