You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by Michelle Caisse <Mi...@Sun.COM> on 2005/07/12 23:47:45 UTC
Proposed solution for JDO-69 - embedded Address field issue
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
Re: Proposed solution for JDO-69
Posted by Michelle Caisse <Mi...@Sun.COM>.
Okay, thanks. I will fix this.
-- Michelle
Craig Russell wrote:
> Hi Michelle,
>
> The addrid field is a persistent field in the application domain, and
> should be mapped in both application and datastore identity cases. I
> think the easiest way to do it is to add field mapping and column
> ADDRID to the schema and mapping files. Even though addrid is not the
> identity field, it's still a persistent field in the model and needs
> to be mapped.
>
> I also notice that in the package.jdo for the company model, Address
> is defined thus:
>
> <class name="Address" requires-extent="false">
> <field name="addrid" persistence-modifier="none"/>
> </class>
>
> This isn't right, as the addrid field is an application field that
> needs to be set to the application value in order for comparisons to
> succeed.
>
> Craig
>
> On Jul 12, 2005, at 2:47 PM, Michelle Caisse wrote:
>
>> 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).
>>
>>
>>
>
> Craig Russell
>
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
>
> 408 276-5638 mailto:Craig.Russell@sun.com
>
> P.S. A good JDO? O, Gasp!
>
>
Re: Proposed solution for JDO-69
Posted by Craig Russell <Cr...@Sun.COM>.
Hi Michelle,
The addrid field is a persistent field in the application domain, and
should be mapped in both application and datastore identity cases. I
think the easiest way to do it is to add field mapping and column
ADDRID to the schema and mapping files. Even though addrid is not the
identity field, it's still a persistent field in the model and needs
to be mapped.
I also notice that in the package.jdo for the company model, Address
is defined thus:
<class name="Address" requires-extent="false">
<field name="addrid" persistence-modifier="none"/>
</class>
This isn't right, as the addrid field is an application field that
needs to be set to the application value in order for comparisons to
succeed.
Craig
On Jul 12, 2005, at 2:47 PM, Michelle Caisse wrote:
> 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).
>
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!
Re: Proposed solution for JDO-69 - embedded Address field issue
Posted by Michelle Caisse <Mi...@Sun.COM>.
Hi Michael,
I've assigned JDO-69 to you.
-- Michelle
Craig Russell wrote:
> Hi Michelle,
>
> Michael and I were talking this morning about a related issue with
> reading an object model and making some of the instances persistent.
> The test case we were talking about was the CompletenessTest but the
> results were relevant.
>
> What we decided as an approach is to define another object in the bean
> xml file called "root". This object is a List that contains all of the
> objects to become persistent. In the case of the CompletenessTest with
> no relationships, we need this to be able to instantiate instances of
> Company, Department, PartTimeEmployee, FullTimeEmployee,
> MedicalInsurance, DentalInsurance, and Project and individually
> persist them and compare them. We don't need to persist the Address
> because these are embedded.
>
> We discussed using this same approach for the QueryTest as well.
> Michael said he would look into modifying the query test to use the
> same pattern, and see if both tests could use the same company.xml
> input files.
>
> Considering persistence by reachability, the only objects needed in
> the "root" list is the root of the connected objects. I think in the
> case of the query test, it is the single object "dept1" that is in the
> "root" list. I suppose it can't hurt to have emp1, emp2, and emp3 in
> the root list as well, but it is only needed if the implementation has
> a bug in persistence by reachability.
>
> I don't think we need an "isEmbedded" feature in the CompanyModelReader.
>
> Craig
>
> On Jul 12, 2005, at 2:47 PM, Michelle Caisse wrote:
>
>> 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();
>>
>
> Craig Russell
>
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
>
> 408 276-5638 mailto:Craig.Russell@sun.com
>
> P.S. A good JDO? O, Gasp!
>
>
Re: Proposed solution for JDO-69 - embedded Address field issue
Posted by Craig Russell <Cr...@Sun.COM>.
Hi Michelle,
Michael and I were talking this morning about a related issue with
reading an object model and making some of the instances persistent.
The test case we were talking about was the CompletenessTest but the
results were relevant.
What we decided as an approach is to define another object in the
bean xml file called "root". This object is a List that contains all
of the objects to become persistent. In the case of the
CompletenessTest with no relationships, we need this to be able to
instantiate instances of Company, Department, PartTimeEmployee,
FullTimeEmployee, MedicalInsurance, DentalInsurance, and Project and
individually persist them and compare them. We don't need to persist
the Address because these are embedded.
We discussed using this same approach for the QueryTest as well.
Michael said he would look into modifying the query test to use the
same pattern, and see if both tests could use the same company.xml
input files.
Considering persistence by reachability, the only objects needed in
the "root" list is the root of the connected objects. I think in the
case of the query test, it is the single object "dept1" that is in
the "root" list. I suppose it can't hurt to have emp1, emp2, and emp3
in the root list as well, but it is only needed if the implementation
has a bug in persistence by reachability.
I don't think we need an "isEmbedded" feature in the CompanyModelReader.
Craig
On Jul 12, 2005, at 2:47 PM, Michelle Caisse wrote:
> 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();
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!