Alex,

O/T a bit for this thread but possibly of interest.

If you're not already aware of it, Eric Pugh wrote a hibernate component
for ECM which, I believe, is on the Hibernate site. 

Regards,

Peter

On Sat, 2003-11-01 at 09:14, Alexis Agahi wrote:
> Hi,
> 
> As I'm now using hibernate on current biz project, some ideas come to my brain 
> about how could have transparent persistence with avalon compenent.
> 
> Based on hibernate (JDO?) approach that all object could be mapped in database 
> with get/setter method to populate the object field from db (or persist state 
> to db), any component could support such feature.
> 
> The main problem would be how manage compenent persistance.
> I have a suggestion: via a Persitence interface that could be added in 
> component lifecycle.
> 
> such as
> public interface Persistence
> {
>       public void persitence( PersistenceManager persistenceManager );
> }
> 
> PersistenceManager class would manage object persistance/lookup(load) and 
> transaction provider.
> 
> 
> 
> For exemple:
> 
> Let say we have a persistant component called "Foo"
> 
> /**
>  * @avalon.component version="1.0" name="Foo" lifestyle="transient"
>  * @avalon.service type="Foo"
>  */
> public class Foo implements (AvalonFrameWorksStuff) 
> {
>       Long m_primaryKey;
>       String m_value;
>       ....
> 
>       public void setId( Long id )
>       {
>               m_primaryKey = id;
>       }
>       public Long getId()
>       {
>               return m_primaryKey;
>       }
> 
> 
>       public void setValue( String value )
>       {
>               m_value = value;
>       }
>       public String getValue()
>       {
>               return m_value;
>       }
> }
> 
> We suppose that this object is mapped in db using persistence mapping 
> descriptor (such as hibernate or jdo) file.
> 
> 
> Now we have a compenent Bar depending on Foo 
> 
> /**
>  * @avalon.component version="1.0" name="Bar" lifestyle="transient"
>  * @avalon.service type="Bar"
>  */
> public class Bar implements
> Servicealbe, Persistence
> {
>       String m_serviceManager;
>       ....
>       /**
>         * @avalon.dependency type="Foo:1.0"  key="Foo"
>        */
>       public void service( ServiceManager serviceManager) 
>       throws ServiceException 
>       {
>               m_serviceManager = serviceManager;
>       }
> 
> 
> 
>       public void persitence( PersistanceManager persistanceManager ){
> 
>               PrimaryLookupCriteria criteria = new PrimaryLookupCriteria( new Long( 
> 1 ) );
>               Foo foo = persistanceManager.lookup( m_serviceManager, "Foo", criteria 
> );
>               
>               getLogger().info( foo.getValue() );
> 
>               Transaction = null;
>               try{
>                       tx = persistanceManager.getTransaction();
>                       foo.setValue( "Dude!" );
>                       tx.save( foo );
>                       tx.commit();
>               }
>               catch( TransactionExcetion te )
>               {
>                       tx.rollback();
>               }
>               finally
>               {
>                       if( tx != null ) tx.close();
>               }
> 
>               
>       }
> 
> }
> 
> 
> 
> 
> Cheers
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
-- 
Peter Courcoux <[EMAIL PROTECTED]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to