-
1. Re: Value object use
rajd May 5, 2004 8:18 AM (in response to rajd)Hi,
I have solved my problem. XDcolet is very powerful !!!
My code wasn't wrong, I just forgot to include the entitycmp subtask in the ejbdoclet. With this subtask, XDoclet will generate one class, which extends the entitybean, for each entitybean. This classes include implementation of the life cycle methods (ejbStore, ejbLoad etc..., which can be empty if they were empty in entitybean or just call super.ejbXXX() if they were no no-op in entitybean), and if the @ejb.value-object tag is present in the entitybean, this classes will include methods like :public LanguageValue getLanguageValue(){ ...}
But in order to they appear in the local and/or remote interface, we have to define these methods abstract in the entitybean with the @ejb.interface-method tag :/** * @ejb.interface-method **/ public abstract LanguageValue getLanguageValue();
And finally, XDoclet generate ejb-jar.xml with the ejb-class tags with the concrete classes and not with entitybean.
For example, my previou example looks like :
My Language Entity Bean :/** * * @ejb.bean cmp-version = "2.x" * name = "Language" * primkey-field = "id" * view-type = "local" * type = "CMP" * * @ejb.persistence table-name = "language" * @jboss.persistence create-table = "true" * pk-constraint = "no" * table-name = "language" * * @ejb.util generate = "physical" * @ejb.value-object * */ public abstract class LanguageBean implements EntityBean { ... /** * @ejb.interface-method */ public abstract LanguageValue getLanguageValue(); // ####################################### /* (non-Javadoc) * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext) */ public void setEntityContext(EntityContext ctx) throws EJBException, RemoteException { this._ctx = ctx; } /* (non-Javadoc) * @see javax.ejb.EntityBean#unsetEntityContext() */ public void unsetEntityContext() throws EJBException, RemoteException { this._ctx = null; } /** * @ejb.create-method */ public Integer ejbCreate(String label)throws javax.ejb.CreateException{ this.setLabel(label); return null; } public void ejbPostCreate(String label) { } }
The auto generated concrete class :/* * Generated by XDoclet - Do not edit! */ package fr.edumedia.ejb.entity.parameter; /** * CMP layer for Language. */ public abstract class LanguageCMP extends fr.edumedia.ejb.entity.parameter.LanguageBean implements javax.ejb.EntityBean { public void ejbLoad() { } public void ejbStore() { } public void ejbActivate() { } public void ejbPassivate() { LanguageValue = null; } public void setEntityContext(javax.ejb.EntityContext ctx) throws javax.ejb.EJBException, java.rmi.RemoteException { super.setEntityContext(ctx); } public void unsetEntityContext() throws javax.ejb.EJBException, java.rmi.RemoteException { super.unsetEntityContext(); } public void ejbRemove() throws javax.ejb.RemoveException { } /* Value Objects BEGIN */ private fr.edumedia.value.parameter.LanguageValue LanguageValue = null; public fr.edumedia.value.parameter.LanguageValue getLanguageValue() { LanguageValue = new fr.edumedia.value.parameter.LanguageValue(); try { LanguageValue.setId( getId() ); LanguageValue.setLabel( getLabel() ); } catch (Exception e) { throw new javax.ejb.EJBException(e); } return LanguageValue; } /* Value Objects END */ public abstract java.lang.Integer getId() ; public abstract void setId( java.lang.Integer id ) ; public abstract java.lang.String getLabel() ; public abstract void setLabel( java.lang.String label ) ; }
And the ejb-jar.xml :<entity > <description>[CDATA[]]</description> <ejb-name>Language</ejb-name> <local-home>fr.edumedia.interfaces.entity.parameter.LanguageLocalHome</local-home> <local>fr.edumedia.interfaces.entity.parameter.LanguageLocal</local> <ejb-class>fr.edumedia.ejb.entity.parameter.LanguageCMP</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>java.lang.Integer</prim-key-class> <reentrant>False</reentrant> <cmp-version>2.x</cmp-version> <abstract-schema-name>Language</abstract-schema-name> <cmp-field > <description>[CDATA[]]</description> <field-name>id</field-name> </cmp-field> <cmp-field > <description>[CDATA[]]</description> <field-name>label</field-name> </cmp-field> <primkey-field>id</primkey-field> <!-- Write a file named ejb-finders-LanguageBean.xml if you want to define extra finders. --> </entity>
I hope that this will help somebody to avoid boring works!!!
To resume, with XDoclet, entityCMP and value-objects, we can :
- avoid to implement no-op life cycle methods which will be implemented in concrete classes,
- get value objects, which avoid network calls for each method calls , for use in views,
- all is generated automatically, except for the definition of the abstract methods in entity bean.
But, I have a problem with the value objects : they don't like cyclic references. I'am trying to solve this. -
2. Re: Replication - JGroups or JBossCache problem.
rajd May 5, 2004 8:21 AM (in response to rajd)I have added some more outputs. This time making changs in both caches at different times.
Run DateTime:Wed May 05 13:46:18 BST 2004
-------------------------------------------------------
GMS: address is lbupajt8111j:2690
-------------------------------------------------------
-------------------------------------------------------
GMS: address is lbupajt8111j:2692
-------------------------------------------------------
Changing to FirstValue in Cache1...
2Key: Key
2Data: FirstValue
1Key: Key
1Data: FirstValue
Changing to SecondValue in Cache2...
1Key: Key
1Data: FirstValue
2Key: Key
2Data: FirstValue
Changing to ThirdValue in Cache2...
1Key: Key
1Data: ThirdValue
2Key: Key
2Data: FirstValue
-----------------------END----------------------------
Run DateTime:Wed May 05 13:46:51 BST 2004
-------------------------------------------------------
GMS: address is lbupajt8111j:2696
-------------------------------------------------------
-------------------------------------------------------
GMS: address is lbupajt8111j:2698
-------------------------------------------------------
Changing to FirstValue in Cache1...
2Key: Key
2Data: FirstValue
1Key: Key
1Data: FirstValue
Changing to SecondValue in Cache2...
1Key: Key
1Data: FirstValue
2Key: Key
2Data: SecondValue
Changing to ThirdValue in Cache2...
1Key: Key
1Data: ThirdValue
2Key: Key
2Data: ThirdValue
-----------------------END----------------------------
Run DateTime:Wed May 05 13:46:57 BST 2004
-------------------------------------------------------
GMS: address is lbupajt8111j:2702
-------------------------------------------------------
-------------------------------------------------------
GMS: address is lbupajt8111j:2704
-------------------------------------------------------
Changing to FirstValue in Cache1...
2Key: Key
2Data: FirstValue
1Key: Key
1Data: FirstValue
Changing to SecondValue in Cache2...
1Key: Key
1Data: FirstValue
2Key: Key
2Data: FirstValue
Changing to ThirdValue in Cache2...
1Key: Key
1Data: ThirdValue
2Key: Key
2Data: FirstValue
-----------------------END---------------------------- -
3. Re: Replication - JGroups or JBossCache problem.
belaban May 5, 2004 9:32 AM (in response to rajd)What are you trying to do ? The output above is useless...
Maybe you want to submit a unit test ?
Bela -
4. Re: Replication - JGroups or JBossCache problem.
rajd May 5, 2004 9:55 AM (in response to rajd)Oops Sorry. I will definitely update to Unit test.
Thanks,
Raj