db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leandro Rodrigo Saad Cruz <lean...@ibnetwork.com.br>
Subject [New Feature] Creating objects with ObjectFactory instances
Date Sun, 17 Oct 2004 20:04:54 GMT
Hi OJB developers.
I did some changes to OJB so that an object can be created with an
instance of ObjectFactory. Here is the change in RowReaderDefaultImpl

// 1. create new object instance if needed
  result =  
  result = ClassHelper.buildNewObjectInstance(targetClassDescriptor);	

the code above is called only if you map your class using the attribute

> useObjectFactory="true" <

in you repository.xml !

The ObjectFactory instance that handles this request is configured when
you create an instance of OJB. I have to wire the Objectfactory and
PersistencebrokerFactory yet !

One may think, we already have factory-class and factory-method
attributes, but this approach is not *ideal* for dependency injection on
created objects since the factory-class/method would have to handle a
reference to some sort of Component manager and manager the lifecycle of
the created object.

My suggestion is to create the ObjectFactory object outside ojb and
handle it to ojb on its initialization. What do you think about it ?!
I have the patches here, 
but I can't run my junit tests (even before my changes), don't know why!

Here is the junit test I wrote to demonstrate the code I wrote.

public void testObjectCreation()
  throws Exception
  PersistenceBroker pb = PersistenceBrokerFactory
  ClassDescriptor cld = pb.getDescriptorRepository()
  RowReader rw = new RowReaderDefaultImpl(cld);
  Map row = new HashMap();
  row.put("ID",new Integer(1));
  InitializableObject obj = (InitializableObject)        
  // initilize is called by my stateful factory
  // other factories can call other methods

Cheers !

Leandro Rodrigo Saad Cruz
InterBusiness Tecnologia e Servi├žos
IB    - www.ibnetwork.com.br
DB    - www.digitalbrand.com.br
OJB   - db.apache.org/ojb
XINGU - xingu.sf.net

To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org

View raw message