* This method gets a contentVersion with a state and a language which is active.
*/
private ContentVersion getContentVersion(ContentVO content, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception
{
ContentVersion contentVersion = null;
String versionKey = "" + content.getId() + "_" + languageId + "_" + operatingMode + "_contentVersionId";
//logger.info("versionKey:" + versionKey);
Object object = CacheController.getCachedObjectFromAdvancedCache("contentVersionIdCache", versionKey);
if(object instanceof NullObject)
{
logger.info("There was an cached parentSiteNodeVO but it was null:" + object);
}
else if(object != null)
{
Integer contentVersionId = (Integer)object;
contentVersion = (ContentVersion)getObjectWithId(ContentVersionImpl.class, contentVersionId, db);
//logger.info("Loaded the version from cache instead of querying it:" + contentVersionId);
}
else
{
//logger.info("Querying for verson: " + versionKey);
OQLQuery oql = db.getOQLQuery( "SELECT cv FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl cv WHERE cv.contentId = $1 AND cv.language.languageId = $2 AND cv.stateId >= $3 AND cv.isActive = $4 ORDER BY cv.contentVersionId desc");
oql.bind(content.getId());
oql.bind(languageId);
oql.bind(operatingMode);
oql.bind(true);
QueryResults results = oql.execute(Database.READONLY);
if (results.hasMore())
{
contentVersion = (ContentVersion)results.next();
CacheController.cacheObjectInAdvancedCache("contentVersionIdCache", versionKey, contentVersion.getId(), new String[]{CacheController.getPooledString(2, contentVersion.getId()), CacheController.getPooledString(1, contentVersion.getValueObject().getContentId())}, true);
}
else
{
CacheController.cacheObjectInAdvancedCache("contentVersionIdCache", versionKey, new NullObject(), new String[]{CacheController.getPooledString(1, content.getId())}, true);
}
results.close();
oql.close();
}
if(contentVersion != null)
deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersion.getId()));
return contentVersion;
}