* This method gets a contentVersion with a state and a language which is active.
*/
private ContentVersionVO getContentVersionVO(Integer contentId, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception
{
ContentVersionVO contentVersionVO = null;
String versionKey = "" + contentId + "_" + languageId + "_" + operatingMode + "_contentVersionVO";
Object object = CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", versionKey);
if(object instanceof NullObject)
{
logger.info("There was an cached contentVersionVO but it was null:" + object);
}
else if(object != null)
{
if(object instanceof SmallestContentVersionVO)
{
logger.warn("Object was instanceof SmallestContentVersionVO for key:" + versionKey);
contentVersionVO = (ContentVersionVO)getVOWithId(SmallContentVersionImpl.class, ((SmallestContentVersionVO)object).getId(), db);
CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
}
else
{
contentVersionVO = (ContentVersionVO)object;
}
}
else
{
Timer t = new Timer();
String smallVersionKey = "" + contentId + "_" + languageId + "_" + operatingMode + "_smallestContentVersionVO";
Object smallestContentVersionVOCandidate = CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", smallVersionKey);
if(smallestContentVersionVOCandidate instanceof NullObject)
{
//logger.info("There was an cached content version but it was null:" + smallestContentVersionVOCandidate);
}
else if(smallestContentVersionVOCandidate != null)
{
if(smallestContentVersionVOCandidate instanceof SmallestContentVersionVO)
{
contentVersionVO = (ContentVersionVO)getVOWithId(SmallContentVersionImpl.class, ((SmallestContentVersionVO)smallestContentVersionVOCandidate).getId(), db);
CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting SmallContentVersionImpl", t.getElapsedTime());
}
else
{
logger.warn("Object was instanceof ContentVersionVO for key:" + versionKey);
contentVersionVO = (ContentVersionVO)smallestContentVersionVOCandidate;
}
CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
}
else
{
//logger.info("Querying for verson: " + versionKey);
OQLQuery oql = db.getOQLQuery( "SELECT cv FROM org.infoglue.cms.entities.content.impl.simple.SmallContentVersionImpl cv WHERE cv.contentId = $1 AND cv.languageId = $2 AND cv.stateId >= $3 AND cv.isActive = $4 ORDER BY cv.contentVersionId desc");
oql.bind(contentId);
oql.bind(languageId);
oql.bind(operatingMode);
oql.bind(true);
QueryResults results = oql.execute(Database.READONLY);
if (results.hasMore())
{
ContentVersion contentVersion = (ContentVersion)results.next();
contentVersionVO = contentVersion.getValueObject();
CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
}
else
{
CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, new NullObject(), new String[]{CacheController.getPooledString(1, contentId)}, true);
}
results.close();
oql.close();
}
if(logger.isInfoEnabled())
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVersionVO(Integer contentId, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db)", t.getElapsedTimeNanos() / 1000);
}
if(contentVersionVO != null)
deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersionVO.getId()));
return contentVersionVO;
}