OPENJPA-926 Add annotation support for embeddables and correct Transient issue

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@774177 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jeremy Bauer 2009-05-13 03:04:58 +00:00
parent 13819e01f7
commit 90ef23a4a9
3 changed files with 26 additions and 36 deletions

View File

@ -26,14 +26,11 @@ import java.util.Random;
import javax.persistence.Query; import javax.persistence.Query;
import org.apache.openjpa.jdbc.ant.ReverseMappingToolTask.AccessType;
import org.apache.openjpa.meta.AccessCode; import org.apache.openjpa.meta.AccessCode;
import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.MetaDataRepository; import org.apache.openjpa.meta.MetaDataRepository;
import org.apache.openjpa.persistence.ArgumentException; import org.apache.openjpa.persistence.ArgumentException;
import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
import org.apache.openjpa.persistence.test.AllowFailure;
import org.apache.openjpa.persistence.test.SingleEMFTestCase; import org.apache.openjpa.persistence.test.SingleEMFTestCase;
public class TestExplicitAccess extends SingleEMFTestCase { public class TestExplicitAccess extends SingleEMFTestCase {
@ -48,17 +45,15 @@ public class TestExplicitAccess extends SingleEMFTestCase {
AbstractMappedSuperProperty.class, FieldSub.class, AbstractMappedSuperProperty.class, FieldSub.class,
MappedSuperProperty.class, FieldSub2.class, MappedSuperProperty.class, FieldSub2.class,
SuperPropertyEntity.class, FieldSub3.class, SuperPropertyEntity.class, FieldSub3.class,
MixedMappedSuper.class, MixedFieldSub.class //, MixedMappedSuper.class, MixedFieldSub.class,
// These persistent types are commented out until FieldEmbedEntity.class, EmbedFieldAccess.class,
// support for embeddable access types is complete PropEmbedEntity.class, EmbedPropAccess.class,
// FieldEmbedEntity.class, EmbedFieldAccess.class, PropMixedEntity.class, EmbedMixedAccess.class,
// PropEmbedEntity.class, EmbedPropAccess.class, MixedNestedEmbedEntity.class, EmbedInnerProp.class,
// PropMixedEntity.class, EmbedMixedAccess.class, EmbedOuterField.class, MixedMultEmbedEntity.class,
// MixedNestedEmbedEntity.class, EmbedInnerProp.class, FieldAccessPropStratsEntity.class,
// EmbedOuterField.class, MixedMultEmbedEntity.class, PropAccessFieldStratsEntity.class,
// FieldAccessPropStratsEntity.class, EmbedId.class);
// PropAccessFieldStratsEntity.class,
/* EmbedId.class */);
} }
@ -626,8 +621,6 @@ public class TestExplicitAccess extends SingleEMFTestCase {
* Validates an embeddable with field access can be used within an * Validates an embeddable with field access can be used within an
* entity with property access * entity with property access
*/ */
@AllowFailure(value=true,
message="Support for explicit Access on embeddables is not complete.")
public void testEmbeddablesField() { public void testEmbeddablesField() {
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
@ -675,8 +668,6 @@ public class TestExplicitAccess extends SingleEMFTestCase {
* Validates an embeddable with property access can be used within an * Validates an embeddable with property access can be used within an
* entity with field access * entity with field access
*/ */
@AllowFailure(value=true,
message="Support for explicit Access on embeddables is not complete.")
public void testEmbeddablesProperty() { public void testEmbeddablesProperty() {
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
@ -724,8 +715,6 @@ public class TestExplicitAccess extends SingleEMFTestCase {
* Validates an embeddable with mixed access can be used within an * Validates an embeddable with mixed access can be used within an
* entity with mixed access * entity with mixed access
*/ */
@AllowFailure(value=true,
message="Support for explicit Access on embeddables is not complete.")
public void testMixedEmbeddables() { public void testMixedEmbeddables() {
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
@ -776,8 +765,6 @@ public class TestExplicitAccess extends SingleEMFTestCase {
* Validates that a mix of access types can be used within * Validates that a mix of access types can be used within
* an embeddable stack. * an embeddable stack.
*/ */
@AllowFailure(value=true,
message="Support for explicit Access on embeddables is not complete.")
public void testNestedEmbeddables() { public void testNestedEmbeddables() {
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
@ -828,8 +815,6 @@ public class TestExplicitAccess extends SingleEMFTestCase {
* Validates that a mix of access types can be used by an * Validates that a mix of access types can be used by an
* an entity with mulitple embeddables. * an entity with mulitple embeddables.
*/ */
@AllowFailure(value=true,
message="Support for explicit Access on embeddables is not complete.")
public void testMultipleEmbeddables() { public void testMultipleEmbeddables() {
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
@ -901,8 +886,6 @@ public class TestExplicitAccess extends SingleEMFTestCase {
* strategies from within an entity with explicit field access (except for * strategies from within an entity with explicit field access (except for
* the id field, which is field default) * the id field, which is field default)
*/ */
@AllowFailure(value=true,
message="Support for explicit Access on embeddables is not complete.")
public void testPropertyAccessStrategies() { public void testPropertyAccessStrategies() {
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
@ -995,8 +978,6 @@ public class TestExplicitAccess extends SingleEMFTestCase {
* strategies from within an entity with explicit property access (except * strategies from within an entity with explicit property access (except
* for the id field, which is property default) * for the id field, which is property default)
*/ */
@AllowFailure(value=true,
message="Support for explicit Access on embeddables is not complete.")
public void testFieldAccessStrategies() { public void testFieldAccessStrategies() {
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();

View File

@ -1446,7 +1446,7 @@ public class AnnotationPersistenceMetaDataParser
fmd.setEmbedded(true); fmd.setEmbedded(true);
if (fmd.getEmbeddedMetaData() == null) if (fmd.getEmbeddedMetaData() == null)
fmd.addEmbeddedMetaData(); fmd.addEmbeddedMetaData(getAccessCode(fmd.getDeclaredType()));
} }
/** /**
@ -1577,7 +1577,7 @@ public class AnnotationPersistenceMetaDataParser
"Persistent(embedded=true)")); "Persistent(embedded=true)"));
fmd.setEmbedded(true); fmd.setEmbedded(true);
if (fmd.getEmbeddedMetaData() == null) { if (fmd.getEmbeddedMetaData() == null) {
fmd.addEmbeddedMetaData(); fmd.addEmbeddedMetaData(getAccessCode(fmd.getDeclaredType()));
} }
} }
} }
@ -1604,7 +1604,8 @@ public class AnnotationPersistenceMetaDataParser
"PersistentCollection(embeddedElement=true)")); "PersistentCollection(embeddedElement=true)"));
fmd.getElement().setEmbedded(true); fmd.getElement().setEmbedded(true);
if (fmd.getElement().getEmbeddedMetaData() == null) { if (fmd.getElement().getEmbeddedMetaData() == null) {
fmd.getElement().addEmbeddedMetaData(); fmd.getElement().addEmbeddedMetaData(
getAccessCode(fmd.getElement().getDeclaredType()));
} }
} }
} }
@ -1630,7 +1631,7 @@ public class AnnotationPersistenceMetaDataParser
if (!isEnum && JavaTypes.maybePC(elem)) { if (!isEnum && JavaTypes.maybePC(elem)) {
elem.setEmbedded(true); elem.setEmbedded(true);
if (elem.getEmbeddedMetaData() == null) if (elem.getEmbeddedMetaData() == null)
elem.addEmbeddedMetaData(); elem.addEmbeddedMetaData(getAccessCode(elem.getDeclaredType()));
} }
} }
@ -1655,7 +1656,8 @@ public class AnnotationPersistenceMetaDataParser
"PersistentMap(embeddedKey=true)")); "PersistentMap(embeddedKey=true)"));
fmd.getKey().setEmbedded(true); fmd.getKey().setEmbedded(true);
if (fmd.getKey().getEmbeddedMetaData() == null) { if (fmd.getKey().getEmbeddedMetaData() == null) {
fmd.getKey().addEmbeddedMetaData(); fmd.getKey().addEmbeddedMetaData(
getAccessCode(fmd.getKey().getDeclaredType()));
} }
} }
if (anno.elementEmbedded()) { if (anno.elementEmbedded()) {
@ -1664,7 +1666,8 @@ public class AnnotationPersistenceMetaDataParser
"PersistentMap(embeddedValue=true)")); "PersistentMap(embeddedValue=true)"));
fmd.getElement().setEmbedded(true); fmd.getElement().setEmbedded(true);
if (fmd.getElement().getEmbeddedMetaData() == null) if (fmd.getElement().getEmbeddedMetaData() == null)
fmd.getElement().addEmbeddedMetaData(); fmd.getElement().addEmbeddedMetaData(
getAccessCode(fmd.getElement().getDeclaredType()));
} }
} }

View File

@ -594,7 +594,12 @@ public class PersistenceMetaDataDefaults
return member != null && member instanceof AnnotatedElement return member != null && member instanceof AnnotatedElement
&& annotatedFilter.includes((AnnotatedElement)member); && annotatedFilter.includes((AnnotatedElement)member);
} }
private boolean isNotTransient(Member member) {
return member != null && member instanceof AnnotatedElement
&& nonTransientFilter.includes((AnnotatedElement)member);
}
/** /**
* Gets either the instance field or the getter method depending upon the * Gets either the instance field or the getter method depending upon the
* access style of the given meta-data. * access style of the given meta-data.
@ -609,7 +614,8 @@ public class PersistenceMetaDataDefaults
access; access;
if (field == null && getter == null) if (field == null && getter == null)
error(meta, _loc.get("access-no-property", cls, property)); error(meta, _loc.get("access-no-property", cls, property));
if (isAnnotated(field) && isAnnotated(getter)) if ((isNotTransient(getter) && isAnnotated(getter)) &&
isNotTransient(field) && isAnnotated(field))
throw new IllegalStateException(_loc.get("access-duplicate", throw new IllegalStateException(_loc.get("access-duplicate",
field, getter).toString()); field, getter).toString());