From 1f37b7725c30b6dde445598f24d30841fba87535 Mon Sep 17 00:00:00 2001 From: Jeremy Bauer Date: Mon, 11 May 2009 21:59:15 +0000 Subject: [PATCH] OPENJPA-926 Tests and code updates for explicit access types git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@773704 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/enhance/PCEnhancer.java | 12 + .../apache/openjpa/meta/FieldMetaData.java | 3 + .../apache/openjpa/meta/ValueMetaData.java | 5 + .../openjpa/meta/ValueMetaDataImpl.java | 10 +- .../access/AbstractMappedSuperField.java | 70 ++ .../access/AbstractMappedSuperProperty.java | 72 ++ .../access/DefFieldMixedPropAccess.java | 95 ++ .../access/DefPropMixedFieldAccess.java | 87 ++ .../persistence/access/EmbedFieldAccess.java | 56 + .../openjpa/persistence/access/EmbedId.java | 60 + .../persistence/access/EmbedInnerProp.java | 60 + .../persistence/access/EmbedMixedAccess.java | 71 ++ .../persistence/access/EmbedOuterField.java | 46 + .../persistence/access/EmbedPropAccess.java | 64 + .../persistence/access/FieldAccess.java | 88 ++ .../access/FieldAccessPropStratsEntity.java | 160 +++ .../persistence/access/FieldEmbedEntity.java | 86 ++ .../openjpa/persistence/access/FieldSub.java | 63 + .../openjpa/persistence/access/FieldSub2.java | 61 + .../openjpa/persistence/access/FieldSub3.java | 63 + .../persistence/access/MappedSuperField.java | 70 ++ .../access/MappedSuperProperty.java | 64 + .../persistence/access/MixedFieldSub.java | 76 ++ .../persistence/access/MixedMappedSuper.java | 71 ++ .../access/MixedMultEmbedEntity.java | 110 ++ .../access/MixedNestedEmbedEntity.java | 90 ++ .../persistence/access/PropAccess.java | 78 ++ .../access/PropAccessFieldStratsEntity.java | 160 +++ .../persistence/access/PropEmbedEntity.java | 87 ++ .../persistence/access/PropMixedEntity.java | 97 ++ .../persistence/access/PropertySub.java | 64 + .../persistence/access/PropertySub2.java | 60 + .../persistence/access/PropertySub3.java | 63 + .../persistence/access/SuperFieldEntity.java | 75 ++ .../access/SuperPropertyEntity.java | 75 ++ .../persistence/access/TestDefaultAccess.java | 206 +++ .../access/TestExplicitAccess.java | 1103 +++++++++++++++++ .../access/xml/TestXMLExplicitAccess.java | 789 ++++++++++++ .../xml/XMLAbstractMappedSuperField.java | 57 + .../xml/XMLAbstractMappedSuperProperty.java | 57 + .../xml/XMLDefFieldMixedPropAccess.java | 69 ++ .../xml/XMLDefPropMixedFieldAccess.java | 69 ++ .../access/xml/XMLEmbedFieldAccess.java | 50 + .../access/xml/XMLEmbedMixedAccess.java | 69 ++ .../access/xml/XMLEmbedPropAccess.java | 58 + .../access/xml/XMLFieldAccess.java | 69 ++ .../access/xml/XMLFieldEmbedEntity.java | 61 + .../persistence/access/xml/XMLFieldSub.java | 45 + .../persistence/access/xml/XMLFieldSub2.java | 44 + .../persistence/access/xml/XMLFieldSub3.java | 44 + .../access/xml/XMLMappedSuperField.java | 55 + .../access/xml/XMLMappedSuperProperty.java | 51 + .../access/xml/XMLMixedFieldSub.java | 54 + .../access/xml/XMLMixedMappedSuper.java | 63 + .../persistence/access/xml/XMLPropAccess.java | 61 + .../access/xml/XMLPropEmbedEntity.java | 62 + .../access/xml/XMLPropMixedEntity.java | 81 ++ .../access/xml/XMLPropertySub.java | 46 + .../access/xml/XMLPropertySub2.java | 42 + .../access/xml/XMLPropertySub3.java | 44 + .../access/xml/XMLSuperFieldEntity.java | 51 + .../access/xml/XMLSuperPropertyEntity.java | 51 + .../persistence/test/PersistenceTestCase.java | 11 + .../access/access-def-field-orm.xml | 62 + .../access/access-def-persistence.xml | 61 + .../access/access-def-prop-orm.xml | 62 + .../openjpa/persistence/access/access-orm.xml | 441 +++++++ .../persistence/access/access-persistence.xml | 59 + .../access/access-pudef-field-orm.xml | 66 + .../access/access-pudef-persistence.xml | 61 + .../access/access-pudef-prop-orm.xml | 66 + .../PersistenceMetaDataDefaults.java | 2 +- .../XMLPersistenceMetaDataParser.java | 19 +- 73 files changed, 6823 insertions(+), 10 deletions(-) create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperField.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperProperty.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefFieldMixedPropAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefPropMixedFieldAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedFieldAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedId.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedInnerProp.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedMixedAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedOuterField.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedPropAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccessPropStratsEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldEmbedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub2.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub3.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperField.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperProperty.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedFieldSub.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMappedSuper.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMultEmbedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedNestedEmbedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccessFieldStratsEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropEmbedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropMixedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub2.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub3.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperFieldEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperPropertyEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestDefaultAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestExplicitAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/TestXMLExplicitAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperField.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperProperty.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefFieldMixedPropAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefPropMixedFieldAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedFieldAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedMixedAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedPropAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldEmbedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub2.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub3.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperField.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperProperty.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedFieldSub.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedMappedSuper.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropAccess.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropEmbedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropMixedEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub2.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub3.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperFieldEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperPropertyEntity.java create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-field-orm.xml create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-persistence.xml create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-prop-orm.xml create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-orm.xml create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-persistence.xml create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-field-orm.xml create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-persistence.xml create mode 100644 openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-prop-orm.xml diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java index a8cd15688..bea542d33 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java @@ -615,6 +615,18 @@ public class PCEnhancer { BCField returned, assigned = null; for (int i = 0; i < fmds.length; i++) { + if (!(fmds[i].getBackingMember() instanceof Method) ) { + // If not mixed access is not defined, flag the field members, + // otherwise do not process them because they are valid + // persistent attributes. + if (!_meta.isMixedAccess()) { + addViolation("property-bad-member", + new Object[]{ fmds[i], fmds[i].getBackingMember() }, + true); + } + continue; + } + meth = (Method) fmds[i].getBackingMember(); // ##### this will fail if we override and don't call super. BCClass declaringType = _managedType.getProject() diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java index 2c4c59fc4..5053ba35f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java @@ -1996,6 +1996,9 @@ public class FieldMetaData return _val.getEmbeddedMetaData(); } + public ClassMetaData addEmbeddedMetaData(int access) { + return _val.addEmbeddedMetaData(access); + } public ClassMetaData addEmbeddedMetaData() { return _val.addEmbeddedMetaData(); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java index 124cad60d..a09233314 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java @@ -156,6 +156,11 @@ public interface ValueMetaData */ public ClassMetaData addEmbeddedMetaData(); + /** + * Add embedded metadata for this value with the given access type + */ + public ClassMetaData addEmbeddedMetaData(int access); + /** * Cascade behavior for delete operation. Only applies to * persistence-capable values. Options are:
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java index 0cacfead8..40fb46e15 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java @@ -185,18 +185,22 @@ public class ValueMetaDataImpl addEmbeddedMetaData(); return _embeddedMeta; } - - public ClassMetaData addEmbeddedMetaData() { + + public ClassMetaData addEmbeddedMetaData(int access) { MetaDataRepository repos = _owner.getRepository(); _embeddedMeta = repos.newEmbeddedClassMetaData(this); _embeddedMeta.setDescribedType(_decType); repos.getMetaDataFactory().getDefaults().populate(_embeddedMeta, - AccessCode.UNKNOWN); + access); setEmbedded(true); return _embeddedMeta; } + public ClassMetaData addEmbeddedMetaData() { + return addEmbeddedMetaData(AccessCode.UNKNOWN); + } + public int getCascadeDelete() { if (_owner.getManagement() != FieldMetaData.MANAGE_PERSISTENT) return CASCADE_NONE; diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperField.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperField.java new file mode 100644 index 000000000..d3c8476e2 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperField.java @@ -0,0 +1,70 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.Basic; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.AccessType; + +@MappedSuperclass +@Access(AccessType.FIELD) +public abstract class AbstractMappedSuperField { + + @Id + @GeneratedValue + private int id; + + @Basic + @Access(AccessType.FIELD) + private String name; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + abstract public Date getCreateDate(); + + abstract public void setCreateDate(Date date); + + public boolean equals(Object obj) { + if (obj instanceof AbstractMappedSuperField) { + AbstractMappedSuperField ps = (AbstractMappedSuperField)obj; + return id == ps.getId() && + name.equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperProperty.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperProperty.java new file mode 100644 index 000000000..0512fe06c --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/AbstractMappedSuperProperty.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.persistence.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.Basic; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.AccessType; +import javax.persistence.Transient; + +@MappedSuperclass +@Access(AccessType.PROPERTY) +public abstract class AbstractMappedSuperProperty { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + @Id + @GeneratedValue + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + @Basic + @Access(AccessType.PROPERTY) + public String getName() { + return name; + } + + @Transient + abstract public Date getCreateDate(); + + abstract public void setCreateDate(Date date); + + public boolean equals(Object obj) { + if (obj instanceof AbstractMappedSuperProperty) { + AbstractMappedSuperProperty ps = (AbstractMappedSuperProperty)obj; + return getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefFieldMixedPropAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefFieldMixedPropAccess.java new file mode 100644 index 000000000..85c220e3f --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefFieldMixedPropAccess.java @@ -0,0 +1,95 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Transient; +import javax.persistence.Version; + +import static javax.persistence.AccessType.FIELD; +import static javax.persistence.AccessType.PROPERTY; + +@Entity(name="DFMPA") +@Access(value=FIELD) +@NamedQueries( { + @NamedQuery(name="DFMPA.query", + query="SELECT df FROM DFMPA df WHERE " + + "df.id = :id AND df.stringField = :strVal"), + @NamedQuery(name="DFMPA.badQuery", + query="SELECT p FROM DFMPA p WHERE " + + "p.id = :id AND p.strField = :strVal") } ) +public class DefFieldMixedPropAccess { + + @Id + @GeneratedValue + private int id; + + @Version + private int version; + + @Transient + private String strField; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + public int getVersion() { + return version; + } + + public void setStringField(String val) { + this.setStrField(val); + } + + @Access(value=PROPERTY) + public String getStringField() { + return getStrField(); + } + + public boolean equals(Object obj) { + if (obj instanceof DefFieldMixedPropAccess) { + DefFieldMixedPropAccess fa = (DefFieldMixedPropAccess)obj; + return id == fa.getId() && + getStrField().equals(fa.getStringField()); + } + return false; + } + + public void setStrField(String strField) { + this.strField = strField; + } + + public String getStrField() { + return strField; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefPropMixedFieldAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefPropMixedFieldAccess.java new file mode 100644 index 000000000..7e5811e03 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/DefPropMixedFieldAccess.java @@ -0,0 +1,87 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Transient; +import javax.persistence.Version; + +import static javax.persistence.AccessType.FIELD; +import static javax.persistence.AccessType.PROPERTY; + +@Entity(name="DPMFA") +@Access(value=PROPERTY) +@NamedQueries( { + @NamedQuery(name="DPMFA.query", + query="SELECT p FROM DPMFA p WHERE " + + "p.id = :id AND p.strField = :strVal"), + @NamedQuery(name="DPMFA.badQuery", + query="SELECT p FROM DPMFA p WHERE " + + "p.id = :id AND p.strProp = :strVal") } ) +public class DefPropMixedFieldAccess { + + private int id; + + private int version; + + @Access(value=FIELD) + private String strField; + + public void setId(int id) { + this.id = id; + } + + @Id + @GeneratedValue + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + @Version + public int getVersion() { + return version; + } + + public void setStrProp(String var) { + this.strField = var; + } + + @Transient + public String getStrProp() { + return strField; + } + + public boolean equals(Object obj) { + if (obj instanceof DefPropMixedFieldAccess) { + DefPropMixedFieldAccess dpmfa = (DefPropMixedFieldAccess)obj; + return getId() == dpmfa.getId() && + strField.equals(dpmfa.getStrProp()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedFieldAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedFieldAccess.java new file mode 100644 index 000000000..d4c31170a --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedFieldAccess.java @@ -0,0 +1,56 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embeddable; + +@Access(AccessType.FIELD) +@Embeddable +public class EmbedFieldAccess { + + String fName; + String lName; + + public String getFirstName() { + return fName; + } + + public void setFirstName(String fname) { + fName = fname; + } + + public String getLastName() { + return lName; + } + + public void setLastName(String lname) { + lName = lname; + } + + public boolean equals(Object obj) { + if (obj instanceof EmbedFieldAccess) { + EmbedFieldAccess ps = (EmbedFieldAccess)obj; + return getFirstName().equals(ps.getFirstName()) && + getLastName().equals(ps.getLastName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedId.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedId.java new file mode 100644 index 000000000..5b1f2f82a --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedId.java @@ -0,0 +1,60 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embeddable; + +@Embeddable +@Access(AccessType.FIELD) +public class EmbedId { + + private long id; + private String code; + + public long getId() { + return id; + } + + public void setId(long lid) { + id = lid; + } + + public String getCode() { + return code; + } + + public void setCode(String c) { + code = c; + } + + public int hashCode() { + return super.hashCode(); + } + + public boolean equals(Object obj) { + if (obj instanceof EmbedId) { + EmbedId eid = (EmbedId)obj; + return getId() == eid.getId() && + getCode().equals(eid.getCode()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedInnerProp.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedInnerProp.java new file mode 100644 index 000000000..e8e69a49f --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedInnerProp.java @@ -0,0 +1,60 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embeddable; +import javax.persistence.Embedded; + +@Access(AccessType.PROPERTY) +@Embeddable +public class EmbedInnerProp { + + private String inName; + + private EmbedOuterField eof; + + public String getInnerName() { + return inName; + } + + public void setInnerName(String innerName) { + inName = innerName; + } + + @Embedded + public EmbedOuterField getOuterField() { + return eof; + } + + public void setOuterField(EmbedOuterField eo) { + eof = eo; + } + + public boolean equals(Object obj) { + if (obj instanceof EmbedInnerProp) { + EmbedInnerProp ps = (EmbedInnerProp)obj; + + return getInnerName().equals(ps.getInnerName()) && + getOuterField().equals(ps.getOuterField()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedMixedAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedMixedAccess.java new file mode 100644 index 000000000..e0fadf11b --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedMixedAccess.java @@ -0,0 +1,71 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embeddable; +import javax.persistence.Transient; + +@Access(AccessType.PROPERTY) +@Embeddable +public class EmbedMixedAccess { + + private transient String fName; + private transient String lName; + + @Access(AccessType.FIELD) + private String mName; + + public String getFirstName() { + return fName; + } + + public void setFirstName(String fname) { + fName = fname; + } + + public String getLastName() { + return lName; + } + + public void setLastName(String lname) { + lName = lname; + } + + @Transient + public String getMiddleName() { + return mName; + } + + public void setMiddleName(String mname) { + mName = mname; + } + + public boolean equals(Object obj) { + if (obj instanceof EmbedMixedAccess) { + EmbedMixedAccess ps = (EmbedMixedAccess)obj; + return getFirstName().equals(ps.getFirstName()) && + getLastName().equals(ps.getLastName()) && + getMiddleName().equals(ps.getMiddleName()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedOuterField.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedOuterField.java new file mode 100644 index 000000000..6c377da12 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedOuterField.java @@ -0,0 +1,46 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embeddable; + +@Access(AccessType.FIELD) +@Embeddable +public class EmbedOuterField { + + private String outName; + + public String getOuterName() { + return outName; + } + + public void setOuterName(String outerName) { + outName = outerName; + } + + public boolean equals(Object obj) { + if (obj instanceof EmbedOuterField) { + EmbedOuterField ps = (EmbedOuterField)obj; + return getOuterName().equals(ps.getOuterName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedPropAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedPropAccess.java new file mode 100644 index 000000000..f95a7f858 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/EmbedPropAccess.java @@ -0,0 +1,64 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embeddable; + +@Access(AccessType.PROPERTY) +@Embeddable +public class EmbedPropAccess { + + String fName; + String lName; + + public EmbedPropAccess() { + } + + public EmbedPropAccess(String fn, String ln) { + setFirstName(fn); + setLastName(ln); + } + + public String getFirstName() { + return fName; + } + + public void setFirstName(String fname) { + fName = fname; + } + + public String getLastName() { + return lName; + } + + public void setLastName(String lname) { + lName = lname; + } + + public boolean equals(Object obj) { + if (obj instanceof EmbedPropAccess) { + EmbedPropAccess ps = (EmbedPropAccess)obj; + return getFirstName().equals(ps.getFirstName()) && + getLastName().equals(ps.getLastName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccess.java new file mode 100644 index 000000000..bdd58935b --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccess.java @@ -0,0 +1,88 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Version; + +import static javax.persistence.AccessType.FIELD; + +@Entity +@Access(value=FIELD) +@NamedQuery(name="FieldAccess.query", + query="SELECT fa FROM FieldAccess fa WHERE " + + "fa.id = :id AND fa.strField = :strVal") +public class FieldAccess { + + @Id + @GeneratedValue + private int id; + + @Version + private int version; + + @Basic + private String strField; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + public int getVersion() { + return version; + } + + public void setStringField(String val) { + this.setStrField(val); + } + + public String getStringField() { + return getStrField(); + } + + public boolean equals(Object obj) { + if (obj instanceof FieldAccess) { + FieldAccess fa = (FieldAccess)obj; + return id == fa.getId() && + getStrField().equals(fa.getStringField()); + } + return false; + } + + public void setStrField(String strField) { + this.strField = strField; + } + + public String getStrField() { + return strField; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccessPropStratsEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccessPropStratsEntity.java new file mode 100644 index 000000000..e2f96e8ef --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldAccessPropStratsEntity.java @@ -0,0 +1,160 @@ +/* + * 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.access; + +import java.util.Collection; + +import javax.persistence.Access; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.ElementCollection; +import javax.persistence.Embedded; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.AccessType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.Transient; +import javax.persistence.Version; + +@Entity +@Access(AccessType.FIELD) +public class FieldAccessPropStratsEntity { + + @EmbeddedId + private EmbedId eid; + + @Transient + private String name; + + @Transient + private PropAccess m2one; + + @Transient + private Collection one2m; + + @Transient + private PropAccess one2one; + + @Transient + private Collection ecoll; + + @Transient + private EmbedFieldAccess embed; + + @Transient + private int ver; + + @Transient + private Collection m2m; + + @ElementCollection + @Access(AccessType.PROPERTY) + public Collection getElementCollection() { + return ecoll; + } + + public void setElementCollection(Collection coll) { + ecoll = coll; + } + + @Embedded + @Access(AccessType.PROPERTY) + public EmbedFieldAccess getEmbedField() { + return embed; + } + + public void setEmbedField(EmbedFieldAccess efa) { + embed = efa; + } + + @Version + @Access(AccessType.PROPERTY) + public int getVersion() { + return ver; + } + + public void setVersion(int version) { + ver = version; + } + + @ManyToOne(cascade=CascadeType.ALL) + @Access(AccessType.PROPERTY) + public PropAccess getManyToOne() { + return m2one; + } + + public void setManyToOne(PropAccess pa) { + m2one = pa; + } + + @OneToMany(cascade=CascadeType.ALL) + @Access(AccessType.PROPERTY) + public Collection getOneToMany() { + return one2m; + } + + public void setOneToMany(Collection c) { + one2m = c; + } + + @OneToOne(cascade=CascadeType.ALL) + @Access(AccessType.PROPERTY) + public PropAccess getOneToOne() { + return one2one; + } + + public void setOneToOne(PropAccess pa) { + one2one = pa; + } + + @ManyToMany(cascade=CascadeType.ALL) + @Access(AccessType.PROPERTY) + public Collection getManyToMany() { + return m2m; + } + + public void setManyToMany(Collection many) { + m2m = many; + } + + @Basic + @Access(AccessType.PROPERTY) + public String getName() { + return name; + } + + public void setName(String n) { + name = n; + } + + public void setEmbedId(EmbedId eid) { + this.eid = eid; + } + + @EmbeddedId + @Access(AccessType.FIELD) + public EmbedId getEmbedId() { + return eid; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldEmbedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldEmbedEntity.java new file mode 100644 index 000000000..932542b9c --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldEmbedEntity.java @@ -0,0 +1,86 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Basic; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; + +@Entity +@Access(AccessType.FIELD) +@NamedQueries( { + @NamedQuery(name="FieldEmbedEntity.query", + query="SELECT fs FROM FieldEmbedEntity fs WHERE " + + "fs.id = :id AND fs.name = :name AND fs.epa.firstName = :firstName " + + "AND fs.epa.lastName = :lastName"), + @NamedQuery(name="FieldEmbedEntity.badQuery", + query="SELECT fs FROM FieldEmbedEntity fs WHERE " + + "fs.id = :id AND fs.name = :name AND fs.epa.fName = :firstName " + + "AND fs.epa.lName = :lastName") } ) +public class FieldEmbedEntity { + + @Id + @GeneratedValue + private int id; + + @Basic + private String name; + + @Embedded + private EmbedPropAccess epa; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public EmbedPropAccess getEPA() { + return epa; + } + + public void setEPA(EmbedPropAccess ep) { + epa = ep; + } + + public boolean equals(Object obj) { + if (obj instanceof FieldEmbedEntity) { + FieldEmbedEntity ps = (FieldEmbedEntity)obj; + return epa.equals(ps.getEPA()) && id == ps.getId() && + name.equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub.java new file mode 100644 index 000000000..92885c377 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub.java @@ -0,0 +1,63 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Entity; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Access(AccessType.FIELD) +@NamedQueries( { + @NamedQuery(name="FieldSub.query", + query="SELECT fs FROM FieldSub fs WHERE " + + "fs.id = :id AND fs.name = :name AND fs.crtDate = :crtDate"), + @NamedQuery(name="FieldSub.badQuery", + query="SELECT fs FROM FieldSub fs WHERE " + + "fs.id = :id AND fs.name = :name AND fs.createDate = :crtDate") } ) +public class FieldSub extends AbstractMappedSuperProperty { + + @Temporal(TemporalType.TIMESTAMP) + private Date crtDate; + + @Override + public Date getCreateDate() { + return crtDate; + } + + @Override + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof FieldSub) { + FieldSub ps = (FieldSub)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub2.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub2.java new file mode 100644 index 000000000..632d8cb8e --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub2.java @@ -0,0 +1,61 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Entity; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Access(AccessType.FIELD) +@NamedQueries( { + @NamedQuery(name="FieldSub2.query", + query="SELECT fs FROM FieldSub2 fs WHERE " + + "fs.id = :id AND fs.name = :name AND fs.crtDate = :crtDate"), + @NamedQuery(name="FieldSub2.badQuery", + query="SELECT ps FROM FieldSub2 ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate") } ) +public class FieldSub2 extends MappedSuperProperty { + + protected Date crtDate; + + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof FieldSub2) { + FieldSub2 ps = (FieldSub2)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub3.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub3.java new file mode 100644 index 000000000..038a8faaa --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/FieldSub3.java @@ -0,0 +1,63 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Entity; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +@Entity +@Access(AccessType.FIELD) +@NamedQueries( { + @NamedQuery(name="FieldSub3.query", + query="SELECT ps FROM FieldSub3 ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate"), + @NamedQuery(name="FieldSub3.badQuery", + query="SELECT ps FROM FieldSub3 ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate") } ) +public class FieldSub3 extends SuperPropertyEntity { + + @Temporal(TemporalType.TIMESTAMP) + protected Date crtDate; + + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof FieldSub3) { + FieldSub3 ps = (FieldSub3)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperField.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperField.java new file mode 100644 index 000000000..09fe92dd2 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperField.java @@ -0,0 +1,70 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Basic; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Transient; + +@MappedSuperclass +@Access(AccessType.FIELD) +public class MappedSuperField { + + @Id + @GeneratedValue + private int id; + + @Basic + @Access(AccessType.FIELD) + private String name; + + @Transient + protected Date crtDate; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof MappedSuperField) { + MappedSuperField ps = (MappedSuperField)obj; + return id == ps.getId() && + name.equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperProperty.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperProperty.java new file mode 100644 index 000000000..b3b569363 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MappedSuperProperty.java @@ -0,0 +1,64 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Basic; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +@Access(AccessType.PROPERTY) +public class MappedSuperProperty { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + @Id + @GeneratedValue + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + @Basic + @Access(AccessType.PROPERTY) + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof MappedSuperProperty) { + MappedSuperProperty ps = (MappedSuperProperty)obj; + return getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedFieldSub.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedFieldSub.java new file mode 100644 index 000000000..eba93f6f6 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedFieldSub.java @@ -0,0 +1,76 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Entity; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +@Entity +@Access(AccessType.FIELD) +@NamedQueries( { + @NamedQuery(name="MixedFieldSub.query", + query="SELECT fs FROM MixedFieldSub fs WHERE " + + "fs.mid = :id AND fs.name = :name AND fs.createDate = :crtDate " + + "AND fs.myField = :myField"), + @NamedQuery(name="MixedFieldSub.badQuery", + query="SELECT fs FROM MixedFieldSub fs WHERE " + + "fs.mid = :id AND fs.name = :name AND fs.myFieldProp = :myField") } ) +public class MixedFieldSub extends MixedMappedSuper { + + private String myField; + + @Transient + private Date crtDate; + + @Access(AccessType.PROPERTY) + @Temporal(TemporalType.TIMESTAMP) + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof MixedFieldSub) { + MixedFieldSub ps = (MixedFieldSub)obj; + return super.equals(obj) && + getCreateDate().equals(ps.getCreateDate()); + } + return false; + } + + public void setMyFieldProp(String myField) { + this.myField = myField; + } + + public String getMyFieldProp() { + return myField; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMappedSuper.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMappedSuper.java new file mode 100644 index 000000000..c420cf9c2 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMappedSuper.java @@ -0,0 +1,71 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Basic; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Transient; + +@MappedSuperclass +@Access(AccessType.PROPERTY) +public class MixedMappedSuper { + + @Id + @GeneratedValue + @Access(AccessType.FIELD) + private int mid; + + private String mname; + + protected Date crtDate; + + public void setId(int id) { + this.mid = id; + } + + @Transient + public int getId() { + return mid; + } + + public void setName(String name) { + this.mname = name; + } + + @Basic + @Access(AccessType.PROPERTY) + public String getName() { + return mname; + } + + public boolean equals(Object obj) { + if (obj instanceof MixedMappedSuper) { + MixedMappedSuper ps = (MixedMappedSuper)obj; + return getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMultEmbedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMultEmbedEntity.java new file mode 100644 index 000000000..d05b57ddd --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedMultEmbedEntity.java @@ -0,0 +1,110 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Transient; + +@Entity +@Access(AccessType.PROPERTY) +@NamedQueries( { + @NamedQuery(name="MixedMultEmbedEntity.query", + query="SELECT fs FROM MixedMultEmbedEntity fs WHERE " + + "fs.mid = :id AND fs.name = :name AND " + + "fs.embedProp.firstName = :firstName AND " + + "fs.embedProp.lastName = :lastName AND " + + "fs.embedField.fName = :fName AND " + + "fs.embedField.lName = :lName"), + @NamedQuery(name="MixedMultEmbedEntity.badQuery1", + query="SELECT fs FROM MixedMultEmbedEntity fs WHERE " + + "fs.mid = :id AND fs.name = :name AND " + + "fs.epa = :epa"), + @NamedQuery(name="MixedMultEmbedEntity.badQuery2", + query="SELECT fs FROM MixedMultEmbedEntity fs WHERE " + + "fs.mid = :id AND fs.name = :name AND " + + "fs.embedProp = :epa AND " + + "fs.embedField.firstName = :firstName AND " + + "fs.embedField.lName = :lastName") }) +public class MixedMultEmbedEntity { + + @Id + @GeneratedValue + @Access(AccessType.FIELD) + private int mid; + + private String name; + + private EmbedPropAccess epa; + + private EmbedFieldAccess efa; + + public void setId(int id) { + this.mid = id; + } + + @Transient + public int getId() { + return mid; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Embedded + public EmbedPropAccess getEmbedProp() { + return epa; + } + + public void setEmbedProp(EmbedPropAccess ep) { + epa = ep; + } + + @Embedded + public EmbedFieldAccess getEmbedField() { + return efa; + } + + public void setEmbedField(EmbedFieldAccess ef) { + efa = ef; + } + + public boolean equals(Object obj) { + if (obj instanceof MixedMultEmbedEntity) { + MixedMultEmbedEntity ps = (MixedMultEmbedEntity)obj; + return getEmbedProp().equals(ps.getEmbedProp()) && + getEmbedField().equals(ps.getEmbedField()) + && getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedNestedEmbedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedNestedEmbedEntity.java new file mode 100644 index 000000000..fa87c7cb3 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/MixedNestedEmbedEntity.java @@ -0,0 +1,90 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Transient; + +@Entity +@Access(AccessType.FIELD) +@NamedQueries( { + @NamedQuery(name="MixedNestedEmbedEntity.query", + query="SELECT fs FROM MixedNestedEmbedEntity fs WHERE " + + "fs.id = :id AND fs.name = :name AND " + + "fs.eip.innerName = :innerName AND " + + "fs.eip.outerField.outName = :outerName"), + @NamedQuery(name="MixedNestedEmbedEntity.badQuery", + query="SELECT fs FROM MixedNestedEmbedEntity fs WHERE " + + "fs.id = :id AND fs.name = :name AND " + + "fs.eip.innerName = :innerName AND " + + "fs.eip.outerField.outerName = :outerName") }) +public class MixedNestedEmbedEntity { + + @Transient + private int mid; + + private String name; + + @Embedded + private EmbedInnerProp eip; + + public void setId(int id) { + this.mid = id; + } + + @Id + @GeneratedValue + @Access(AccessType.PROPERTY) + public int getId() { + return mid; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public EmbedInnerProp getEmbedProp() { + return eip; + } + + public void setEmbedProp(EmbedInnerProp ep) { + eip = ep; + } + + public boolean equals(Object obj) { + if (obj instanceof MixedNestedEmbedEntity) { + MixedNestedEmbedEntity ps = (MixedNestedEmbedEntity)obj; + return getEmbedProp().equals(ps.getEmbedProp()) + && getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccess.java new file mode 100644 index 000000000..f20bf33f4 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccess.java @@ -0,0 +1,78 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Version; + +import static javax.persistence.AccessType.PROPERTY; + +@Entity +@Access(value=PROPERTY) +@NamedQuery(name="PropertyAccess.query", + query="SELECT pa FROM PropAccess pa WHERE " + + "pa.id = :id AND pa.strProp = :strVal") +public class PropAccess { + + private int id; + + private int version; + + private String strField; + + public void setId(int id) { + this.id = id; + } + + @Id + @GeneratedValue + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + @Version + public int getVersion() { + return version; + } + + public void setStrProp(String var) { + this.strField = var; + } + + public String getStrProp() { + return strField; + } + + public boolean equals(Object obj) { + if (obj instanceof PropAccess) { + PropAccess pa = (PropAccess)obj; + return getId() == pa.getId() && + getStrProp().equals(pa.getStrProp()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccessFieldStratsEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccessFieldStratsEntity.java new file mode 100644 index 000000000..2f59e9d4e --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropAccessFieldStratsEntity.java @@ -0,0 +1,160 @@ +/* + * 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.access; + +import java.util.Collection; + +import javax.persistence.Access; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.ElementCollection; +import javax.persistence.Embedded; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.AccessType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.Transient; +import javax.persistence.Version; + +@Entity +@Access(AccessType.PROPERTY) +public class PropAccessFieldStratsEntity { + + @Transient + private EmbedId eid; + + @Basic + @Access(AccessType.FIELD) + private String name; + + @ManyToOne(cascade=CascadeType.ALL) + @Access(AccessType.FIELD) + private PropAccess m2one; + + @OneToMany(cascade=CascadeType.ALL) + @Access(AccessType.FIELD) + private Collection one2m; + + @OneToOne(cascade=CascadeType.ALL) + @Access(AccessType.FIELD) + private PropAccess one2one; + + @ElementCollection + @Access(AccessType.FIELD) + private Collection ecoll; + + @Embedded + @Access(AccessType.FIELD) + private EmbedFieldAccess embed; + + @Version + @Access(AccessType.FIELD) + private int ver; + + @ManyToMany(cascade=CascadeType.ALL) + @Access(AccessType.FIELD) + private Collection m2m; + + @Transient + public Collection getElementCollection() { + return ecoll; + } + + public void setElementCollection(Collection elc) { + ecoll = elc; + } + + @Transient + public EmbedFieldAccess getEmbedField() { + return embed; + } + + public void setEmbedField(EmbedFieldAccess efa) { + embed = efa; + } + + @Transient + public int getVersion() { + return ver; + } + + public void setVersion(int version) { + ver = version; + } + + @Transient + public PropAccess getManyToOne() { + return m2one; + } + + public void setManyToOne(PropAccess pa) { + m2one = pa; + } + + @Transient + public Collection getOneToMany() { + return one2m; + } + + public void setOneToMany(Collection c) { + one2m = c; + } + + @Transient + public PropAccess getOneToOne() { + return one2one; + } + + public void setOneToOne(PropAccess pa) { + one2one = pa; + } + + @Transient + public Collection getManyToMany() { + return m2m; + } + + public void setManyToMany(Collection many) { + m2m = many; + } + + @Transient + public String getName() { + return name; + } + + public void setName(String n) { + name = n; + } + + public void setEmbedId(EmbedId eid) { + this.eid = eid; + } + + @EmbeddedId + @Access(AccessType.PROPERTY) + public EmbedId getEmbedId() { + return eid; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropEmbedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropEmbedEntity.java new file mode 100644 index 000000000..f3a6d64b8 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropEmbedEntity.java @@ -0,0 +1,87 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Basic; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; + +@Entity +@Access(AccessType.PROPERTY) +@NamedQueries( { + @NamedQuery(name="PropEmbedEntity.query", + query="SELECT fs FROM PropEmbedEntity fs WHERE " + + "fs.id = :id AND fs.name = :name AND fs.embedProp.fName = :firstName " + + "AND fs.embedProp.lName = :lastName"), + @NamedQuery(name="PropEmbedEntity.badQuery", + query="SELECT fs FROM PropEmbedEntity fs WHERE " + + "fs.id = :id AND fs.name = :name AND fs.embedProp.firstName = " + + ":firstName AND fs.embedProp.lastName = :lastName") } ) +public class PropEmbedEntity { + + private int id; + + private String name; + + private EmbedFieldAccess efa; + + public void setId(int id) { + this.id = id; + } + + @Id + @GeneratedValue + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + @Basic + public String getName() { + return name; + } + + @Embedded + public EmbedFieldAccess getEmbedProp() { + return efa; + } + + public void setEmbedProp(EmbedFieldAccess ef) { + efa = ef; + } + + public boolean equals(Object obj) { + if (obj instanceof PropEmbedEntity) { + PropEmbedEntity ps = (PropEmbedEntity)obj; + return getEmbedProp().equals(ps.getEmbedProp()) + && getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropMixedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropMixedEntity.java new file mode 100644 index 000000000..873a541b3 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropMixedEntity.java @@ -0,0 +1,97 @@ +/* + * 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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Transient; + +@Entity +@Access(AccessType.PROPERTY) +@NamedQueries( { + @NamedQuery(name="PropMixedEntity.query", + query="SELECT fs FROM PropMixedEntity fs WHERE " + + "fs.idval = :id AND fs.name = :name AND " + + "fs.ema.firstName = :firstName " + + "AND fs.ema.lastName = :lastName AND " + + "fs.ema.mName = :middleName"), + @NamedQuery(name="PropMixedEntity.badQuery", + query="SELECT fs FROM PropMixedEntity fs WHERE " + + "fs.idval = :id AND fs.name = :name AND " + + "fs.ema.firstName = :firstName AND " + + "fs.ema.lastName = :lastName AND " + + "fs.ema.middleName = :middleName") }) +public class PropMixedEntity { + + @Id + @GeneratedValue + @Access(AccessType.FIELD) + private int idval; + + private String myName; + + @Access(AccessType.FIELD) + @Embedded + private EmbedMixedAccess ema; + + public void setId(int id) { + this.idval = id; + } + + @Transient + public int getId() { + return idval; + } + + public void setName(String name) { + this.myName = name; + } + + // Property access + public String getName() { + return myName; + } + + @Transient + public EmbedMixedAccess getEmbedProp() { + return ema; + } + + public void setEmbedProp(EmbedMixedAccess ef) { + ema = ef; + } + + public boolean equals(Object obj) { + if (obj instanceof PropMixedEntity) { + PropMixedEntity ps = (PropMixedEntity)obj; + return getEmbedProp().equals(ps.getEmbedProp()) + && getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } + + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub.java new file mode 100644 index 000000000..f01a1fcfb --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub.java @@ -0,0 +1,64 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Entity; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Access(AccessType.PROPERTY) +@NamedQueries( { + @NamedQuery(name="PropertySub.query", + query="SELECT ps FROM PropertySub ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate"), + @NamedQuery(name="PropertySub.badQuery", + query="SELECT ps FROM PropertySub ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate") } ) +public class PropertySub extends AbstractMappedSuperField { + + private Date crtDate; + + @Override + @Temporal(TemporalType.TIMESTAMP) + public Date getCreateDate() { + return crtDate; + } + + @Override + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof PropertySub) { + PropertySub ps = (PropertySub)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub2.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub2.java new file mode 100644 index 000000000..454523ab6 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub2.java @@ -0,0 +1,60 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Entity; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Access(AccessType.PROPERTY) +@NamedQueries( { + @NamedQuery(name="PropertySub2.query", + query="SELECT ps FROM PropertySub2 ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate"), + @NamedQuery(name="PropertySub2.badQuery", + query="SELECT ps FROM PropertySub2 ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate") } ) +public class PropertySub2 extends MappedSuperField { + + @Temporal(TemporalType.TIMESTAMP) + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof PropertySub2) { + PropertySub2 ps = (PropertySub2)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub3.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub3.java new file mode 100644 index 000000000..928fc23f0 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/PropertySub3.java @@ -0,0 +1,63 @@ +/* + * 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.access; + +import java.util.Date; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Entity; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +@Entity +@Access(AccessType.PROPERTY) +@NamedQueries( { + @NamedQuery(name="PropertySub3.query", + query="SELECT ps FROM PropertySub3 ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate"), + @NamedQuery(name="PropertySub3.badQuery", + query="SELECT ps FROM PropertySub3 ps WHERE " + + "ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate") } ) +public class PropertySub3 extends SuperFieldEntity { + + protected Date crtDate; + + @Temporal(TemporalType.TIMESTAMP) + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof PropertySub3) { + PropertySub3 ps = (PropertySub3)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperFieldEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperFieldEntity.java new file mode 100644 index 000000000..3c7a48bec --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperFieldEntity.java @@ -0,0 +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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; + +@Entity +@Inheritance +@Access(AccessType.FIELD) +@NamedQueries( { + @NamedQuery(name="SuperFieldEntity.query", + query="SELECT sfe FROM SuperFieldEntity sfe WHERE " + + "sfe.id = :id AND sfe.name = :name"), + @NamedQuery(name="SuperFieldEntity.badQuery", + query="SELECT sfe FROM SuperFieldEntity sfe WHERE " + + "sfe.id = :id AND sfe.name = :name AND sfe.crtDate = :crtDate") } ) +public class SuperFieldEntity { + + @Id + @GeneratedValue + @Access(AccessType.FIELD) + private int id; + + @Basic + private String name; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof SuperFieldEntity) { + SuperFieldEntity sfe = (SuperFieldEntity)obj; + return id == sfe.getId() && + name.equals(sfe.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperPropertyEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperPropertyEntity.java new file mode 100644 index 000000000..e9a02c79f --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/SuperPropertyEntity.java @@ -0,0 +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.access; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; + +@Entity +@Inheritance +@Access(AccessType.PROPERTY) +@NamedQueries( { + @NamedQuery(name="SuperPropertyEntity.query", + query="SELECT sfe FROM SuperPropertyEntity sfe WHERE " + + "sfe.id = :id AND sfe.name = :name"), + @NamedQuery(name="SuperPropertyEntity.badQuery", + query="SELECT sfe FROM SuperPropertyEntity sfe WHERE " + + "sfe.id = :id AND sfe.name = :name AND sfe.crtDate = :crtDate") } ) +public class SuperPropertyEntity { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + @Id + @GeneratedValue + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + @Basic + @Access(AccessType.PROPERTY) + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof SuperPropertyEntity) { + SuperPropertyEntity sfe = (SuperPropertyEntity)obj; + return getId() == sfe.getId() && + getName().equals(sfe.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestDefaultAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestDefaultAccess.java new file mode 100644 index 000000000..5e397666c --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestDefaultAccess.java @@ -0,0 +1,206 @@ +/* + * 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.access; + +import javax.persistence.Query; + +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; +import org.apache.openjpa.persistence.OpenJPAPersistence; +import org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess; +import org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess; +import org.apache.openjpa.persistence.access.xml.XMLFieldAccess; +import org.apache.openjpa.persistence.access.xml.XMLPropAccess; +import org.apache.openjpa.persistence.test.SingleEMFTestCase; + +public class TestDefaultAccess extends SingleEMFTestCase { + + /** + * Validates use of access specifier of FIELD in entity-mappings. + */ + public void testEMDefaultFieldAccess() { + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-EMFldDef", + "org/apache/openjpa/persistence/access/" + + "access-def-persistence.xml"); + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + verifyDefaultFieldAccess(em); + + em.close(); + emf.close(); + } + + /** + * Validates use of access specifier of PROPERTY in entity-mappings. + */ + public void testEMDefaultPropertyAccess() { + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-EMPropDef", + "org/apache/openjpa/persistence/access/" + + "access-def-persistence.xml"); + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + verifyDefaultPropertyAccess(em); + + em.close(); + emf.close(); + } + + /** + * Validates use of access specifier of FIELD in persistence unit defaults. + */ + public void testPUDefaultFieldAccess() { + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-PUFldDef", + "org/apache/openjpa/persistence/access/" + + "access-pudef-persistence.xml"); + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + verifyDefaultFieldAccess(em); + + em.close(); + emf.close(); + } + + /** + * Validates use of access specifier of PROPERTY in persistence unit + * defaults. + */ + public void testPUDefaultPropertyAccess() { + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-PUPropDef", + "org/apache/openjpa/persistence/access/" + + "access-pudef-persistence.xml"); + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + verifyDefaultPropertyAccess(em); + + em.close(); + emf.close(); + } + + private void verifyDefaultFieldAccess(OpenJPAEntityManagerSPI em) { + XMLFieldAccess fa = new XMLFieldAccess(); + // Set the persistent field through a misnamed setter + fa.setStringField("XMLFieldAccess2"); + + em.getTransaction().begin(); + em.persist(fa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the field name to verify that + // field access is in use. + Query qry = em.createNamedQuery("XMLFieldAccess2.query"); + qry.setParameter("id", fa.getId()); + qry.setParameter("strVal", "XMLFieldAccess2"); + XMLFieldAccess fa2 = (XMLFieldAccess)qry.getSingleResult(); + assertEquals(fa.getId(), fa2.getId()); + + XMLDefFieldMixedPropAccess dfmpa = new XMLDefFieldMixedPropAccess(); + // Call non-PC setter + dfmpa.setStrField("NonPCSetter"); + // Call setter with property access + dfmpa.setStringField("XMLDFMPA2"); + + em.getTransaction().begin(); + em.persist(dfmpa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent property was set using the setter + // above, but this query will use the property name to verify that + // property access is in use. + qry = em.createNamedQuery("XMLDFMPA2.query"); + qry.setParameter("id", dfmpa.getId()); + qry.setParameter("strVal", "XMLDFMPA2"); + XMLDefFieldMixedPropAccess dfmpa2 = + (XMLDefFieldMixedPropAccess)qry.getSingleResult(); + assertEquals(dfmpa, dfmpa2); + assertEquals(dfmpa2.getStringField(), "XMLDFMPA2"); + + try { + qry = em.createNamedQuery("XMLDFMPA2.badQuery"); + qry.setParameter("id", dfmpa.getId()); + qry.setParameter("strVal", "XMLDFMPA2"); + qry.getSingleResult(); + fail("Execution of this query should have thrown an exception"); + } + catch (Exception e) { + // Expected exception + } + } + + private void verifyDefaultPropertyAccess(OpenJPAEntityManagerSPI em) { + XMLPropAccess pa = new XMLPropAccess(); + // Set the persistent field through a mis-named setter + pa.setStrProp("PropertyAccess"); + + em.getTransaction().begin(); + em.persist(pa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the field name to verify that + // field access is in use. + Query qry = em.createNamedQuery("XMLPropAccess2.query"); + qry.setParameter("id", pa.getId()); + qry.setParameter("strVal", "PropertyAccess"); + XMLPropAccess pa2 = (XMLPropAccess)qry.getSingleResult(); + assertEquals(pa, pa2); + + XMLDefPropMixedFieldAccess dpmfa = new XMLDefPropMixedFieldAccess(); + // Call setter with underlying field access + dpmfa.setStrProp("XMLDPMFA2"); + + em.getTransaction().begin(); + em.persist(dpmfa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // property access is in use. + qry = em.createNamedQuery("XMLDPMFA2.query"); + qry.setParameter("id", dpmfa.getId()); + qry.setParameter("strVal", "XMLDPMFA2"); + XMLDefPropMixedFieldAccess dpmfa2 = + (XMLDefPropMixedFieldAccess)qry.getSingleResult(); + assertEquals(dpmfa, dpmfa2); + assertEquals(dpmfa2.getStrProp(), "XMLDPMFA2"); + + try { + qry = em.createNamedQuery("XMLDPMFA2.badQuery"); + qry.setParameter("id", dpmfa.getId()); + qry.setParameter("strVal", "XMLDPMFA2"); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + // Expected exception + } + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestExplicitAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestExplicitAccess.java new file mode 100644 index 000000000..87b9cd233 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/TestExplicitAccess.java @@ -0,0 +1,1103 @@ +/* + * 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.access; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Random; + +import javax.persistence.Query; + +import org.apache.openjpa.jdbc.ant.ReverseMappingToolTask.AccessType; +import org.apache.openjpa.meta.AccessCode; +import org.apache.openjpa.meta.ClassMetaData; +import org.apache.openjpa.meta.FieldMetaData; +import org.apache.openjpa.meta.MetaDataRepository; +import org.apache.openjpa.persistence.ArgumentException; +import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; +import org.apache.openjpa.persistence.test.AllowFailure; +import org.apache.openjpa.persistence.test.SingleEMFTestCase; + +public class TestExplicitAccess extends SingleEMFTestCase { + + public void setUp() { + setUp(CLEAR_TABLES, + PropAccess.class, FieldAccess.class, + DefFieldMixedPropAccess.class , DefPropMixedFieldAccess.class, + AbstractMappedSuperField.class, PropertySub.class, + MappedSuperField.class, PropertySub2.class, + SuperFieldEntity.class, PropertySub3.class, + AbstractMappedSuperProperty.class, FieldSub.class, + MappedSuperProperty.class, FieldSub2.class, + SuperPropertyEntity.class, FieldSub3.class, + MixedMappedSuper.class, MixedFieldSub.class //, + // These persistent types are commented out until + // support for embeddable access types is complete +// FieldEmbedEntity.class, EmbedFieldAccess.class, +// PropEmbedEntity.class, EmbedPropAccess.class, +// PropMixedEntity.class, EmbedMixedAccess.class, +// MixedNestedEmbedEntity.class, EmbedInnerProp.class, +// EmbedOuterField.class, MixedMultEmbedEntity.class, +// FieldAccessPropStratsEntity.class, +// PropAccessFieldStratsEntity.class, + /* EmbedId.class */); + } + + + /** + * Validates the use of field level access on an + * entity, mappedsuperclass, and embeddable at the + * class level. + */ + public void testClassSpecifiedFieldAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + FieldAccess fa = new FieldAccess(); + // Set the persistent field through a misnamed setter + fa.setStringField("FieldAccess"); + + em.getTransaction().begin(); + em.persist(fa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the field name to verify that + // field access is in use. + Query qry = em.createNamedQuery("FieldAccess.query"); + qry.setParameter("id", fa.getId()); + qry.setParameter("strVal", "FieldAccess"); + FieldAccess fa2 = (FieldAccess)qry.getSingleResult(); + assertEquals(fa.getId(), fa2.getId()); + + em.close(); + } + + /** + * Validates the use of property level access on an + * entity, mappedsuperclass, and embeddable at the + * class level. + */ + public void testClassSpecifiedPropertyAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + PropAccess pa = new PropAccess(); + // Set the persistent field through a misnamed setter + pa.setStrProp("PropertyAccess"); + + em.getTransaction().begin(); + em.persist(pa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the field name to verify that + // field access is in use. + Query qry = em.createNamedQuery("PropertyAccess.query"); + qry.setParameter("id", pa.getId()); + qry.setParameter("strVal", "PropertyAccess"); + PropAccess pa2 = (PropAccess)qry.getSingleResult(); + assertEquals(pa, pa2); + } + + /** + * Validates the use of explicit field access on an entity, + * mappedsuperclass, and embeddable with property access + * defined at the class level and field access defined + * on specific methods. + */ + public void testClassSpecifiedMixedSinglePCFieldAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + DefFieldMixedPropAccess dfmpa = new DefFieldMixedPropAccess(); + // Call non-PC setter + dfmpa.setStrField("NonPCSetter"); + // Call setter with property access + dfmpa.setStringField("DFMPA"); + + em.getTransaction().begin(); + em.persist(dfmpa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent property was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("DFMPA.query"); + qry.setParameter("id", dfmpa.getId()); + qry.setParameter("strVal", "DFMPA"); + DefFieldMixedPropAccess dfmpa2 = + (DefFieldMixedPropAccess)qry.getSingleResult(); + assertEquals(dfmpa, dfmpa2); + assertEquals(dfmpa2.getStringField(), "DFMPA"); + + try { + qry = em.createNamedQuery("DFMPA.badQuery"); + qry.setParameter("id", dfmpa.getId()); + qry.setParameter("strVal", "DFMPA"); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"strField\" in \"DefFieldMixedPropAccess\"", + "[id, stringField, version]"); + } + + em.close(); + } + + /** + * Validates the use of explicit property access on an entity, + * mappedsuperclass, and embeddable with field access + * defined at the class level and property access defined + * on specific methods. + */ + public void testClassSpecifiedMixedSinglePCPropertyAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + DefPropMixedFieldAccess dpmfa = new DefPropMixedFieldAccess(); + // Call setter with underlying field access + dpmfa.setStrProp("DPMFA"); + + em.getTransaction().begin(); + em.persist(dpmfa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("DPMFA.query"); + qry.setParameter("id", dpmfa.getId()); + qry.setParameter("strVal", "DPMFA"); + DefPropMixedFieldAccess dpmfa2 = + (DefPropMixedFieldAccess)qry.getSingleResult(); + assertEquals(dpmfa, dpmfa2); + assertEquals(dpmfa2.getStrProp(), "DPMFA"); + + try { + qry = em.createNamedQuery("DPMFA.badQuery"); + qry.setParameter("id", dpmfa.getId()); + qry.setParameter("strVal", "DPMFA"); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"strProp\" in \"DefPropMixedFieldAccess\"", + "[id, strField, version]"); + } + + em.close(); + } + + /** + * Validates that a mapped superclass using field access and an entity + * subclass using property access get mapped properly. + */ + public void testAbstractMappedSuperField() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + PropertySub ps = new PropertySub(); + // Call super setter with underlying field access + ps.setName("AbsMappedSuperName"); + // Call base setter with property access + Date now = new Date(); + ps.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(ps); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("PropertySub.query"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + PropertySub ps2 = + (PropertySub)qry.getSingleResult(); + assertEquals(ps, ps2); + assertEquals(ps2.getName(), "AbsMappedSuperName"); + assertEquals(ps2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("PropertySub.badQuery"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"PropertySub\"", + "[createDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that a mapped superclass using property access and an entity + * subclass using field access get mapped properly. + */ + public void testAbstractMappedSuperProperty() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + FieldSub fs = new FieldSub(); + // Call super setter with underlying field access + fs.setName("AbsMappedSuperName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(fs); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("FieldSub.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + FieldSub fs2 = + (FieldSub)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "AbsMappedSuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("FieldSub.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"createDate\" in \"FieldSub\"", + "[crtDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that an mapped superclass using field access and an + * entity subclass using property access get mapped properly. + * The subclass uses a storage field in the superclass. + */ + public void testMappedSuperField() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + PropertySub2 ps = new PropertySub2(); + // Call super setter with underlying field access + ps.setName("MappedSuperName"); + // Call base setter with property access + Date now = new Date(); + ps.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(ps); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("PropertySub2.query"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + PropertySub2 ps2 = + (PropertySub2)qry.getSingleResult(); + assertEquals(ps, ps2); + assertEquals(ps2.getName(), "MappedSuperName"); + assertEquals(ps2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("PropertySub2.badQuery"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"PropertySub2\"", + "[createDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that an mapped superclass using field access and an + * entity subclass using property access get mapped properly. + * The subclass uses a storage field in the superclass. + */ + public void testMappedSuperProperty() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + FieldSub2 fs = new FieldSub2(); + // Call super setter with underlying field access + fs.setName("MappedSuperName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(fs); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("FieldSub2.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + FieldSub2 fs2 = + (FieldSub2)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "MappedSuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("FieldSub2.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"createDate\" in \"FieldSub2\"", + "[crtDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that a mix of access types can be used within multiple + * persistent classes within an inheritance hierarchy that uses + * MappedSuperclass. + */ + public void testMixedMappedSuper() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + MixedFieldSub fs = new MixedFieldSub(); + // Call super setter with underlying field access + fs.setName("MixedMappedSuperName"); + fs.setMyFieldProp("MyFieldName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(fs); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("MixedFieldSub.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "MixedMappedSuperName"); + qry.setParameter("crtDate", now); + qry.setParameter("myField", "MyFieldName"); + MixedFieldSub fs2 = + (MixedFieldSub)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "MixedMappedSuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("MixedFieldSub.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "MixedMappedSuperName"); + qry.setParameter("myField", "MyFieldName"); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"myFieldProp\" in \"MixedFieldSub\"", + "[createDate, mid, myField, name]"); + } + + em.close(); + + } + + /** + * Validates that a mix of access types can be used within + * an inheritance hierarchy which uses default Entity inheritance. + * NOTE: be sure to test with all forms of inheritance. + */ + public void testEntityFieldDefaultInheritance() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + FieldSub3 fs = new FieldSub3(); + // Call super setter with underlying field access + fs.setName("EntitySuperName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + SuperPropertyEntity spe = new SuperPropertyEntity(); + spe.setName("SuperPropertyEntity"); + + em.getTransaction().begin(); + em.persist(fs); + em.persist(spe); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("FieldSub3.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + FieldSub3 fs2 = + (FieldSub3)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "EntitySuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("FieldSub3.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"createDate\" in \"FieldSub3\"", + "[crtDate, id, name]"); + } + + qry = em.createNamedQuery("SuperPropertyEntity.query"); + qry.setParameter("id", spe.getId()); + qry.setParameter("name", "SuperPropertyEntity"); + SuperPropertyEntity spe2 = + (SuperPropertyEntity)qry.getSingleResult(); + assertEquals(spe, spe2); + assertEquals(spe2.getName(), "SuperPropertyEntity"); + + try { + // This query ensures that a subclass property didn't somehow get + // picked up by the superclass while building field metadata using + // explicit access. + qry = em.createNamedQuery("SuperPropertyEntity.badQuery"); + qry.setParameter("id", spe.getId()); + qry.setParameter("name", "SuperPropertyEntity"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"SuperPropertyEntity\"", + "[id, name]"); + } + + em.close(); + } + + /** + * Validates that a mix of access types can be used within + * an inheritance hierarchy which uses default Entity inheritance. + * NOTE: be sure to test with all forms of inheritance. + */ + public void testEntityPropertyDefaultInheritance() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + PropertySub3 ps = new PropertySub3(); + // Call super setter with underlying field access + ps.setName("EntitySuperName"); + // Call base setter with property access + Date now = new Date(); + ps.setCreateDate(now); + + SuperFieldEntity sfe = new SuperFieldEntity(); + sfe.setName("SuperFieldEntity"); + + em.getTransaction().begin(); + em.persist(ps); + em.persist(sfe); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("PropertySub3.query"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + PropertySub3 ps2 = + (PropertySub3)qry.getSingleResult(); + assertEquals(ps, ps2); + assertEquals(ps2.getName(), "EntitySuperName"); + assertEquals(ps2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("PropertySub3.badQuery"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"PropertySub3\"", + "[createDate, id, name]"); + } + + qry = em.createNamedQuery("SuperFieldEntity.query"); + qry.setParameter("id", sfe.getId()); + qry.setParameter("name", "SuperFieldEntity"); + SuperFieldEntity sfe2 = + (SuperFieldEntity)qry.getSingleResult(); + assertEquals(sfe2, sfe2); + assertEquals(sfe2.getName(), "SuperFieldEntity"); + + try { + // This query ensures that a subclass property didn't somehow get + // picked up by the superclass while building field metadata using + // explicit access. + qry = em.createNamedQuery("SuperFieldEntity.badQuery"); + qry.setParameter("id", sfe.getId()); + qry.setParameter("name", "SuperFieldEntity"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"SuperFieldEntity\"", + "[id, name]"); + } + em.close(); + } + + /** + * Validates an embeddable with field access can be used within an + * entity with property access + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testEmbeddablesField() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + EmbedFieldAccess efa = new EmbedFieldAccess(); + efa.setFirstName("J"); + efa.setLastName("Tolkien"); + + PropEmbedEntity pe = new PropEmbedEntity(); + pe.setName("PropEmbedEntity"); + pe.setEmbedProp(efa); + + em.getTransaction().begin(); + em.persist(pe); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("PropEmbedEntity.query"); + qry.setParameter("id", pe.getId()); + qry.setParameter("name", "PropEmbedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + PropEmbedEntity pe2 = (PropEmbedEntity)qry.getSingleResult(); + assertEquals(pe, pe2); + assertEquals(efa, pe2.getEmbedProp()); + + try { + qry = em.createNamedQuery("PropEmbedEntity.badQuery"); + qry.setParameter("id", pe.getId()); + qry.setParameter("name", "PropEmbedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"firstName\" in \"EmbedFieldAccess\"", + "[fName, lName]"); + } + + em.close(); + } + + /** + * Validates an embeddable with property access can be used within an + * entity with field access + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testEmbeddablesProperty() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + EmbedPropAccess epa = new EmbedPropAccess(); + epa.setFirstName("Walt"); + epa.setLastName("Whitman"); + + FieldEmbedEntity fe = new FieldEmbedEntity(); + fe.setName("FieldEmbedEntity"); + fe.setEPA(epa); + + em.getTransaction().begin(); + em.persist(fe); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("FieldEmbedEntity.query"); + qry.setParameter("id", fe.getId()); + qry.setParameter("name", "FieldEmbedEntity"); + qry.setParameter("firstName", "Walt"); + qry.setParameter("lastName", "Whitman"); + FieldEmbedEntity fe2 = (FieldEmbedEntity)qry.getSingleResult(); + assertEquals(fe, fe2); + assertEquals(epa, fe2.getEPA()); + + try { + qry = em.createNamedQuery("FieldEmbedEntity.badQuery"); + qry.setParameter("id", fe.getId()); + qry.setParameter("name", "FieldEmbedEntity"); + qry.setParameter("firstName", "Walt"); + qry.setParameter("lastName", "Whitman"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"fName\" in \"EmbedPropAccess\"", + "[firstName, lastName]"); + } + + em.close(); + } + + /** + * Validates an embeddable with mixed access can be used within an + * entity with mixed access + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testMixedEmbeddables() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + EmbedMixedAccess ema = new EmbedMixedAccess(); + ema.setFirstName("J"); + ema.setLastName("Tolkien"); + ema.setMiddleName("R"); + + PropMixedEntity pm = new PropMixedEntity(); + pm.setName("PropMixedEntity"); + pm.setEmbedProp(ema); + + em.getTransaction().begin(); + em.persist(pm); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("PropMixedEntity.query"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "PropMixedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + qry.setParameter("middleName", "R"); + PropMixedEntity pm2 = (PropMixedEntity)qry.getSingleResult(); + assertEquals(pm, pm2); + assertEquals(ema, pm2.getEmbedProp()); + + try { + qry = em.createNamedQuery("PropMixedEntity.badQuery"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "PropMixedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + qry.setParameter("middleName", "R"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"middleName\" in \"EmbedMixedAccess\"", + "[firstName, lastName, mName]"); + } + + em.close(); + } + + /** + * Validates that a mix of access types can be used within + * an embeddable stack. + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testNestedEmbeddables() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + EmbedInnerProp eip = new EmbedInnerProp(); + eip.setInnerName("Inner"); + EmbedOuterField eof = new EmbedOuterField(); + eof.setOuterName("Outer"); + eip.setOuterField(eof); + + MixedNestedEmbedEntity pm = new MixedNestedEmbedEntity(); + pm.setName("MixedNestedEmbedEntity"); + pm.setEmbedProp(eip); + + em.getTransaction().begin(); + em.persist(pm); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("MixedNestedEmbedEntity.query"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "MixedNestedEmbedEntity"); + qry.setParameter("innerName", "Inner"); + qry.setParameter("outerName", "Outer"); + MixedNestedEmbedEntity pm2 = + (MixedNestedEmbedEntity)qry.getSingleResult(); + assertEquals(pm, pm2); + assertEquals(eip, pm2.getEmbedProp()); + + try { + qry = em.createNamedQuery("MixedNestedEmbedEntity.badQuery"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "MixedNestedEmbedEntity"); + qry.setParameter("innerName", "Inner"); + qry.setParameter("outerName", "Outer"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"outerName\" in \"EmbedOuterField\"", + "[outName]"); + } + + em.close(); + } + + /** + * Validates that a mix of access types can be used by an + * an entity with mulitple embeddables. + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testMultipleEmbeddables() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + EmbedFieldAccess efa = new EmbedFieldAccess(); + efa.setFirstName("First"); + efa.setLastName("Last"); + + EmbedPropAccess epa = new EmbedPropAccess(); + epa.setFirstName("fname"); + epa.setLastName("lname"); + + MixedMultEmbedEntity pm = new MixedMultEmbedEntity(); + pm.setName("MixedMultEmbedEntity"); + pm.setEmbedProp(epa); + pm.setEmbedField(efa); + + em.getTransaction().begin(); + em.persist(pm); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("MixedMultEmbedEntity.query"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "MixedMultEmbedEntity"); + qry.setParameter("firstName", "fname"); + qry.setParameter("lastName", "lname"); + qry.setParameter("fName", "First"); + qry.setParameter("lName", "Last"); + MixedMultEmbedEntity pm2 = + (MixedMultEmbedEntity)qry.getSingleResult(); + assertEquals(pm, pm2); + assertEquals(epa, pm2.getEmbedProp()); + assertEquals(efa, pm2.getEmbedField()); + + try { + qry = em.createNamedQuery("MixedMultEmbedEntity.badQuery1"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "MixedMultEmbedEntity"); + qry.setParameter("epa", epa); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"epa\" in \"MixedMultEmbedEntity\"", + "[embedField, embedProp, mid, name]"); + } + + try { + qry = em.createNamedQuery("MixedMultEmbedEntity.badQuery2"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "MixedMultEmbedEntity"); + qry.setParameter("epa", epa); + qry.setParameter("firstName", "First"); + qry.setParameter("lastName", "Last"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"firstName\" in \"EmbedFieldAccess\"", + "[fName, lName]"); + } + + em.close(); + } + + /** + * Validates explicit property access can be applied to all the access + * strategies from within an entity with explicit field access (except for + * the id field, which is field default) + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testPropertyAccessStrategies() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + PropAccessFieldStratsEntity pa = new PropAccessFieldStratsEntity(); + + // Load all persistent fields + EmbedId eid = new EmbedId(); + eid.setId(new Random().nextInt()); + eid.setCode("IdCode"); + pa.setEmbedId(eid); // embedded id + + Collection elc = new ArrayList(); + EmbedPropAccess epa1 = new EmbedPropAccess("Abe", "Lincoln"); + EmbedPropAccess epa2 = new EmbedPropAccess("John", "Kennedy"); + elc.add(epa1); + elc.add(epa2); + pa.setElementCollection(elc); // element collection of embeddables + + EmbedFieldAccess efa = new EmbedFieldAccess(); + efa.setFirstName("The"); + efa.setLastName("President"); + pa.setEmbedField(efa); // embedded + + pa.setName("PropAccessFieldStratsEntity"); // basic + + PropAccess propa = new PropAccess(); + propa.setStrProp("PropAccess"); + pa.setManyToOne(propa); // many to one + + Collection fac = new ArrayList(); + FieldAccess fa = new FieldAccess(); + fa.setStrField("FieldAccess"); + fac.add(fa); + pa.setOneToMany(fac); // one to many + + PropAccess pa2 = new PropAccess(); + pa2.setStrProp("PropAccess2"); + pa.setOneToOne(pa2); // one to one + + em.getTransaction().begin(); + em.persist(pa); + em.getTransaction().commit(); + + em.clear(); + // Verify list of persistent fields + PropAccessFieldStratsEntity newpa = + em.find(PropAccessFieldStratsEntity.class, eid); + assertNotNull(newpa); + // simple key validation + assertEquals(newpa.getEmbedId(), eid); + + // Verify the persistent member names + MetaDataRepository mdr = + em.getConfiguration().getMetaDataRepositoryInstance(); + + ClassMetaData cmd = mdr.getMetaData(PropAccessFieldStratsEntity.class, + null, true); + // Assert expected persistent fields and properties were created + assertNotNull(cmd.getField("embedId")); + assertNotNull(cmd.getField("m2one")); + assertNotNull(cmd.getField("one2m")); + assertNotNull(cmd.getField("one2one")); + assertNotNull(cmd.getField("ecoll")); + assertNotNull(cmd.getField("embed")); + assertNotNull(cmd.getField("ver")); + assertNotNull(cmd.getField("m2m")); + + // Name has a matching getter/setter. Make sure the access type + // is field & not property + assertNotNull(cmd.getField("name")); + assertTrue((cmd.getField("name").getAccessType() & AccessCode.FIELD) == + AccessCode.FIELD); + + // Assert mappings were not created for fields or properties which + // should not be persistent + assertNull(cmd.getField("eid")); + assertNull(cmd.getField("elementCollection")); + assertNull(cmd.getField("embedField")); + assertNull(cmd.getField("version")); + assertNull(cmd.getField("manyToOne")); + assertNull(cmd.getField("oneToMany")); + assertNull(cmd.getField("oneToOne")); + assertNull(cmd.getField("manyToMany")); + + em.close(); + } + + /** + * Validates explicit field access can be applied to all the access + * strategies from within an entity with explicit property access (except + * for the id field, which is property default) + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testFieldAccessStrategies() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + FieldAccessPropStratsEntity fa = new FieldAccessPropStratsEntity(); + + // Load all persistent fields + EmbedId eid = new EmbedId(); + eid.setId(new Random().nextInt()); + eid.setCode("IdCode"); + fa.setEmbedId(eid); // embedded id + + Collection elc = new ArrayList(); + EmbedPropAccess epa1 = new EmbedPropAccess("George", "Washington"); + EmbedPropAccess epa2 = new EmbedPropAccess("James", "Carter"); + elc.add(epa1); + elc.add(epa2); + fa.setElementCollection(elc); // element collection of embeddables + + EmbedFieldAccess efa = new EmbedFieldAccess(); + efa.setFirstName("The"); + efa.setLastName("President"); + fa.setEmbedField(efa); // embedded + + fa.setName("FieldAccessPropStratsEntity"); // basic + + PropAccess propa = new PropAccess(); + propa.setStrProp("PropAccess"); + fa.setManyToOne(propa); // many to one + + Collection fac = new ArrayList(); + FieldAccess fae = new FieldAccess(); + fae.setStrField("FieldAccess"); + fac.add(fae); + fa.setOneToMany(fac); // one to many + + PropAccess pa = new PropAccess(); + pa.setStrProp("PropAccess"); + fa.setOneToOne(pa); // one to one + + em.getTransaction().begin(); + em.persist(fa); + em.getTransaction().commit(); + + em.clear(); + // Verify list of persistent fields + FieldAccessPropStratsEntity newpa = + em.find(FieldAccessPropStratsEntity.class, eid); + assertNotNull(newpa); + // simple key validation + assertEquals(newpa.getEmbedId(), eid); + + // Verify the persistent member names + MetaDataRepository mdr = + em.getConfiguration().getMetaDataRepositoryInstance(); + + ClassMetaData cmd = mdr.getMetaData(FieldAccessPropStratsEntity.class, + null, true); + // Assert expected persistent fields and properties were created + assertNotNull(cmd.getField("eid")); + assertNotNull(cmd.getField("elementCollection")); + assertNotNull(cmd.getField("embedField")); + assertNotNull(cmd.getField("version")); + assertNotNull(cmd.getField("manyToOne")); + assertNotNull(cmd.getField("oneToMany")); + assertNotNull(cmd.getField("oneToOne")); + assertNotNull(cmd.getField("manyToMany")); + + // Name has a matching getter/setter. Make sure the access type + // is property & not field + assertNotNull(cmd.getField("name")); + assertTrue((cmd.getField("name").getAccessType() & AccessCode.PROPERTY) + == AccessCode.PROPERTY); + + // Assert mappings were not created for fields or properties which + // should not be persistent + assertNull(cmd.getField("embedId")); + assertNull(cmd.getField("m2one")); + assertNull(cmd.getField("one2m")); + assertNull(cmd.getField("one2one")); + assertNull(cmd.getField("ecoll")); + assertNull(cmd.getField("embed")); + assertNull(cmd.getField("ver")); + assertNull(cmd.getField("m2m")); + + em.close(); + } + + + /* + * Simple method to verify if an exception is of the correct type and + * that it contains the expected message fragments. + */ + private boolean verifyException(Exception e, Class c, String...strings) { + if (c.isInstance(e)) { + String exMessage = e.getMessage(); + for (String msg : strings) { + if (!exMessage.contains(msg)) + return false; + } + return true; + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/TestXMLExplicitAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/TestXMLExplicitAccess.java new file mode 100644 index 000000000..a006e2679 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/TestXMLExplicitAccess.java @@ -0,0 +1,789 @@ +/* + * 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.access.xml; + +import java.util.Date; + +import javax.persistence.Query; + +import org.apache.openjpa.persistence.ArgumentException; +import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; +import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; +import org.apache.openjpa.persistence.OpenJPAPersistence; +import org.apache.openjpa.persistence.access.EmbedMixedAccess; +import org.apache.openjpa.persistence.access.PropMixedEntity; +import org.apache.openjpa.persistence.test.AllowFailure; +import org.apache.openjpa.persistence.test.PersistenceTestCase; + +public class TestXMLExplicitAccess extends PersistenceTestCase { + + private OpenJPAEntityManagerFactorySPI emf = null; + + public void setUp() throws Exception { + super.setUp(); + emf = (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-1", + "org/apache/openjpa/persistence/access/" + + "access-persistence.xml"); + } + + public void tearDown() throws Exception { + super.tearDown(); + if (emf != null) { + clear(emf); + emf.close(); + } + } + /** + * Validates the use of field level access on an + * entity, mappedsuperclass, and embeddable at the + * class level. + */ + public void testClassSpecifiedFieldAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLFieldAccess fa = new XMLFieldAccess(); + // Set the persistent field through a misnamed setter + fa.setStringField("XMLFieldAccess"); + + em.getTransaction().begin(); + em.persist(fa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the field name to verify that + // field access is in use. + Query qry = em.createNamedQuery("XMLFieldAccess.query"); + qry.setParameter("id", fa.getId()); + qry.setParameter("strVal", "XMLFieldAccess"); + XMLFieldAccess fa2 = (XMLFieldAccess)qry.getSingleResult(); + assertEquals(fa.getId(), fa2.getId()); + + em.close(); + } + + /** + * Validates the use of property level access on an + * entity, mappedsuperclass, and embeddable at the + * class level. + */ + public void testClassSpecifiedPropertyAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLPropAccess pa = new XMLPropAccess(); + // Set the persistent field through a misnamed setter + pa.setStrProp("PropertyAccess"); + + em.getTransaction().begin(); + em.persist(pa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the field name to verify that + // field access is in use. + Query qry = em.createNamedQuery("XMLPropAccess.query"); + qry.setParameter("id", pa.getId()); + qry.setParameter("strVal", "PropertyAccess"); + XMLPropAccess pa2 = (XMLPropAccess)qry.getSingleResult(); + assertEquals(pa, pa2); + + em.close(); + } + + /** + * Validates the use of explicit field access on an entity, + * mappedsuperclass, and embeddable with property access + * defined at the class level and field access defined + * on specific methods. + */ + + public void testClassSpecifiedMixedSinglePCFieldAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLDefFieldMixedPropAccess dfmpa = new XMLDefFieldMixedPropAccess(); + // Call non-PC setter + dfmpa.setStrField("NonPCSetter"); + // Call setter with property access + dfmpa.setStringField("XMLDFMPA"); + + em.getTransaction().begin(); + em.persist(dfmpa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent property was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLDFMPA.query"); + qry.setParameter("id", dfmpa.getId()); + qry.setParameter("strVal", "XMLDFMPA"); + XMLDefFieldMixedPropAccess dfmpa2 = + (XMLDefFieldMixedPropAccess)qry.getSingleResult(); + assertEquals(dfmpa, dfmpa2); + assertEquals(dfmpa2.getStringField(), "XMLDFMPA"); + + try { + qry = em.createNamedQuery("XMLDFMPA.badQuery"); + qry.setParameter("id", dfmpa.getId()); + qry.setParameter("strVal", "XMLDFMPA"); + qry.getSingleResult(); + fail("Execution of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"strField\" in \"XMLDefFieldMixedPropAccess\"", + "[id, stringField, version]"); + } + + em.close(); + } + + /** + * Validates the use of explicit property access on an entity, + * mappedsuperclass, and embeddable with field access + * defined at the class level and property access defined + * on specific methods. + */ + public void testClassSpecifiedMixedSinglePCPropertyAccess() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLDefPropMixedFieldAccess dpmfa = new XMLDefPropMixedFieldAccess(); + // Call setter with underlying field access + dpmfa.setStrProp("XMLDPMFA"); + + em.getTransaction().begin(); + em.persist(dpmfa); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLDPMFA.query"); + qry.setParameter("id", dpmfa.getId()); + qry.setParameter("strVal", "XMLDPMFA"); + XMLDefPropMixedFieldAccess dpmfa2 = + (XMLDefPropMixedFieldAccess)qry.getSingleResult(); + assertEquals(dpmfa, dpmfa2); + assertEquals(dpmfa2.getStrProp(), "XMLDPMFA"); + + try { + qry = em.createNamedQuery("XMLDPMFA.badQuery"); + qry.setParameter("id", dpmfa.getId()); + qry.setParameter("strVal", "XMLDPMFA"); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"strProp\" in \"XMLDefPropMixedFieldAccess\"", + "[id, strField, version]"); + } + + em.close(); + } + + /** + * Validates that a mapped superclass using field access and an entity + * subclass using property access get mapped properly. + */ + public void testAbstractMappedSuperField() { + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-1", + "org/apache/openjpa/persistence/access/" + + "access-persistence.xml"); + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLPropertySub ps = new XMLPropertySub(); + // Call super setter with underlying field access + ps.setName("AbsMappedSuperName"); + // Call base setter with property access + Date now = new Date(); + ps.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(ps); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLPropertySub.query"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + XMLPropertySub ps2 = + (XMLPropertySub)qry.getSingleResult(); + assertEquals(ps, ps2); + assertEquals(ps2.getName(), "AbsMappedSuperName"); + assertEquals(ps2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("XMLPropertySub.badQuery"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"XMLPropertySub\"", + "[createDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that a mapped superclass using property access and an entity + * subclass using field access get mapped properly. + */ + public void testAbstractMappedSuperProperty() { + + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-1", + "org/apache/openjpa/persistence/access/" + + "access-persistence.xml"); + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLFieldSub fs = new XMLFieldSub(); + // Call super setter with underlying field access + fs.setName("AbsMappedSuperName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(fs); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLFieldSub.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + XMLFieldSub fs2 = + (XMLFieldSub)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "AbsMappedSuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("XMLFieldSub.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "AbsMappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"createDate\" in \"XMLFieldSub\"", + "[crtDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that an mapped superclass using field access and an + * entity subclass using property access get mapped properly. + * The subclass uses a storage field in the superclass. + */ + public void testMappedSuperField() { + + OpenJPAEntityManagerFactorySPI emf = + (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence. + createEntityManagerFactory("Access-1", + "org/apache/openjpa/persistence/access/" + + "access-persistence.xml"); + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLPropertySub2 ps = new XMLPropertySub2(); + // Call super setter with underlying field access + ps.setName("MappedSuperName"); + // Call base setter with property access + Date now = new Date(); + ps.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(ps); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLPropertySub2.query"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + XMLPropertySub2 ps2 = + (XMLPropertySub2)qry.getSingleResult(); + assertEquals(ps, ps2); + assertEquals(ps2.getName(), "MappedSuperName"); + assertEquals(ps2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("XMLPropertySub2.badQuery"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"XMLPropertySub2\"", + "[createDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that an mapped superclass using field access and an + * entity subclass using property access get mapped properly. + * The subclass uses a storage field in the superclass. + */ + public void testMappedSuperProperty() { + + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLFieldSub2 fs = new XMLFieldSub2(); + // Call super setter with underlying field access + fs.setName("MappedSuperName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(fs); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLFieldSub2.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + XMLFieldSub2 fs2 = + (XMLFieldSub2)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "MappedSuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("XMLFieldSub2.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "MappedSuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"createDate\" in \"XMLFieldSub2\"", + "[crtDate, id, name]"); + } + + em.close(); + } + + /** + * Validates that a mix of access types can be used within multiple + * persistent classes within an inheritance hierarchy that uses + * MappedSuperclass. + */ + public void testMixedMappedSuper() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLMixedFieldSub fs = new XMLMixedFieldSub(); + // Call super setter with underlying field access + fs.setName("XMLMixedMappedSuperName"); + fs.setMyFieldProp("MyFieldName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + em.getTransaction().begin(); + em.persist(fs); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLMixedFieldSub.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "XMLMixedMappedSuperName"); + qry.setParameter("crtDate", now); + qry.setParameter("myField", "MyFieldName"); + XMLMixedFieldSub fs2 = + (XMLMixedFieldSub)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "XMLMixedMappedSuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("XMLMixedFieldSub.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "XMLMixedMappedSuperName"); + qry.setParameter("myField", "MyFieldName"); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"myFieldProp\" in \"XMLMixedFieldSub\"", + "[createDate, mid, myField, name]"); + } + + em.close(); + + } + + /** + * Validates that a mix of access types can be used within + * an inheritance hierarchy which uses default Entity inheritance. + * NOTE: be sure to test with all forms of inheritance. + */ + public void testEntityFieldDefaultInheritance() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLFieldSub3 fs = new XMLFieldSub3(); + // Call super setter with underlying field access + fs.setName("EntitySuperName"); + // Call base setter with property access + Date now = new Date(); + fs.setCreateDate(now); + + XMLSuperPropertyEntity spe = new XMLSuperPropertyEntity(); + spe.setName("SuperPropertyEntity"); + + em.getTransaction().begin(); + em.persist(fs); + em.persist(spe); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLFieldSub3.query"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + XMLFieldSub3 fs2 = + (XMLFieldSub3)qry.getSingleResult(); + assertEquals(fs, fs2); + assertEquals(fs2.getName(), "EntitySuperName"); + assertEquals(fs2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("XMLFieldSub3.badQuery"); + qry.setParameter("id", fs.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"createDate\" in \"XMLFieldSub3\"", + "[crtDate, id, name]"); + } + + qry = em.createNamedQuery("XMLSuperPropertyEntity.query"); + qry.setParameter("id", spe.getId()); + qry.setParameter("name", "SuperPropertyEntity"); + XMLSuperPropertyEntity spe2 = + (XMLSuperPropertyEntity)qry.getSingleResult(); + assertEquals(spe, spe2); + assertEquals(spe2.getName(), "SuperPropertyEntity"); + + try { + // This query ensures that a subclass property didn't somehow get + // picked up by the superclass while building field metadata using + // explicit access. + qry = em.createNamedQuery("XMLSuperPropertyEntity.badQuery"); + qry.setParameter("id", spe.getId()); + qry.setParameter("name", "SuperPropertyEntity"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"XMLSuperPropertyEntity\"", + "[id, name]"); + } + + em.close(); + } + + /** + * Validates that a mix of access types can be used within + * an inheritance hierarchy which uses default Entity inheritance. + * NOTE: be sure to test with all forms of inheritance. + */ + public void testEntityPropertyDefaultInheritance() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLPropertySub3 ps = new XMLPropertySub3(); + // Call super setter with underlying field access + ps.setName("EntitySuperName"); + // Call base setter with property access + Date now = new Date(); + ps.setCreateDate(now); + + XMLSuperFieldEntity sfe = new XMLSuperFieldEntity(); + sfe.setName("SuperFieldEntity"); + + em.getTransaction().begin(); + em.persist(ps); + em.persist(sfe); + em.getTransaction().commit(); + em.clear(); + + // This value of a persistent field was set using the setter + // above, but this query will use the property name to verify that + // propety access is in use. + Query qry = em.createNamedQuery("XMLPropertySub3.query"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + XMLPropertySub3 ps2 = + (XMLPropertySub3)qry.getSingleResult(); + assertEquals(ps, ps2); + assertEquals(ps2.getName(), "EntitySuperName"); + assertEquals(ps2.getCreateDate(), now); + + try { + qry = em.createNamedQuery("XMLPropertySub3.badQuery"); + qry.setParameter("id", ps.getId()); + qry.setParameter("name", "EntitySuperName"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"XMLPropertySub3\"", + "[createDate, id, name]"); + } + + qry = em.createNamedQuery("XMLSuperFieldEntity.query"); + qry.setParameter("id", sfe.getId()); + qry.setParameter("name", "SuperFieldEntity"); + XMLSuperFieldEntity sfe2 = + (XMLSuperFieldEntity)qry.getSingleResult(); + assertEquals(sfe2, sfe2); + assertEquals(sfe2.getName(), "SuperFieldEntity"); + + try { + // This query ensures that a subclass property didn't somehow get + // picked up by the superclass while building field metadata using + // explicit access. + qry = em.createNamedQuery("XMLSuperFieldEntity.badQuery"); + qry.setParameter("id", sfe.getId()); + qry.setParameter("name", "SuperFieldEntity"); + qry.setParameter("crtDate", now); + qry.getSingleResult(); + fail("Usage of this query should have thrown an exception"); + } + catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"crtDate\" in \"XMLSuperFieldEntity\"", + "[id, name]"); + } + em.close(); + } + + /** + * Validates an embeddable with field access can be used within an + * entity with property access + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testEmbeddablesField() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLEmbedFieldAccess efa = new XMLEmbedFieldAccess(); + efa.setFirstName("J"); + efa.setLastName("Tolkien"); + + XMLPropEmbedEntity pe = new XMLPropEmbedEntity(); + pe.setName("PropEmbedEntity"); + pe.setEmbedProp(efa); + + em.getTransaction().begin(); + em.persist(pe); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("XMLPropEmbedEntity.query"); + qry.setParameter("id", pe.getId()); + qry.setParameter("name", "PropEmbedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + XMLPropEmbedEntity pe2 = (XMLPropEmbedEntity)qry.getSingleResult(); + assertEquals(pe, pe2); + assertEquals(efa, pe2.getEmbedProp()); + + try { + qry = em.createNamedQuery("XMLPropEmbedEntity.badQuery"); + qry.setParameter("id", pe.getId()); + qry.setParameter("name", "PropEmbedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"firstName\" in \"XMLEmbedFieldAccess\"", + "[fName, lName]"); + } + + em.close(); + } + + /** + * Validates an embeddable with property access can be used within an + * entity with field access + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testEmbeddablesProperty() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLEmbedPropAccess epa = new XMLEmbedPropAccess(); + epa.setFirstName("Walt"); + epa.setLastName("Whitman"); + + XMLFieldEmbedEntity fe = new XMLFieldEmbedEntity(); + fe.setName("FieldEmbedEntity"); + fe.setEPA(epa); + + em.getTransaction().begin(); + em.persist(fe); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("XMLFieldEmbedEntity.query"); + qry.setParameter("id", fe.getId()); + qry.setParameter("name", "FieldEmbedEntity"); + qry.setParameter("firstName", "Walt"); + qry.setParameter("lastName", "Whitman"); + XMLFieldEmbedEntity fe2 = (XMLFieldEmbedEntity)qry.getSingleResult(); + fe2.getEPA().getFirstName(); + fe2.getEPA().getLastName(); + assertEquals(fe, fe2); + assertEquals(epa, fe2.getEPA()); + + try { + qry = em.createNamedQuery("XMLFieldEmbedEntity.badQuery"); + qry.setParameter("id", fe.getId()); + qry.setParameter("name", "FieldEmbedEntity"); + qry.setParameter("firstName", "Walt"); + qry.setParameter("lastName", "Whitman"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"fName\" in \"XMLEmbedPropAccess\"", + "[firstName, lastName]"); + } + + em.close(); + } + + /** + * Validates an embeddable with mixed access can be used within an + * entity with mixed access + */ + @AllowFailure(value=true, + message="Support for explicit Access on embeddables is not complete.") + public void testMixedEmbeddables() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + + XMLEmbedMixedAccess ema = new XMLEmbedMixedAccess(); + ema.setFirstName("J"); + ema.setLastName("Tolkien"); + ema.setMiddleName("R"); + + XMLPropMixedEntity pm = new XMLPropMixedEntity(); + pm.setName("PropMixedEntity"); + pm.setEmbedProp(ema); + + em.getTransaction().begin(); + em.persist(pm); + em.getTransaction().commit(); + + em.clear(); + + Query qry = em.createNamedQuery("XMLPropMixedEntity.query"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "PropMixedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + qry.setParameter("middleName", "R"); + XMLPropMixedEntity pm2 = (XMLPropMixedEntity)qry.getSingleResult(); + assertEquals(pm, pm2); + assertEquals(ema, pm2.getEmbedProp()); + + try { + qry = em.createNamedQuery("XMLPropMixedEntity.badQuery"); + qry.setParameter("id", pm.getId()); + qry.setParameter("name", "PropMixedEntity"); + qry.setParameter("firstName", "J"); + qry.setParameter("lastName", "Tolkien"); + qry.setParameter("middleName", "R"); + qry.getSingleResult(); + fail("Query execution should have failed."); + } catch (Exception e) { + assertExceptionMessage(e, ArgumentException.class, + "No field named \"middleName\" in \"XMLEmbedMixedAccess\"", + "[firstName, lastName, mName]"); + } + + em.close(); + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperField.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperField.java new file mode 100644 index 000000000..ed0fe0099 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperField.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.persistence.access.xml; + +import java.util.Date; + +public abstract class XMLAbstractMappedSuperField { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + abstract public Date getCreateDate(); + + abstract public void setCreateDate(Date date); + + public boolean equals(Object obj) { + if (obj instanceof XMLAbstractMappedSuperField) { + XMLAbstractMappedSuperField ps = (XMLAbstractMappedSuperField)obj; + return id == ps.getId() && + name.equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperProperty.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperProperty.java new file mode 100644 index 000000000..f846a9b94 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLAbstractMappedSuperProperty.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.persistence.access.xml; + +import java.util.Date; + +public abstract class XMLAbstractMappedSuperProperty { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + abstract public Date getCreateDate(); + + abstract public void setCreateDate(Date date); + + public boolean equals(Object obj) { + if (obj instanceof XMLAbstractMappedSuperProperty) { + XMLAbstractMappedSuperProperty ps = (XMLAbstractMappedSuperProperty)obj; + return getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefFieldMixedPropAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefFieldMixedPropAccess.java new file mode 100644 index 000000000..c167bf7b2 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefFieldMixedPropAccess.java @@ -0,0 +1,69 @@ +/* + * 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.access.xml; + +public class XMLDefFieldMixedPropAccess { + + private int id; + + private int version; + + private String strField; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + public int getVersion() { + return version; + } + + public void setStringField(String val) { + strField = val; + } + + public String getStringField() { + return strField; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLDefFieldMixedPropAccess) { + XMLDefFieldMixedPropAccess fa = (XMLDefFieldMixedPropAccess)obj; + return id == fa.getId() && + getStringField().equals(fa.getStringField()); + } + return false; + } + + public void setStrField(String strField) { + this.strField = strField; + } + + public String getStrField() { + return strField; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefPropMixedFieldAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefPropMixedFieldAccess.java new file mode 100644 index 000000000..344363c37 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLDefPropMixedFieldAccess.java @@ -0,0 +1,69 @@ +/* + * 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.access.xml; + +public class XMLDefPropMixedFieldAccess { + + private int id; + + private int version; + + private String strField; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + public int getVersion() { + return version; + } + + public void setStrProp(String var) { + this.setStrField(var); + } + + public String getStrProp() { + return getStrField(); + } + + public boolean equals(Object obj) { + if (obj instanceof XMLDefPropMixedFieldAccess) { + XMLDefPropMixedFieldAccess dpmfa = (XMLDefPropMixedFieldAccess)obj; + return getId() == dpmfa.getId() && + getStrField().equals(dpmfa.getStrProp()); + } + return false; + } + + public void setStrField(String strField) { + this.strField = strField; + } + + public String getStrField() { + return strField; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedFieldAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedFieldAccess.java new file mode 100644 index 000000000..9095c22db --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedFieldAccess.java @@ -0,0 +1,50 @@ +/* + * 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.access.xml; + +public class XMLEmbedFieldAccess { + + String fName; + String lName; + + public String getFirstName() { + return fName; + } + + public void setFirstName(String fname) { + fName = fname; + } + + public String getLastName() { + return lName; + } + + public void setLastName(String lname) { + lName = lname; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLEmbedFieldAccess) { + XMLEmbedFieldAccess ps = (XMLEmbedFieldAccess)obj; + return getFirstName().equals(ps.getFirstName()) && + getLastName().equals(ps.getLastName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedMixedAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedMixedAccess.java new file mode 100644 index 000000000..02b768254 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedMixedAccess.java @@ -0,0 +1,69 @@ +/* + * 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.access.xml; + +public class XMLEmbedMixedAccess { + + private transient String fName; + private transient String lName; + + private String mName; + + public String getFirstName() { + return fName; + } + + public void setFirstName(String fname) { + fName = fname; + } + + public String getLastName() { + return lName; + } + + public void setLastName(String lname) { + lName = lname; + } + + public String getMiddleName() { + return getMName(); + } + + public void setMiddleName(String mname) { + setMName(mname); + } + + public boolean equals(Object obj) { + if (obj instanceof XMLEmbedMixedAccess) { + XMLEmbedMixedAccess ps = (XMLEmbedMixedAccess)obj; + return getFirstName().equals(ps.getFirstName()) && + getLastName().equals(ps.getLastName()) && + getMiddleName().equals(ps.getMiddleName()); + } + return false; + } + + public void setMName(String mName) { + this.mName = mName; + } + + public String getMName() { + return mName; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedPropAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedPropAccess.java new file mode 100644 index 000000000..46743973d --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLEmbedPropAccess.java @@ -0,0 +1,58 @@ +/* + * 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.access.xml; + +public class XMLEmbedPropAccess { + + String fName; + String lName; + + public XMLEmbedPropAccess() { + } + + public XMLEmbedPropAccess(String fn, String ln) { + setFirstName(fn); + setLastName(ln); + } + + public String getFirstName() { + return fName; + } + + public void setFirstName(String fname) { + fName = fname; + } + + public String getLastName() { + return lName; + } + + public void setLastName(String lname) { + lName = lname; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLEmbedPropAccess) { + XMLEmbedPropAccess ps = (XMLEmbedPropAccess)obj; + return getFirstName().equals(ps.getFirstName()) && + getLastName().equals(ps.getLastName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldAccess.java new file mode 100644 index 000000000..78820d4b8 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldAccess.java @@ -0,0 +1,69 @@ +/* + * 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.access.xml; + +public class XMLFieldAccess { + + private int id; + + private int version; + + private String strField; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + public int getVersion() { + return version; + } + + public void setStringField(String val) { + this.setStrField(val); + } + + public String getStringField() { + return getStrField(); + } + + public boolean equals(Object obj) { + if (obj instanceof XMLFieldAccess) { + XMLFieldAccess fa = (XMLFieldAccess)obj; + return id == fa.getId() && + getStrField().equals(fa.getStringField()); + } + return false; + } + + public void setStrField(String strField) { + this.strField = strField; + } + + public String getStrField() { + return strField; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldEmbedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldEmbedEntity.java new file mode 100644 index 000000000..9b388a4fa --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldEmbedEntity.java @@ -0,0 +1,61 @@ +/* + * 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.access.xml; + +public class XMLFieldEmbedEntity { + + private int id; + + private String name; + + private XMLEmbedPropAccess epa; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public XMLEmbedPropAccess getEPA() { + return epa; + } + + public void setEPA(XMLEmbedPropAccess ep) { + epa = ep; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLFieldEmbedEntity) { + XMLFieldEmbedEntity ps = (XMLFieldEmbedEntity)obj; + return epa.equals(ps.getEPA()) && getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub.java new file mode 100644 index 000000000..d677db52a --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub.java @@ -0,0 +1,45 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLFieldSub extends XMLAbstractMappedSuperProperty { + + private Date crtDate; + + @Override + public Date getCreateDate() { + return crtDate; + } + + @Override + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLFieldSub) { + XMLFieldSub ps = (XMLFieldSub)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub2.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub2.java new file mode 100644 index 000000000..b267bf28e --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub2.java @@ -0,0 +1,44 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLFieldSub2 extends XMLMappedSuperProperty { + + protected Date crtDate; + + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLFieldSub2) { + XMLFieldSub2 ps = (XMLFieldSub2)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub3.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub3.java new file mode 100644 index 000000000..5b79b0540 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLFieldSub3.java @@ -0,0 +1,44 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLFieldSub3 extends XMLSuperPropertyEntity { + + protected Date crtDate; + + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLFieldSub3) { + XMLFieldSub3 ps = (XMLFieldSub3)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperField.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperField.java new file mode 100644 index 000000000..dcf413e57 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperField.java @@ -0,0 +1,55 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLMappedSuperField { + + private int id; + + private String name; + + protected Date crtDate; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLMappedSuperField) { + XMLMappedSuperField ps = (XMLMappedSuperField)obj; + return id == ps.getId() && + name.equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperProperty.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperProperty.java new file mode 100644 index 000000000..866ae9b78 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMappedSuperProperty.java @@ -0,0 +1,51 @@ +/* + * 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.access.xml; + +public class XMLMappedSuperProperty { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLMappedSuperProperty) { + XMLMappedSuperProperty ps = (XMLMappedSuperProperty)obj; + return getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedFieldSub.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedFieldSub.java new file mode 100644 index 000000000..0fff8724d --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedFieldSub.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.persistence.access.xml; + +import java.util.Date; + +public class XMLMixedFieldSub extends XMLMixedMappedSuper { + + private String myField; + + private Date crtDate; + + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLMixedFieldSub) { + XMLMixedFieldSub ps = (XMLMixedFieldSub)obj; + return super.equals(obj) && + getCreateDate().equals(ps.getCreateDate()); + } + return false; + } + + public void setMyFieldProp(String myField) { + this.myField = myField; + } + + public String getMyFieldProp() { + return myField; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedMappedSuper.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedMappedSuper.java new file mode 100644 index 000000000..d0b2d86a4 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLMixedMappedSuper.java @@ -0,0 +1,63 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLMixedMappedSuper { + + private int mid; + + private String mname; + + protected Date crtDate; + + public void setId(int id) { + this.setMid(id); + } + + public int getId() { + return getMid(); + } + + public void setName(String name) { + this.mname = name; + } + + public String getName() { + return mname; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLMixedMappedSuper) { + XMLMixedMappedSuper ps = (XMLMixedMappedSuper)obj; + return getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } + + public void setMid(int mid) { + this.mid = mid; + } + + public int getMid() { + return mid; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropAccess.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropAccess.java new file mode 100644 index 000000000..0467d247f --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropAccess.java @@ -0,0 +1,61 @@ +/* + * 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.access.xml; + +public class XMLPropAccess { + + private int id; + + private int version; + + private String strField; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setVersion(int version) { + this.version = version; + } + + public int getVersion() { + return version; + } + + public void setStrProp(String var) { + this.strField = var; + } + + public String getStrProp() { + return strField; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLPropAccess) { + XMLPropAccess pa = (XMLPropAccess)obj; + return getId() == pa.getId() && + getStrProp().equals(pa.getStrProp()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropEmbedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropEmbedEntity.java new file mode 100644 index 000000000..d37234757 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropEmbedEntity.java @@ -0,0 +1,62 @@ +/* + * 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.access.xml; + +public class XMLPropEmbedEntity { + + private int id; + + private String name; + + private XMLEmbedFieldAccess efa; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public XMLEmbedFieldAccess getEmbedProp() { + return efa; + } + + public void setEmbedProp(XMLEmbedFieldAccess ef) { + efa = ef; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLPropEmbedEntity) { + XMLPropEmbedEntity ps = (XMLPropEmbedEntity)obj; + return getEmbedProp().equals(ps.getEmbedProp()) + && getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropMixedEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropMixedEntity.java new file mode 100644 index 000000000..a622e95ac --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropMixedEntity.java @@ -0,0 +1,81 @@ +/* + * 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.access.xml; + +public class XMLPropMixedEntity { + + private int idval; + + private String myName; + + private XMLEmbedMixedAccess ema; + + public void setId(int id) { + this.setIdval(id); + } + + public int getId() { + return getIdval(); + } + + public void setName(String name) { + this.myName = name; + } + + // Property access + public String getName() { + return myName; + } + + public XMLEmbedMixedAccess getEmbedProp() { + return getEma(); + } + + public void setEmbedProp(XMLEmbedMixedAccess ef) { + setEma(ef); + } + + public boolean equals(Object obj) { + if (obj instanceof XMLPropMixedEntity) { + XMLPropMixedEntity ps = (XMLPropMixedEntity)obj; + return getEmbedProp().equals(ps.getEmbedProp()) + && getId() == ps.getId() && + getName().equals(ps.getName()); + } + return false; + } + + public void setIdval(int idval) { + this.idval = idval; + } + + public int getIdval() { + return idval; + } + + public void setEma(XMLEmbedMixedAccess ema) { + this.ema = ema; + } + + public XMLEmbedMixedAccess getEma() { + return ema; + } + + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub.java new file mode 100644 index 000000000..e955c958d --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub.java @@ -0,0 +1,46 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLPropertySub extends XMLAbstractMappedSuperField { + + private Date crtDate; + + @Override + public Date getCreateDate() { + return crtDate; + } + + @Override + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLPropertySub) { + XMLPropertySub ps = (XMLPropertySub)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub2.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub2.java new file mode 100644 index 000000000..3e953699c --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub2.java @@ -0,0 +1,42 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLPropertySub2 extends XMLMappedSuperField { + + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLPropertySub2) { + XMLPropertySub2 ps = (XMLPropertySub2)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub3.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub3.java new file mode 100644 index 000000000..a4284ae36 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLPropertySub3.java @@ -0,0 +1,44 @@ +/* + * 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.access.xml; + +import java.util.Date; + +public class XMLPropertySub3 extends XMLSuperFieldEntity { + + protected Date crtDate; + + public Date getCreateDate() { + return crtDate; + } + + public void setCreateDate(Date date) { + crtDate = date; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLPropertySub3) { + XMLPropertySub3 ps = (XMLPropertySub3)obj; + return super.equals(obj) && + crtDate.equals(ps.getCreateDate()); + } + return false; + } + +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperFieldEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperFieldEntity.java new file mode 100644 index 000000000..3e6c9968b --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperFieldEntity.java @@ -0,0 +1,51 @@ +/* + * 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.access.xml; + +public class XMLSuperFieldEntity { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLSuperFieldEntity) { + XMLSuperFieldEntity sfe = (XMLSuperFieldEntity)obj; + return id == sfe.getId() && + name.equals(sfe.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperPropertyEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperPropertyEntity.java new file mode 100644 index 000000000..bf6995212 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/access/xml/XMLSuperPropertyEntity.java @@ -0,0 +1,51 @@ +/* + * 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.access.xml; + +public class XMLSuperPropertyEntity { + + private int id; + + private String name; + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj instanceof XMLSuperPropertyEntity) { + XMLSuperPropertyEntity sfe = (XMLSuperPropertyEntity)obj; + return getId() == sfe.getId() && + getName().equals(sfe.getName()); + } + return false; + } +} diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java index 0dbd27837..ae684f0b9 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java @@ -413,6 +413,17 @@ public abstract class PersistenceTestCase } } + /** + * Asserts that the given targetType is assignable from given actual + * Throwable and that the exception message contains the specified message + * or message fragments. + */ + protected void assertExceptionMessage(final Throwable actual, + Class targetType, String...messages) { + assertException(actual, targetType, null); + assertMessage(actual, messages); + } + /** * Assert that each of given keys are present in the message of the given * Throwable. diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-field-orm.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-field-orm.xml new file mode 100644 index 000000000..12e767546 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-field-orm.xml @@ -0,0 +1,62 @@ + + + + FIELD + + + SELECT xfa FROM XMLFieldAccess2 xfa WHERE + xfa.id = :id AND xfa.strField = :strVal + + + + + + + + + + + + + SELECT df FROM XMLDFMPA2 df WHERE + df.id = :id AND df.stringField = :strVal + + + + SELECT p FROM XMLDFMPA2 p WHERE + p.id = :id AND p.strField = :strVal + + + + + + + + + + + + \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-persistence.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-persistence.xml new file mode 100644 index 000000000..86208872c --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-persistence.xml @@ -0,0 +1,61 @@ + + + + + PU for access testing + + org.apache.openjpa.persistence.PersistenceProviderImpl + + + org/apache/openjpa/persistence/access/access-def-prop-orm.xml + + org.apache.openjpa.persistence.access.xml.XMLPropAccess + + org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess + + + + + + + + PU for access testing + + org.apache.openjpa.persistence.PersistenceProviderImpl + + + org/apache/openjpa/persistence/access/access-def-field-orm.xml + + org.apache.openjpa.persistence.access.xml.XMLFieldAccess + + org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess + + + + + + \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-prop-orm.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-prop-orm.xml new file mode 100644 index 000000000..1e79f2641 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-def-prop-orm.xml @@ -0,0 +1,62 @@ + + + + PROPERTY + + + SELECT dp FROM XMLDPMFA2 dp WHERE + dp.id = :id AND dp.strField = :strVal + + + + SELECT p FROM XMLDPMFA2 p WHERE + p.id = :id AND p.strProp = :strVal + + + + + + + + + + + + + + SELECT xpa FROM XMLPropAccess2 xpa WHERE + xpa.id = :id AND xpa.strProp = :strVal + + + + + + + + + + + \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-orm.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-orm.xml new file mode 100644 index 000000000..8efb642a3 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-orm.xml @@ -0,0 +1,441 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT xfa FROM XMLFieldAccess xfa WHERE + xfa.id = :id AND xfa.strField = :strVal + + + + + + + + + + + + + SELECT xpa FROM XMLPropAccess xpa WHERE + xpa.id = :id AND xpa.strProp = :strVal + + + + + + + + + + + + + SELECT df FROM XMLDFMPA df WHERE + df.id = :id AND df.stringField = :strVal + + + + SELECT p FROM XMLDFMPA p WHERE + p.id = :id AND p.strField = :strVal + + + + + + + + + + + + + + SELECT dp FROM XMLDPMFA dp WHERE + dp.id = :id AND dp.strField = :strVal + + + + SELECT p FROM XMLDPMFA p WHERE + p.id = :id AND p.strProp = :strVal + + + + + + + + + + + + + + + SELECT ps FROM XMLPropertySub ps WHERE + ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate + + + + SELECT ps FROM XMLPropertySub ps WHERE + ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate + + + + + TIMESTAMP + + + + + + SELECT fs FROM XMLFieldSub fs WHERE + fs.id = :id AND fs.name = :name AND fs.crtDate = :crtDate + + + + SELECT fs FROM XMLFieldSub fs WHERE + fs.id = :id AND fs.name = :name AND fs.createDate = :crtDate + + + + + TIMESTAMP + + + + + + SELECT ps FROM XMLPropertySub2 ps WHERE + ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate + + + + SELECT ps FROM XMLPropertySub2 ps WHERE + ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate + + + + + TIMESTAMP + + + + + + SELECT ps FROM XMLFieldSub2 ps WHERE + ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate + + + + SELECT ps FROM XMLFieldSub2 ps WHERE + ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate + + + + + TIMESTAMP + + + + + + SELECT fs FROM XMLMixedFieldSub fs WHERE + fs.mid = :id AND fs.name = :name AND fs.createDate = :crtDate + AND fs.myField = :myField + + + + SELECT fs FROM XMLMixedFieldSub fs WHERE + fs.mid = :id AND fs.name = :name AND fs.myFieldProp = :myField + + + + + + TIMESTAMP + + + + + + + + SELECT sfe FROM XMLSuperPropertyEntity sfe WHERE + sfe.id = :id AND sfe.name = :name + + + + SELECT sfe FROM XMLSuperPropertyEntity sfe WHERE + sfe.id = :id AND sfe.name = :name AND sfe.crtDate = :crtDate + + + + + + + + + + + + + SELECT ps FROM XMLFieldSub3 ps WHERE + ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate + + + + SELECT ps FROM XMLFieldSub3 ps WHERE + ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate + + + + + TIMESTAMP + + + + + + + SELECT sfe FROM XMLSuperFieldEntity sfe WHERE + sfe.id = :id AND sfe.name = :name + + + + SELECT sfe FROM XMLSuperFieldEntity sfe WHERE + sfe.id = :id AND sfe.name = :name AND sfe.crtDate = :crtDate + + + + + + + + + + + + + SELECT ps FROM XMLPropertySub3 ps WHERE + ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate + + + + SELECT ps FROM XMLPropertySub3 ps WHERE + ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate + + + + + TIMESTAMP + + + + + + SELECT fs FROM XMLPropEmbedEntity fs WHERE + fs.id = :id AND fs.name = :name AND fs.embedProp.fName = :firstName + AND fs.embedProp.lName = :lastName + + + + SELECT fs FROM XMLPropEmbedEntity fs WHERE + fs.id = :id AND fs.name = :name AND fs.embedProp.firstName = + :firstName AND fs.embedProp.lastName = :lastName + + + + + + + + + + + + + SELECT fs FROM XMLFieldEmbedEntity fs WHERE + fs.id = :id AND fs.name = :name AND fs.epa.firstName = :firstName + AND fs.epa.lastName = :lastName + + + + SELECT fs FROM XMLFieldEmbedEntity fs WHERE + fs.id = :id AND fs.name = :name AND fs.epa.fName = :firstName + AND fs.epa.lName = :lastName + + + + + + + + + + + + + SELECT fs FROM XMLPropMixedEntity fs WHERE + fs.idval = :id AND fs.name = :name AND + fs.ema.firstName = :firstName + AND fs.ema.lastName = :lastName AND + fs.ema.mName = :middleName + + + + SELECT fs FROM XMLPropMixedEntity fs WHERE + fs.idval = :id AND fs.name = :name AND + fs.ema.firstName = :firstName AND + fs.ema.lastName = :lastName AND + fs.ema.middleName = :middleName + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-persistence.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-persistence.xml new file mode 100644 index 000000000..46e71984b --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-persistence.xml @@ -0,0 +1,59 @@ + + + + + PU for access testing + + org.apache.openjpa.persistence.PersistenceProviderImpl + + + org/apache/openjpa/persistence/access/access-orm.xml + + org.apache.openjpa.persistence.access.xml.XMLFieldAccess + org.apache.openjpa.persistence.access.xml.XMLPropAccess + + org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess + + + org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess + + + org.apache.openjpa.persistence.access.xml.XMLPropEmbedEntity + + + org.apache.openjpa.persistence.access.xml.XMLEmbedFieldAccess + + + org.apache.openjpa.persistence.access.xml.XMLFieldEmbedEntity + + + org.apache.openjpa.persistence.access.xml.XMLEmbedPropAccess + + + + + + \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-field-orm.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-field-orm.xml new file mode 100644 index 000000000..e331f12b4 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-field-orm.xml @@ -0,0 +1,66 @@ + + + + + + FIELD + + + + + SELECT xfa FROM XMLFieldAccess2 xfa WHERE + xfa.id = :id AND xfa.strField = :strVal + + + + + + + + + + + + + SELECT df FROM XMLDFMPA2 df WHERE + df.id = :id AND df.stringField = :strVal + + + + SELECT p FROM XMLDFMPA2 p WHERE + p.id = :id AND p.strField = :strVal + + + + + + + + + + + + \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-persistence.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-persistence.xml new file mode 100644 index 000000000..f5e4a30b9 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-persistence.xml @@ -0,0 +1,61 @@ + + + + + PU for access testing + + org.apache.openjpa.persistence.PersistenceProviderImpl + + + org/apache/openjpa/persistence/access/access-pudef-prop-orm.xml + + org.apache.openjpa.persistence.access.xml.XMLPropAccess + + org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess + + + + + + + + PU for access testing + + org.apache.openjpa.persistence.PersistenceProviderImpl + + + org/apache/openjpa/persistence/access/access-pudef-field-orm.xml + + org.apache.openjpa.persistence.access.xml.XMLFieldAccess + + org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess + + + + + + \ No newline at end of file diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-prop-orm.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-prop-orm.xml new file mode 100644 index 000000000..dafcf9214 --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/access/access-pudef-prop-orm.xml @@ -0,0 +1,66 @@ + + + + + + PROPERTY + + + + + SELECT dp FROM XMLDPMFA2 dp WHERE + dp.id = :id AND dp.strField = :strVal + + + + SELECT p FROM XMLDPMFA2 p WHERE + p.id = :id AND p.strProp = :strVal + + + + + + + + + + + + + + SELECT xpa FROM XMLPropAccess2 xpa WHERE + xpa.id = :id AND xpa.strProp = :strVal + + + + + + + + + + + \ No newline at end of file diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java index 1b1ea49c6..ef4238aa3 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java @@ -744,7 +744,7 @@ public class PersistenceMetaDataDefaults public boolean includes(AnnotatedElement obj) { Access access = obj.getAnnotation(Access.class); - return access != null && access.equals(target); + return access != null && access.value().equals(target); } } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java index d590f79cd..718901355 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java @@ -843,8 +843,14 @@ public class XMLPersistenceMetaDataParser return false; } + int access = AccessCode.UNKNOWN; if (meta == null) { int accessCode = toAccessType(attrs.getValue("access")); + // if access not specified and access was specified at + // the system level, use the system default (which may + // be UNKNOWN) + if (accessCode == AccessCode.UNKNOWN) + accessCode = _access; meta = repos.addMetaData(_cls, accessCode); meta.setEnvClassLoader(_envLoader); meta.setSourceMode(MODE_NONE); @@ -853,7 +859,8 @@ public class XMLPersistenceMetaDataParser if (_parser != null) _parser.parse(_cls); } - + access = meta.getAccessType(); + boolean mappedSuper = "mapped-superclass".equals(elem); boolean embeddable = "embeddable".equals(elem); if (isMetaDataMode()) { @@ -872,7 +879,7 @@ public class XMLPersistenceMetaDataParser meta.setEmbeddedOnly(mappedSuper || embeddable); if (embeddable) { - addDeferredEmbeddableMetaData(_cls); + addDeferredEmbeddableMetaData(_cls, access); } } if (isMappingMode()) @@ -935,7 +942,6 @@ public class XMLPersistenceMetaDataParser return AccessCode.EXPLICIT | AccessCode.PROPERTY; return AccessCode.EXPLICIT | AccessCode.FIELD; } - /** * Parse flush-mode element. */ @@ -1882,16 +1888,17 @@ public class XMLPersistenceMetaDataParser * @param embedType embeddable class * @param access class level access for embeddable */ - protected void addDeferredEmbeddableMetaData(Class embedType) { + protected void addDeferredEmbeddableMetaData(Class embedType, + int access) { ArrayList fmds = _embeddables.get(embedType); if (fmds != null && fmds.size() > 0) { for (int i = fmds.size() -1 ; i >= 0; i--) { MetaDataContext md = fmds.get(i); if (md instanceof FieldMetaData) { - ((FieldMetaData)md).addEmbeddedMetaData(); + ((FieldMetaData)md).addEmbeddedMetaData(access); } else if (md instanceof ValueMetaData) { - ((ValueMetaData)md).addEmbeddedMetaData(); + ((ValueMetaData)md).addEmbeddedMetaData(access); } fmds.remove(i); }