Thank you for your answer Alessandro, but it doesn't work with OSCache.

Anybody has another solution?

Alessandro Colantoni wrote:

you can do:
broker = ServiceLocator.getInstance().findBroker();
FieldDescriptor[] pkFields = broker.getClassDescriptor
(realClass).getPkFields();
String[] fieldNames = new String[pkFields.length];
for (int i=0; i<pkFields.length ;i++){
fieldNames[i]=pkFields[i].getAttributeName();
}
Identity oid = broker.serviceIdentity().buildIdentity(realClass, fieldNames, pkValues);
result = broker.getObjectByIdentity(oid);
where pkValues is an array with your key values.
pkValues should have the same order of pk field values in repository.
You can have a look at it.aco.mandragora.dao.ojb.pb.OjbPbDAO in the method
public Object findByPrimaryKey(Class realClass,Object[] pkValues)
you can find it at
http://sourceforge.net/projects/mandragora/
See you
On 7/6/05, JML (Brujula) <[EMAIL PROTECTED]> wrote:
Hi!

I want to put into cache memory a table which has a primary key
composite of various (two) fields. In repository.xml this table is
mapped as follow:

<class-descriptor class="com.brujulatelecom.srv.vo.ParametroOficinaVO"
table="T_SRV_PARAMETROOFICINA">
<object-cache
class="com.brujulatelecom.srv.util.ObjectCacheOSCacheImpl"/>
<field-descriptor id="1" name="pofCodigo" column="POF_CODIGO"
jdbc-type="INTEGER"/>
<field-descriptor id="2" name="pofOfiCodigo" column="POF_OFICODIGO"
jdbc-type="INTEGER" primarykey="true"/>
<field-descriptor id="3" name="pofParCodigo" column="POF_PARCODIGO"
jdbc-type="INTEGER" primarykey="true"/>
</class-descriptor>

In DAO class, the code is:

PersistenceBroker broker = null;
ParametroOficinaVO parametroOficinaVO = null;
broker = ServiceLocator.getInstance().findBroker();
// start caching management
parametroOficinaVO = new ParametroOficinaVO();
parametroOficinaVO.setPofParCodigo(new Integer(parCodigo));
parametroOficinaVO.setPofOfiCodigo(new Integer(ofiCodigo));
Identity oid = new Identity(parametroOficinaVO, broker);
ObjectCache cache = broker.serviceObjectCache();
parametroOficinaVO = (ParametroOficinaVO)cache.lookup(oid);
// final caching management
if (parametroOficinaVO==null){
System.out.println("parametroOficinaVO not in cache:
" + oid);
Criteria criteria = new Criteria();
criteria.addEqualTo("pofParCodigo", parCodigo);
criteria.addEqualTo("pofOfiCodigo", ofiCodigo);
Query query = new
QueryByCriteria(ParametroOficinaVO.class, criteria);
parametroOficinaVO =
(ParametroOficinaVO)broker.getObjectByQuery(query);
} else {
System.out.println("parametroOficinaVO in cache: " + oid);
}

Is this correct?

Thank you for advance!!

Joan Miralles Ramis
Junior Programmer
Development Department
Brújula Telecom


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






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

Reply via email to