cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r890179 - in /cayenne/main/trunk/framework/cayenne-project-unpublished/src: main/java/org/apache/cayenne/project2/ main/java/org/apache/cayenne/project2/upgrade/ main/java/org/apache/cayenne/project2/upgrade/v6/ test/java/org/apache/cayenne...
Date Mon, 14 Dec 2009 04:56:53 GMT
Author: aadamchik
Date: Mon Dec 14 04:56:50 2009
New Revision: 890179

URL: http://svn.apache.org/viewvc?rev=890179&view=rev
Log:
CAY-1329 DI-based cayenne-project module

* project upgrade framework - in progress

Added:
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/BaseUpgradeHandler.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/ProjectUpgrader.java
      - copied, changed from r890150, cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeHandler.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeMetaData.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeType.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6.java
      - copied, changed from r890150, cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/UpgradeHandler_V6.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/java/org/apache/cayenne/project2/upgrade/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/java/org/apache/cayenne/project2/upgrade/v6/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6Test.java
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/cayenne.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Map.map.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Node.driver.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/cayenne.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map1.map.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map2.map.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1NodeDriver.driver.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/cayenne-PROJECT1.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_1.map.xml
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_2.map.xml
Modified:
    cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java

Modified: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java?rev=890179&r1=890178&r2=890179&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java
Mon Dec 14 04:56:50 2009
@@ -21,6 +21,8 @@
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.Scopes;
+import org.apache.cayenne.project2.upgrade.ProjectUpgrader;
+import org.apache.cayenne.project2.upgrade.v6.ProjectUpgrader_V6;
 
 /**
  * A dependency injection (DI) module contributing configuration related to Cayenne
@@ -33,7 +35,7 @@
     public void configure(Binder binder) {
         binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class).in(
                 Scopes.SINGLETON);
-        binder.bind(ProjectSaver.class).to(FileProjectSaver.class).in(
-                Scopes.SINGLETON);
+        binder.bind(ProjectSaver.class).to(FileProjectSaver.class).in(Scopes.SINGLETON);
+        binder.bind(ProjectUpgrader.class).to(ProjectUpgrader_V6.class);
     }
 }

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/BaseUpgradeHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/BaseUpgradeHandler.java?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/BaseUpgradeHandler.java
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/BaseUpgradeHandler.java
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,187 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.project2.upgrade;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.resource.Resource;
+import org.apache.cayenne.util.Util;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * A common superclass of UpgradeHandlers.
+ * 
+ * @since 3.1
+ */
+// there's no guarantee this will survive the further version upgrades, but for now all
+// the code here seems like version-agnostic
+public abstract class BaseUpgradeHandler implements UpgradeHandler {
+
+    static final String UNKNOWN_VERSION = "0";
+
+    protected Resource projectSource;
+    protected UpgradeMetaData metaData;
+
+    public BaseUpgradeHandler(Resource projectSource) {
+
+        if (projectSource == null) {
+            throw new NullPointerException("Null project source");
+        }
+
+        this.projectSource = projectSource;
+    }
+
+    public Resource getProjectSource() {
+        return projectSource;
+    }
+
+    public UpgradeMetaData getUpgradeMetaData() {
+        // no attempts at thread-safety... shouldn't be needed for upgrades
+        if (metaData == null) {
+            metaData = loadMetaData();
+        }
+
+        return metaData;
+    }
+
+    public Resource performUpgrade() throws ConfigurationException {
+        UpgradeMetaData metaData = getUpgradeMetaData();
+        switch (metaData.getUpgradeType()) {
+            case DOWNGRADE_NEEDED:
+                throw new ConfigurationException("Downgrade can not be performed");
+            case INTERMEDIATE_UPGRADE_NEEDED:
+                throw new ConfigurationException(
+                        "Upgrade can not be performed - intermediate version upgrade needed");
+            case UPGRADE_NEEDED:
+                return performNeededUpgrade();
+            default:
+                return getProjectSource();
+        }
+    }
+
+    protected abstract Resource performNeededUpgrade() throws ConfigurationException;
+
+    protected abstract UpgradeMetaData loadMetaData();
+
+    /**
+     * A default method for quick extraction of the project version from an XML file.
+     */
+    protected String loadProjectVersion() {
+
+        RootTagHandler rootHandler = new RootTagHandler();
+        URL url = projectSource.getURL();
+
+        InputStream in = null;
+
+        try {
+            in = url.openStream();
+            XMLReader parser = Util.createXmlReader();
+
+            parser.setContentHandler(rootHandler);
+            parser.setErrorHandler(rootHandler);
+            parser.parse(new InputSource(in));
+        }
+        catch (SAXException e) {
+            // expected ... handler will terminate as soon as it finds a root tag.
+
+        }
+        catch (Exception e) {
+            throw new ConfigurationException(
+                    "Error reading configuration from %s",
+                    e,
+                    url);
+        }
+        finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            }
+            catch (IOException ioex) {
+                // ignoring...
+            }
+        }
+
+        return rootHandler.projectVersion != null
+                ? rootHandler.projectVersion
+                : UNKNOWN_VERSION;
+    }
+
+    /**
+     * Compares two String versions.
+     */
+    protected int compareVersions(String v1, String v2) {
+
+        if (v1.equals(v2)) {
+            return 0;
+        }
+
+        double v1Double = decodeVersion(v1);
+        double v2Double = decodeVersion(v2);
+        return v1Double < v2Double ? -1 : 1;
+    }
+
+    protected double decodeVersion(String version) {
+        if (version == null || version.trim().length() == 0) {
+            return 0;
+        }
+
+        // leave the first dot, and treat remaining as a fraction
+        // remove all non digit chars
+        StringBuilder buffer = new StringBuilder(version.length());
+        boolean dotProcessed = false;
+        for (int i = 0; i < version.length(); i++) {
+            char nextChar = version.charAt(i);
+            if (nextChar == '.' && !dotProcessed) {
+                dotProcessed = true;
+                buffer.append('.');
+            }
+            else if (Character.isDigit(nextChar)) {
+                buffer.append(nextChar);
+            }
+        }
+
+        return Double.parseDouble(buffer.toString());
+    }
+
+    class RootTagHandler extends DefaultHandler {
+
+        private String projectVersion;
+
+        @Override
+        public void startElement(
+                String uri,
+                String localName,
+                String qName,
+                Attributes attributes) throws SAXException {
+
+            this.projectVersion = attributes.getValue("", "project-version");
+
+            // bail right away - we are not interested in reading this to the end
+            throw new SAXException("finished");
+        }
+    }
+}

Copied: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/ProjectUpgrader.java
(from r890150, cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/ProjectUpgrader.java?p2=cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/ProjectUpgrader.java&p1=cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java&r1=890150&r2=890179&rev=890179&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/ProjectUpgrader.java
Mon Dec 14 04:56:50 2009
@@ -16,24 +16,19 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.project2;
+package org.apache.cayenne.project2.upgrade;
 
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
+import org.apache.cayenne.resource.Resource;
 
 /**
- * A dependency injection (DI) module contributing configuration related to Cayenne
- * mapping project manipulation to a DI container.
+ * Defines API of an upgrade handler for Cayenne projects.
  * 
  * @since 3.1
  */
-public class CayenneProjectModule implements Module {
+public interface ProjectUpgrader {
 
-    public void configure(Binder binder) {
-        binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class).in(
-                Scopes.SINGLETON);
-        binder.bind(ProjectSaver.class).to(FileProjectSaver.class).in(
-                Scopes.SINGLETON);
-    }
+    /**
+     * Returns an upgrade handler to process upgrades of a given project.
+     */
+    UpgradeHandler getUpgradeHandler(Resource projectSource);
 }

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeHandler.java?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeHandler.java
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeHandler.java
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,57 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.project2.upgrade;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.resource.Resource;
+
+/**
+ * A stateful helper object for analyzing the projects and performing upgrades.
+ * 
+ * @since 3.1
+ */
+public interface UpgradeHandler {
+
+    /**
+     * Returns the original configuration source for the project before the upgrade.
+     */
+    Resource getProjectSource();
+
+    /**
+     * Returns a metadata object containing information about the upgrade to be performed.
+     * Users should call this method before invoking {@link #performUpgrade()}, to make
+     * sure upgrade is needed and possible. Tools (like CayenneModeler) may use this
+     * object to build user-friendly messages asking for user input on the upgrade.
+     */
+    UpgradeMetaData getUpgradeMetaData();
+
+    /**
+     * Performs an in-place project configuration upgrade, throwing a
+     * {@link ConfigurationException} if the upgrade fails. Before doing the upgrade,
+     * check the handler {@link UpgradeMetaData}. Upgrades will succeed only for projects
+     * that have {@link UpgradeType#UPGRADE_NEEDED} or
+     * {@link UpgradeType#UPGRADE_NOT_NEEDED} statuses. In the later case of course,
+     * upgrade will simply be skipped.
+     * 
+     * @return a configuration Resource for the upgraded project. Depending on the upgrade
+     *         type, it may be the same resource as the original configuration, or a
+     *         totally different resource.
+     */
+    Resource performUpgrade() throws ConfigurationException;
+}

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeMetaData.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeMetaData.java?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeMetaData.java
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeMetaData.java
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,66 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.project2.upgrade;
+
+/**
+ * An object providing upgrade information about a specific project in the context of
+ * enclosing Cayenne runtime.
+ * 
+ * @since 3.1
+ */
+public class UpgradeMetaData {
+
+    protected UpgradeType upgradeType;
+    protected String projectVersion;
+    protected String supportedVersion;
+    protected String intermediateUpgradeVersion;
+
+    public UpgradeType getUpgradeType() {
+        return upgradeType;
+    }
+
+    public void setUpgradeType(UpgradeType upgradeType) {
+        this.upgradeType = upgradeType;
+    }
+
+    public String getProjectVersion() {
+        return projectVersion;
+    }
+
+    public void setProjectVersion(String projectVersion) {
+        this.projectVersion = projectVersion;
+    }
+
+    public String getSupportedVersion() {
+        return supportedVersion;
+    }
+
+    public void setSupportedVersion(String supportedVersion) {
+        this.supportedVersion = supportedVersion;
+    }
+
+    public String getIntermediateUpgradeVersion() {
+        return intermediateUpgradeVersion;
+    }
+
+    public void setIntermediateUpgradeVersion(String intermediateUpgradeVersion) {
+        this.intermediateUpgradeVersion = intermediateUpgradeVersion;
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeType.java?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeType.java
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/UpgradeType.java
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,54 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.project2.upgrade;
+
+/**
+ * An enum indicating what type of upgrade, if any, is needed and possible to bring the
+ * project configuration format in sync with the current Cayenne runtime.
+ * 
+ * @since 3.1
+ */
+public enum UpgradeType {
+
+    /**
+     * The project configuration is current and can be used with the enclosing Cayenne
+     * runtime.
+     */
+    UPGRADE_NOT_NEEDED,
+
+    /**
+     * The project configuration format is from an older version of Cayenne, and it can be
+     * fully upgraded to the current Cayenne version.
+     */
+    UPGRADE_NEEDED,
+
+    /**
+     * The project configuration format is from an older version of Cayenne, and it can be
+     * upgraded to the current Cayenne version, however some information may get lost
+     * during the upgrade. A user may still chose to upgrade, however a recommended
+     * upgrade path is to do an intermediary upgrade using previous versions of Cayenne.
+     */
+    INTERMEDIATE_UPGRADE_NEEDED,
+
+    /**
+     * The project configuration format is from a newer version of Cayenne, and the
+     * current runtime can't work with it.
+     */
+    DOWNGRADE_NEEDED
+}

Copied: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6.java
(from r890150, cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6.java?p2=cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6.java&p1=cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java&r1=890150&r2=890179&rev=890179&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/CayenneProjectModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6.java
Mon Dec 14 04:56:50 2009
@@ -16,24 +16,21 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.project2;
+package org.apache.cayenne.project2.upgrade.v6;
 
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
+import org.apache.cayenne.project2.upgrade.UpgradeHandler;
+import org.apache.cayenne.project2.upgrade.ProjectUpgrader;
+import org.apache.cayenne.resource.Resource;
 
 /**
- * A dependency injection (DI) module contributing configuration related to Cayenne
- * mapping project manipulation to a DI container.
+ * A ProjectUpgrader that handles project upgrades to version 6.
  * 
  * @since 3.1
  */
-public class CayenneProjectModule implements Module {
+public class ProjectUpgrader_V6 implements ProjectUpgrader {
 
-    public void configure(Binder binder) {
-        binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class).in(
-                Scopes.SINGLETON);
-        binder.bind(ProjectSaver.class).to(FileProjectSaver.class).in(
-                Scopes.SINGLETON);
+    public UpgradeHandler getUpgradeHandler(Resource projectSource) {
+        return new UpgradeHandler_V6(projectSource);
     }
+
 }

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/UpgradeHandler_V6.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/UpgradeHandler_V6.java?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/UpgradeHandler_V6.java
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/main/java/org/apache/cayenne/project2/upgrade/v6/UpgradeHandler_V6.java
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,72 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.project2.upgrade.v6;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.project2.upgrade.BaseUpgradeHandler;
+import org.apache.cayenne.project2.upgrade.UpgradeMetaData;
+import org.apache.cayenne.project2.upgrade.UpgradeType;
+import org.apache.cayenne.resource.Resource;
+
+/**
+ * @since 3.1
+ */
+class UpgradeHandler_V6 extends BaseUpgradeHandler {
+
+    static final String TO_VERSION = "6";
+    static final String MIN_SUPPORTED_VERSION = "3.0.0.1";
+
+    UpgradeHandler_V6(Resource source) {
+        super(source);
+    }
+
+    @Override
+    protected UpgradeMetaData loadMetaData() {
+        String version = loadProjectVersion();
+
+        UpgradeMetaData metadata = new UpgradeMetaData();
+        metadata.setSupportedVersion(TO_VERSION);
+        metadata.setProjectVersion(version);
+
+        int c1 = compareVersions(version, MIN_SUPPORTED_VERSION);
+        int c2 = compareVersions(TO_VERSION, version);
+
+        if (c1 < 0) {
+            metadata.setIntermediateUpgradeVersion(MIN_SUPPORTED_VERSION);
+            metadata.setUpgradeType(UpgradeType.INTERMEDIATE_UPGRADE_NEEDED);
+        }
+        else if (c2 < 0) {
+            metadata.setUpgradeType(UpgradeType.DOWNGRADE_NEEDED);
+        }
+        else if (c2 == 0) {
+            metadata.setUpgradeType(UpgradeType.UPGRADE_NOT_NEEDED);
+        }
+        else {
+            metadata.setUpgradeType(UpgradeType.UPGRADE_NEEDED);
+        }
+
+        return metadata;
+    }
+
+    @Override
+    protected Resource performNeededUpgrade() throws ConfigurationException {
+        throw new UnsupportedOperationException("TODO");
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6Test.java?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6Test.java
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/java/org/apache/cayenne/project2/upgrade/v6/ProjectUpgrader_V6Test.java
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,99 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.project2.upgrade.v6;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.project2.upgrade.UpgradeHandler;
+import org.apache.cayenne.project2.upgrade.UpgradeMetaData;
+import org.apache.cayenne.project2.upgrade.UpgradeType;
+import org.apache.cayenne.resource.Resource;
+import org.apache.cayenne.resource.URLResource;
+
+public class ProjectUpgrader_V6Test extends TestCase {
+
+    public void testMetadata_3_0_0_1() {
+
+        String baseUrl = getClass().getPackage().getName().replace('.', '/');
+        URL url = getClass().getClassLoader().getResource(
+                baseUrl + "/3_0_0_1a/cayenne.xml");
+        assertNotNull(url);
+
+        ProjectUpgrader_V6 upgrader = new ProjectUpgrader_V6();
+
+        Resource source = new URLResource(url);
+        UpgradeHandler handler = upgrader.getUpgradeHandler(source);
+
+        assertNotNull(handler);
+        assertSame(source, handler.getProjectSource());
+
+        UpgradeMetaData md = handler.getUpgradeMetaData();
+        assertNotNull(md);
+
+        assertSame(UpgradeType.UPGRADE_NEEDED, md.getUpgradeType());
+        assertNull(md.getIntermediateUpgradeVersion());
+        assertEquals("3.0.0.1", md.getProjectVersion());
+        assertEquals("6", md.getSupportedVersion());
+    }
+
+    public void testMetadata_Type2_0() {
+        String baseUrl = getClass().getPackage().getName().replace('.', '/');
+        URL url = getClass().getClassLoader().getResource(baseUrl + "/2_0a/cayenne.xml");
+        assertNotNull(url);
+
+        ProjectUpgrader_V6 upgrader = new ProjectUpgrader_V6();
+
+        Resource source = new URLResource(url);
+        UpgradeHandler handler = upgrader.getUpgradeHandler(source);
+
+        assertNotNull(handler);
+        assertSame(source, handler.getProjectSource());
+
+        UpgradeMetaData md = handler.getUpgradeMetaData();
+        assertNotNull(md);
+        assertSame(UpgradeType.INTERMEDIATE_UPGRADE_NEEDED, md.getUpgradeType());
+        assertEquals("3.0.0.1", md.getIntermediateUpgradeVersion());
+        assertEquals("2.0", md.getProjectVersion());
+        assertEquals("6", md.getSupportedVersion());
+    }
+
+    public void testMetadata_Type6() {
+        String baseUrl = getClass().getPackage().getName().replace('.', '/');
+        URL url = getClass().getClassLoader().getResource(
+                baseUrl + "/6a/cayenne-PROJECT1.xml");
+        assertNotNull(url);
+
+        ProjectUpgrader_V6 upgrader = new ProjectUpgrader_V6();
+
+        Resource source = new URLResource(url);
+        UpgradeHandler handler = upgrader.getUpgradeHandler(source);
+
+        assertNotNull(handler);
+        assertSame(source, handler.getProjectSource());
+
+        UpgradeMetaData md = handler.getUpgradeMetaData();
+        assertNotNull(md);
+        assertSame(UpgradeType.UPGRADE_NOT_NEEDED, md.getUpgradeType());
+        assertNull(md.getIntermediateUpgradeVersion());
+        assertEquals("6", md.getProjectVersion());
+        assertEquals("6", md.getSupportedVersion());
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/cayenne.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/cayenne.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/cayenne.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/cayenne.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domains project-version="2.0">
+<domain name="d1">
+	<map name="d1Map" location="d1Map.map.xml"/>
+
+	<node name="d1Node"
+		 datasource="d1Node.driver.xml"
+		 factory="org.apache.cayenne.conf.DriverDataSourceFactory">
+			<map-ref name="d1Map"/>
+	 </node>
+</domain>
+</domains>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Map.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Map.map.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Map.map.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Map.map.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map project-version="2.0">
+</data-map>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Node.driver.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Node.driver.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Node.driver.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/2_0a/d1Node.driver.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<driver project-version="2.0">
+	<connectionPool min="1" max="1" />
+</driver>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/cayenne.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/cayenne.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/cayenne.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/cayenne.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domains project-version="3.0.0.1">
+<domain name="d1">
+	<map name="d1Map1" location="d1Map1.map.xml"/>
+	<map name="d1Map2" location="d1Map2.map.xml"/>
+
+	<node name="d1NodeDriver"
+		 datasource="d1NodeDriver.driver.xml"
+		 factory="org.apache.cayenne.conf.DriverDataSourceFactory">
+			<map-ref name="d1Map1"/>
+			<map-ref name="d1Map2"/>
+	 </node>
+</domain>
+<domain name="d2">
+	<node name="d2NodeDBCP"
+		 datasource="dbcpx"
+		 factory="org.apache.cayenne.conf.DBCPDataSourceFactory">
+	 </node>
+	<node name="d2NodeJNDI"
+		 datasource="jndi/x"
+		 factory="org.apache.cayenne.conf.JNDIDataSourceFactory">
+	 </node>
+</domain>
+</domains>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map1.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map1.map.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map1.map.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map1.map.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+  project-version="3.0.0.1">
+</data-map>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map2.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map2.map.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map2.map.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1Map2.map.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+  project-version="3.0.0.1">
+	<db-entity name="table1">
+		<db-attribute name="pk" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
+</data-map>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1NodeDriver.driver.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1NodeDriver.driver.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1NodeDriver.driver.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/3_0_0_1a/d1NodeDriver.driver.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<driver project-version="3.0.0.1" class="org.hsqldb.jdbcDriver">
+	<url value="jdbc:hsqldb:mem:xdb"/>
+	<connectionPool min="1" max="1"/>
+	<login userName="user" password="password"/>
+</driver>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/cayenne-PROJECT1.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/cayenne-PROJECT1.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/cayenne-PROJECT1.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/cayenne-PROJECT1.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain name="DefaultDomain" project-version="6">
+
+	<map name="testProjectMap1_1" />
+	<map name="testProjectMap1_2" />
+
+	<node name="testProjectNode1"
+		adapter="org.example.test.Adapter" factory="org.example.test.DataSourceFactory">
+		<data-source>
+			<connectionPool min="1" max="1" />
+			<login />
+		</data-source>
+		<map-ref name="testProjectMap1_1" />
+	</node>
+</domain>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_1.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_1.map.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_1.map.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_1.map.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+	project-version="6">
+
+</data-map>

Added: cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_2.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_2.map.xml?rev=890179&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_2.map.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-project-unpublished/src/test/resources/org/apache/cayenne/project2/upgrade/v6/6a/testProjectMap1_2.map.xml
Mon Dec 14 04:56:50 2009
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+	project-version="6">
+
+</data-map>



Mime
View raw message