Index: lams_contentrepository/conf/hibernate/mappings/org/lamsfoundation/lams/contentrepository/CrNode.hbm.xml
===================================================================
diff -u -r09decccca1a4d871be5772d51638fa13aa928349 -rd3f488ff70266c8a676e11ee261b74b7a4c43d51
--- lams_contentrepository/conf/hibernate/mappings/org/lamsfoundation/lams/contentrepository/CrNode.hbm.xml (.../CrNode.hbm.xml) (revision 09decccca1a4d871be5772d51638fa13aa928349)
+++ lams_contentrepository/conf/hibernate/mappings/org/lamsfoundation/lams/contentrepository/CrNode.hbm.xml (.../CrNode.hbm.xml) (revision d3f488ff70266c8a676e11ee261b74b7a4c43d51)
@@ -140,6 +140,19 @@
-
+
+
+ true
+
+ @hibernate.many-to-one
+ not-null="true"
+ @hibernate.column name="parent_nv_id"
+
+
+
Index: lams_contentrepository/conf/hibernate/mappings/org/lamsfoundation/lams/contentrepository/CrNodeVersion.hbm.xml
===================================================================
diff -u -r09decccca1a4d871be5772d51638fa13aa928349 -rd3f488ff70266c8a676e11ee261b74b7a4c43d51
--- lams_contentrepository/conf/hibernate/mappings/org/lamsfoundation/lams/contentrepository/CrNodeVersion.hbm.xml (.../CrNodeVersion.hbm.xml) (revision 09decccca1a4d871be5772d51638fa13aa928349)
+++ lams_contentrepository/conf/hibernate/mappings/org/lamsfoundation/lams/contentrepository/CrNodeVersion.hbm.xml (.../CrNodeVersion.hbm.xml) (revision d3f488ff70266c8a676e11ee261b74b7a4c43d51)
@@ -88,46 +88,35 @@
-
-
- true
-
- @hibernate.many-to-one
- not-null="true"
- @hibernate.column name="parent_nv_id"
-
-
-
-
-
- @hibernate.set
- lazy="true"
- inverse="false"
- cascade="all-delete-orphan"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- @hibernate.collection-key
- column="parent_nv_id"
-
- @hibernate.collection-one-to-many
- class="org.lamsfoundation.lams.contentrepository.CrNodeVersion"
-
-
-
-
-
-
0 )
+ if ( deleted != null && deleted.length() > 0 )
msg = msg + " deleted file(s) "+deleted;
- if ( failedDeleted.length() > 0)
+ if ( failedDeleted != null && failedDeleted.length() > 0)
msg = msg + " unable to delete file(s) "+failedDeleted;
log.error(msg);
}
@@ -646,6 +657,18 @@
nodeVersion.setVersionDescription(versionDescription);
nodeDAO.insert(node);
+
+ // child nodes are done manually as the set is lazy loaded
+ // and can't work out how to do that properly using the DAO template!
+ // 'cause the session goes away.
+ if ( childNodes != null ) {
+ Iterator iter = childNodes.iterator();
+ while ( iter.hasNext() ) {
+ CrNode node = (CrNode) iter.next();
+ nodeDAO.insert(node);
+ }
+ }
+
}
/** Write the file out (if one exists). Sets the private attribute filePath.
@@ -681,18 +704,24 @@
public IVersionedNode getNode(String relPath)
throws ItemNotFoundException {
+ String key = "getNode "+getUUID();
+ long start = System.currentTimeMillis();
+ log.error(key+" start 0");
+
nodeObjectInitilised("Unable to get child node.");
if ( log.isDebugEnabled() ) {
log.debug("getNode for path "+relPath+" start.");
}
- CrNodeVersion childNodeVersion = nodeVersion.getChildNodeVersion(relPath);
+ CrNode childNode = nodeDAO.findChildNode(nodeVersion, relPath);
+ log.error(key+" childNodeDB"+(System.currentTimeMillis()-start));
- if ( childNodeVersion != null ) {
+ if ( childNode != null ) {
SimpleVersionedNode newNode = (SimpleVersionedNode) beanFactory.getBean("node", SimpleVersionedNode.class);
- newNode.node = childNodeVersion.getNode();
- newNode.nodeVersion = childNodeVersion;
+ newNode.node = childNode;
+ newNode.nodeVersion = childNode.getNodeVersion(null); // get latest and only version
+ log.error(key+" returningNode"+(System.currentTimeMillis()-start));
return (IVersionedNode) newNode;
} else {
throw new ItemNotFoundException("Unable to find node with path "+relPath
@@ -705,16 +734,16 @@
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#getChildNodes()
*/
public Set getChildNodes() {
- Set childCrNodeVersions = nodeVersion.getChildNodeVersions();
+ List childCrNodes = nodeDAO.findChildNodes(nodeVersion);
Set childNodes = new HashSet();
- if ( childCrNodeVersions != null ) {
- Iterator iter = childCrNodeVersions.iterator();
+ if ( childCrNodes != null ) {
+ Iterator iter = childCrNodes.iterator();
while (iter.hasNext()) {
- CrNodeVersion element = (CrNodeVersion) iter.next();
+ CrNode element = (CrNode) iter.next();
SimpleVersionedNode newNode = (SimpleVersionedNode) beanFactory.getBean("node", SimpleVersionedNode.class);
- newNode.node = element.getNode();
- newNode.nodeVersion = element;
+ newNode.node = element;
+ newNode.nodeVersion = element.getNodeVersion(null);
childNodes.add(newNode);
}
}
@@ -734,7 +763,7 @@
nodeObjectInitilised("Unable to check if there is a parent node.");
- return (nodeVersion.getParentNodeVersion() != null);
+ return (node.getParentNodeVersion() != null);
}
@@ -756,7 +785,7 @@
* @see org.lamsfoundation.lams.contentrepository.IVersionedNode#hasNodes()
*/
public boolean hasNodes() {
- Set childNodes = nodeVersion.getChildNodeVersions();
+ List childNodes = nodeDAO.findChildNodes(nodeVersion);
return (childNodes != null && childNodes.size() > 0);
}
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/INodeDAO.java
===================================================================
diff -u -r09decccca1a4d871be5772d51638fa13aa928349 -rd3f488ff70266c8a676e11ee261b74b7a4c43d51
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/INodeDAO.java (.../INodeDAO.java) (revision 09decccca1a4d871be5772d51638fa13aa928349)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/INodeDAO.java (.../INodeDAO.java) (revision d3f488ff70266c8a676e11ee261b74b7a4c43d51)
@@ -6,6 +6,9 @@
import java.io.Serializable;
import java.util.List;
+import org.lamsfoundation.lams.contentrepository.CrNode;
+import org.lamsfoundation.lams.contentrepository.CrNodeVersion;
+
/**
* Data access routines for Nodes, versions and properties
*
@@ -26,4 +29,8 @@
public List findAll(Class objClass);
+ public List findChildNodes(CrNodeVersion parentNodeVersion);
+ public CrNode findChildNode(CrNodeVersion parentNodeVersion, String relPath);
+
+
}
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/NodeDAO.java
===================================================================
diff -u -r09decccca1a4d871be5772d51638fa13aa928349 -rd3f488ff70266c8a676e11ee261b74b7a4c43d51
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/NodeDAO.java (.../NodeDAO.java) (revision 09decccca1a4d871be5772d51638fa13aa928349)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/NodeDAO.java (.../NodeDAO.java) (revision d3f488ff70266c8a676e11ee261b74b7a4c43d51)
@@ -7,6 +7,8 @@
import java.util.List;
import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.contentrepository.CrNode;
+import org.lamsfoundation.lams.contentrepository.CrNodeVersion;
import org.lamsfoundation.lams.contentrepository.dao.INodeDAO;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
@@ -42,4 +44,65 @@
return this.getHibernateTemplate().find(query);
}
+ /** Get all child nodes for a node/version.
+ *
+ * The child/parent relationship set is lazy loaded to make things
+ * more efficient. But as the repository doesn't keep the session
+ * open, the lazy loading can't occur! So load manually.
+ *
+ * @param workspaceId
+ * @return Set of CrNodes that are child nodes of this node/version
+ */
+ public List findChildNodes(CrNodeVersion parentNodeVersion) {
+
+ if ( log.isDebugEnabled() )
+ log.debug("Getting all child nodes for "+parentNodeVersion);
+
+ String queryString = "from CrNode as n where n.parentNodeVersion = ?";
+ List nodes = getHibernateTemplate().find(queryString,parentNodeVersion);
+
+ if(nodes.size() == 0){
+ log.debug("No nodes found");
+ return null;
+ }else{
+ if ( log.isDebugEnabled() )
+ log.debug("Returning "+nodes.size()+" nodes.");
+ return nodes;
+ }
+ }
+
+
+ /** Get all child nodes for a node/version.
+ *
+ * The child/parent relationship set is lazy loaded to make things
+ * more efficient. But as the repository doesn't keep the session
+ * open, the lazy loading can't occur! So load manually.
+ *
+ * @param workspaceId
+ * @return Set of CrNodes that are child nodes of this node/version
+ */
+ public CrNode findChildNode(CrNodeVersion parentNodeVersion, String relPath) {
+
+ long start = System.currentTimeMillis();
+
+ if ( log.isDebugEnabled() )
+ log.debug("Getting child node from "+parentNodeVersion+" path "+relPath);
+
+
+ String queryString = "from CrNode as n where n.parentNodeVersion = ? and n.path = ? ";
+ List nodes = getHibernateTemplate().find(queryString,new Object[] {parentNodeVersion, relPath});
+
+ log.error("findChildNodeDBLookup"+(System.currentTimeMillis()-start));
+
+ if(nodes.size() == 0){
+ log.debug("No nodes found");
+ return null;
+ }else{
+ if ( nodes.size() == 0 ) {
+ log.error(nodes.size()+" matches found for "+parentNodeVersion+" path "+relPath);
+ }
+ return (CrNode) nodes.get(0);
+ }
+ }
+
}
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/WorkspaceDAO.java
===================================================================
diff -u -r09decccca1a4d871be5772d51638fa13aa928349 -rd3f488ff70266c8a676e11ee261b74b7a4c43d51
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/WorkspaceDAO.java (.../WorkspaceDAO.java) (revision 09decccca1a4d871be5772d51638fa13aa928349)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/dao/hibernate/WorkspaceDAO.java (.../WorkspaceDAO.java) (revision d3f488ff70266c8a676e11ee261b74b7a4c43d51)
@@ -57,14 +57,6 @@
* the necessary info when workspace is returned to the calling
* code.
*
- * In fact, doing getNodes() here still doesn't work - there isn't
- * a session! So as a hack, I'll look up the nodes directly.
- * Yuck. The only other solution I can find easily doing a google
- * search is using OpenSessionInViewInterceptor/OpenSessionInViewFilter
- * but they seem to be designed for using when the whole item is beind
- * passed to a webapp - and we don't necessarily have a webapp here.
- * Maybe I'm just missing something in HibernateDaoSupport!
- *
* @param workspaceId
* @return Set of CrNodes applicable to this workspace.
*/
Index: lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/Download.java
===================================================================
diff -u -r09decccca1a4d871be5772d51638fa13aa928349 -rd3f488ff70266c8a676e11ee261b74b7a4c43d51
--- lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/Download.java (.../Download.java) (revision 09decccca1a4d871be5772d51638fa13aa928349)
+++ lams_contentrepository/src/java/org/lamsfoundation/lams/contentrepository/struts/action/Download.java (.../Download.java) (revision d3f488ff70266c8a676e11ee261b74b7a4c43d51)
@@ -146,7 +146,7 @@
version = RepositoryDispatchAction.getLong(request.getParameter(RepositoryDispatchAction.VERSION_NAME));
IVersionedNode node = getFileItem(ticket, uuid, version,null);
- log.error(callId+" getFileItem1 (ms) "+(System.currentTimeMillis()-start));
+ log.error(callId+" getFileItem1 "+(System.currentTimeMillis()-start));
// update versionId in case it was null and we got the latest version...
version = node.getVersion();
@@ -194,8 +194,9 @@
if ( relPathString == null )
errorInContent(request, response, "Filename is missing. "+expectedFormat,null);
+ log.error(callId+" beforeGetFileItem2 "+(System.currentTimeMillis()-start));
IVersionedNode node = getFileItem(ticket, uuid, version, relPathString);
- log.error(callId+" getFileItem2 (ms) "+(System.currentTimeMillis()-start));
+ log.error(callId+" getFileItem2 "+(System.currentTimeMillis()-start));
if ( ! node.isNodeType(NodeType.FILENODE) ) {
errorInContent(request, response,"Unexpected type of node "
+node.getNodeType()+" Expected File node. Data is "+node,null);
@@ -204,7 +205,7 @@
}
- log.error(callId+" handleFileNode (ms) "+(System.currentTimeMillis()-start));
+ log.error(callId+" handleFileNode "+(System.currentTimeMillis()-start));
}