Hi,

JML (Brujula) wrote:
Thank you for your answer Alessandro, but it doesn't work with OSCache.

Anybody has another solution?


Why doesn't it work with OSCache what's the problem?

Could you describe why you need to this access to cache in your method, why you can't use broker.getObjectByIdentity(oid):
http://db.apache.org/ojb/docu/tutorials/pb-tutorial.html#find-by-pk
This method first lookup the cache and when the object is not found it lookup from DB.


If you use the two-level cache
http://db.apache.org/ojb/docu/guides/objectcache.html#ObjectCacheTwoLevelImpl
with OSCache as backend you can't store objects to the second level cache by hand (it's suppressed to avoid synchronization problems)


regards,
Armin


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]




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

Reply via email to