jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r157330 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: NodeImpl.java WorkspaceImpl.java xml/SessionImporter.java
Date Sun, 13 Mar 2005 13:23:27 GMT
Author: stefan
Date: Sun Mar 13 05:23:25 2005
New Revision: 157330

URL: http://svn.apache.org/viewcvs?view=rev&rev=157330
Log:
forgot to close temporary session on other workspace

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java?view=diff&r1=157329&r2=157330
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java Sun Mar 13
05:23:25 2005
@@ -2586,51 +2586,58 @@
         // check state of this instance
         sanityCheck();
 
-        // create session on other workspace for current subject
-        // (may throw NoSuchWorkspaceException and AccessDeniedException)
-        SessionImpl srcSession =
-                rep.createSession(session.getSubject(), workspaceName);
-
-        // search nearest ancestor that is referenceable
-        NodeImpl m1 = this;
-        while (m1.getDepth() != 0 && !m1.isNodeType(MIX_REFERENCEABLE)) {
-            m1 = (NodeImpl) m1.getParent();
-        }
+        SessionImpl srcSession = null;
+        try {
+            // create session on other workspace for current subject
+            // (may throw NoSuchWorkspaceException and AccessDeniedException)
+            srcSession = rep.createSession(session.getSubject(), workspaceName);
+
+            // search nearest ancestor that is referenceable
+            NodeImpl m1 = this;
+            while (m1.getDepth() != 0 && !m1.isNodeType(MIX_REFERENCEABLE)) {
+                m1 = (NodeImpl) m1.getParent();
+            }
 
-        // if root is common ancestor, corresponding path is same as ours
-        if (m1.getDepth() == 0) {
-            // check existence
-            if (!srcSession.getItemManager().itemExists(getPrimaryPath())) {
-                throw new ItemNotFoundException(safeGetJCRPath());
-            } else {
-                return getPath();
+            // if root is common ancestor, corresponding path is same as ours
+            if (m1.getDepth() == 0) {
+                // check existence
+                if (!srcSession.getItemManager().itemExists(getPrimaryPath())) {
+                    throw new ItemNotFoundException(safeGetJCRPath());
+                } else {
+                    return getPath();
+                }
             }
-        }
 
-        // get corresponding ancestor
-        Node m2 = srcSession.getNodeByUUID(m1.getUUID());
+            // get corresponding ancestor
+            Node m2 = srcSession.getNodeByUUID(m1.getUUID());
 
-        // return path of m2, if m1 == n1
-        if (m1 == this) {
-            return m2.getPath();
-        }
+            // return path of m2, if m1 == n1
+            if (m1 == this) {
+                return m2.getPath();
+            }
 
-        String relPath;
-        try {
-            Path p = m1.getPrimaryPath().computeRelativePath(getPrimaryPath());
-            // use prefix mappings of srcSession
-            relPath = p.toJCRPath(srcSession.getNamespaceResolver());
-        } catch (BaseException be) {
-            // should never get here...
-            String msg = "internal error: failed to determine relative path";
-            log.error(msg, be);
-            throw new RepositoryException(msg, be);
-        }
+            String relPath;
+            try {
+                Path p = m1.getPrimaryPath().computeRelativePath(getPrimaryPath());
+                // use prefix mappings of srcSession
+                relPath = p.toJCRPath(srcSession.getNamespaceResolver());
+            } catch (BaseException be) {
+                // should never get here...
+                String msg = "internal error: failed to determine relative path";
+                log.error(msg, be);
+                throw new RepositoryException(msg, be);
+            }
 
-        if (!m2.hasNode(relPath)) {
-            throw new ItemNotFoundException();
-        } else {
-            return m2.getNode(relPath).getPath();
+            if (!m2.hasNode(relPath)) {
+                throw new ItemNotFoundException();
+            } else {
+                return m2.getNode(relPath).getPath();
+            }
+        } finally {
+            if (srcSession != null) {
+                // we don't need the other session anymore, logout
+                srcSession.logout();
+            }
         }
     }
 
@@ -2743,36 +2750,43 @@
         // check lock status
         checkLock();
 
-        // create session on other workspace for current subject
-        // (may throw NoSuchWorkspaceException and AccessDeniedException)
-        SessionImpl srcSession =
-                rep.createSession(session.getSubject(), srcWorkspaceName);
+        SessionImpl srcSession = null;
+        try {
+            // create session on other workspace for current subject
+            // (may throw NoSuchWorkspaceException and AccessDeniedException)
+            srcSession = rep.createSession(session.getSubject(), srcWorkspaceName);
+
+            NodeImpl srcNode = getCorrespondingNode(srcSession);
+            if (srcNode == null) {
+                /*
+                 * If this node does not have a corresponding node in the workspace
+                 * <code>srcWorkspaceName</code>, then the <code>update</code>
method
+                 * has no effect (it does not traverse down the subtree).
+                */
+                return;
+            }
 
-        NodeImpl srcNode = getCorrespondingNode(srcSession);
-        if (srcNode == null) {
             /*
-             * If this node does not have a corresponding node in the workspace
-             * <code>srcWorkspaceName</code>, then the <code>update</code>
method
-             * has no effect (it does not traverse down the subtree).
-            */
-            return;
-        }
-
-        /*
-         * If this node does have a corresponding node in the workspace <code>srcWorkspaceName</code>,
-         * then this method traverses down the subtree rooted at this node and
-         * replaces the state of each node in the subtree rooted at this node with that
-         * of its corresponding node in the specified source workspace.
-         */
-        boolean removeExisting = false;
-        boolean replaceExisting = true;
-        try {
-            internalUpdate(srcNode, removeExisting, replaceExisting);
-        } catch (RepositoryException e) {
-            session.refresh(false);
-            throw e;
+             * If this node does have a corresponding node in the workspace <code>srcWorkspaceName</code>,
+             * then this method traverses down the subtree rooted at this node and
+             * replaces the state of each node in the subtree rooted at this node with that
+             * of its corresponding node in the specified source workspace.
+             */
+            boolean removeExisting = false;
+            boolean replaceExisting = true;
+            try {
+                internalUpdate(srcNode, removeExisting, replaceExisting);
+            } catch (RepositoryException e) {
+                session.refresh(false);
+                throw e;
+            }
+            session.save();
+        } finally {
+            if (srcSession != null) {
+                // we don't need the other session anymore, logout
+                srcSession.logout();
+            }
         }
-        session.save();
     }
 
     /**
@@ -2800,62 +2814,69 @@
         // check lock status
         checkLock();
 
-        // create session on other workspace for current subject
-        // (may throw NoSuchWorkspaceException and AccessDeniedException)
-        SessionImpl srcSession =
-                rep.createSession(session.getSubject(), srcWorkspace);
-
-        NodeImpl srcNode = doMergeTest(srcSession, bestEffort);
-        if (srcNode != null) {
-            // remove properties
-            PropertyIterator pi = getProperties();
-            while (pi.hasNext()) {
-                Property p = pi.nextProperty();
-                if (!srcNode.hasProperty(p.getName())) {
-                    p.setValue((Value) null);
+        SessionImpl srcSession = null;
+        try {
+            // create session on other workspace for current subject
+            // (may throw NoSuchWorkspaceException and AccessDeniedException)
+            srcSession = rep.createSession(session.getSubject(), srcWorkspace);
+
+            NodeImpl srcNode = doMergeTest(srcSession, bestEffort);
+            if (srcNode != null) {
+                // remove properties
+                PropertyIterator pi = getProperties();
+                while (pi.hasNext()) {
+                    Property p = pi.nextProperty();
+                    if (!srcNode.hasProperty(p.getName())) {
+                        p.setValue((Value) null);
+                    }
                 }
-            }
-            // copy properties
-            pi = srcNode.getProperties();
-            while (pi.hasNext()) {
-                PropertyImpl p = (PropertyImpl) pi.nextProperty();
-                internalCopyPropertyFrom(p);
-            }
-
-            // remove subnodes
-            NodeIterator ni = getNodes();
-            while (ni.hasNext()) {
-                // if the subnode does not exist in the src, and this is update,
-                // so delete here as well?
-                Node n = ni.nextNode();
-                if (!srcNode.hasNode(n.getName())) {
-                    // todo: how does this work for same name siblings?
-                    n.remove();
+                // copy properties
+                pi = srcNode.getProperties();
+                while (pi.hasNext()) {
+                    PropertyImpl p = (PropertyImpl) pi.nextProperty();
+                    internalCopyPropertyFrom(p);
                 }
-            }
-            // 'clone' nodes that do not exist
-            ni = srcNode.getNodes();
-            while (ni.hasNext()) {
-                Node n = ni.nextNode();
-                if (!hasNode(n.getName())) {
-                    // todo: probably need some internal stuff
-                    // todo: how does this work for same name siblings?
-                    // todo: since clone is a ws operation, 'save' does not work later
-                    session.getWorkspace().clone(srcWorkspace, n.getPath(), getPath() + "/"
+ n.getName(), true);
-                } else {
-                    // do recursive merge
-                    n.merge(srcWorkspace, bestEffort);
+
+                // remove subnodes
+                NodeIterator ni = getNodes();
+                while (ni.hasNext()) {
+                    // if the subnode does not exist in the src, and this is update,
+                    // so delete here as well?
+                    Node n = ni.nextNode();
+                    if (!srcNode.hasNode(n.getName())) {
+                        // todo: how does this work for same name siblings?
+                        n.remove();
+                    }
+                }
+                // 'clone' nodes that do not exist
+                ni = srcNode.getNodes();
+                while (ni.hasNext()) {
+                    Node n = ni.nextNode();
+                    if (!hasNode(n.getName())) {
+                        // todo: probably need some internal stuff
+                        // todo: how does this work for same name siblings?
+                        // todo: since clone is a ws operation, 'save' does not work later
+                        session.getWorkspace().clone(srcWorkspace, n.getPath(), getPath()
+ "/" + n.getName(), true);
+                    } else {
+                        // do recursive merge
+                        n.merge(srcWorkspace, bestEffort);
+                    }
+                }
+            } else {
+                // do not change this node, but recuse merge
+                NodeIterator ni = srcNode.getNodes();
+                while (ni.hasNext()) {
+                    ni.nextNode().merge(srcWorkspace, bestEffort);
                 }
             }
-        } else {
-            // do not change this node, but recuse merge
-            NodeIterator ni = srcNode.getNodes();
-            while (ni.hasNext()) {
-                ni.nextNode().merge(srcWorkspace, bestEffort);
+
+            save();
+        } finally {
+            if (srcSession != null) {
+                // we don't need the other session anymore, logout
+                srcSession.logout();
             }
         }
-
-        save();
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java?view=diff&r1=157329&r2=157330
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java Sun
Mar 13 05:23:25 2005
@@ -796,14 +796,21 @@
         // clone (i.e. pull) subtree at srcAbsPath from srcWorkspace
         // to 'this' workspace at destAbsPath
 
-        // create session on other workspace for current subject
-        // (may throw NoSuchWorkspaceException and AccessDeniedException)
-        SessionImpl srcSession =
-                rep.createSession(session.getSubject(), srcWorkspace);
-        WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace();
-
-        // do cross-workspace copy
-        internalCopy(srcAbsPath, srcWsp, destAbsPath, true);
+        SessionImpl srcSession = null;
+        try {
+            // create session on other workspace for current subject
+            // (may throw NoSuchWorkspaceException and AccessDeniedException)
+            srcSession = rep.createSession(session.getSubject(), srcWorkspace);
+            WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace();
+
+            // do cross-workspace copy
+            internalCopy(srcAbsPath, srcWsp, destAbsPath, true);
+        } finally {
+            if (srcSession != null) {
+                // we don't need the other session anymore, logout
+                srcSession.logout();
+            }
+        }
     }
 
     /**
@@ -847,14 +854,21 @@
         // copy (i.e. pull) subtree at srcAbsPath from srcWorkspace
         // to 'this' workspace at destAbsPath
 
-        // create session on other workspace for current subject
-        // (may throw NoSuchWorkspaceException and AccessDeniedException)
-        SessionImpl srcSession =
-                rep.createSession(session.getSubject(), srcWorkspace);
-        WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace();
-
-        // do cross-workspace copy
-        internalCopy(srcAbsPath, srcWsp, destAbsPath, false);
+        SessionImpl srcSession = null;
+        try {
+            // create session on other workspace for current subject
+            // (may throw NoSuchWorkspaceException and AccessDeniedException)
+            srcSession = rep.createSession(session.getSubject(), srcWorkspace);
+            WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace();
+
+            // do cross-workspace copy
+            internalCopy(srcAbsPath, srcWsp, destAbsPath, false);
+        } finally {
+            if (srcSession != null) {
+                // we don't need the other session anymore, logout
+                srcSession.logout();
+            }
+        }
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java?view=diff&r1=157329&r2=157330
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
Sun Mar 13 05:23:25 2005
@@ -162,6 +162,9 @@
         QName nodeName = nodeInfo.getName();
         QName ntName = nodeInfo.getNodeTypeName();
         QName[] mixins = nodeInfo.getMixinNames();
+
+        // @todo check for auto-created node (JIRA issue JCR-31)
+        
         if (uuid == null) {
             // no potential uuid conflict, always add new node
             node = createNode(parent, nodeName, ntName, mixins, null);



Mime
View raw message