OPENJPA-240 XMLMapping Query support, fix eol delimiters to unix style

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@558221 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David J. Wisneski 2007-07-21 01:25:48 +00:00
parent e2556dd6b2
commit a5ed9f701d
14 changed files with 1771 additions and 1771 deletions

View File

@ -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];
}
}

View File

@ -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);
}
}
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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>
* &lt;complexType name="Address">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Street" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="3"/>
* &lt;element name="City" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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>
* &lt;complexType name="Address">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Street" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="3"/>
* &lt;element name="City" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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();
}
}

View File

@ -1,111 +1,111 @@
//
// 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 javax.xml.bind.JAXBElement;
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 CAN_Address complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="CAN_Address">
* &lt;complexContent>
* &lt;extension base="{}Address">
* &lt;sequence>
* &lt;element name="Province" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="PostalCode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CAN_Address", propOrder = {
"province",
"postalCode"
})
public class CANAddress
extends Address
{
@XmlElement(name = "Province")
protected String province;
@XmlElement(name = "PostalCode")
protected String postalCode;
/**
* Gets the value of the province property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getProvince() {
return province;
}
/**
* Sets the value of the province property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setProvince(String value) {
this.province = value;
}
/**
* Gets the value of the postalCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPostalCode() {
return postalCode;
}
/**
* Sets the value of the postalCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPostalCode(String value) {
this.postalCode = value;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(super.toString())
.append("\n ")
.append(this.province)
.append(" ")
.append(this.postalCode);
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 javax.xml.bind.JAXBElement;
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 CAN_Address complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="CAN_Address">
* &lt;complexContent>
* &lt;extension base="{}Address">
* &lt;sequence>
* &lt;element name="Province" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="PostalCode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CAN_Address", propOrder = {
"province",
"postalCode"
})
public class CANAddress
extends Address
{
@XmlElement(name = "Province")
protected String province;
@XmlElement(name = "PostalCode")
protected String postalCode;
/**
* Gets the value of the province property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getProvince() {
return province;
}
/**
* Sets the value of the province property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setProvince(String value) {
this.province = value;
}
/**
* Gets the value of the postalCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPostalCode() {
return postalCode;
}
/**
* Sets the value of the postalCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPostalCode(String value) {
this.postalCode = value;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(super.toString())
.append("\n ")
.append(this.province)
.append(" ")
.append(this.postalCode);
return sb.toString();
}
}

View File

@ -1,111 +1,111 @@
//
// 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 javax.xml.bind.JAXBElement;
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 GBR_Address complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="GBR_Address">
* &lt;complexContent>
* &lt;extension base="{}Address">
* &lt;sequence>
* &lt;element name="County" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Postcode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement(name = "GBR_Address")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GBR_Address", propOrder = {
"county",
"postcode"
})
public class GBRAddress
extends Address
{
@XmlElement(name = "County")
protected String county;
@XmlElement(name = "Postcode")
protected String postcode;
/**
* Gets the value of the county property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCounty() {
return county;
}
/**
* Sets the value of the county property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCounty(String value) {
this.county = value;
}
/**
* Gets the value of the postcode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPostcode() {
return postcode;
}
/**
* Sets the value of the postcode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPostcode(String value) {
this.postcode = value;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(super.toString())
.append("\n ")
.append(this.county)
.append(" ")
.append(this.postcode);
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 javax.xml.bind.JAXBElement;
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 GBR_Address complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="GBR_Address">
* &lt;complexContent>
* &lt;extension base="{}Address">
* &lt;sequence>
* &lt;element name="County" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Postcode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement(name = "GBR_Address")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GBR_Address", propOrder = {
"county",
"postcode"
})
public class GBRAddress
extends Address
{
@XmlElement(name = "County")
protected String county;
@XmlElement(name = "Postcode")
protected String postcode;
/**
* Gets the value of the county property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCounty() {
return county;
}
/**
* Sets the value of the county property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCounty(String value) {
this.county = value;
}
/**
* Gets the value of the postcode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPostcode() {
return postcode;
}
/**
* Sets the value of the postcode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPostcode(String value) {
this.postcode = value;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(super.toString())
.append("\n ")
.append(this.county)
.append(" ")
.append(this.postcode);
return sb.toString();
}
}

View File

@ -1,122 +1,122 @@
//
// 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 javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the myaddress package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _AddrUSA_QNAME = new QName("", "AddrUSA");
private final static QName _AddrCAN_QNAME = new QName("", "AddrCAN");
private final static QName _MailAddress_QNAME = new QName("", "MailAddress");
private final static QName _AddrGBR_QNAME = new QName("", "AddrGBR");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: myaddress
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Address }
*
*/
public Address createAddress() {
return new Address();
}
/**
* Create an instance of {@link ShortAddress }
*
*/
public ShortAddress createShortAddress() {
return new ShortAddress();
}
/**
* Create an instance of {@link USAAddress }
*
*/
public USAAddress createUSAAddress() {
return new USAAddress();
}
/**
* Create an instance of {@link GBRAddress }
*
*/
public GBRAddress createGBRAddress() {
return new GBRAddress();
}
/**
* Create an instance of {@link CANAddress }
*
*/
public CANAddress createCANAddress() {
return new CANAddress();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link USAAddress }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "AddrUSA", substitutionHeadNamespace = "", substitutionHeadName = "MailAddress")
public JAXBElement<USAAddress> createAddrUSA(USAAddress value) {
return new JAXBElement<USAAddress>(_AddrUSA_QNAME, USAAddress.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link CANAddress }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "AddrCAN", substitutionHeadNamespace = "", substitutionHeadName = "MailAddress")
public JAXBElement<CANAddress> createAddrCAN(CANAddress value) {
return new JAXBElement<CANAddress>(_AddrCAN_QNAME, CANAddress.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Address }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "MailAddress")
public JAXBElement<Address> createMailAddress(Address value) {
return new JAXBElement<Address>(_MailAddress_QNAME, Address.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link GBRAddress }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "AddrGBR", substitutionHeadNamespace = "", substitutionHeadName = "MailAddress")
public JAXBElement<GBRAddress> createAddrGBR(GBRAddress value) {
return new JAXBElement<GBRAddress>(_AddrGBR_QNAME, GBRAddress.class, null, value);
}
}
//
// 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 javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the myaddress package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _AddrUSA_QNAME = new QName("", "AddrUSA");
private final static QName _AddrCAN_QNAME = new QName("", "AddrCAN");
private final static QName _MailAddress_QNAME = new QName("", "MailAddress");
private final static QName _AddrGBR_QNAME = new QName("", "AddrGBR");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: myaddress
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Address }
*
*/
public Address createAddress() {
return new Address();
}
/**
* Create an instance of {@link ShortAddress }
*
*/
public ShortAddress createShortAddress() {
return new ShortAddress();
}
/**
* Create an instance of {@link USAAddress }
*
*/
public USAAddress createUSAAddress() {
return new USAAddress();
}
/**
* Create an instance of {@link GBRAddress }
*
*/
public GBRAddress createGBRAddress() {
return new GBRAddress();
}
/**
* Create an instance of {@link CANAddress }
*
*/
public CANAddress createCANAddress() {
return new CANAddress();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link USAAddress }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "AddrUSA", substitutionHeadNamespace = "", substitutionHeadName = "MailAddress")
public JAXBElement<USAAddress> createAddrUSA(USAAddress value) {
return new JAXBElement<USAAddress>(_AddrUSA_QNAME, USAAddress.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link CANAddress }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "AddrCAN", substitutionHeadNamespace = "", substitutionHeadName = "MailAddress")
public JAXBElement<CANAddress> createAddrCAN(CANAddress value) {
return new JAXBElement<CANAddress>(_AddrCAN_QNAME, CANAddress.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Address }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "MailAddress")
public JAXBElement<Address> createMailAddress(Address value) {
return new JAXBElement<Address>(_MailAddress_QNAME, Address.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link GBRAddress }{@code >}}
*
*/
@XmlElementDecl(namespace = "", name = "AddrGBR", substitutionHeadNamespace = "", substitutionHeadName = "MailAddress")
public JAXBElement<GBRAddress> createAddrGBR(GBRAddress value) {
return new JAXBElement<GBRAddress>(_AddrGBR_QNAME, GBRAddress.class, null, value);
}
}

View File

@ -1,46 +1,46 @@
//
// 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 javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for ShortAddress complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="ShortAddress">
* &lt;complexContent>
* &lt;restriction base="{}Address">
* &lt;sequence>
* &lt;element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Street" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="City" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ShortAddress")
public class ShortAddress
extends Address
{
}
//
// 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 javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for ShortAddress complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="ShortAddress">
* &lt;complexContent>
* &lt;restriction base="{}Address">
* &lt;sequence>
* &lt;element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Street" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="City" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ShortAddress")
public class ShortAddress
extends Address
{
}

View File

@ -1,103 +1,103 @@
//
// 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 javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for USA_Address complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="USA_Address">
* &lt;complexContent>
* &lt;extension base="{}Address">
* &lt;sequence>
* &lt;element name="State" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="ZIP" type="{}USPS_ZIP"/>
* &lt;/sequence>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "USA_Address", propOrder = {
"state",
"zip"
})
public class USAAddress
extends Address
{
@XmlElement(name = "State")
protected String state;
@XmlElement(name = "ZIP")
protected int zip;
/**
* Gets the value of the state property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getState() {
return state;
}
/**
* Sets the value of the state property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setState(String value) {
this.state = value;
}
/**
* Gets the value of the zip property.
*
*/
public int getZIP() {
return zip;
}
/**
* Sets the value of the zip property.
*
*/
public void setZIP(int value) {
this.zip = value;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(super.toString())
.append("\n ")
.append(this.state)
.append(" ")
.append(this.zip);
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 javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for USA_Address complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="USA_Address">
* &lt;complexContent>
* &lt;extension base="{}Address">
* &lt;sequence>
* &lt;element name="State" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="ZIP" type="{}USPS_ZIP"/>
* &lt;/sequence>
* &lt;/extension>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "USA_Address", propOrder = {
"state",
"zip"
})
public class USAAddress
extends Address
{
@XmlElement(name = "State")
protected String state;
@XmlElement(name = "ZIP")
protected int zip;
/**
* Gets the value of the state property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getState() {
return state;
}
/**
* Sets the value of the state property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setState(String value) {
this.state = value;
}
/**
* Gets the value of the zip property.
*
*/
public int getZIP() {
return zip;
}
/**
* Sets the value of the zip property.
*
*/
public void setZIP(int value) {
this.zip = value;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(super.toString())
.append("\n ")
.append(this.state)
.append(" ")
.append(this.zip);
return sb.toString();
}
}