Difference between revisions of "Folders deep"
From OpenKM Documentation
(Created page with 'Find folders with some deep. <source lang="java"> // com.openkm.dao.NodeBaseDAO.getInstance().fixNodePath(); import org.hibernate.HibernateException; import org.hibernate.Query…') |
(No difference)
|
Revision as of 09:41, 6 February 2013
Find folders with some deep.
// com.openkm.dao.NodeBaseDAO.getInstance().fixNodePath();
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.core.DatabaseException;
import com.openkm.dao.bean.NodeBase;
import com.openkm.dao.HibernateUtil;
import com.openkm.core.Config;
Logger log = LoggerFactory.getLogger("com.openkm.folder.deep");
int MAX_DEPTH = 5;
int count = 0;
void findNodePathHelper(Session session, NodeBase parentNode, int depth) throws HibernateException {
String qs = "from NodeBase nb where nb.parent=:parent";
Query q = session.createQuery(qs).setCacheable(true);
q.setString("parent", parentNode.getUuid());
for (NodeBase nb : q.list()) {
if (depth == MAX_DEPTH) {
print("uuid:"+nb.getUuid()+ " path:"+OKMRepository.getInstance().getNodePath(null, nb.getUuid())+"<br/>");
} else if (depth < MAX_DEPTH) {
findNodePathHelper(session, nb, depth + 1);
}
}
}
log.info("***** Process BEGIN *****");
String qs = "from NodeBase nb where nb.parent=:parent";
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
// First level nodes
Query q = session.createQuery(qs);
q.setString("parent", Config.ROOT_NODE_UUID);
for (NodeBase nb : q.list()) {
// Process in depth
findNodePathHelper(session, nb, 1);
}
HibernateUtil.commit(session.getTransaction());
} catch (HibernateException e) {
HibernateUtil.rollback(session.getTransaction());
throw new DatabaseException(e.getMessage(), e);
} finally {
HibernateUtil.close(session);
}
log.info("***** Process END *****");