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
This commit is contained in:
Jeremy Bauer 2009-05-11 21:59:15 +00:00
parent c26d742712
commit 1f37b7725c
73 changed files with 6823 additions and 10 deletions

View File

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

View File

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

View File

@ -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:<br />

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<FieldAccess> one2m;
@Transient
private PropAccess one2one;
@Transient
private Collection<EmbedPropAccess> ecoll;
@Transient
private EmbedFieldAccess embed;
@Transient
private int ver;
@Transient
private Collection<PropAccess> m2m;
@ElementCollection
@Access(AccessType.PROPERTY)
public Collection<EmbedPropAccess> getElementCollection() {
return ecoll;
}
public void setElementCollection(Collection<EmbedPropAccess> 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<FieldAccess> getOneToMany() {
return one2m;
}
public void setOneToMany(Collection<FieldAccess> 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<PropAccess> getManyToMany() {
return m2m;
}
public void setManyToMany(Collection<PropAccess> 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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<FieldAccess> one2m;
@OneToOne(cascade=CascadeType.ALL)
@Access(AccessType.FIELD)
private PropAccess one2one;
@ElementCollection
@Access(AccessType.FIELD)
private Collection<EmbedPropAccess> ecoll;
@Embedded
@Access(AccessType.FIELD)
private EmbedFieldAccess embed;
@Version
@Access(AccessType.FIELD)
private int ver;
@ManyToMany(cascade=CascadeType.ALL)
@Access(AccessType.FIELD)
private Collection<PropAccess> m2m;
@Transient
public Collection<EmbedPropAccess> getElementCollection() {
return ecoll;
}
public void setElementCollection(Collection<EmbedPropAccess> 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<FieldAccess> getOneToMany() {
return one2m;
}
public void setOneToMany(Collection<FieldAccess> c) {
one2m = c;
}
@Transient
public PropAccess getOneToOne() {
return one2one;
}
public void setOneToOne(PropAccess pa) {
one2one = pa;
}
@Transient
public Collection<PropAccess> getManyToMany() {
return m2m;
}
public void setManyToMany(Collection<PropAccess> 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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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.

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<access>FIELD</access>
<entity name="XMLFieldAccess2"
class="org.apache.openjpa.persistence.access.xml.XMLFieldAccess">
<named-query name="XMLFieldAccess2.query">
<query>SELECT xfa FROM XMLFieldAccess2 xfa WHERE
xfa.id = :id AND xfa.strField = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strField"/>
<version name="version"/>
</attributes>
</entity>
<entity name="XMLDFMPA2"
class=
"org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess">
<named-query name="XMLDFMPA2.query">
<query>SELECT df FROM XMLDFMPA2 df WHERE
df.id = :id AND df.stringField = :strVal
</query>
</named-query>
<named-query name="XMLDFMPA2.badQuery">
<query>SELECT p FROM XMLDFMPA2 p WHERE
p.id = :id AND p.strField = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="stringField" access="PROPERTY"/>
<version name="version"/>
<transient name="strField"/>
</attributes>
</entity>
</entity-mappings>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" >
<persistence-unit name="Access-EMPropDef" transaction-type="RESOURCE_LOCAL">
<description>PU for access testing</description>
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<mapping-file>
org/apache/openjpa/persistence/access/access-def-prop-orm.xml
</mapping-file>
<class>org.apache.openjpa.persistence.access.xml.XMLPropAccess</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess
</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
</properties>
</persistence-unit>
<persistence-unit name="Access-EMFldDef" transaction-type="RESOURCE_LOCAL">
<description>PU for access testing</description>
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<mapping-file>
org/apache/openjpa/persistence/access/access-def-field-orm.xml
</mapping-file>
<class>org.apache.openjpa.persistence.access.xml.XMLFieldAccess</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess
</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
</properties>
</persistence-unit>
</persistence>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<access>PROPERTY</access>
<entity name="XMLDPMFA2"
class=
"org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess">
<named-query name="XMLDPMFA2.query">
<query>SELECT dp FROM XMLDPMFA2 dp WHERE
dp.id = :id AND dp.strField = :strVal
</query>
</named-query>
<named-query name="XMLDPMFA2.badQuery">
<query>SELECT p FROM XMLDPMFA2 p WHERE
p.id = :id AND p.strProp = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strField" access="FIELD"/>
<version name="version"/>
<transient name="strProp"/>
</attributes>
</entity>
<entity name="XMLPropAccess2"
class="org.apache.openjpa.persistence.access.xml.XMLPropAccess">
<named-query name="XMLPropAccess2.query">
<query>SELECT xpa FROM XMLPropAccess2 xpa WHERE
xpa.id = :id AND xpa.strProp = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strProp"/>
<version name="version"/>
</attributes>
</entity>
</entity-mappings>

View File

@ -0,0 +1,441 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<mapped-superclass
class=
"org.apache.openjpa.persistence.access.xml.XMLAbstractMappedSuperField"
access="FIELD">
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="name" access="FIELD"/>
</attributes>
</mapped-superclass>
<mapped-superclass
class=
"org.apache.openjpa.persistence.access.xml.XMLAbstractMappedSuperProperty"
access="PROPERTY">
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="name" access="PROPERTY"/>
<transient name="createDate"/>
</attributes>
</mapped-superclass>
<mapped-superclass
class="org.apache.openjpa.persistence.access.xml.XMLMappedSuperField"
access="FIELD">
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="name" access="FIELD"/>
<transient name="crtDate"/>
</attributes>
</mapped-superclass>
<mapped-superclass
class="org.apache.openjpa.persistence.access.xml.XMLMappedSuperProperty"
access="PROPERTY">
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="name" access="PROPERTY"/>
</attributes>
</mapped-superclass>
<mapped-superclass
class="org.apache.openjpa.persistence.access.xml.XMLMixedMappedSuper"
access="PROPERTY">
<attributes>
<id name="mid" access="FIELD">
<generated-value/>
</id>
<basic name="name" access="PROPERTY"/>
<transient name="id"/>
</attributes>
</mapped-superclass>
<entity name="XMLFieldAccess"
class="org.apache.openjpa.persistence.access.xml.XMLFieldAccess"
access="FIELD">
<named-query name="XMLFieldAccess.query">
<query>SELECT xfa FROM XMLFieldAccess xfa WHERE
xfa.id = :id AND xfa.strField = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strField"/>
<version name="version"/>
</attributes>
</entity>
<entity name="XMLPropAccess"
class="org.apache.openjpa.persistence.access.xml.XMLPropAccess"
access="PROPERTY">
<named-query name="XMLPropAccess.query">
<query>SELECT xpa FROM XMLPropAccess xpa WHERE
xpa.id = :id AND xpa.strProp = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strProp"/>
<version name="version"/>
</attributes>
</entity>
<entity name="XMLDFMPA"
class=
"org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess"
access="FIELD">
<named-query name="XMLDFMPA.query">
<query>SELECT df FROM XMLDFMPA df WHERE
df.id = :id AND df.stringField = :strVal
</query>
</named-query>
<named-query name="XMLDFMPA.badQuery">
<query>SELECT p FROM XMLDFMPA p WHERE
p.id = :id AND p.strField = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="stringField" access="PROPERTY"/>
<version name="version"/>
<transient name="strField"/>
</attributes>
</entity>
<entity name="XMLDPMFA"
class=
"org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess"
access="PROPERTY">
<named-query name="XMLDPMFA.query">
<query>SELECT dp FROM XMLDPMFA dp WHERE
dp.id = :id AND dp.strField = :strVal
</query>
</named-query>
<named-query name="XMLDPMFA.badQuery">
<query>SELECT p FROM XMLDPMFA p WHERE
p.id = :id AND p.strProp = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strField" access="FIELD"/>
<version name="version"/>
<transient name="strProp"/>
</attributes>
</entity>
<entity name="XMLPropertySub"
class="org.apache.openjpa.persistence.access.xml.XMLPropertySub"
access="PROPERTY">
<named-query name="XMLPropertySub.query">
<query>SELECT ps FROM XMLPropertySub ps WHERE
ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate
</query>
</named-query>
<named-query name="XMLPropertySub.badQuery">
<query>SELECT ps FROM XMLPropertySub ps WHERE
ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate
</query>
</named-query>
<attributes>
<basic name="createDate">
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</entity>
<entity name="XMLFieldSub"
class="org.apache.openjpa.persistence.access.xml.XMLFieldSub"
access="FIELD">
<named-query name="XMLFieldSub.query">
<query>SELECT fs FROM XMLFieldSub fs WHERE
fs.id = :id AND fs.name = :name AND fs.crtDate = :crtDate
</query>
</named-query>
<named-query name="XMLFieldSub.badQuery">
<query>SELECT fs FROM XMLFieldSub fs WHERE
fs.id = :id AND fs.name = :name AND fs.createDate = :crtDate
</query>
</named-query>
<attributes>
<basic name="crtDate">
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</entity>
<entity name="XMLPropertySub2"
class="org.apache.openjpa.persistence.access.xml.XMLPropertySub2"
access="PROPERTY">
<named-query name="XMLPropertySub2.query">
<query>SELECT ps FROM XMLPropertySub2 ps WHERE
ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate
</query>
</named-query>
<named-query name="XMLPropertySub2.badQuery">
<query>SELECT ps FROM XMLPropertySub2 ps WHERE
ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate
</query>
</named-query>
<attributes>
<basic name="createDate">
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</entity>
<entity name="XMLFieldSub2"
class="org.apache.openjpa.persistence.access.xml.XMLFieldSub2"
access="FIELD">
<named-query name="XMLFieldSub2.query">
<query>SELECT ps FROM XMLFieldSub2 ps WHERE
ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate
</query>
</named-query>
<named-query name="XMLFieldSub2.badQuery">
<query>SELECT ps FROM XMLFieldSub2 ps WHERE
ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate
</query>
</named-query>
<attributes>
<basic name="crtDate">
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</entity>
<entity name="XMLMixedFieldSub"
class="org.apache.openjpa.persistence.access.xml.XMLMixedFieldSub"
access="FIELD">
<named-query name="XMLMixedFieldSub.query">
<query>SELECT fs FROM XMLMixedFieldSub fs WHERE
fs.mid = :id AND fs.name = :name AND fs.createDate = :crtDate
AND fs.myField = :myField
</query>
</named-query>
<named-query name="XMLMixedFieldSub.badQuery">
<query>SELECT fs FROM XMLMixedFieldSub fs WHERE
fs.mid = :id AND fs.name = :name AND fs.myFieldProp = :myField
</query>
</named-query>
<attributes>
<basic name="myField"/>
<basic name="createDate" access="PROPERTY">
<temporal>TIMESTAMP</temporal>
</basic>
<transient name="crtDate"/>
</attributes>
</entity>
<entity name="XMLSuperPropertyEntity"
class="org.apache.openjpa.persistence.access.xml.XMLSuperPropertyEntity"
access="PROPERTY">
<inheritance/>
<named-query name="XMLSuperPropertyEntity.query">
<query>SELECT sfe FROM XMLSuperPropertyEntity sfe WHERE
sfe.id = :id AND sfe.name = :name
</query>
</named-query>
<named-query name="XMLSuperPropertyEntity.badQuery">
<query>SELECT sfe FROM XMLSuperPropertyEntity sfe WHERE
sfe.id = :id AND sfe.name = :name AND sfe.crtDate = :crtDate
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="name" access="PROPERTY"/>
</attributes>
</entity>
<entity name="XMLFieldSub3"
class="org.apache.openjpa.persistence.access.xml.XMLFieldSub3"
access="FIELD">
<inheritance/>
<named-query name="XMLFieldSub3.query">
<query>SELECT ps FROM XMLFieldSub3 ps WHERE
ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate
</query>
</named-query>
<named-query name="XMLFieldSub3.badQuery">
<query>SELECT ps FROM XMLFieldSub3 ps WHERE
ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate
</query>
</named-query>
<attributes>
<basic name="crtDate">
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</entity>
<entity name="XMLSuperFieldEntity"
class="org.apache.openjpa.persistence.access.xml.XMLSuperFieldEntity"
access="FIELD">
<inheritance/>
<named-query name="XMLSuperFieldEntity.query">
<query>SELECT sfe FROM XMLSuperFieldEntity sfe WHERE
sfe.id = :id AND sfe.name = :name
</query>
</named-query>
<named-query name="XMLSuperFieldEntity.badQuery">
<query>SELECT sfe FROM XMLSuperFieldEntity sfe WHERE
sfe.id = :id AND sfe.name = :name AND sfe.crtDate = :crtDate
</query>
</named-query>
<attributes>
<id name="id" access="FIELD">
<generated-value/>
</id>
<basic name="name"/>
</attributes>
</entity>
<entity name="XMLPropertySub3"
class="org.apache.openjpa.persistence.access.xml.XMLPropertySub3"
access="PROPERTY">
<inheritance/>
<named-query name="XMLPropertySub3.query">
<query>SELECT ps FROM XMLPropertySub3 ps WHERE
ps.id = :id AND ps.name = :name AND ps.createDate = :crtDate
</query>
</named-query>
<named-query name="XMLPropertySub3.badQuery">
<query>SELECT ps FROM XMLPropertySub3 ps WHERE
ps.id = :id AND ps.name = :name AND ps.crtDate = :crtDate
</query>
</named-query>
<attributes>
<basic name="createDate">
<temporal>TIMESTAMP</temporal>
</basic>
</attributes>
</entity>
<entity name="XMLPropEmbedEntity"
class="org.apache.openjpa.persistence.access.xml.XMLPropEmbedEntity"
access="PROPERTY">
<named-query name="XMLPropEmbedEntity.query">
<query>SELECT fs FROM XMLPropEmbedEntity fs WHERE
fs.id = :id AND fs.name = :name AND fs.embedProp.fName = :firstName
AND fs.embedProp.lName = :lastName
</query>
</named-query>
<named-query name="XMLPropEmbedEntity.badQuery">
<query>SELECT fs FROM XMLPropEmbedEntity fs WHERE
fs.id = :id AND fs.name = :name AND fs.embedProp.firstName =
:firstName AND fs.embedProp.lastName = :lastName
</query>
</named-query>
<attributes>
<id name="id" access="FIELD">
<generated-value/>
</id>
<basic name="name"/>
<embedded name="embedProp"/>
</attributes>
</entity>
<entity name="XMLFieldEmbedEntity"
class="org.apache.openjpa.persistence.access.xml.XMLFieldEmbedEntity"
access="FIELD">
<named-query name="XMLFieldEmbedEntity.query">
<query>SELECT fs FROM XMLFieldEmbedEntity fs WHERE
fs.id = :id AND fs.name = :name AND fs.epa.firstName = :firstName
AND fs.epa.lastName = :lastName
</query>
</named-query>
<named-query name="XMLFieldEmbedEntity.badQuery">
<query>SELECT fs FROM XMLFieldEmbedEntity fs WHERE
fs.id = :id AND fs.name = :name AND fs.epa.fName = :firstName
AND fs.epa.lName = :lastName
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="name"/>
<embedded name="epa" access="FIELD"/>
</attributes>
</entity>
<entity name="XMLPropMixedEntity"
class="org.apache.openjpa.persistence.access.xml.XMLPropMixedEntity"
access="PROPERTY">
<named-query name="XMLPropMixedEntity.query">
<query>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
</query>
</named-query>
<named-query name="XMLPropMixedEntity.badQuery">
<query>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
</query>
</named-query>
<attributes>
<id name="idval" access="FIELD">
<generated-value/>
</id>
<basic name="name"/>
<embedded name="ema" access="FIELD"/>
<transient name="id"/>
<transient name="embedProp"/>
</attributes>
</entity>
<embeddable
class="org.apache.openjpa.persistence.access.xml.XMLEmbedFieldAccess"
access="FIELD">
<attributes>
<basic name="fName"/>
<basic name="lName"/>
</attributes>
</embeddable>
<embeddable
class="org.apache.openjpa.persistence.access.xml.XMLEmbedPropAccess"
access="PROPERTY">
<attributes>
<basic name="firstName"/>
<basic name="lastName"/>
</attributes>
</embeddable>
<embeddable
class="org.apache.openjpa.persistence.access.xml.XMLEmbedMixedAccess"
access="PROPERTY">
<attributes>
<basic name="mName" access="FIELD"/>
<basic name="firstName"/>
<basic name="lastName"/>
<transient name="middleName"/>
</attributes>
</embeddable>
</entity-mappings>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" >
<persistence-unit name="Access-1" transaction-type="RESOURCE_LOCAL">
<description>PU for access testing</description>
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<mapping-file>
org/apache/openjpa/persistence/access/access-orm.xml
</mapping-file>
<class>org.apache.openjpa.persistence.access.xml.XMLFieldAccess</class>
<class>org.apache.openjpa.persistence.access.xml.XMLPropAccess</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess
</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess
</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLPropEmbedEntity
</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLEmbedFieldAccess
</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLFieldEmbedEntity
</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLEmbedPropAccess
</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
</properties>
</persistence-unit>
</persistence>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<access>FIELD</access>
</persistence-unit-defaults>
</persistence-unit-metadata>
<entity name="XMLFieldAccess2"
class="org.apache.openjpa.persistence.access.xml.XMLFieldAccess">
<named-query name="XMLFieldAccess2.query">
<query>SELECT xfa FROM XMLFieldAccess2 xfa WHERE
xfa.id = :id AND xfa.strField = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strField"/>
<version name="version"/>
</attributes>
</entity>
<entity name="XMLDFMPA2"
class=
"org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess">
<named-query name="XMLDFMPA2.query">
<query>SELECT df FROM XMLDFMPA2 df WHERE
df.id = :id AND df.stringField = :strVal
</query>
</named-query>
<named-query name="XMLDFMPA2.badQuery">
<query>SELECT p FROM XMLDFMPA2 p WHERE
p.id = :id AND p.strField = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="stringField" access="PROPERTY"/>
<version name="version"/>
<transient name="strField"/>
</attributes>
</entity>
</entity-mappings>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" >
<persistence-unit name="Access-PUPropDef" transaction-type="RESOURCE_LOCAL">
<description>PU for access testing</description>
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<mapping-file>
org/apache/openjpa/persistence/access/access-pudef-prop-orm.xml
</mapping-file>
<class>org.apache.openjpa.persistence.access.xml.XMLPropAccess</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess
</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
</properties>
</persistence-unit>
<persistence-unit name="Access-PUFldDef" transaction-type="RESOURCE_LOCAL">
<description>PU for access testing</description>
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<mapping-file>
org/apache/openjpa/persistence/access/access-pudef-field-orm.xml
</mapping-file>
<class>org.apache.openjpa.persistence.access.xml.XMLFieldAccess</class>
<class>
org.apache.openjpa.persistence.access.xml.XMLDefFieldMixedPropAccess
</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
</properties>
</persistence-unit>
</persistence>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<access>PROPERTY</access>
</persistence-unit-defaults>
</persistence-unit-metadata>
<entity name="XMLDPMFA2"
class=
"org.apache.openjpa.persistence.access.xml.XMLDefPropMixedFieldAccess">
<named-query name="XMLDPMFA2.query">
<query>SELECT dp FROM XMLDPMFA2 dp WHERE
dp.id = :id AND dp.strField = :strVal
</query>
</named-query>
<named-query name="XMLDPMFA2.badQuery">
<query>SELECT p FROM XMLDPMFA2 p WHERE
p.id = :id AND p.strProp = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strField" access="FIELD"/>
<version name="version"/>
<transient name="strProp"/>
</attributes>
</entity>
<entity name="XMLPropAccess2"
class="org.apache.openjpa.persistence.access.xml.XMLPropAccess">
<named-query name="XMLPropAccess2.query">
<query>SELECT xpa FROM XMLPropAccess2 xpa WHERE
xpa.id = :id AND xpa.strProp = :strVal
</query>
</named-query>
<attributes>
<id name="id">
<generated-value/>
</id>
<basic name="strProp"/>
<version name="version"/>
</attributes>
</entity>
</entity-mappings>

View File

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

View File

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