if (debug) log.debug("GlobalTransaction: " + gtx + "; Root: " + workspaceNode);
// we do not have the root in the workspace! Put it into thr workspace now.
if (workspaceNode == null)
{
NodeSPI node = dataContainer.getRoot();
workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, node, workspace, gtx, lockAcquisitionTimeout);
workspace.addNode(workspaceNode);
log.debug("Created root node in workspace.");
}
else
{
log.debug("Found root node in workspace.");
}
// iterate through the target Fqn's elements.
int targetFqnSize = targetFqn.size(), currentDepth = 1;
for (Object childName : targetFqn.peekElements())
{
boolean isTargetFqn = (currentDepth == targetFqnSize);
currentDepth++;
// current workspace node canot be null.
// try and get the child of current node
if (debug) log.debug("Attempting to get child " + childName);
NodeSPI currentNode = workspaceNode.getNode().getChildDirect(childName);
if (currentNode == null)
{
// first test that it exists in the workspace and has been created in thix tx!
WorkspaceNode peekInWorkspace = workspace.getNode(Fqn.fromRelativeElements(workspaceNode.getFqn(), childName));
if (peekInWorkspace != null && peekInWorkspace.isCreated())
{
// exists in workspace and has just been created.
currentNode = peekInWorkspace.getNode();
if (peekInWorkspace.isRemoved())
{
peekInWorkspace.setRemoved(false);
// add in parent again
workspaceNode.addChild(peekInWorkspace);
}
}
}
if (currentNode == null)
{
// no child exists with this name; create it in the underlying data structure and then add it to the workspace.
if (trace) log.trace("Creating new child, since it doesn't exist in the cache.");
// we put the parent node into the workspace as we are changing its children.
// at this point "workspaceNode" refers to the parent of the current node. It should never be null if
// you got this far!
if (workspaceNode.isRemoved())
{
//add a new one or overwrite an existing one that has been deleted
if (trace)
log.trace("Parent node doesn't exist in workspace or has been deleted. Adding to workspace.");
workspace.addNode(workspaceNode);
if (!(workspaceNode.getVersion() instanceof DefaultDataVersion))
workspaceNode.setVersioningImplicit(false);
}
else
{
if (trace) log.trace("Parent node exists: " + workspaceNode);
}
// get the version passed in, if we need to use explicit versioning.
DataVersion versionToPassIn = null;
if (isTargetFqn && !workspace.isVersioningImplicit()) versionToPassIn = version;
NodeSPI newUnderlyingChildNode = workspaceNode.createChild(childName, workspaceNode.getNode(), cache, versionToPassIn);
// now assign "workspaceNode" to the new child created.
workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, newUnderlyingChildNode, workspace, gtx, lockAcquisitionTimeout);
workspaceNode.setVersioningImplicit(versionToPassIn == null || !isTargetFqn);
if (trace)