mirror of https://github.com/apache/openjpa.git
OPENJPA-314, OPENJPA-315
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@567875 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0a40e8c9a4
commit
8dd6857f67
|
@ -2608,7 +2608,7 @@ public class PCEnhancer {
|
|||
Code code = getOrCreateClassInitCode(true);
|
||||
if (_meta.getPCSuperclass() != null) {
|
||||
if (getCreateSubclass()) {
|
||||
code.constant().setValue(_meta.getFields().length);
|
||||
code.constant().setValue(0);
|
||||
code.putstatic().setField(INHERIT, int.class);
|
||||
} else {
|
||||
// pcInheritedFieldCount = <superClass>.pcGetManagedFieldCount()
|
||||
|
|
|
@ -128,41 +128,41 @@ public class ApplicationIds {
|
|||
if (!convert && !(val instanceof Byte))
|
||||
throw new ClassCastException("!(x instanceof Byte)");
|
||||
return new ByteId(meta.getDescribedType(),
|
||||
((Number) val).byteValue());
|
||||
val == null ? 0 : ((Number) val).byteValue());
|
||||
case JavaTypes.CHAR:
|
||||
case JavaTypes.CHAR_OBJ:
|
||||
return new CharId(meta.getDescribedType(),
|
||||
((Character) val).charValue());
|
||||
val == null ? 0 : ((Character) val).charValue());
|
||||
case JavaTypes.DOUBLE:
|
||||
case JavaTypes.DOUBLE_OBJ:
|
||||
if (!convert && !(val instanceof Double))
|
||||
throw new ClassCastException("!(x instanceof Double)");
|
||||
return new DoubleId(meta.getDescribedType(),
|
||||
((Number) val).doubleValue());
|
||||
val == null ? 0 : ((Number) val).doubleValue());
|
||||
case JavaTypes.FLOAT:
|
||||
case JavaTypes.FLOAT_OBJ:
|
||||
if (!convert && !(val instanceof Float))
|
||||
throw new ClassCastException("!(x instanceof Float)");
|
||||
return new FloatId(meta.getDescribedType(),
|
||||
((Number) val).floatValue());
|
||||
val == null ? 0 : ((Number) val).floatValue());
|
||||
case JavaTypes.INT:
|
||||
case JavaTypes.INT_OBJ:
|
||||
if (!convert && !(val instanceof Integer))
|
||||
throw new ClassCastException("!(x instanceof Integer)");
|
||||
return new IntId(meta.getDescribedType(),
|
||||
((Number) val).intValue());
|
||||
val == null ? 0 : ((Number) val).intValue());
|
||||
case JavaTypes.LONG:
|
||||
case JavaTypes.LONG_OBJ:
|
||||
if (!convert && !(val instanceof Long))
|
||||
throw new ClassCastException("!(x instanceof Long)");
|
||||
return new LongId(meta.getDescribedType(),
|
||||
((Number) val).longValue());
|
||||
val == null ? 0 : ((Number) val).longValue());
|
||||
case JavaTypes.SHORT:
|
||||
case JavaTypes.SHORT_OBJ:
|
||||
if (!convert && !(val instanceof Short))
|
||||
throw new ClassCastException("!(x instanceof Short)");
|
||||
return new ShortId(meta.getDescribedType(),
|
||||
((Number) val).shortValue());
|
||||
val == null ? 0 : ((Number) val).shortValue());
|
||||
case JavaTypes.STRING:
|
||||
return new StringId(meta.getDescribedType(), (String) val);
|
||||
case JavaTypes.DATE:
|
||||
|
|
|
@ -314,8 +314,7 @@ public abstract class AbstractUnenhancedClassTest
|
|||
|
||||
// make sure that the value was cleared...
|
||||
Field field = getUnenhancedClass().getDeclaredField(
|
||||
this instanceof TestUnenhancedFieldAccess
|
||||
? "stringField" : "sf");
|
||||
isFieldAccessTest() ? "stringField" : "sf");
|
||||
field.setAccessible(true);
|
||||
assertEquals(null, field.get(un));
|
||||
|
||||
|
@ -331,8 +330,7 @@ public abstract class AbstractUnenhancedClassTest
|
|||
|
||||
// make sure that the value was not cleared
|
||||
Field field = getUnenhancedClass().getDeclaredField(
|
||||
this instanceof TestUnenhancedFieldAccess
|
||||
? "stringField" : "sf");
|
||||
isFieldAccessTest() ? "stringField" : "sf");
|
||||
field.setAccessible(true);
|
||||
assertEquals("foo", field.get(un));
|
||||
}
|
||||
|
@ -340,6 +338,8 @@ public abstract class AbstractUnenhancedClassTest
|
|||
em.close();
|
||||
}
|
||||
|
||||
protected abstract boolean isFieldAccessTest();
|
||||
|
||||
public void testLazyLoading()
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
OpenJPAEntityManager em = emf.createEntityManager();
|
||||
|
|
|
@ -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.enhance;
|
||||
|
||||
import org.apache.openjpa.persistence.test.SingleEMTestCase;
|
||||
|
||||
public class TestUnenhancedCompoundPKSubclass extends SingleEMTestCase {
|
||||
|
||||
public void setUp() {
|
||||
setUp(UnenhancedCompoundPKFieldAccessSuperclass.class,
|
||||
UnenhancedCompoundPKFieldAccessSubclass.class, CLEAR_TABLES);
|
||||
}
|
||||
|
||||
public void testCompoundPKFieldAccessUserDefined() {
|
||||
UnenhancedCompoundPKFieldAccessSuperclass un =
|
||||
new UnenhancedCompoundPKFieldAccessSubclass(17, 31);
|
||||
UnenhancedCompoundPKFieldAccessSuperclass.PK oid =
|
||||
new UnenhancedCompoundPKFieldAccessSuperclass.PK(17, 31);
|
||||
compoundPKHelper(un, oid, true);
|
||||
}
|
||||
|
||||
public void testCompoundPKFieldAccessOpenJPADefined() {
|
||||
UnenhancedCompoundPKFieldAccessSuperclass un =
|
||||
new UnenhancedCompoundPKFieldAccessSubclass(17, 31);
|
||||
UnenhancedCompoundPKFieldAccessSuperclass.PK oid =
|
||||
new UnenhancedCompoundPKFieldAccessSuperclass.PK(17, 31);
|
||||
compoundPKHelper(un, oid, false);
|
||||
}
|
||||
|
||||
private void compoundPKHelper(Object o, Object oid, boolean userDefined) {
|
||||
em.getTransaction().begin();
|
||||
em.persist(o);
|
||||
em.getTransaction().commit();
|
||||
|
||||
if (!userDefined) {
|
||||
em.close();
|
||||
em = emf.createEntityManager();
|
||||
}
|
||||
|
||||
em.find(o.getClass(), oid);
|
||||
}
|
||||
}
|
|
@ -36,4 +36,8 @@ public class TestUnenhancedFieldAccess
|
|||
protected UnenhancedSubtype newUnenhancedSubclassInstance() {
|
||||
return new UnenhancedFieldAccessSubclass();
|
||||
}
|
||||
|
||||
protected boolean isFieldAccessTest() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.enhance;
|
||||
|
||||
public class TestUnenhancedFieldAccessPrimitiveWrapper
|
||||
extends AbstractUnenhancedClassTest {
|
||||
|
||||
protected Class<? extends UnenhancedType> getUnenhancedClass() {
|
||||
return UnenhancedFieldAccessPrimitiveWrapper.class;
|
||||
}
|
||||
|
||||
protected UnenhancedType newUnenhancedInstance() {
|
||||
return new UnenhancedFieldAccessPrimitiveWrapper();
|
||||
}
|
||||
|
||||
protected Class<? extends UnenhancedSubtype> getUnenhancedSubclass() {
|
||||
return UnenhancedFieldAccessPrimitiveWrapperSubclass.class;
|
||||
}
|
||||
|
||||
protected UnenhancedSubtype newUnenhancedSubclassInstance() {
|
||||
return new UnenhancedFieldAccessPrimitiveWrapperSubclass();
|
||||
}
|
||||
|
||||
protected boolean isFieldAccessTest() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -36,4 +36,8 @@ public class TestUnenhancedPropertyAccess
|
|||
protected UnenhancedSubtype newUnenhancedSubclassInstance() {
|
||||
return new UnenhancedPropertyAccessSubclass();
|
||||
}
|
||||
|
||||
protected boolean isFieldAccessTest() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
*
|
||||
* 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.enhance;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.IdClass;
|
||||
|
||||
@Entity
|
||||
@IdClass(UnenhancedCompoundPKFieldAccessSubclass.PK.class)
|
||||
public class UnenhancedCompoundPKFieldAccessSubclass
|
||||
extends UnenhancedCompoundPKFieldAccessSuperclass {
|
||||
|
||||
public UnenhancedCompoundPKFieldAccessSubclass() {
|
||||
}
|
||||
|
||||
public UnenhancedCompoundPKFieldAccessSubclass(int i0, int i1) {
|
||||
super(i0, i1);
|
||||
}
|
||||
}
|
|
@ -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.enhance;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
@IdClass(UnenhancedCompoundPKFieldAccessSuperclass.PK.class)
|
||||
public class UnenhancedCompoundPKFieldAccessSuperclass {
|
||||
|
||||
@Id
|
||||
private int id0;
|
||||
@Id
|
||||
private int id1;
|
||||
|
||||
protected UnenhancedCompoundPKFieldAccessSuperclass() {
|
||||
}
|
||||
|
||||
public UnenhancedCompoundPKFieldAccessSuperclass(int i0, int i1) {
|
||||
id0 = i0;
|
||||
id1 = i1;
|
||||
}
|
||||
|
||||
public static class PK {
|
||||
|
||||
static {
|
||||
// register persistent class in JVM
|
||||
try {
|
||||
Class.forName(
|
||||
UnenhancedCompoundPKFieldAccessSuperclass.class.getName());
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public int id0;
|
||||
public int id1;
|
||||
|
||||
public PK() {
|
||||
}
|
||||
|
||||
public PK(int i0, int i1) {
|
||||
id0 = i0;
|
||||
id1 = i1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(id0)
|
||||
+ "::" + String.valueOf(id1);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int rs = 17;
|
||||
rs = rs * 37 + (int) (id0 ^ (id1 >>> 32));
|
||||
rs = rs * 37 + (int) (id0 ^ (id1 >>> 32));
|
||||
return rs;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || obj.getClass() != getClass())
|
||||
return false;
|
||||
|
||||
UnenhancedCompoundPKFieldAccessSuperclass.PK other =
|
||||
(UnenhancedCompoundPKFieldAccessSuperclass.PK) obj;
|
||||
return (id0 == other.id0)
|
||||
&& (id1 == other.id1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.enhance;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
@Table(name = "UN_FIELD_WRAP")
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
public class UnenhancedFieldAccessPrimitiveWrapper
|
||||
implements UnenhancedType, Serializable, Cloneable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
@Version
|
||||
public int version;
|
||||
protected String stringField = "foo";
|
||||
|
||||
@Basic(fetch = FetchType.LAZY)
|
||||
private String lazyField = "lazy";
|
||||
|
||||
public int getId() {
|
||||
return id == null ? -1 : id;
|
||||
}
|
||||
|
||||
public void setStringField(String s) {
|
||||
stringField = s;
|
||||
}
|
||||
|
||||
public String getStringField() {
|
||||
return stringField;
|
||||
}
|
||||
|
||||
public String getLazyField() {
|
||||
return lazyField;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
if (o == null)
|
||||
return false;
|
||||
if (!getClass().isAssignableFrom(o.getClass()))
|
||||
return false;
|
||||
|
||||
return id == ((UnenhancedFieldAccessPrimitiveWrapper) o).id;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return id == null ? 0 : id;
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
}
|
|
@ -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.enhance;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class UnenhancedFieldAccessPrimitiveWrapperSubclass
|
||||
extends UnenhancedFieldAccessPrimitiveWrapper
|
||||
implements UnenhancedSubtype {
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private UnenhancedFieldAccessPrimitiveWrapper related;
|
||||
private int intField;
|
||||
|
||||
public UnenhancedType getRelated() {
|
||||
return related;
|
||||
}
|
||||
|
||||
public void setRelated(UnenhancedType related) {
|
||||
this.related = (UnenhancedFieldAccessPrimitiveWrapper) related;
|
||||
}
|
||||
|
||||
public void setIntField(int i) {
|
||||
intField = i;
|
||||
}
|
||||
|
||||
public int getIntField() {
|
||||
return intField;
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
UnenhancedFieldAccessPrimitiveWrapperSubclass un =
|
||||
(UnenhancedFieldAccessPrimitiveWrapperSubclass) super.clone();
|
||||
un.setRelated((UnenhancedType) getRelated().clone());
|
||||
return un;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue