//System.out.println("Returning cached");
return siteNodeVOList;
}
else
{
Timer t = new Timer();
ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db);
List<ContentTypeAttribute> attributes = (List<ContentTypeAttribute>)ContentTypeDefinitionController.getController().getContentTypeAttributes(ctdVO.getSchemaValue());
StringBuffer SQL = new StringBuffer();
if(CmsPropertyHandler.getUseShortTableNames() != null && CmsPropertyHandler.getUseShortTableNames().equalsIgnoreCase("true"))
{
SQL.append("CALL SQL select sn.siNoId, sn.name, sn.publishDateTime, sn.expireDateTime, sn.isBranch, sn.parentsiNoId, sn.metaInfoContentId, sn.repositoryId, sn.siNoTypeDefId, sn.creator, (select count(*) from cmSiNo sn2 where sn2.parentsiNoId = sn.siNoId) AS childCount, snv.siNoVerId, snv.stateId, snv.isProtected, snv.versionModifier, snv.modifiedDateTime, cv.languageId, ");
//SQL.append("concat ");
//SQL.append("( ");
//SQL.append(" concat ");
//SQL.append(" ( ");
/*
StringBuffer attributesSB = new StringBuffer();
int i = 0;
for(ContentTypeAttribute attribute : attributes)
{
if(!attribute.getName().equals("ComponentStructure"))
{
attributesSB.append(" \n '");
if(i > 0)
attributesSB.append("igcomma");
attributesSB.append("" + attribute.getName() + "='||SUBSTR(verValue,INSTR(verValue,'<" + attribute.getName() + "><![CDATA[')+" + (attribute.getName().length() + 11) + ",INSTR(verValue,']]></" + attribute.getName() + ">') - (INSTR(verValue,'<" + attribute.getName() + "><![CDATA[') + " + (attribute.getName().length() + 11) + ")) ||");
}
i++;
}
attributesSB.deleteCharAt(attributesSB.length()-1).deleteCharAt(attributesSB.length()-1);
//System.out.println("attributesSB:" + attributesSB);
SQL.append(attributesSB.toString());
*/
SQL.append(" cv.verValue ");
//SQL.append(" ) ");
//SQL.append(") AS attributes ");
SQL.append(" AS attributes ");
SQL.append("from ");
SQL.append("(");
SQL.append("select sn1.siNoId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiNoId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siNoTypeDefId, sn1.creator from cmSiNo sn1 where sn1.parentsiNoId = " + siteNodeId + " ");
if(levelsToPopulate > 1)
{
SQL.append("UNION ");
SQL.append("select sn2.siNoId, sn2.name, sn2.publishDateTime, sn2.expireDateTime, sn2.isBranch, sn2.parentsiNoId, sn2.metaInfoContentId, sn2.repositoryId, sn2.siNoTypeDefId, sn2.creator ");
SQL.append("from ");
SQL.append("(");
SQL.append(" select sn1.siNoId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiNoId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siNoTypeDefId, sn1.creator from cmSiNo sn1 where sn1.parentsiNoId = " + siteNodeId + " ");
SQL.append(") sn1, cmSiNo sn2 where sn2.parentsiNoId = sn1.siNoId ");
}
if(levelsToPopulate > 2)
{
SQL.append("UNION ");
SQL.append("select sn3.siNoId, sn3.name, sn3.publishDateTime, sn3.expireDateTime, sn3.isBranch, sn3.parentsiNoId, sn3.metaInfoContentId, sn3.repositoryId, sn3.siNoTypeDefId, sn3.creator ");
SQL.append("from ");
SQL.append(" (");
SQL.append(" select sn2.siNoId, sn2.name, sn2.publishDateTime, sn2.expireDateTime, sn2.isBranch, sn2.parentsiNoId, sn2.metaInfoContentId, sn2.repositoryId, sn2.siNoTypeDefId, sn2.creator ");
SQL.append(" from ");
SQL.append(" (");
SQL.append(" select sn1.siNoId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiNoId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siNoTypeDefId, sn1.creator from cmSiNo sn1 where sn1.parentsiNoId = " + siteNodeId + " ");
SQL.append(" ) sn1, cmSiNo sn2 where sn2.parentsiNoId = sn1.siNoId ");
SQL.append(") sn2, cmSiNo sn3 where sn3.parentsiNoId = sn2.siNoId ");
}
if(levelsToPopulate > 3)
{
SQL.append("UNION ");
SQL.append("select sn4.siNoId, sn4.name, sn4.publishDateTime, sn4.expireDateTime, sn4.isBranch, sn4.parentsiNoId, sn4.metaInfoContentId, sn4.repositoryId, sn4.siNoTypeDefId, sn4.creator ");
SQL.append("from ");
SQL.append("(");
SQL.append(" select sn3.siNoId, sn3.name, sn3.publishDateTime, sn3.expireDateTime, sn3.isBranch, sn3.parentsiNoId, sn3.metaInfoContentId, sn3.repositoryId, sn3.siNoTypeDefId, sn3.creator ");
SQL.append(" from ");
SQL.append(" (");
SQL.append(" select sn2.siNoId, sn2.name, sn2.publishDateTime, sn2.expireDateTime, sn2.isBranch, sn2.parentsiNoId, sn2.metaInfoContentId, sn2.repositoryId, sn2.siNoTypeDefId, sn2.creator ");
SQL.append(" from ");
SQL.append(" (");
SQL.append(" select sn1.siNoId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiNoId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siNoTypeDefId, sn1.creator from cmSiNo sn1 where sn1.parentsiNoId = " + siteNodeId + " ");
SQL.append(" ) sn1, cmSiNo sn2 where sn2.parentsiNoId = sn1.siNoId ");
SQL.append(" ) sn2, cmSiNo sn3 where sn3.parentsiNoId = sn2.siNoId ");
SQL.append(" ) sn3, cmSiNo sn4 where sn4.parentsiNoId = sn3.siNoId ");
}
SQL.append(") sn, cmSiNoVer snv, cmContVer cv ");
SQL.append("where ");
SQL.append("snv.siNoId = sn.siNoId AND ");
SQL.append("cv.contId = sn.metaInfoContentId AND ");
SQL.append("cv.contVerId in (select max(contVerId) from cmContVer cv2 where cv2.contId=cv.contId group by cv2.languageId) ");
SQL.append("AND snv.siNoVerId = ( ");
SQL.append(" select max(siNoVerId) from cmSiNoVer snv2 ");
SQL.append(" WHERE ");
SQL.append(" snv2.siNoId = snv.siNoId AND ");
SQL.append(" snv2.isActive = $1 AND snv2.stateId >= $2 ");
SQL.append(") ");
SQL.append("order by sn.parentSiNoId asc, sn.name ASC AS org.infoglue.cms.entities.structure.impl.simple.SmallestSiteNodeImpl");
}
else
{
SQL.append("CALL SQL select sn.siteNodeId, sn.name, sn.publishDateTime, sn.expireDateTime, sn.isBranch, sn.parentsiteNodeId, sn.metaInfoContentId, sn.repositoryId, sn.siteNodeTypeDefinitionId, sn.creator, (select count(*) from cmSiteNode sn2 where sn2.parentsiteNodeId = sn.siteNodeId) AS childCount, snv.siteNodeVersionId, snv.stateId, snv.isProtected, snv.versionModifier, snv.modifiedDateTime, cv.languageId, ");
/*
SQL.append("concat ");
SQL.append("( ");
SQL.append(" concat ");
SQL.append(" ( ");
StringBuffer attributesSB = new StringBuffer();
int i = 0;
for(ContentTypeAttribute attribute : attributes)
{
if(!attribute.getName().equals("ComponentStructure"))
{
attributesSB.append(" \n '");
if(i > 0)
attributesSB.append("igcomma");
attributesSB.append("" + attribute.getName() + "=',SUBSTR(versionValue,INSTR(versionValue,'<" + attribute.getName() + "><![CDATA[')+" + (attribute.getName().length() + 11) + ",INSTR(versionValue,']]></" + attribute.getName() + ">') - (INSTR(versionValue,'<" + attribute.getName() + "><![CDATA[') + " + (attribute.getName().length() + 11) + ")),");
}
i++;
}
attributesSB.deleteCharAt(attributesSB.length()-1);
//System.out.println("attributesSB:" + attributesSB);
SQL.append(attributesSB.toString());
SQL.append(" ) ");
SQL.append(") AS attributes ");
*/
SQL.append(" cv.versionValue AS attributes ");
SQL.append("from ");
SQL.append("(");
SQL.append("select sn1.siteNodeId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiteNodeId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siteNodeTypeDefinitionId, sn1.creator from cmSiteNode sn1 where sn1.parentsiteNodeId = " + siteNodeId + " ");
if(levelsToPopulate > 1)
{
SQL.append("UNION ");
SQL.append("select sn2.siteNodeId, sn2.name, sn2.publishDateTime, sn2.expireDateTime, sn2.isBranch, sn2.parentsiteNodeId, sn2.metaInfoContentId, sn2.repositoryId, sn2.siteNodeTypeDefinitionId, sn2.creator ");
SQL.append("from ");
SQL.append("(");
SQL.append(" select sn1.siteNodeId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiteNodeId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siteNodeTypeDefinitionId, sn1.creator from cmSiteNode sn1 where sn1.parentsiteNodeId = " + siteNodeId + " ");
SQL.append(") sn1, cmSiteNode sn2 where sn2.parentsiteNodeId = sn1.siteNodeId ");
}
if(levelsToPopulate > 2)
{
SQL.append("UNION ");
SQL.append("select sn3.siteNodeId, sn3.name, sn3.publishDateTime, sn3.expireDateTime, sn3.isBranch, sn3.parentsiteNodeId, sn3.metaInfoContentId, sn3.repositoryId, sn3.siteNodeTypeDefinitionId, sn3.creator ");
SQL.append("from ");
SQL.append(" (");
SQL.append(" select sn2.siteNodeId, sn2.name, sn2.publishDateTime, sn2.expireDateTime, sn2.isBranch, sn2.parentsiteNodeId, sn2.metaInfoContentId, sn2.repositoryId, sn2.siteNodeTypeDefinitionId, sn2.creator ");
SQL.append(" from ");
SQL.append(" (");
SQL.append(" select sn1.siteNodeId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiteNodeId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siteNodeTypeDefinitionId, sn1.creator from cmSiteNode sn1 where sn1.parentsiteNodeId = " + siteNodeId + " ");
SQL.append(" ) sn1, cmSiteNode sn2 where sn2.parentsiteNodeId = sn1.siteNodeId ");
SQL.append(") sn2, cmSiteNode sn3 where sn3.parentsiteNodeId = sn2.siteNodeId ");
}
if(levelsToPopulate > 3)
{
SQL.append("UNION ");
SQL.append("select sn4.siteNodeId, sn4.name, sn4.publishDateTime, sn4.expireDateTime, sn4.isBranch, sn4.parentsiteNodeId, sn4.metaInfoContentId, sn4.repositoryId, sn4.siteNodeTypeDefinitionId, sn4.creator ");
SQL.append("from ");
SQL.append("(");
SQL.append(" select sn3.siteNodeId, sn3.name, sn3.publishDateTime, sn3.expireDateTime, sn3.isBranch, sn3.parentsiteNodeId, sn3.metaInfoContentId, sn3.repositoryId, sn3.siteNodeTypeDefinitionId, sn3.creator ");
SQL.append(" from ");
SQL.append(" (");
SQL.append(" select sn2.siteNodeId, sn2.name, sn2.publishDateTime, sn2.expireDateTime, sn2.isBranch, sn2.parentsiteNodeId, sn2.metaInfoContentId, sn2.repositoryId, sn2.siteNodeTypeDefinitionId, sn2.creator ");
SQL.append(" from ");
SQL.append(" (");
SQL.append(" select sn1.siteNodeId, sn1.name, sn1.publishDateTime, sn1.expireDateTime, sn1.isBranch, sn1.parentsiteNodeId, sn1.metaInfoContentId, sn1.repositoryId, sn1.siteNodeTypeDefinitionId, sn1.creator from cmSiteNode sn1 where sn1.parentsiteNodeId = " + siteNodeId + " ");
SQL.append(" ) sn1, cmSiteNode sn2 where sn2.parentsiteNodeId = sn1.siteNodeId ");
SQL.append(" ) sn2, cmSiteNode sn3 where sn3.parentsiteNodeId = sn2.siteNodeId ");
SQL.append(" ) sn3, cmSiteNode sn4 where sn4.parentsiteNodeId = sn3.siteNodeId ");
}
SQL.append(") sn, cmSiteNodeVersion snv, cmContentVersion cv ");
SQL.append("where ");
SQL.append("snv.siteNodeId = sn.siteNodeId AND ");
SQL.append("cv.contentId = sn.metaInfoContentId AND ");
SQL.append("cv.contentVersionId in (select max(contentVersionId) from cmContentVersion cv2 where cv2.contentId=cv.contentId group by cv2.languageId) ");
SQL.append("AND snv.siteNodeVersionId = ( ");
SQL.append(" select max(siteNodeVersionId) from cmSiteNodeVersion snv2 ");
SQL.append(" WHERE ");
SQL.append(" snv2.siteNodeId = snv.siteNodeId AND ");
SQL.append(" snv2.isActive = $1 AND snv2.stateId >= $2 ");
SQL.append(") ");
SQL.append("order by sn.parentsiteNodeId asc, sn.name ASC AS org.infoglue.cms.entities.structure.impl.simple.SmallestSiteNodeImpl");
}
logger.info("\n\n" + SQL);
logger.info("Running SQL QUERY for children to " + siteNodeId + " and possibly below");
//Thread.dumpStack();
//logger.info("SQL:" + SQL);
//logger.info("siteNodeId:" + siteNodeId);
OQLQuery oql = db.getOQLQuery(SQL.toString());
//oql.bind(siteNodeId);
oql.bind(true);
oql.bind(getOperatingMode());
QueryResults results = oql.execute(Database.READONLY);
t.printElapsedTime("Query took");
//RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getChildSiteNodes part 1", t.getElapsedTime());
Map<Integer,SiteNodeVO> allSiteNodeVOMap = new HashMap<Integer,SiteNodeVO>();
Integer parentSiteNodeId = null;
siteNodeVOList = new ArrayList<SiteNodeVO>();
CacheController.cacheObjectInAdvancedCache("childPagesCache", ""+siteNodeId, siteNodeVOList, new String[] {CacheController.getPooledString(3, siteNodeId)}, true);
//populatedSiteNodeVOList.put(siteNodeId, siteNodeVOList);
String groupKey1 = null;
String groupKey2 = null;
while (results.hasMore())
{
SiteNode siteNode = (SiteNode)results.next();
String siteNodeCacheKey = "" + siteNode.getValueObject().getId();
CacheController.cacheObjectInAdvancedCache("siteNodeCache", siteNodeCacheKey, siteNode.getValueObject());
String versionValue = siteNode.getValueObject().getAttributes();
Integer contentId = siteNode.getValueObject().getMetaInfoContentId();
Integer languageId = siteNode.getValueObject().getLanguageId();
Integer contentVersionId = siteNode.getValueObject().getContentVersionId();
if(versionValue == null)
{
logger.info("Null version for " + siteNode.getSiteNodeId() + ":" + siteNode.getValueObject().getSiteNodeVersionId());
}
else
{
groupKey1 = CacheController.getPooledString(2, contentVersionId);
groupKey2 = CacheController.getPooledString(1, contentId);
for(ContentTypeAttribute attribute : attributes)
{
if(!attribute.getName().equals("ComponentStructure"))
{
String attributeKey = "" + siteNode.getId() + "_" + languageId + "_" + attribute.getName();
String attributeKeyContentId = "c_" + siteNode.getMetaInfoContentId() + "_" + languageId + "_" + attribute.getName();
//System.out.println("Caching empty on " + attributeKey);
CacheController.cacheObjectInAdvancedCache("metaInfoContentAttributeCache", attributeKey, "", new String[]{groupKey1, groupKey2}, true);
CacheController.cacheObjectInAdvancedCache("metaInfoContentAttributeCache", attributeKeyContentId, "", new String[]{groupKey1, groupKey2}, true);
}
}
for(ContentTypeAttribute attribute : attributes)
{
//if(!attribute.getName().equals("ComponentStructure"))
//{
String value = ContentDeliveryController.getContentDeliveryController().getAttributeValue(versionValue, attribute.getName(), false);
String attributeKey = "" + siteNode.getId() + "_" + languageId + "_" + attribute.getName();
String attributeKeyContentId = "c_" + siteNode.getMetaInfoContentId() + "_" + languageId + "_" + attribute.getName();
//System.out.println("Caching " + value + " on " + attributeKey);
CacheController.cacheObjectInAdvancedCache("metaInfoContentAttributeCache", attributeKey, value, new String[]{groupKey1, groupKey2}, true);
CacheController.cacheObjectInAdvancedCache("metaInfoContentAttributeCache", attributeKeyContentId, value, new String[]{groupKey1, groupKey2}, true);
//}
}
}
/*
if(attributesString != null)
{
String[] attributesArray = attributesString.split("igcomma");
for(String attr : attributesArray)
{
if(attr != null && !attr.equals(""))
{
String name = attr.substring(0, attr.indexOf("="));
String value = attr.substring(attr.indexOf("=") + 1);
String attributeKey = "" + siteNode.getId() + "_" + languageId + "_" + name;
String attributeKeyContentId = "c_" + siteNode.getMetaInfoContentId() + "_" + languageId + "_" + name;
//System.out.println("Caching " + name + "=" + value + " on " + attributeKey);
CacheController.cacheObjectInAdvancedCache("metaInfoContentAttributeCache", attributeKey, value, new String[]{groupKey1, groupKey2}, true);
CacheController.cacheObjectInAdvancedCache("metaInfoContentAttributeCache", attributeKeyContentId, value, new String[]{groupKey1, groupKey2}, true);
}
}
}
else
System.out.println("Error null on " + siteNode.getId());
*/
//if(allSiteNodeVOMap.get(siteNode.getId()) != null)
//{
// allSiteNodeVOMap.get(siteNode.getId()).addAttributes(siteNode.getValueObject().getLanguageId(), siteNode.getValueObject().getAttributes());
// continue;
//}
allSiteNodeVOMap.put(siteNode.getId(), siteNode.getValueObject());
//System.out.println("siteNode:" + siteNode.getName());
if(isValidSiteNode(siteNode, db))
{
//System.out.println("Caching empty list initially on " + siteNode.getId());
//CacheController.cacheObjectInAdvancedCache("childPagesCache", ""+siteNode.getId(), new ArrayList<SiteNodeVO>(), new String[] {groupKey1, groupKey2, CacheController.getPooledString(3, siteNode.getId())}, true);
//populatedSiteNodeVOList.put(siteNode.getId(), new ArrayList<SiteNodeVO>());
if(parentSiteNodeId != null && !siteNode.getValueObject().getParentSiteNodeId().equals(parentSiteNodeId))
{
//System.out.println("Caching list:" + siteNodeVOList + " on " + parentSiteNodeId);
CacheController.cacheObjectInAdvancedCache("childPagesCache", ""+parentSiteNodeId, siteNodeVOList, new String[] {groupKey1, groupKey2, CacheController.getPooledString(3, parentSiteNodeId)}, true);
//populatedSiteNodeVOList.put(parentSiteNodeId, siteNodeVOList);
siteNodeVOList = new ArrayList<SiteNodeVO>();
}
parentSiteNodeId = siteNode.getValueObject().getParentSiteNodeId();
siteNodeVOList.add(siteNode.getValueObject());
}
}
//System.out.println("Caching list:" + siteNodeVOList + " on " + parentSiteNodeId);
if(groupKey1 == null) groupKey1 = "";
if(groupKey2 == null) groupKey2 = "";
CacheController.cacheObjectInAdvancedCache("childPagesCache", ""+parentSiteNodeId, siteNodeVOList, new String[] {groupKey1, groupKey2, CacheController.getPooledString(3, parentSiteNodeId)}, true);
//populatedSiteNodeVOList.put(parentSiteNodeId, siteNodeVOList);
//RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getChildSiteNodes part 2", t.getElapsedTime());
t.printElapsedTime("Read took");
results.close();
oql.close();
//System.out.println("SIZE:" + populatedSiteNodeVOList.size());