}
private WorkspaceNode getOrCreateWorkspaceNode(Fqn fqn, TransactionWorkspace workspace, boolean undeleteIfNecessary)
{
if (log.isTraceEnabled()) log.trace("Attempting to get node " + fqn + " into the workspace");
WorkspaceNode workspaceNode = workspace.getNode(fqn);
// if we do not have the node then we need to add it to the workspace
if (workspaceNode == null)
{
DataNode node = cache.peek(fqn);
if (node == null)
{
return null; // seems to happen quite a bit
}
workspaceNode = NodeFactory.getInstance().createWorkspaceNode(node, workspace);
workspace.addNode(workspaceNode);
}
// the node has been deleted dude!
if (workspaceNode.isDeleted())
{
if (log.isDebugEnabled()) log.debug("Node " + fqn + " has been deleted in the workspace.");
if (undeleteIfNecessary)
{
workspaceNode.markAsDeleted(false);
// re-add to parent
WorkspaceNode parent = getOrCreateWorkspaceNode(fqn.getParent(), workspace, true);
parent.addChild(workspaceNode);
}
else
{
workspaceNode = null;
}