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

View File

@ -1446,7 +1446,7 @@ public class AnnotationPersistenceMetaDataParser
fmd.setEmbedded(true);
if (fmd.getEmbeddedMetaData() == null)
fmd.addEmbeddedMetaData();
fmd.addEmbeddedMetaData(getAccessCode(fmd.getDeclaredType()));
}
/**
@ -1577,7 +1577,7 @@ public class AnnotationPersistenceMetaDataParser
"Persistent(embedded=true)"));
fmd.setEmbedded(true);
if (fmd.getEmbeddedMetaData() == null) {
fmd.addEmbeddedMetaData();
fmd.addEmbeddedMetaData(getAccessCode(fmd.getDeclaredType()));
}
}
}
@ -1604,7 +1604,8 @@ public class AnnotationPersistenceMetaDataParser
"PersistentCollection(embeddedElement=true)"));
fmd.getElement().setEmbedded(true);
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)) {
elem.setEmbedded(true);
if (elem.getEmbeddedMetaData() == null)
elem.addEmbeddedMetaData();
elem.addEmbeddedMetaData(getAccessCode(elem.getDeclaredType()));
}
}
@ -1655,7 +1656,8 @@ public class AnnotationPersistenceMetaDataParser
"PersistentMap(embeddedKey=true)"));
fmd.getKey().setEmbedded(true);
if (fmd.getKey().getEmbeddedMetaData() == null) {
fmd.getKey().addEmbeddedMetaData();
fmd.getKey().addEmbeddedMetaData(
getAccessCode(fmd.getKey().getDeclaredType()));
}
}
if (anno.elementEmbedded()) {
@ -1664,7 +1666,8 @@ public class AnnotationPersistenceMetaDataParser
"PersistentMap(embeddedValue=true)"));
fmd.getElement().setEmbedded(true);
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
&& 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
* access style of the given meta-data.
@ -609,7 +614,8 @@ public class PersistenceMetaDataDefaults
access;
if (field == null && getter == null)
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",
field, getter).toString());