You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by wi...@apache.org on 2007/07/21 03:25:49 UTC
svn commit: r558221 [1/2] - in /openjpa/trunk:
openjpa-jdbc-5/src/main/java/org/apache/openjpa/jdbc/meta/
openjpa-jdbc-5/src/main/java/org/apache/openjpa/meta/
openjpa-kernel/src/main/java/org/apache/openjpa/meta/
openjpa-persistence-jdbc/src/test/java...
Author: wisneskid
Date: Fri Jul 20 18:25:48 2007
New Revision: 558221
URL: http://svn.apache.org/viewvc?view=rev&rev=558221
Log:
OPENJPA-240 XMLMapping Query support, fix eol delimiters to unix style
Modified:
openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/jdbc/meta/XMLMappingRepository.java
openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/meta/XMLClassMetaData.java
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMapping.java
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMetaData.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Customer.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/EAddress.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Order.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/Address.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/CANAddress.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/GBRAddress.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/ObjectFactory.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/ShortAddress.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/USAAddress.java
Modified: openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/jdbc/meta/XMLMappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/jdbc/meta/XMLMappingRepository.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/jdbc/meta/XMLMappingRepository.java (original)
+++ openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/jdbc/meta/XMLMappingRepository.java Fri Jul 20 18:25:48 2007
@@ -1,82 +1,82 @@
-/*
- * 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.openjpa.jdbc.meta;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.openjpa.meta.FieldMetaData;
-import org.apache.openjpa.meta.XMLClassMetaData;
-import org.apache.openjpa.meta.XMLMapping;
-
-/**
- * Repository of object/relational mapping information.
- * (extended to include XML mapping metadata for XML columns)
- *
- * @author Catalina Wei
- * @since 1.0.0
- */
-public class XMLMappingRepository extends MappingRepository {
- // xml mapping
- protected final XMLMapping[] EMPTY_XMLMETAS;
- private final Map _xmlmetas = new HashMap();
-
- public XMLMappingRepository() {
- super();
- EMPTY_XMLMETAS = newXMLClassMetaDataArray(0);
- }
-
- public synchronized XMLClassMetaData addXMLClassMetaData(FieldMetaData fmd,
- String name) {
- XMLClassMetaData meta = newXMLClassMetaData(fmd, name);
- addXMLClassMetaData(fmd.getDeclaredType(), meta);
- return meta;
- }
-
- public XMLMapping getXMLClassMetaData(Class cls) {
- synchronized(_xmlmetas) {
- if (_xmlmetas.isEmpty())
- return null;
- else
- return (XMLClassMetaData) _xmlmetas.get(cls);
- }
- }
-
- public XMLMapping getXMLMetaData(FieldMetaData fmd) {
- XMLMapping xmlmeta = null;
- if (XMLClassMetaData.isXMLMapping(fmd.getDeclaredType())) {
- xmlmeta = getXMLClassMetaData(fmd.getDeclaredType());
- if (xmlmeta == null)
- xmlmeta = addXMLClassMetaData(fmd, fmd.getName());
- }
- return xmlmeta;
- }
-
- public synchronized void addXMLClassMetaData(Class cls, XMLMapping meta) {
- _xmlmetas.put(cls, meta);
- }
-
- protected XMLClassMetaData newXMLClassMetaData(FieldMetaData fmd, String name) {
- return new XMLClassMetaData(fmd.getDeclaredType(), name, this);
- }
-
- protected XMLMapping[] newXMLClassMetaDataArray(int length) {
- return new XMLClassMetaData[length];
- }
-}
+/*
+ * 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.openjpa.jdbc.meta;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.meta.XMLClassMetaData;
+import org.apache.openjpa.meta.XMLMapping;
+
+/**
+ * Repository of object/relational mapping information.
+ * (extended to include XML mapping metadata for XML columns)
+ *
+ * @author Catalina Wei
+ * @since 1.0.0
+ */
+public class XMLMappingRepository extends MappingRepository {
+ // xml mapping
+ protected final XMLMapping[] EMPTY_XMLMETAS;
+ private final Map _xmlmetas = new HashMap();
+
+ public XMLMappingRepository() {
+ super();
+ EMPTY_XMLMETAS = newXMLClassMetaDataArray(0);
+ }
+
+ public synchronized XMLClassMetaData addXMLClassMetaData(FieldMetaData fmd,
+ String name) {
+ XMLClassMetaData meta = newXMLClassMetaData(fmd, name);
+ addXMLClassMetaData(fmd.getDeclaredType(), meta);
+ return meta;
+ }
+
+ public XMLMapping getXMLClassMetaData(Class cls) {
+ synchronized(_xmlmetas) {
+ if (_xmlmetas.isEmpty())
+ return null;
+ else
+ return (XMLClassMetaData) _xmlmetas.get(cls);
+ }
+ }
+
+ public XMLMapping getXMLMetaData(FieldMetaData fmd) {
+ XMLMapping xmlmeta = null;
+ if (XMLClassMetaData.isXMLMapping(fmd.getDeclaredType())) {
+ xmlmeta = getXMLClassMetaData(fmd.getDeclaredType());
+ if (xmlmeta == null)
+ xmlmeta = addXMLClassMetaData(fmd, fmd.getName());
+ }
+ return xmlmeta;
+ }
+
+ public synchronized void addXMLClassMetaData(Class cls, XMLMapping meta) {
+ _xmlmetas.put(cls, meta);
+ }
+
+ protected XMLClassMetaData newXMLClassMetaData(FieldMetaData fmd, String name) {
+ return new XMLClassMetaData(fmd.getDeclaredType(), name, this);
+ }
+
+ protected XMLMapping[] newXMLClassMetaDataArray(int length) {
+ return new XMLClassMetaData[length];
+ }
+}
Modified: openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/meta/XMLClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/meta/XMLClassMetaData.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/meta/XMLClassMetaData.java (original)
+++ openjpa/trunk/openjpa-jdbc-5/src/main/java/org/apache/openjpa/meta/XMLClassMetaData.java Fri Jul 20 18:25:48 2007
@@ -1,227 +1,227 @@
-/*
- * 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.openjpa.meta;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Member;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-import org.apache.openjpa.jdbc.meta.XMLMappingRepository;
-import org.apache.openjpa.meta.JavaTypes;
-import org.apache.openjpa.meta.XMLMapping;
-import org.apache.openjpa.meta.XMLMetaData;
-import org.apache.commons.lang.StringUtils;
-
-/**
- * Contains metadata about a persistent field that maps to an xml column.
- * This metadata is loaded at runtime when query involves predicates
- * that navigate through xpath.
- *
- * @author Catalina Wei
- * @since 1.0.0
- */
-public class XMLClassMetaData implements XMLMapping
-{
- private Class _type;
- private int _code = JavaTypes.OBJECT;
- private int _xmltype = XMLTYPE;
- private String _name = null;
- private String _xmlname = null;
- private String _xmlnamespace = null;
- private boolean _isXMLRootElement = false;
- private HashMap _fieldMap = new HashMap();
-
- /**
- * Constructor.
- *
- * @param type the class that contains XmlType annotation.
- * @name the persistent field name that maps to xml column
- * @param repo the meta repository.
- */
- public XMLClassMetaData(Class type, String name, XMLMappingRepository repos) {
- _type = type;
- _isXMLRootElement = _type.getAnnotation(XmlRootElement.class) != null;
- if (_isXMLRootElement) {
- _xmlname = ((XmlRootElement) _type.getAnnotation
- (XmlRootElement.class)).name();
- _xmlnamespace = ((XmlRootElement) _type.getAnnotation
- (XmlRootElement.class)).namespace();
- }
- else {
- _xmlname = ((XmlType) _type.getAnnotation
- (XmlType.class)).name();
- _xmlnamespace = ((XmlType) _type.getAnnotation
- (XmlType.class)).namespace();
- _name = name;
- }
- populateFromReflection(_type, repos);
- }
-
- /**
- * Constructor. Supply described type and repository.
- *
- * @param type the class that contains XmlType annotation.
- * @param repo the meta repository.
- */
- protected XMLClassMetaData(Class type, XMLMappingRepository repos) {
- _type = type;
- _isXMLRootElement = _type.getAnnotation(XmlRootElement.class) != null;
- if (_isXMLRootElement) {
- _xmlname = ((XmlRootElement) _type.getAnnotation
- (XmlRootElement.class)).name();
- _xmlnamespace = ((XmlRootElement) _type.getAnnotation
- (XmlRootElement.class)).namespace();
- }
- else {
- _xmlname = ((XmlType) _type.getAnnotation
- (XmlType.class)).name();
- _xmlnamespace = ((XmlType) _type.getAnnotation
- (XmlType.class)).namespace();
- }
- populateFromReflection(_type, repos);
- repos.addXMLClassMetaData(type, this);
- }
-
- /**
- * Given a class type return true if XmlType annotation exists
- * @param type
- * @return true if XmlType annotation is present else false.
- */
- public static boolean isXMLMapping(Class type) {
- return type.isAnnotationPresent(XmlType.class);
- }
-
- public void setName(String name) {
- _name = name;
- }
-
- public String getName() {
- return _name;
- }
-
- public void setXmlname(String name) {
- _xmlname = name;
- }
-
- public String getXmlname() {
- return _isXMLRootElement ? null : _xmlname;
- }
-
- public void setXmlnamespace(String name) {
- // avoid JAXB XML bind default name
- if (!StringUtils.equals(defaultName, name))
- _xmlnamespace = name;
- }
-
- public String getXmlnamespace() {
- return _xmlnamespace;
- }
-
- public boolean isXmlRootElement() {
- return _isXMLRootElement;
- }
-
- public boolean isXmlElement() {
- return false;
- }
-
- public boolean isXmlAttribute() {
- return false;
- }
-
- public XMLMapping getFieldMapping(String name) {
- return (XMLMapping) _fieldMap.get(name);
- }
-
- public void setType(Class type) {
- _type = type;
- }
-
- public Class getType() {
- return _type;
- }
-
- public int getTypeCode() {
- return _code;
- }
-
- public void setXmltype(int type) {
- _xmltype = type;
- }
- public int getXmltype() {
- return _xmltype;
- }
-
- private synchronized void populateFromReflection(Class cls,
- XMLMappingRepository repos) {
- Member[] members;
- if (((XmlAccessorType)cls.getAnnotation(XmlAccessorType.class)).value()
- == XmlAccessType.FIELD)
- members = cls.getDeclaredFields();
- else
- members = cls.getDeclaredMethods();
- for (int i = 0; i < members.length; i++) {
- Member member = members[i];
- AnnotatedElement el = (AnnotatedElement) member;
- XMLMapping field = null;
- if (el.getAnnotation(XmlElement.class) != null) {
- String xmlname = el.getAnnotation(XmlElement.class).name();
- // avoid JAXB XML bind default name
- if (StringUtils.equals(defaultName, xmlname))
- xmlname = member.getName();
- if (((Field) member).getType().
- isAnnotationPresent(XmlType.class)) {
- field = new XMLClassMetaData(((Field) member).getType(),
- repos);
- field.setXmltype(XMLTYPE);
- field.setXmlname(xmlname);
- }
- else {
- field = new XMLMetaData();
- field.setXmltype(ELEMENT);
- field.setXmlname(xmlname);
- field.setXmlnamespace(el.getAnnotation(XmlElement.class)
- .namespace());
- }
- }
- else if (el.getAnnotation(XmlAttribute.class) != null) {
- field = new XMLMetaData();
- field.setXmltype(XMLMetaData.ATTRIBUTE);
- String xmlname = el.getAnnotation(XmlAttribute.class).name();
- // avoid JAXB XML bind default name
- if (StringUtils.equals(defaultName, xmlname))
- xmlname = member.getName();
- field.setXmlname("@"+xmlname);
- field.setXmlnamespace(el.getAnnotation(XmlAttribute.class)
- .namespace());
- }
- field.setName(member.getName());
- field.setType(((Field) member).getType());
- _fieldMap.put(member.getName(), field);
- }
- }
-}
+/*
+ * 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.openjpa.meta;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Member;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.openjpa.jdbc.meta.XMLMappingRepository;
+import org.apache.openjpa.meta.JavaTypes;
+import org.apache.openjpa.meta.XMLMapping;
+import org.apache.openjpa.meta.XMLMetaData;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Contains metadata about a persistent field that maps to an xml column.
+ * This metadata is loaded at runtime when query involves predicates
+ * that navigate through xpath.
+ *
+ * @author Catalina Wei
+ * @since 1.0.0
+ */
+public class XMLClassMetaData implements XMLMapping
+{
+ private Class _type;
+ private int _code = JavaTypes.OBJECT;
+ private int _xmltype = XMLTYPE;
+ private String _name = null;
+ private String _xmlname = null;
+ private String _xmlnamespace = null;
+ private boolean _isXMLRootElement = false;
+ private HashMap _fieldMap = new HashMap();
+
+ /**
+ * Constructor.
+ *
+ * @param type the class that contains XmlType annotation.
+ * @name the persistent field name that maps to xml column
+ * @param repo the meta repository.
+ */
+ public XMLClassMetaData(Class type, String name, XMLMappingRepository repos) {
+ _type = type;
+ _isXMLRootElement = _type.getAnnotation(XmlRootElement.class) != null;
+ if (_isXMLRootElement) {
+ _xmlname = ((XmlRootElement) _type.getAnnotation
+ (XmlRootElement.class)).name();
+ _xmlnamespace = ((XmlRootElement) _type.getAnnotation
+ (XmlRootElement.class)).namespace();
+ }
+ else {
+ _xmlname = ((XmlType) _type.getAnnotation
+ (XmlType.class)).name();
+ _xmlnamespace = ((XmlType) _type.getAnnotation
+ (XmlType.class)).namespace();
+ _name = name;
+ }
+ populateFromReflection(_type, repos);
+ }
+
+ /**
+ * Constructor. Supply described type and repository.
+ *
+ * @param type the class that contains XmlType annotation.
+ * @param repo the meta repository.
+ */
+ protected XMLClassMetaData(Class type, XMLMappingRepository repos) {
+ _type = type;
+ _isXMLRootElement = _type.getAnnotation(XmlRootElement.class) != null;
+ if (_isXMLRootElement) {
+ _xmlname = ((XmlRootElement) _type.getAnnotation
+ (XmlRootElement.class)).name();
+ _xmlnamespace = ((XmlRootElement) _type.getAnnotation
+ (XmlRootElement.class)).namespace();
+ }
+ else {
+ _xmlname = ((XmlType) _type.getAnnotation
+ (XmlType.class)).name();
+ _xmlnamespace = ((XmlType) _type.getAnnotation
+ (XmlType.class)).namespace();
+ }
+ populateFromReflection(_type, repos);
+ repos.addXMLClassMetaData(type, this);
+ }
+
+ /**
+ * Given a class type return true if XmlType annotation exists
+ * @param type
+ * @return true if XmlType annotation is present else false.
+ */
+ public static boolean isXMLMapping(Class type) {
+ return type.isAnnotationPresent(XmlType.class);
+ }
+
+ public void setName(String name) {
+ _name = name;
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public void setXmlname(String name) {
+ _xmlname = name;
+ }
+
+ public String getXmlname() {
+ return _isXMLRootElement ? null : _xmlname;
+ }
+
+ public void setXmlnamespace(String name) {
+ // avoid JAXB XML bind default name
+ if (!StringUtils.equals(defaultName, name))
+ _xmlnamespace = name;
+ }
+
+ public String getXmlnamespace() {
+ return _xmlnamespace;
+ }
+
+ public boolean isXmlRootElement() {
+ return _isXMLRootElement;
+ }
+
+ public boolean isXmlElement() {
+ return false;
+ }
+
+ public boolean isXmlAttribute() {
+ return false;
+ }
+
+ public XMLMapping getFieldMapping(String name) {
+ return (XMLMapping) _fieldMap.get(name);
+ }
+
+ public void setType(Class type) {
+ _type = type;
+ }
+
+ public Class getType() {
+ return _type;
+ }
+
+ public int getTypeCode() {
+ return _code;
+ }
+
+ public void setXmltype(int type) {
+ _xmltype = type;
+ }
+ public int getXmltype() {
+ return _xmltype;
+ }
+
+ private synchronized void populateFromReflection(Class cls,
+ XMLMappingRepository repos) {
+ Member[] members;
+ if (((XmlAccessorType)cls.getAnnotation(XmlAccessorType.class)).value()
+ == XmlAccessType.FIELD)
+ members = cls.getDeclaredFields();
+ else
+ members = cls.getDeclaredMethods();
+ for (int i = 0; i < members.length; i++) {
+ Member member = members[i];
+ AnnotatedElement el = (AnnotatedElement) member;
+ XMLMapping field = null;
+ if (el.getAnnotation(XmlElement.class) != null) {
+ String xmlname = el.getAnnotation(XmlElement.class).name();
+ // avoid JAXB XML bind default name
+ if (StringUtils.equals(defaultName, xmlname))
+ xmlname = member.getName();
+ if (((Field) member).getType().
+ isAnnotationPresent(XmlType.class)) {
+ field = new XMLClassMetaData(((Field) member).getType(),
+ repos);
+ field.setXmltype(XMLTYPE);
+ field.setXmlname(xmlname);
+ }
+ else {
+ field = new XMLMetaData();
+ field.setXmltype(ELEMENT);
+ field.setXmlname(xmlname);
+ field.setXmlnamespace(el.getAnnotation(XmlElement.class)
+ .namespace());
+ }
+ }
+ else if (el.getAnnotation(XmlAttribute.class) != null) {
+ field = new XMLMetaData();
+ field.setXmltype(XMLMetaData.ATTRIBUTE);
+ String xmlname = el.getAnnotation(XmlAttribute.class).name();
+ // avoid JAXB XML bind default name
+ if (StringUtils.equals(defaultName, xmlname))
+ xmlname = member.getName();
+ field.setXmlname("@"+xmlname);
+ field.setXmlnamespace(el.getAnnotation(XmlAttribute.class)
+ .namespace());
+ }
+ field.setName(member.getName());
+ field.setType(((Field) member).getType());
+ _fieldMap.put(member.getName(), field);
+ }
+ }
+}
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMapping.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMapping.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMapping.java Fri Jul 20 18:25:48 2007
@@ -1,119 +1,119 @@
-/*
- * 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.openjpa.meta;
-
-import java.io.Serializable;
-
-/**
- * Describe metadata about an xml type.
- *
- * @author Catalina Wei
- * @since 1.0.0
- */
-public interface XMLMapping extends Serializable {
- /**
- * JAXB XML binding default name
- */
- public static final String defaultName = "##default";
- public static final int XMLTYPE = 0;
- public static final int ELEMENT = 1;
- public static final int ATTRIBUTE = 2;
-
- /**
- * Return true if mapping on an XmlRootElement.
- */
- public boolean isXmlRootElement();
-
- /**
- * Return true if mapping on an XmlElement.
- */
- public boolean isXmlElement();
-
- /**
- * Return true if mapping on an XmlAttribute.
- */
- public boolean isXmlAttribute();
-
- /**
- * Return XMLMapping for a given field.
- * @param name the field name.
- * @return XMLMapping.
- */
- public XMLMapping getFieldMapping(String name);
-
- /**
- * Set type.
- */
- public void setType(Class type);
-
- /**
- * Return type.
- */
- public Class getType();
-
- /**
- * Return type code.
- */
- public int getTypeCode();
-
- /**
- * Return the mapping name.
- */
- public String getName();
-
- /**
- * Return xml element tag name or xml attribute name.
- */
- public String getXmlname();
-
- /**
- * Return xml namespace.
- */
- public String getXmlnamespace();
-
- /**
- * Set field name.
- * @param name the field name.
- */
- public void setName(String name);
-
- /**
- * Set xml element or attribute name.
- * @param name the element name or attribute name
- */
- public void setXmlname(String name);
-
- /**
- * Set namespace.
- * @param namespace
- */
- public void setXmlnamespace(String namespace);
-
- /**
- * Set xmltype
- * @param type XMLTYPE, ELEMENT, or ATTRIBUTE
- */
- public void setXmltype(int type);
-
- /**
- * Return xmltype
- * @return xmltype
- */
- public int getXmltype();
-}
+/*
+ * 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.openjpa.meta;
+
+import java.io.Serializable;
+
+/**
+ * Describe metadata about an xml type.
+ *
+ * @author Catalina Wei
+ * @since 1.0.0
+ */
+public interface XMLMapping extends Serializable {
+ /**
+ * JAXB XML binding default name
+ */
+ public static final String defaultName = "##default";
+ public static final int XMLTYPE = 0;
+ public static final int ELEMENT = 1;
+ public static final int ATTRIBUTE = 2;
+
+ /**
+ * Return true if mapping on an XmlRootElement.
+ */
+ public boolean isXmlRootElement();
+
+ /**
+ * Return true if mapping on an XmlElement.
+ */
+ public boolean isXmlElement();
+
+ /**
+ * Return true if mapping on an XmlAttribute.
+ */
+ public boolean isXmlAttribute();
+
+ /**
+ * Return XMLMapping for a given field.
+ * @param name the field name.
+ * @return XMLMapping.
+ */
+ public XMLMapping getFieldMapping(String name);
+
+ /**
+ * Set type.
+ */
+ public void setType(Class type);
+
+ /**
+ * Return type.
+ */
+ public Class getType();
+
+ /**
+ * Return type code.
+ */
+ public int getTypeCode();
+
+ /**
+ * Return the mapping name.
+ */
+ public String getName();
+
+ /**
+ * Return xml element tag name or xml attribute name.
+ */
+ public String getXmlname();
+
+ /**
+ * Return xml namespace.
+ */
+ public String getXmlnamespace();
+
+ /**
+ * Set field name.
+ * @param name the field name.
+ */
+ public void setName(String name);
+
+ /**
+ * Set xml element or attribute name.
+ * @param name the element name or attribute name
+ */
+ public void setXmlname(String name);
+
+ /**
+ * Set namespace.
+ * @param namespace
+ */
+ public void setXmlnamespace(String namespace);
+
+ /**
+ * Set xmltype
+ * @param type XMLTYPE, ELEMENT, or ATTRIBUTE
+ */
+ public void setXmltype(int type);
+
+ /**
+ * Return xmltype
+ * @return xmltype
+ */
+ public int getXmltype();
+}
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMetaData.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMetaData.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/XMLMetaData.java Fri Jul 20 18:25:48 2007
@@ -1,111 +1,111 @@
-/*
- * 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.openjpa.meta;
-
-import org.apache.commons.lang.StringUtils;
-
-/**
- * Contains metadata about an xml element or attribute
- *
- * @author Catalina Wei
- * @since 1.0.0
- */
-public class XMLMetaData implements XMLMapping {
-
- private String _name;
- private String _xmlname = null;
- private String _xmlnamespace = null;
- private Class _decType = Object.class;
- private int _decCode = JavaTypes.OBJECT;
- private Class _type = Object.class;
- private int _code = JavaTypes.OBJECT;
- private int _xmltype;
-
- public XMLMetaData() {
- }
-
- public Class getType() {
- return (_type == null) ? _decType : _type;
- }
-
- public void setType(Class type) {
- _type = type;
- if (type != null)
- setTypeCode(JavaTypes.getTypeCode(type));
- }
-
- public int getTypeCode() {
- return (_type == null) ? _decCode : _code;
- }
-
- // set JavaTypes code
- public void setTypeCode(int code) {
- _code = code;
- }
-
- public void setName(String name) {
- _name = name;
- }
-
- public String getName() {
- return _name;
- }
-
- public void setXmlname(String name) {
- _xmlname = name;
- }
-
- public String getXmlname() {
- return _xmlname;
- }
-
- public void setXmlnamespace(String name) {
- // avoid JAXB XML bind default name
- if (!StringUtils.equals(defaultName, name))
- _xmlnamespace = name;
- }
-
- public String getXmlnamespace() {
- return _xmlnamespace;
- }
-
- public void setXmltype(int type) {
- _xmltype = type;
- }
-
- public int getXmltype() {
- return _xmltype;
- }
-
- public boolean isXmlRootElement() {
- return false;
- }
-
- public boolean isXmlElement() {
- return _xmltype == ELEMENT;
- }
-
- public boolean isXmlAttribute() {
- return _xmltype == ATTRIBUTE;
- }
-
- public XMLMapping getFieldMapping(String name) {
- return null;
- }
-}
+/*
+ * 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.openjpa.meta;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Contains metadata about an xml element or attribute
+ *
+ * @author Catalina Wei
+ * @since 1.0.0
+ */
+public class XMLMetaData implements XMLMapping {
+
+ private String _name;
+ private String _xmlname = null;
+ private String _xmlnamespace = null;
+ private Class _decType = Object.class;
+ private int _decCode = JavaTypes.OBJECT;
+ private Class _type = Object.class;
+ private int _code = JavaTypes.OBJECT;
+ private int _xmltype;
+
+ public XMLMetaData() {
+ }
+
+ public Class getType() {
+ return (_type == null) ? _decType : _type;
+ }
+
+ public void setType(Class type) {
+ _type = type;
+ if (type != null)
+ setTypeCode(JavaTypes.getTypeCode(type));
+ }
+
+ public int getTypeCode() {
+ return (_type == null) ? _decCode : _code;
+ }
+
+ // set JavaTypes code
+ public void setTypeCode(int code) {
+ _code = code;
+ }
+
+ public void setName(String name) {
+ _name = name;
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public void setXmlname(String name) {
+ _xmlname = name;
+ }
+
+ public String getXmlname() {
+ return _xmlname;
+ }
+
+ public void setXmlnamespace(String name) {
+ // avoid JAXB XML bind default name
+ if (!StringUtils.equals(defaultName, name))
+ _xmlnamespace = name;
+ }
+
+ public String getXmlnamespace() {
+ return _xmlnamespace;
+ }
+
+ public void setXmltype(int type) {
+ _xmltype = type;
+ }
+
+ public int getXmltype() {
+ return _xmltype;
+ }
+
+ public boolean isXmlRootElement() {
+ return false;
+ }
+
+ public boolean isXmlElement() {
+ return _xmltype == ELEMENT;
+ }
+
+ public boolean isXmlAttribute() {
+ return _xmltype == ATTRIBUTE;
+ }
+
+ public XMLMapping getFieldMapping(String name) {
+ return null;
+ }
+}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Customer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Customer.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Customer.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Customer.java Fri Jul 20 18:25:48 2007
@@ -1,131 +1,131 @@
-/*
- * 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.openjpa.persistence.xmlmapping.entities;
-
-import javax.persistence.*;
-import java.util.Collection;
-import java.util.ArrayList;
-
-@Entity
-@Table(name="TCUSTOMER")
-public class Customer {
-
- @Embeddable
- public static class CustomerKey {
- public String countryCode;
- public int id;
-
- public CustomerKey(){}
-
- public CustomerKey(String cc, int id){
- countryCode=cc;
- this.id=id;
- }
-
- public String toString() {
- return countryCode+"/"+id;
- }
- @Override
- public boolean equals(Object obj){
- if (obj == this)
- return true;
- if (! (obj instanceof CustomerKey))
- return false;
- CustomerKey key = (CustomerKey)obj;
- if (key.countryCode.equals(this.countryCode)
- && key.id==this.id)
- return true;
- return false;
- }
-
- @Override
- public int hashCode() {
- return this.countryCode.hashCode()
- ^ this.id;
- }
- }
-
- public enum CreditRating { POOR, GOOD, EXCELLENT };
-
- @EmbeddedId
- CustomerKey cid;
- @Column(length=30)
- String name;
- @Enumerated
- CreditRating creditRating;
- @Embedded
- EAddress address;
- @Version
- long version;
-
- @OneToMany(fetch=FetchType.LAZY, mappedBy="customer")
- private Collection<Order> orders = new ArrayList<Order>();
-
- public Customer() {
- }
-
- public Customer(CustomerKey cid, String name, CreditRating rating) {
- this.cid=cid;
- this.name=name;
- this.creditRating=rating;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public CreditRating getRating() {
- return creditRating;
- }
-
- public void setRating(CreditRating rating) {
- this.creditRating = rating;
- }
-
- public Collection<Order> getOrders() {
- return orders;
- }
- public void setOrders(Collection<Order> orders) {
- this.orders = orders;
- }
-
- public String toString() {
- return "Customer:" + cid + " name:" + name;
- }
-
- public CustomerKey getCid() {
- return cid;
- }
-
- public void setCid(CustomerKey cid) {
- this.cid = cid;
- }
-
- public EAddress getAddress() {
- return address;
- }
-
- public void setAddress(EAddress address) {
- this.address = address;
- }
-}
+/*
+ * 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.openjpa.persistence.xmlmapping.entities;
+
+import javax.persistence.*;
+import java.util.Collection;
+import java.util.ArrayList;
+
+@Entity
+@Table(name="TCUSTOMER")
+public class Customer {
+
+ @Embeddable
+ public static class CustomerKey {
+ public String countryCode;
+ public int id;
+
+ public CustomerKey(){}
+
+ public CustomerKey(String cc, int id){
+ countryCode=cc;
+ this.id=id;
+ }
+
+ public String toString() {
+ return countryCode+"/"+id;
+ }
+ @Override
+ public boolean equals(Object obj){
+ if (obj == this)
+ return true;
+ if (! (obj instanceof CustomerKey))
+ return false;
+ CustomerKey key = (CustomerKey)obj;
+ if (key.countryCode.equals(this.countryCode)
+ && key.id==this.id)
+ return true;
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return this.countryCode.hashCode()
+ ^ this.id;
+ }
+ }
+
+ public enum CreditRating { POOR, GOOD, EXCELLENT };
+
+ @EmbeddedId
+ CustomerKey cid;
+ @Column(length=30)
+ String name;
+ @Enumerated
+ CreditRating creditRating;
+ @Embedded
+ EAddress address;
+ @Version
+ long version;
+
+ @OneToMany(fetch=FetchType.LAZY, mappedBy="customer")
+ private Collection<Order> orders = new ArrayList<Order>();
+
+ public Customer() {
+ }
+
+ public Customer(CustomerKey cid, String name, CreditRating rating) {
+ this.cid=cid;
+ this.name=name;
+ this.creditRating=rating;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public CreditRating getRating() {
+ return creditRating;
+ }
+
+ public void setRating(CreditRating rating) {
+ this.creditRating = rating;
+ }
+
+ public Collection<Order> getOrders() {
+ return orders;
+ }
+ public void setOrders(Collection<Order> orders) {
+ this.orders = orders;
+ }
+
+ public String toString() {
+ return "Customer:" + cid + " name:" + name;
+ }
+
+ public CustomerKey getCid() {
+ return cid;
+ }
+
+ public void setCid(CustomerKey cid) {
+ this.cid = cid;
+ }
+
+ public EAddress getAddress() {
+ return address;
+ }
+
+ public void setAddress(EAddress address) {
+ this.address = address;
+ }
+}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/EAddress.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/EAddress.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/EAddress.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/EAddress.java Fri Jul 20 18:25:48 2007
@@ -1,75 +1,75 @@
-/*
- * 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.openjpa.persistence.xmlmapping.entities;
-import javax.persistence.*;
-
-/*
- * example of an JPA embeddable class.
- * This class is used in Customer Entity.
- */
-
-@Embeddable
-public class EAddress {
- @Column(columnDefinition="varchar(30)")
- String street;
- @Column(columnDefinition="varchar(20)")
- String city;
- @Column(columnDefinition="char(2)")
- String state;
- @Column(columnDefinition="char(9)")
- String zip;
-
- public EAddress() {}
-
- public EAddress(String street, String city, String state, String zip){
- this.street = street;
- this.city = city;
- this.state = state;
- this.zip = zip;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this.city = city;
- }
- public String getState() {
- return state;
- }
- public void setState(String state) {
- this.state = state;
- }
- public String getStreet() {
- return street;
- }
- public void setStreet(String street) {
- this.street = street;
- }
- public String getZip() {
- return zip;
- }
- public void setZip(String zip) {
- this.zip = zip;
- }
-
- public void modifyCity(String value){
- city=value;
- }
-
-}
+/*
+ * 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.openjpa.persistence.xmlmapping.entities;
+import javax.persistence.*;
+
+/*
+ * example of an JPA embeddable class.
+ * This class is used in Customer Entity.
+ */
+
+@Embeddable
+public class EAddress {
+ @Column(columnDefinition="varchar(30)")
+ String street;
+ @Column(columnDefinition="varchar(20)")
+ String city;
+ @Column(columnDefinition="char(2)")
+ String state;
+ @Column(columnDefinition="char(9)")
+ String zip;
+
+ public EAddress() {}
+
+ public EAddress(String street, String city, String state, String zip){
+ this.street = street;
+ this.city = city;
+ this.state = state;
+ this.zip = zip;
+ }
+ public String getCity() {
+ return city;
+ }
+ public void setCity(String city) {
+ this.city = city;
+ }
+ public String getState() {
+ return state;
+ }
+ public void setState(String state) {
+ this.state = state;
+ }
+ public String getStreet() {
+ return street;
+ }
+ public void setStreet(String street) {
+ this.street = street;
+ }
+ public String getZip() {
+ return zip;
+ }
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+
+ public void modifyCity(String value){
+ city=value;
+ }
+
+}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Order.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Order.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Order.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/entities/Order.java Fri Jul 20 18:25:48 2007
@@ -1,98 +1,98 @@
-/*
- * 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.openjpa.persistence.xmlmapping.entities;
-
-import org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress.Address;
-
-import javax.persistence.*;
-
-import org.apache.openjpa.persistence.Persistent;
-import org.apache.openjpa.persistence.jdbc.Strategy;
-
-@Entity
-@Table(name="TORDER")
-public class Order {
- @Id
- int oid;
-
- double amount;
- boolean delivered;
-
- @ManyToOne(fetch=FetchType.LAZY)
- Customer customer;
-
- @Persistent
- @Strategy("org.apache.openjpa.jdbc.meta.strats.XMLValueHandler")
- Address shipAddress;
-
- @Version
- long version;
-
- public Order(){}
-
- public Order(int id, double amt, boolean delivered, Customer c) {
- oid = id;
- amount = amt;
- this.delivered = delivered;
- customer = c;
- if (c != null)
- c.getOrders().add(this);
- }
-
- public double getAmount() {
- return amount;
- }
-
- public void setAmount(double amount) {
- this.amount = amount;
- }
-
- public Customer getCustomer() {
- return customer;
- }
-
- public void setCustomer(Customer customer) {
- this.customer = customer;
- }
-
- public boolean isDelivered() {
- return delivered;
- }
-
- public void setDelivered(boolean delivered) {
- this.delivered = delivered;
- }
-
- public int getOid() {
- return oid;
- }
-
- public String toString(){
- return "Order:" + oid + " amount:" + amount + " delivered:" + delivered
- + " customer:" + ((customer != null) ? customer.getCid() : -1);
- }
-
- public Address getShipAddress() {
- return shipAddress;
- }
-
- public void setShipAddress(Address shipAddress) {
- this.shipAddress = shipAddress;
- }
-}
+/*
+ * 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.openjpa.persistence.xmlmapping.entities;
+
+import org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress.Address;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.Persistent;
+import org.apache.openjpa.persistence.jdbc.Strategy;
+
+@Entity
+@Table(name="TORDER")
+public class Order {
+ @Id
+ int oid;
+
+ double amount;
+ boolean delivered;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ Customer customer;
+
+ @Persistent
+ @Strategy("org.apache.openjpa.jdbc.meta.strats.XMLValueHandler")
+ Address shipAddress;
+
+ @Version
+ long version;
+
+ public Order(){}
+
+ public Order(int id, double amt, boolean delivered, Customer c) {
+ oid = id;
+ amount = amt;
+ this.delivered = delivered;
+ customer = c;
+ if (c != null)
+ c.getOrders().add(this);
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(double amount) {
+ this.amount = amount;
+ }
+
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ public boolean isDelivered() {
+ return delivered;
+ }
+
+ public void setDelivered(boolean delivered) {
+ this.delivered = delivered;
+ }
+
+ public int getOid() {
+ return oid;
+ }
+
+ public String toString(){
+ return "Order:" + oid + " amount:" + amount + " delivered:" + delivered
+ + " customer:" + ((customer != null) ? customer.getCid() : -1);
+ }
+
+ public Address getShipAddress() {
+ return shipAddress;
+ }
+
+ public void setShipAddress(Address shipAddress) {
+ this.shipAddress = shipAddress;
+ }
+}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/query/TestXMLCustomerOrder.java Fri Jul 20 18:25:48 2007
@@ -1,293 +1,293 @@
-/*
- * 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.openjpa.persistence.xmlmapping.query;
-
-import java.io.FileWriter;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Query;
-
-import junit.textui.TestRunner;
-
-import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
-import org.apache.openjpa.jdbc.sql.DB2Dictionary;
-import org.apache.openjpa.jdbc.sql.DBDictionary;
-import org.apache.openjpa.jdbc.sql.OracleDictionary;
-import org.apache.openjpa.jdbc.sql.SQLServerDictionary;
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
-import org.apache.openjpa.persistence.test.SQLListenerTestCase;
-import org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress.*;
-import org.apache.openjpa.persistence.xmlmapping.entities.*;
-import org.apache.openjpa.persistence.xmlmapping.entities.Customer.CreditRating;
-
-/**
- * Test query with predicates on persistent field mapped to XML column.
- *
- * @author Catalina Wei
- * @since 1.0.0
- */
-public class TestXMLCustomerOrder
- extends SQLListenerTestCase {
-
- public void setUp() {
- setUp(org.apache.openjpa.persistence.xmlmapping.entities.Customer.class
- , org.apache.openjpa.persistence.xmlmapping.entities.Customer
- .CustomerKey.class
- , org.apache.openjpa.persistence.xmlmapping.entities.Order.class
- , org.apache.openjpa.persistence.xmlmapping.entities.EAddress.class
- , "openjpa.MetaDataRepository"
- , "org.apache.openjpa.jdbc.meta.XMLMappingRepository"
-// , "openjpa.ConnectionDriverName"
-// , "org.apache.commons.dbcp.BasicDataSource"
-// , "openjpa.ConnectionProperties"
-// , "DriverClassName=com.ibm.db2.jcc.DB2Driver,Url=jdbc:db2:testdb"
- );
- }
-
- public static void main(String[] args) {
- TestRunner.run(TestXMLCustomerOrder.class);
- }
-
- public void testXMLCustomerOrder() {
- OpenJPAEntityManager em =
- OpenJPAPersistence.cast(emf.createEntityManager());
- DBDictionary dict = ((JDBCConfiguration) em.getConfiguration())
- .getDBDictionaryInstance();
-
- // skip if dictionary has no support for XML column type
- if (!dict.supportsXMLColumn)
- return;
-
- String sqllog = TestXMLCustomerOrder.class.getName();
- sqllog = sqllog.replace('.', '/');
- sqllog = "./" + sqllog;
- if (dict instanceof DB2Dictionary)
- sqllog += ".db2";
- else if (dict instanceof OracleDictionary)
- sqllog += ".oracle";
- else if (dict instanceof SQLServerDictionary)
- sqllog += ".sqlserver";
-
- // For platform specific expected sqls are under resources.
- // The generated sql of the test is captured and written to file:
- // ./TestXMLCustomerOrder.log
- // This output file contents should match with the platform specfic
- // sqls.
- System.out.println("Expected pushdown SQL log file is in: " + sqllog);
-
- sql.clear();
-
- try {
- em.getTransaction().begin();
- deleteAllData(em );
- em.getTransaction().commit();
-
- em.getTransaction().begin();
- loadData(em);
- em.getTransaction().commit();
-
- em.close();
-
- // By closing and recreating the EntityManager,
- // this guarantees that data will be retrieved from
- // the database rather than just reused from the
- // persistence context created by the load methods above.
-
- em = emf.createEntityManager();
-
- System.err.println("Main started.");
- int test=1;
- List<Address> addrs = em.createQuery(
- "select o.shipAddress from Order o")
- .getResultList();
- for (Address addr : addrs) {
- System.out.println("addr= " + addr.toString());
- }
- String qstrings[] = {
- "select o from Order o",
- "select o from Order o, Order o2 where o.shipAddress.city " +
- "= o2.shipAddress.city",
- "select o from Order o, Customer c where o.shipAddress.city " +
- "= c.address.city",
- "select o from Order o where o.shipAddress.city = 'San Jose'"
- };
- String qstring = null;
- for (int i = 0;i < qstrings.length; i++) {
- qstring = qstrings[i];
- List orders = em.createQuery(qstring).getResultList();
- printOrders(orders, test++);
- }
-
- // query passing parameters
- qstring = "select o from Order o where o.shipAddress.city = ?1";
- Query q5 = em.createQuery(qstring);
- q5.setParameter(1, "San Jose");
- List orders =q5.getResultList();
- printOrders(orders, test++);
-
- qstring = "select o from Order o where ?1 = o.shipAddress.city";
- Query q6 = em.createQuery(qstring);
- q6.setParameter(1, "San Jose");
- orders = q6.getResultList();
- printOrders(orders, test++);
-
- em.close();
-
- // test updates
- em = emf.createEntityManager();
- testUpdateShipaddress(em, test++);
-
- em.close();
- em = emf.createEntityManager();
-
- // query after updates
- orders = em.createQuery("select o from Order o").getResultList();
- System.out.println("After Update:");
- printOrders(orders, test++);
-
- // queries expecting exceptions
- String[] badqstrings = {
- "select o from Order o where o.shipAddress.city = 95141",
- "select o from Order o where o.shipAddress.street " +
- "= '555 Bailey'",
- "select o from Order o where o.shipAddress.zip = 95141"
- };
- for (int i = 0; i < badqstrings.length; i++) {
- qstring = badqstrings[i];
- try {
- System.out.println("\n>> Query "+test+": "+qstring);
- test++;
- orders = em.createQuery(qstring).getResultList();
- }
- catch (Exception e){
- System.out.println("Exception: "+e);
- }
- }
-
- dumpSql();
- em.close();
- emf.close();
- System.out.println("Main ended normally.");
- } catch (Exception e){
- System.out.println("Exception: "+e);
- e.printStackTrace();
- }
- }
-
- private void dumpSql() {
- String out = "./TestXMLCustomerOrder.log";
- try {
- FileWriter fw = new FileWriter(out);
- for (int i = 0; i < sql.size(); i++) {
- System.out.println(sql.get(i));
- fw.write(sql.get(i)+"\n");
- }
- fw.close();
- } catch (Exception e) {
- }
- }
-
- private void printOrders(List orders, int test) {
- System.out.println("\n>> Query "+test);
- System.out.println("result size = "+orders.size());
- for (int i = 0; i < orders.size(); i++) {
- printOrder((Order) orders.get(i));
- }
- }
-
- private void loadData(EntityManager em) {
-
- ObjectFactory addressFactory = new ObjectFactory();
-
- Customer c2 = new Customer();
- c2.setCid( new Customer.CustomerKey("USA", 2) );
- c2.setName("A&J Auto");
- c2.setRating( CreditRating.GOOD );
- c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA"
- , "95123"));
- em.persist(c2);
-
- Customer c1 = new Customer();
- c1.setCid( new Customer.CustomerKey("USA", 1) );
- c1.setName("Harry's Auto");
- c1.setRating( CreditRating.GOOD );
- c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA"
- , "95141"));
- em.persist(c1);
-
- Order o1 = new Order(10, 850, false, c1);
- USAAddress addr1 = addressFactory.createUSAAddress();
- addr1.setCity("San Jose");
- addr1.setState("CA");
- addr1.setZIP(new Integer("95141"));
- addr1.getStreet().add("12500 Monterey");
- addr1.setName( c1.getName());
- o1.setShipAddress(addr1);
- em.persist(o1);
-
- Order o2 = new Order(20, 1000, false, c1);
- CANAddress addr2 = addressFactory.createCANAddress();
- addr2.setName(c2.getName());
- addr2.getStreet().add("123 Warden Road");
- addr2.setCity("Markham");
- addr2.setPostalCode("L6G 1C7");
- addr2.setProvince("ON");
- o2.setShipAddress(addr2);
- em.persist(o2);
- }
-
- private void testUpdateShipaddress(EntityManager em, int test)
- throws Exception {
- em.getTransaction().begin();
- String query = "select o from Order o where o.shipAddress.city " +
- "= 'San Jose'";
- List orders = em.createQuery(query).getResultList();
- System.out.println("Before Update: ");
- printOrders(orders, test);
- em.getTransaction().commit();
-
- // update in separate transaction
- Order o = (Order) orders.get(0);
- EntityTransaction et = em.getTransaction();
- et.begin();
- Address addr = o.getShipAddress();
- addr.setCity("Cupertino");
- if (addr instanceof USAAddress)
- ((USAAddress) addr).setZIP(95014);
-
- // update shipAddress
- o.setShipAddress(addr);
- et.commit();
- }
-
- private void deleteAllData(EntityManager em) {
- em.createQuery("delete from Order o").executeUpdate();
- em.createQuery("delete from Customer c").executeUpdate();
- }
-
- private void printOrder(Order o){
- System.out.println(" Customer ID:"+o.getCustomer().getCid());
- System.out.println(" Order Number:"+o.getOid());
- System.out.println("Ship to: "+o.getShipAddress().toString());
- System.out.println();
- }
-}
+/*
+ * 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.openjpa.persistence.xmlmapping.query;
+
+import java.io.FileWriter;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+
+import junit.textui.TestRunner;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DB2Dictionary;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.OracleDictionary;
+import org.apache.openjpa.jdbc.sql.SQLServerDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+import org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress.*;
+import org.apache.openjpa.persistence.xmlmapping.entities.*;
+import org.apache.openjpa.persistence.xmlmapping.entities.Customer.CreditRating;
+
+/**
+ * Test query with predicates on persistent field mapped to XML column.
+ *
+ * @author Catalina Wei
+ * @since 1.0.0
+ */
+public class TestXMLCustomerOrder
+ extends SQLListenerTestCase {
+
+ public void setUp() {
+ setUp(org.apache.openjpa.persistence.xmlmapping.entities.Customer.class
+ , org.apache.openjpa.persistence.xmlmapping.entities.Customer
+ .CustomerKey.class
+ , org.apache.openjpa.persistence.xmlmapping.entities.Order.class
+ , org.apache.openjpa.persistence.xmlmapping.entities.EAddress.class
+ , "openjpa.MetaDataRepository"
+ , "org.apache.openjpa.jdbc.meta.XMLMappingRepository"
+// , "openjpa.ConnectionDriverName"
+// , "org.apache.commons.dbcp.BasicDataSource"
+// , "openjpa.ConnectionProperties"
+// , "DriverClassName=com.ibm.db2.jcc.DB2Driver,Url=jdbc:db2:testdb"
+ );
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(TestXMLCustomerOrder.class);
+ }
+
+ public void testXMLCustomerOrder() {
+ OpenJPAEntityManager em =
+ OpenJPAPersistence.cast(emf.createEntityManager());
+ DBDictionary dict = ((JDBCConfiguration) em.getConfiguration())
+ .getDBDictionaryInstance();
+
+ // skip if dictionary has no support for XML column type
+ if (!dict.supportsXMLColumn)
+ return;
+
+ String sqllog = TestXMLCustomerOrder.class.getName();
+ sqllog = sqllog.replace('.', '/');
+ sqllog = "./" + sqllog;
+ if (dict instanceof DB2Dictionary)
+ sqllog += ".db2";
+ else if (dict instanceof OracleDictionary)
+ sqllog += ".oracle";
+ else if (dict instanceof SQLServerDictionary)
+ sqllog += ".sqlserver";
+
+ // For platform specific expected sqls are under resources.
+ // The generated sql of the test is captured and written to file:
+ // ./TestXMLCustomerOrder.log
+ // This output file contents should match with the platform specfic
+ // sqls.
+ System.out.println("Expected pushdown SQL log file is in: " + sqllog);
+
+ sql.clear();
+
+ try {
+ em.getTransaction().begin();
+ deleteAllData(em );
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ loadData(em);
+ em.getTransaction().commit();
+
+ em.close();
+
+ // By closing and recreating the EntityManager,
+ // this guarantees that data will be retrieved from
+ // the database rather than just reused from the
+ // persistence context created by the load methods above.
+
+ em = emf.createEntityManager();
+
+ System.err.println("Main started.");
+ int test=1;
+ List<Address> addrs = em.createQuery(
+ "select o.shipAddress from Order o")
+ .getResultList();
+ for (Address addr : addrs) {
+ System.out.println("addr= " + addr.toString());
+ }
+ String qstrings[] = {
+ "select o from Order o",
+ "select o from Order o, Order o2 where o.shipAddress.city " +
+ "= o2.shipAddress.city",
+ "select o from Order o, Customer c where o.shipAddress.city " +
+ "= c.address.city",
+ "select o from Order o where o.shipAddress.city = 'San Jose'"
+ };
+ String qstring = null;
+ for (int i = 0;i < qstrings.length; i++) {
+ qstring = qstrings[i];
+ List orders = em.createQuery(qstring).getResultList();
+ printOrders(orders, test++);
+ }
+
+ // query passing parameters
+ qstring = "select o from Order o where o.shipAddress.city = ?1";
+ Query q5 = em.createQuery(qstring);
+ q5.setParameter(1, "San Jose");
+ List orders =q5.getResultList();
+ printOrders(orders, test++);
+
+ qstring = "select o from Order o where ?1 = o.shipAddress.city";
+ Query q6 = em.createQuery(qstring);
+ q6.setParameter(1, "San Jose");
+ orders = q6.getResultList();
+ printOrders(orders, test++);
+
+ em.close();
+
+ // test updates
+ em = emf.createEntityManager();
+ testUpdateShipaddress(em, test++);
+
+ em.close();
+ em = emf.createEntityManager();
+
+ // query after updates
+ orders = em.createQuery("select o from Order o").getResultList();
+ System.out.println("After Update:");
+ printOrders(orders, test++);
+
+ // queries expecting exceptions
+ String[] badqstrings = {
+ "select o from Order o where o.shipAddress.city = 95141",
+ "select o from Order o where o.shipAddress.street " +
+ "= '555 Bailey'",
+ "select o from Order o where o.shipAddress.zip = 95141"
+ };
+ for (int i = 0; i < badqstrings.length; i++) {
+ qstring = badqstrings[i];
+ try {
+ System.out.println("\n>> Query "+test+": "+qstring);
+ test++;
+ orders = em.createQuery(qstring).getResultList();
+ }
+ catch (Exception e){
+ System.out.println("Exception: "+e);
+ }
+ }
+
+ dumpSql();
+ em.close();
+ emf.close();
+ System.out.println("Main ended normally.");
+ } catch (Exception e){
+ System.out.println("Exception: "+e);
+ e.printStackTrace();
+ }
+ }
+
+ private void dumpSql() {
+ String out = "./TestXMLCustomerOrder.log";
+ try {
+ FileWriter fw = new FileWriter(out);
+ for (int i = 0; i < sql.size(); i++) {
+ System.out.println(sql.get(i));
+ fw.write(sql.get(i)+"\n");
+ }
+ fw.close();
+ } catch (Exception e) {
+ }
+ }
+
+ private void printOrders(List orders, int test) {
+ System.out.println("\n>> Query "+test);
+ System.out.println("result size = "+orders.size());
+ for (int i = 0; i < orders.size(); i++) {
+ printOrder((Order) orders.get(i));
+ }
+ }
+
+ private void loadData(EntityManager em) {
+
+ ObjectFactory addressFactory = new ObjectFactory();
+
+ Customer c2 = new Customer();
+ c2.setCid( new Customer.CustomerKey("USA", 2) );
+ c2.setName("A&J Auto");
+ c2.setRating( CreditRating.GOOD );
+ c2.setAddress(new EAddress("2480 Campbell Ave", "Campbell", "CA"
+ , "95123"));
+ em.persist(c2);
+
+ Customer c1 = new Customer();
+ c1.setCid( new Customer.CustomerKey("USA", 1) );
+ c1.setName("Harry's Auto");
+ c1.setRating( CreditRating.GOOD );
+ c1.setAddress( new EAddress("12500 Monterey", "San Jose", "CA"
+ , "95141"));
+ em.persist(c1);
+
+ Order o1 = new Order(10, 850, false, c1);
+ USAAddress addr1 = addressFactory.createUSAAddress();
+ addr1.setCity("San Jose");
+ addr1.setState("CA");
+ addr1.setZIP(new Integer("95141"));
+ addr1.getStreet().add("12500 Monterey");
+ addr1.setName( c1.getName());
+ o1.setShipAddress(addr1);
+ em.persist(o1);
+
+ Order o2 = new Order(20, 1000, false, c1);
+ CANAddress addr2 = addressFactory.createCANAddress();
+ addr2.setName(c2.getName());
+ addr2.getStreet().add("123 Warden Road");
+ addr2.setCity("Markham");
+ addr2.setPostalCode("L6G 1C7");
+ addr2.setProvince("ON");
+ o2.setShipAddress(addr2);
+ em.persist(o2);
+ }
+
+ private void testUpdateShipaddress(EntityManager em, int test)
+ throws Exception {
+ em.getTransaction().begin();
+ String query = "select o from Order o where o.shipAddress.city " +
+ "= 'San Jose'";
+ List orders = em.createQuery(query).getResultList();
+ System.out.println("Before Update: ");
+ printOrders(orders, test);
+ em.getTransaction().commit();
+
+ // update in separate transaction
+ Order o = (Order) orders.get(0);
+ EntityTransaction et = em.getTransaction();
+ et.begin();
+ Address addr = o.getShipAddress();
+ addr.setCity("Cupertino");
+ if (addr instanceof USAAddress)
+ ((USAAddress) addr).setZIP(95014);
+
+ // update shipAddress
+ o.setShipAddress(addr);
+ et.commit();
+ }
+
+ private void deleteAllData(EntityManager em) {
+ em.createQuery("delete from Order o").executeUpdate();
+ em.createQuery("delete from Customer c").executeUpdate();
+ }
+
+ private void printOrder(Order o){
+ System.out.println(" Customer ID:"+o.getCustomer().getCid());
+ System.out.println(" Order Number:"+o.getOid());
+ System.out.println("Ship to: "+o.getShipAddress().toString());
+ System.out.println();
+ }
+}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/Address.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/Address.java?view=diff&rev=558221&r1=558220&r2=558221
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/Address.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xmlmapping/xmlbindings/myaddress/Address.java Fri Jul 20 18:25:48 2007
@@ -1,142 +1,142 @@
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.2-b01-fcs
-// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2006.10.04 at 03:08:16 PM PDT
-//
-
-
-package org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- * <p>Java class for Address complex type.
- *
- * <p>The following schema fragment specifies the expected content contained within this class.
- *
- * <pre>
- * <complexType name="Address">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * <element name="Street" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="3"/>
- * <element name="City" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * </sequence>
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "Address", propOrder = {
- "name",
- "street",
- "city"
-})
-public class Address {
-
- @XmlElement(name = "Name")
- protected String name;
- @XmlElement(name = "Street")
- protected List<String> street;
- @XmlElement(name = "City")
- protected String city;
-
- /**
- * Gets the value of the name property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the value of the name property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setName(String value) {
- this.name = value;
- }
-
- /**
- * Gets the value of the street property.
- *
- * <p>
- * This accessor method returns a reference to the live list,
- * not a snapshot. Therefore any modification you make to the
- * returned list will be present inside the JAXB object.
- * This is why there is not a <CODE>set</CODE> method for the street property.
- *
- * <p>
- * For example, to add a new item, do as follows:
- * <pre>
- * getStreet().add(newItem);
- * </pre>
- *
- *
- * <p>
- * Objects of the following type(s) are allowed in the list
- * {@link String }
- *
- *
- */
- public List<String> getStreet() {
- if (street == null) {
- street = new ArrayList<String>();
- }
- return this.street;
- }
-
- /**
- * Gets the value of the city property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getCity() {
- return city;
- }
-
- /**
- * Sets the value of the city property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setCity(String value) {
- this.city = value;
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append(this.name);
- for (int i=0; i< this.getStreet().size(); i++)
- sb.append("\n "+this.getStreet().get(i));
- sb.append("\n "+this.getCity());
- return sb.toString();
- }
-}
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.2-b01-fcs
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2006.10.04 at 03:08:16 PM PDT
+//
+
+
+package org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * <p>Java class for Address complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="Address">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="Street" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="3"/>
+ * <element name="City" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Address", propOrder = {
+ "name",
+ "street",
+ "city"
+})
+public class Address {
+
+ @XmlElement(name = "Name")
+ protected String name;
+ @XmlElement(name = "Street")
+ protected List<String> street;
+ @XmlElement(name = "City")
+ protected String city;
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+ /**
+ * Gets the value of the street property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the street property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getStreet().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link String }
+ *
+ *
+ */
+ public List<String> getStreet() {
+ if (street == null) {
+ street = new ArrayList<String>();
+ }
+ return this.street;
+ }
+
+ /**
+ * Gets the value of the city property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getCity() {
+ return city;
+ }
+
+ /**
+ * Sets the value of the city property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setCity(String value) {
+ this.city = value;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(this.name);
+ for (int i=0; i< this.getStreet().size(); i++)
+ sb.append("\n "+this.getStreet().get(i));
+ sb.append("\n "+this.getCity());
+ return sb.toString();
+ }
+}