Hello,

First, let me say I've been using Xdoclet for sometime now, and I have been quite
pleased!

Second, I'm trying to re-code a legacy app with EJBs to use Xdoclet now, and I'm
running into some areas that I'm having some problems with.  I'm using the lomboz
plugin for eclipse, which appears to ship with xdoclet 1.2b4.

I've attached my Bean code, and the resultant code for one of my ValueObjects for
reference.

I have a table called Organization which, in addition to various fields about the
Organization, contains a self-referencing foreign key called parentOrganization
(the CMP field is called parentOrg).

As you can see, I've created a bean that I've called TestOrganization.  In
addition, I've defined, with Xdoclet, two ValueObjects, TestOrganization and
LinkedTestOrganization.  TestOrganization contains all the persistent fields from
my table Organization.  LinkedTestOrganization contains the CMRs for the parent
and child references.  LinkedTestOrganizationValue extends TestOrganizationValue.
(The purpose of this is to allow the client code to decide if it wants a light
weight TestOrganizationValue or a heavier LinkedTestOrganization that supports
tree navigation.)

(Please note that the code that is attached below is a heavily edited piece of
'real' code, such that the extraneous information is left out, to make my points
clearer.  As such, there are some things that don't match up perfectly.)

Unfortunately, as I currently have the code written, the generated code has a
number of problems.  Here is the output from javac:

       [javac]
C:\Projects\Party2.0\ejb\gen\party\vo\LinkedTestOrganizationValue.java:28:
LinkedTestOrganizationValue() is already defined in
party.vo.LinkedTestOrganizationValue
       [javac]    public LinkedTestOrganizationValue(  )
       [javac]           ^
       [javac]
C:\Projects\Party2.0\ejb\gen\party\vo\LinkedOrganizationValue.java:216:
organizationIDHasBeenSet has private access in party.vo.OrganizationValue
       [javac]    return organizationIDHasBeenSet;
       [javac]                  ^
       [javac]
C:\Projects\Party2.0\ejb\gen\party\cmp\TestOrganizationCMP.java:58: cannot
resolve symbol
       [javac] symbol  : method create
(gov.doe.eia.party.vo.TestOrganizationValue)
       [javac] location: interface party.interfaces.TestOrganizationLocalHome
       [javac]           party.interfaces.TestOrganizationLocal relation =
home.create(added);
       [javac]
^
       [javac]
C:\Projects\Party2.0\ejb\gen\party\vo\LinkedTestOrganizationValue.java:181:
cannot resolve symbol
       [javac] symbol  : method append ()
       [javac] location: class java.lang.StringBuffer
       [javac]    str.append();
       [javac]                ^
       [javac]
C:\Projects\Party2.0\ejb\gen\party\vo\LinkedTestOrganizationValue.java:194:
testOrganizationIDHasBeenSet has private access in party.vo.TestOrganizationValue
       [javac]    return testOrganizationIDHasBeenSet;
       [javac]                  ^
       [javac] 5 errors


I've done some investigation, and I believe that this code is generated from
valueobject.xdt.  I have a couple things that I was curious if someone far more
knowledgable about the valueobject code could address:

- The second constructor that contains the list of persistent fields seems to
assume that there are persistent fields associated with the value object being
generated.  I think this is dangerous, primarily because of the way in which I am
trying to use them.

- The LinkedTestOrganizationValue does not contain a primary key, and relies upon
the base class TestOrganizationValue to provide this.  As a result, I believe
that the direct access to the instance variable organizationIDHasBeenSet should
be replaced with a call to testOrganizationIDHasBeenSet(), which would call the
base class method implmentation.

- The toString() method from valueobject.xdt also seems to assume that there is a
set of persistent fields provided.  I believe that this should be handled
similarly to the second constructor.



Any suggestions for how to make this work would be greatly appreciated.  And I am
willing to contribute a patch for valueobject.xdt if that ends up being the final
solution.

Thanks again for a wonderful piece of software.  It has saved me a great deal of
time and headaches!

Troy Poppe




[-- begin code: TestOrganizationBean.java --]

package party;

import party.interfaces.TestOrganizationLocal;
import party.vo.LinkedTestOrganizationValue;
import party.vo.TestOrganizationValue;

import java.util.Collection;

import javax.ejb.EntityBean;

/**
 * @ejb.bean 
 *              name="TestOrganization"
 *              jndi-name="ejb/TestOrganization"
 *              local-jndi-name = "ejb/TestOrganizationLocal"
 *              type="CMP"
 *              primkey-field="testOrganizationID"
 *              cmp-version="2.x"
 *      view-type = "local"
 *
 * @ejb.persistence 
 *              table-name = "testorganization" 
 *
 * @jboss.persistence            
 *              datasource = "java:/jdbc/PartyDS"
 *              datasource-mapping = "Oracle9i"
 *              create-table = "false"
 *              remove-table = "false"
 *
 * @ejb.value-object 
 *              name = "TestOrganization"
 *              match = "TestOrganization"
 * 
 * @ejb.value-object
 *              name = "LinkedTestOrganization"
 *              extends = "party.vo.TestOrganizationValue"
 *              match = "LinkedTestOrganization"
 * 
 */
public abstract class TestOrganizationBean implements EntityBean
{
        
        /**
         * Returns the testorganizationID
         * @return the testorganizationID
         * 
         * @ejb.persistent-field 
         * 
         * @ejb.persistence
         *              column-name="testorganizationID"
         *              sql-type="NUMBER"
         *
         * @ejb.pk-field
         *  
         * @ejb.interface-method
         * 
         * @ejb.value-object
         *              match = "TestOrganization"
         * 
         */
        public abstract java.lang.Integer getTestOrganizationID();
        
        /**
         * Sets the testorganizationID
         * 
         * @param java.lang.Integer the new testorganizationID value
         * 
         * @ejb.interface-method
         */
        public abstract void setTestOrganizationID(java.lang.Integer
testorganizationID);
        
        /**
         * Returns the parentOrg ID
         * @return the parentOrg ID
         * 
         * @ejb.persistent-field 
         
         * @ejb.persistence
         *              column-name="parentOrg"
         *              sql-type="NUMBER"
         *  
         * @ejb.interface-method
         *              view-type = "local"
         * 
         * @ejb.value-object
         *              match = "TestOrganization"
         * 
         * @jboss.load-group
         *              name="complete"
         * 
         */
        public abstract java.lang.Integer getParentOrg();
        
        /**
         * Sets the parentOrg ID
         * 
         * @param java.lang.Integer the new parentOrg ID
         * 
         * @ejb.interface-method
         *              view-type = "local"
         * 
         * @jboss.load-group
         *              name="complete"
         */
        public abstract void setParentOrg(java.lang.Integer parentOrg);

        /**
         * 
         * @ejb.interface-method
         *              view-type = "local"
         * 
         * @ejb.transaction
     *          type = "Required"
         * 
         * @return
         */
        public abstract TestOrganizationValue getTestOrganizationValue();
        
        /**
         * @ejb.interface-method 
         *              view-type = "local"
         * 
         * @param valueHolder
         */
        public abstract void setTestOrganizationValue(TestOrganizationValue
valueHolder);

        /**
         * 
         * @ejb.interface-method
         *              view-type = "local"
         * 
         * @ejb.transaction
         *              type = "Required"
         * 
         * @return
         */
        public abstract LinkedTestOrganizationValue
getLinkedTestOrganizationValue();
        
        /**
         * @ejb.interface-method 
         *              view-type = "local"
         * 
         * @param valueHolder
         */
        public abstract void
setLinkedTestOrganizationValue(LinkedTestOrganizationValue valueHolder);




        //      -------------------------- RELATIONS
---------------------------------//

        /**
         * @ejb.relation 
         *              name = "TestOrganizationParentChild"
         *              role-name =
"ChildTestOrganizationHasAParentTestOrganization"
         * 
         * @ejb.interface-method
         *              view-type = "local"
         *  
         * @jboss.relation
         *              fk-column = "parentOrg"
         *              related-pk-field = "testOrganizationID"
         * 
         * @ejb.value-object
         *              aggregate="party.vo.TestOrganizationValue"
         *              aggregate-name="ParentTestOrganization"
         *              relation = "external"
         *              match = "LinkedTestOrganization"
         * 
         */
        public abstract TestOrganizationLocal getParentTestOrganization();
        
        /**
         * @ejb.interface-method
         *              view-type = "local"
         * 
         * @param parentOrg
         *
         */     
        public abstract void setParentTestOrganization(TestOrganizationLocal
parentOrg);

        /**
         * @ejb.relation 
         *              name = "TestOrganizationParentChild"
         *              role-name =
"ParentTestOrganizationHasChildTestOrganizations"
         *              cascade-delete = "no"
         * 
         * @ejb.interface-method 
         *              view-type = "local"
         * 
         * @ejb.value-object
         *              compose="party.vo.TestOrganizationValue"
         *              compose-name="ChildTestOrganization"
         *              members="party.interfaces.TestOrganizationLocal"
         *              member-name="ChildTestOrganization"
         *              relation="external"
         *              type="Collection"
         *              match = "LinkedTestOrganization"
         * 
         */
        public abstract Collection getChildTestOrganizations();

        /**
         * @ejb.interface-method
         *              view-type = "local"
         * 
         * @param childOrgs
         */
        public abstract void setChildTestOrganizations(Collection childOrgs);
        
}

[-- end code: TestOrganizationBean.java --]

[-- begin code: LinkedTestOrganizatioNValue.java --]

/*
 * Generated by XDoclet - Do not edit!
 */
package gov.doe.eia.party.vo;

import java.util.*;

/**
 * Value object for TestOrganization.
 *
 * @lomboz generated
 */
public class LinkedTestOrganizationValue
   extends  
gov.doe.eia.party.vo.TestOrganizationValue 
   implements java.io.Serializable 
{
   private gov.doe.eia.party.vo.TestOrganizationValue ParentTestOrganization;
   private boolean ParentTestOrganizationHasBeenSet = false;
   private Collection ChildTestOrganizations = new java.util.ArrayList();

   private java.lang.Integer pk;

   public LinkedTestOrganizationValue()
   {
   }

   public LinkedTestOrganizationValue(  )
   {
          pk = this.getTestOrganizationID();
   }

   //TODO Cloneable is better than this !
   public LinkedTestOrganizationValue( LinkedTestOrganizationValue otherValue )
   {
        // TODO Clone is better no ?
          this.ParentTestOrganization = otherValue.ParentTestOrganization;
          ParentTestOrganizationHasBeenSet = true;
        // TODO Clone is better no ?
          this.ChildTestOrganizations = otherValue.ChildTestOrganizations;

          pk = this.getTestOrganizationID();
   }

   public java.lang.Integer getPrimaryKey()
   {
          return pk;
   }

   public void setPrimaryKey( java.lang.Integer pk )
   {
      // it's also nice to update PK object - just in case
      // somebody would ask for it later...
      this.pk = pk;
   }

   public gov.doe.eia.party.vo.TestOrganizationValue getParentTestOrganization()
   {
          return this.ParentTestOrganization;
   }
   public void setParentTestOrganization(
gov.doe.eia.party.vo.TestOrganizationValue ParentTestOrganization )
   {
          this.ParentTestOrganization = ParentTestOrganization;
          ParentTestOrganizationHasBeenSet = true;
   }
   protected Collection addedChildTestOrganizations = new java.util.ArrayList();
   protected Collection onceAddedChildTestOrganizations = new
java.util.ArrayList();
   protected Collection removedChildTestOrganizations = new
java.util.ArrayList();
   protected Collection updatedChildTestOrganizations = new
java.util.ArrayList();

   public Collection getAddedChildTestOrganizations() { return
addedChildTestOrganizations; }
   public Collection getOnceAddedChildTestOrganizations() { return
onceAddedChildTestOrganizations; }
   public Collection getRemovedChildTestOrganizations() { return
removedChildTestOrganizations; }
   public Collection getUpdatedChildTestOrganizations() { return
updatedChildTestOrganizations; }

   public void setAddedChildTestOrganizations(Collection
addedChildTestOrganizations)
   {
      this.addedChildTestOrganizations.clear();
      this.addedChildTestOrganizations.addAll(addedChildTestOrganizations);
   }

   public void setOnceAddedChildTestOrganizations(Collection
onceAddedChildTestOrganizations)
   {
      this.onceAddedChildTestOrganizations.clear();
 
this.onceAddedChildTestOrganizations.addAll(onceAddedChildTestOrganizations);
   }

   public void setRemovedChildTestOrganizations(Collection
removedChildTestOrganizations)
   {
      this.removedChildTestOrganizations.clear();
      this.removedChildTestOrganizations.addAll(removedChildTestOrganizations);
   }

   public void setUpdatedChildTestOrganizations(Collection
updatedChildTestOrganizations)
   {
      this.updatedChildTestOrganizations.clear();
      this.updatedChildTestOrganizations.addAll(updatedChildTestOrganizations);
   }

   public gov.doe.eia.party.vo.TestOrganizationValue[]
getChildTestOrganizations()
   {
          return
(gov.doe.eia.party.vo.TestOrganizationValue[])this.ChildTestOrganizations.toArray
(new gov.doe.eia.party.vo.TestOrganizationValue[ChildTestOrganizations.size()]);
   }

   public void
setChildTestOrganizations(gov.doe.eia.party.vo.TestOrganizationValue[]
ChildTestOrganizations)
   {
      this.ChildTestOrganizations.clear();
      for (int i=0; i < ChildTestOrganizations.length; i++)
        this.ChildTestOrganizations.add(ChildTestOrganizations[i]);
   }

   public void clearChildTestOrganizations()
   {
          this.ChildTestOrganizations.clear();
   }

   public void
addChildTestOrganization(gov.doe.eia.party.vo.TestOrganizationValue added)
   {
          this.ChildTestOrganizations.add(added);

      if (this.removedChildTestOrganizations.contains(added))
      {
        this.removedChildTestOrganizations.remove(added);
        if (this.onceAddedChildTestOrganizations.contains(added))
        {
          if (! this.addedChildTestOrganizations.contains(added))
            this.addedChildTestOrganizations.add(added);
        }
        else if (! this.updatedChildTestOrganizations.contains(added))
        {
            this.updatedChildTestOrganizations.add(added);
        }
      }
      else
      {
        if (! this.onceAddedChildTestOrganizations.contains(added))
          this.onceAddedChildTestOrganizations.add(added);
        if (! this.addedChildTestOrganizations.contains(added))
          this.addedChildTestOrganizations.add(added);
      }
   }

   public void
removeChildTestOrganization(gov.doe.eia.party.vo.TestOrganizationValue removed)
   {
          this.ChildTestOrganizations.remove(removed);

      if (this.addedChildTestOrganizations.contains(removed))
        this.addedChildTestOrganizations.remove(removed);
      else if (! this.removedChildTestOrganizations.contains(removed))
        this.removedChildTestOrganizations.add(removed);

          if (this.updatedChildTestOrganizations.contains(removed))
                 this.updatedChildTestOrganizations.remove(removed);
   }

   public void
updateChildTestOrganization(gov.doe.eia.party.vo.TestOrganizationValue updated)
   {
          if ( !this.updatedChildTestOrganizations.contains(updated) &&
!this.addedChildTestOrganizations.contains(updated))
                 this.updatedChildTestOrganizations.add(updated);
      if (this.removedChildTestOrganizations.contains(updated))
         this.removedChildTestOrganizations.remove(updated);
   }

   public void cleanChildTestOrganization(){
          this.addedChildTestOrganizations = new java.util.ArrayList();
      this.onceAddedChildTestOrganizations = new java.util.ArrayList();
          this.removedChildTestOrganizations = new java.util.ArrayList();
          this.updatedChildTestOrganizations = new java.util.ArrayList();
   }

   public void
copyChildTestOrganizationsFrom(gov.doe.eia.party.vo.LinkedTestOrganizationValue
from)
   {
          // TODO Clone the List ????
          this.ChildTestOrganizations = from.ChildTestOrganizations;
   }

   public String toString()
   {
          StringBuffer str = new StringBuffer("{");

          str.append();
          str.append('}');

          return(str.toString());
   }

   /**
    * A Value Object has an identity if the attributes making its Primary Key
have all been set. An object without identity is never equal to any other object.
    *
    * @return true if this instance has an identity.
    */
   protected boolean hasIdentity()
   {
          return testOrganizationIDHasBeenSet;
   }

   public boolean equals(Object other)
   {
      if (this == other)
         return true;
          if ( ! hasIdentity() ) return false;
          if (other instanceof LinkedTestOrganizationValue)
          {
                 LinkedTestOrganizationValue that = (LinkedTestOrganizationValue)
other;
                 if ( ! that.hasIdentity() ) return false;
                 boolean lEquals = true;

                 lEquals = lEquals && isIdentical(that);

                 return lEquals;
          }
          else
          {
                 return false;
          }
   }

   public boolean isIdentical(Object other)
   {
          if (other instanceof LinkedTestOrganizationValue)
          {
                 LinkedTestOrganizationValue that = (LinkedTestOrganizationValue)
other;
                 boolean lEquals = true;
                 if( this.ParentTestOrganization == null )
                 {
                        lEquals = lEquals && ( that.ParentTestOrganization ==
null );
                 }
                 else
                 {
                        lEquals = lEquals && this.ParentTestOrganization.equals(
that.ParentTestOrganization );
                 }
                 if( this.getChildTestOrganizations() == null )
                 {
                        lEquals = lEquals && ( that.getChildTestOrganizations()
== null );
                 }
                 else
                 {
                        lEquals = lEquals &&
java.util.Arrays.equals(this.getChildTestOrganizations() ,
that.getChildTestOrganizations()) ;
                 }

                 return lEquals;
          }
          else
          {
                 return false;
          }
   }

   public int hashCode(){
          int result = 17;
          result = 37*result + ((this.ParentTestOrganization != null) ?
this.ParentTestOrganization.hashCode() : 0);
          result = 37*result + ((this.getChildTestOrganizations() != null) ?
this.getChildTestOrganizations().hashCode() : 0);
          return result;
   }

}

[-- end code: LinkedTestOrganizatioNValue.java --]



-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user

Reply via email to