Hi,
JDO-69 describes a test error that occurs when the test attempts to make
an embedded class persistent. The solution that I propose is an
extension of one we previously implemented for tearDownClasses In this
case, I propose adding to CompanyModelReader an array containing the
embedded classes for the model and a boolean method isEmbedded(Class).
In QueryTest, I check if the class is embedded before making it
persistent. See the attached patch.
The concern that I have about this solution is that it only works for a
particular mapping of the company model.
The proposed solution fixes most of the 17 errors caused by this issue
under application identity. Under datastore identity, the affected
tests produce a different error -- the implementation expects an
identity field for the embedded Address class (JDO-83).
-- Michelle
Index: test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java
===================================================================
--- test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java
(revision 215964)
+++ test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java
(working copy)
@@ -48,7 +48,7 @@
Project.class
};
- /** All classes in the model
+ /** Non-embedded classes in the model
*/
private static final Class[] tearDownClasses = new Class[] {
DentalInsurance.class, MedicalInsurance.class,
@@ -56,6 +56,12 @@
Project.class, Department.class, Company.class
};
+ /** Embedded classes in the model
+ */
+ private static final Class[] embeddedClasses = new Class[] {
+ Address.class
+ };
+
/**
* Create a CompanyModelReader for the specified resourceName.
* @param resourceName the name of the resource
@@ -240,5 +246,17 @@
public Class[] getTearDownClasses() {
return tearDownClasses;
}
+
+ /**
+ * @return Returns true if class is embedded.
+ */
+ public boolean isEmbedded(Class c) {
+ for (int i=0; i < embeddedClasses.length; i++) {
+ if (c.equals(embeddedClasses[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Index: test/java/org/apache/jdo/tck/query/QueryTest.java
===================================================================
--- test/java/org/apache/jdo/tck/query/QueryTest.java (revision 215964)
+++ test/java/org/apache/jdo/tck/query/QueryTest.java (working copy)
@@ -126,7 +126,9 @@
String[] names = reader.getBeanDefinitionNames();
for (int i = 0; i < names.length; i++) {
Object bean = reader.getBean(names[i]);
- pm.makePersistent(bean);
+ if (!reader.isEmbedded(bean.getClass())) {
+ pm.makePersistent(bean);
+ }
if (debug) logger.debug("inserted " + bean);
}
tx.commit();