Author: ppoddar
Date: Wed Aug 11 19:00:15 2010
New Revision: 984536
URL: http://svn.apache.org/viewvc?rev=984536&view=rev
Log:
Process discrimnator tag
Modified:
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xml
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xsd
Modified:
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
URL:
http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java?rev=984536&r1=984535&r2=984536&view=diff
==============================================================================
---
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
(original)
+++
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
Wed Aug 11 19:00:15 2010
@@ -285,12 +285,14 @@ public class MigrationTool {
}
/**
- * Actions in order of their operation.
- * @param target
- * @param source
- * @param current TODO
- * @param actions
- * @return
+ * Execute actions associated with the given source element. The source
element is associated
+ * with a sequence of actions for its attributes and sub-elements while
{...@link #buildparsing the input
+ * rules.
+ *
+ * @param target the target document to be populated
+ * @param source the source DOM element to be migrated.
+ * @param current the latest/current target element that may be
structurally modified
+ * @return the
*/
protected Element executeActions(Document target, Element source, Element
current) {
List<Actions> actions = actionMap.get(source.getNodeName());
Modified:
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
URL:
http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java?rev=984536&r1=984535&r2=984536&view=diff
==============================================================================
---
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
(original)
+++
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
Wed Aug 11 19:00:15 2010
@@ -19,8 +19,10 @@
package org.apache.openjpa.tools.action;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.w3c.dom.Attr;
@@ -234,11 +236,20 @@ public interface Actions {//extends Comp
public static class RenameChildNode extends Abstract {
private final String sourcetName;
private final String targetName;
+ private List<String> _ignores = new ArrayList<String>();
+ private Map<String, String> _valueMap = new HashMap<String, String>();
public RenameChildNode(Element s) {
super(Code.RENAME_CHILD_NODE, s);
sourcetName = getAttribute("from");
targetName = getAttribute("to", "from");
+
+ NodeList values = s.getElementsByTagName("ignore-attr");
+ int M = values.getLength();
+ for (int i = 0; i < M; i++) {
+ Element item = (Element)values.item(i);
+ _ignores.add(item.getAttribute("name"));
+ }
}
public Node run(Document targetDoc, Element source, Element current,
@@ -252,7 +263,9 @@ public interface Actions {//extends Comp
int M = attrs.getLength();
for (int i = 0; i< M ; i++) {
Attr sourceAttr = (Attr)attrs.item(i);
- newNode.setAttribute(sourceAttr.getNodeName(),
sourceAttr.getValue());
+ if (!_ignores.contains(sourceAttr.getNodeName())) {
+ newNode.setAttribute(sourceAttr.getNodeName(),
sourceAttr.getValue());
+ }
}
return newNode;
}
@@ -400,11 +413,13 @@ public interface Actions {//extends Comp
String sourceName;
String targetName;
String sourceAttrName;
+ String targetAttrName;
public SplitNode(Element e) {
super(Code.SPLIT_NODE, e);
sourceName = e.getAttribute("from");
targetName = e.getAttribute("to");
sourceAttrName = e.getAttribute("on");
+ targetAttrName = getAttribute("as", sourceAttrName);
}
public Node run(Document targetDoc, Element source, Element current,
@@ -413,9 +428,9 @@ public interface Actions {//extends Comp
Element sourceChild = getElementByName(source, sourceName, false);
if (sourceChild == null)
return null;
- forParent.setAttribute(sourceAttrName,
sourceChild.getAttribute(sourceAttrName));
+ forParent.setAttribute(targetAttrName,
sourceChild.getAttribute(sourceAttrName));
current.getParentNode().insertBefore(forParent, current);
-
+ consumedElements.add(sourceName);
return null;
}
}
Modified:
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xml
URL:
http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xml?rev=984536&r1=984535&r2=984536&view=diff
==============================================================================
---
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xml
(original)
+++
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xml
Wed Aug 11 19:00:15 2010
@@ -54,6 +54,7 @@
<ignore-node name="cache"/>
<insert-node name="attributes"/>
<split-node from="composite-id" to="id-class" on="class"/>
+ <split-node from="discriminator" to="discriminator-column" on="column"
as="name"/>
</actions>
@@ -110,7 +111,9 @@
<promote-attr from="column" to="join-column" as="name">
<consume-attr from="length" to="length"/>
</promote-attr>
- <rename-child-node from="column" to="join-column"/>
+ <rename-child-node from="column" to="join-column">
+ <ignore-attr name="index"/>
+ </rename-child-node>
</actions>
<actions for="column">
@@ -141,4 +144,10 @@
<actions for="cache">
</actions>
+
+<actions for="discriminator">
+ <rename-node to="discrimnator-column"></rename-node>
+</actions>
+<actions for="subclass">
+</actions>
</migration-actions>
Modified:
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xsd
URL:
http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xsd?rev=984536&r1=984535&r2=984536&view=diff
==============================================================================
---
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xsd
(original)
+++
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/migration-actions.xsd
Wed Aug 11 19:00:15 2010
@@ -1,32 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!--
- 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.
+<!--
+ 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.
-->
-
<!-- =========================================================================
Schema for specifying actions to migrate a Hibernate Mapping file to JPA
mapping file.
=======================================================================
-->
-<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- attributeFormDefault="unqualified"
- elementFormDefault="qualified"
- version="1.0">
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -49,7 +45,7 @@
<xsd:element name="migration-actions">
<xsd:complexType>
<xsd:sequence>
- <xsd:element name="actions"
type="action-sequence-type" minOccurs="1" maxOccurs="unbounded"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="1" name="actions" type="action-sequence-type"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
@@ -57,27 +53,18 @@
<xsd:complexType name="action-sequence-type">
<xsd:choice>
<xsd:sequence>
- <xsd:element name="replace-node"
minOccurs="0" maxOccurs="1"
- type="replace-node-type"/>
- <xsd:element name="rename-node"
minOccurs="0" maxOccurs="1"
- type="rename-node-type"/>
- <xsd:element name="rename-attr"
minOccurs="0" maxOccurs="unbounded"
- type="rename-attr-type"/>
- <xsd:element name="promote-attr"
minOccurs="0" maxOccurs="unbounded"
- type="promote-attr-type"/>
- <xsd:element name="rename-child-node"
minOccurs="0" maxOccurs="unbounded"
- type="rename-child-node-type"/>
- <xsd:element name="ignore-attr"
minOccurs="0" maxOccurs="unbounded"
- type="ignore-attr-type"/>
- <xsd:element name="ignore-node"
minOccurs="0" maxOccurs="unbounded"
- type="ignore-node-type"/>
- <xsd:element name="insert-node"
minOccurs="0" maxOccurs="unbounded"
- type="insert-node-type"/>
- <xsd:element name="split-node" minOccurs="0"
maxOccurs="unbounded"
- type="split-node-type"/>
+ <xsd:element maxOccurs="1" minOccurs="0"
name="replace-node" type="replace-node-type"/>
+ <xsd:element maxOccurs="1" minOccurs="0"
name="rename-node" type="rename-node-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="rename-attr" type="rename-attr-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="promote-attr" type="promote-attr-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="rename-child-node" type="rename-child-node-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="ignore-attr" type="ignore-attr-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="ignore-node" type="ignore-node-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="insert-node" type="insert-node-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="split-node" type="split-node-type"/>
</xsd:sequence>
- <xsd:element name="custom-node" minOccurs="1"
maxOccurs="1"/>
+ <xsd:element maxOccurs="1" minOccurs="1"
name="custom-node"/>
</xsd:choice>
<xsd:attribute name="for" type="xsd:string"
use="required"/>
</xsd:complexType>
@@ -85,18 +72,18 @@
<!-- Replace an element with one of its sub-element.
-->
<!-- Used for collection container tags such as bag/set of Hibernate
-->
<xsd:complexType name="replace-node-type">
- <xsd:attribute name="with" type="xsd:string" use="required"/>
+ <xsd:attribute name="with" type="xsd:string" use="required"/>
</xsd:complexType>
<!-- Ignores an attribute. -->
<xsd:complexType name="ignore-attr-type">
- <xsd:attribute name="name" type="xsd:string" use="required"/>
+ <xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="warn" type="xsd:boolean"/>
</xsd:complexType>
<!-- Ignores a sub-element. -->
<xsd:complexType name="ignore-node-type">
- <xsd:attribute name="name" type="xsd:string" use="required"/>
+ <xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="warn" type="xsd:boolean"/>
</xsd:complexType>
@@ -108,7 +95,7 @@
<!-- Renames a attribute. -->
<xsd:complexType name="rename-attr-type">
<xsd:sequence>
- <xsd:element name="map-value" minOccurs="0"
maxOccurs="unbounded" type="map-value-type"/>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="map-value" type="map-value-type"/>
</xsd:sequence>
<xsd:attribute name="from" type="xsd:string" use="required"/>
<xsd:attribute name="to" type="xsd:string"/>
@@ -119,19 +106,20 @@
<xsd:complexType name="promote-attr-type">
<xsd:sequence>
<xsd:choice>
- <xsd:element name="consume-attr" minOccurs="0"
maxOccurs="unbounded" type="consume-attr-type"/>
- <xsd:element name="map-value" minOccurs="0"
maxOccurs="unbounded" type="map-value-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="consume-attr" type="consume-attr-type"/>
+ <xsd:element maxOccurs="unbounded"
minOccurs="0" name="map-value" type="map-value-type"/>
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="from" type="xsd:string" use="required"/>
- <xsd:attribute name="to" type="xsd:string"/>
- <xsd:attribute name="as" type="xsd:string"/>
+ <xsd:attribute name="to" type="xsd:string"/>
+ <xsd:attribute name="as" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="split-node-type">
<xsd:attribute name="from" type="xsd:string" use="required"/>
- <xsd:attribute name="to" type="xsd:string"/>
- <xsd:attribute name="on" type="xsd:string" use="required"/>
+ <xsd:attribute name="to" type="xsd:string"/>
+ <xsd:attribute name="on" type="xsd:string" use="required"/>
+ <xsd:attribute name="as" type="xsd:string"/>
</xsd:complexType>
<!-- Inserts a 'dummy' sub-element that had no source counterpart. -->
@@ -141,23 +129,26 @@
<!-- Renames a child node -->
<xsd:complexType name="rename-child-node-type">
+ <xsd:sequence>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="ignore-attr" type="ignore-attr-type"/>
+ </xsd:sequence>
<xsd:attribute name="from" type="xsd:string" use="required"/>
- <xsd:attribute name="to" type="xsd:string" use="required"/>
+ <xsd:attribute name="to" type="xsd:string" use="required"/>
</xsd:complexType>
<!-- Maps an attribute value to another -->
<xsd:complexType name="map-value-type">
<xsd:attribute name="from" type="xsd:string" use="required"/>
- <xsd:attribute name="to" type="xsd:string" use="required"/>
+ <xsd:attribute name="to" type="xsd:string" use="required"/>
</xsd:complexType>
<!-- Maps an attribute value to another while transferring it from
parent to a child -->
<xsd:complexType name="consume-attr-type">
<xsd:sequence>
- <xsd:element name="map-value" minOccurs="0"
maxOccurs="unbounded" type="map-value-type"/>
+ <xsd:element maxOccurs="unbounded" minOccurs="0"
name="map-value" type="map-value-type"/>
</xsd:sequence>
<xsd:attribute name="from" type="xsd:string" use="required"/>
- <xsd:attribute name="to" type="xsd:string" use="required"/>
+ <xsd:attribute name="to" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>