You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Alessandro Colantoni <ac...@brujulatelecom.com> on 2004/12/16 14:27:38 UTC
Cache and PersistenceBroker optimization
-----Mensaje original-----
De: Alessandro Colantoni [mailto:acolantoni@brujulatelecom.com]
Enviado el: jueves, 16 de diciembre de 2004 14:23
Para: 'OJB Users List'
Asunto: Cache and per
Hi all!!
I'm doing a very large use of caching.
I have to do thousands of small queries that look for a small number of
entries.
I'm using the connection pool of OC4J.
The application consumes rapidly a large number of connections.
I implemented the queries in DAOs that have methods like this one
public ValueObject findByPrimaryKey(Integer parCodigo)throws
DataAccessException{
PersistenceBroker broker = null;
ParametroVO parametroVO = null;
try{
broker =
PersistenceBrokerFactoryFactory.instance().defaultPersistenceBroker();
parametroVO = new ParametroVO();
parametroVO.setParCodigo(parCodigo);
Identity oid = new Identity(parametroVO,broker);
ObjectCache cache = broker.serviceObjectCache();
parametroVO = (ParametroVO)cache.lookup(oid);
if (parametroVO==null){
Criteria criteria = new Criteria();
criteria.addEqualTo("parCodigo",parCodigo);
Query query = new QueryByCriteria(ParametroVO.class,
criteria);
parametroVO =
(ParametroVO)broker.getObjectByQuery(query);
}else {
log.info("************parametroVO in
cache***************");
}
} catch (ServiceLocatorException e) {
log.error("ServiceLocatorException thrown in
ParametroDAO.findByPrimaryKey(Integer parCodigo): " + e.toString());
throw new DataAccessException("Error in
ParametroDAO.findByPrimaryKey(Integer parCodigo): " + e.toString(),e);
} catch (ClassNotPersistenceCapableException e) {
log.error("ClassNotPersistenceCapableException thrown in
ParametroDAO.findByPrimaryKey(Integer parCodigo): " + e.toString());
throw new DataAccessException("Error in
ParametroDAO.findByPrimaryKey(Integer parCodigo): " + e.toString(),e);
} finally {
if (broker != null) broker.close();
}
return parametroVO;
}
My question is:
The DB connection is opened when I do
broker =
PersistenceBrokerFactoryFactory.instance().defaultPersistenceBroker();
and is released when I do broker.close()?;
As I told quite always the ValueObject is found in cache.
Is there any way to check if it is in cache without opening a broker?
I saw in documentation the constructor
public Identity(java.lang.Class realClass,
java.lang.Class topLevel,
java.lang.Object[] pkValues)
But I don't understand how to use it.
What's the difference between realClass and topLevel?
Does this constructor could be useful for me?
Hoping someone can help me
Thanks in advance
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org