Clean session management.
authorBruno Sinou <bsinou@argeo.org>
Wed, 19 Mar 2014 13:27:39 +0000 (13:27 +0000)
committerBruno Sinou <bsinou@argeo.org>
Wed, 19 Mar 2014 13:27:39 +0000 (13:27 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6897 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/core/AbstractJcrRepoManager.java

index 1e1265a1d3a1b2a962527f71a62db83689c48afe..d70d904f9bfdaf5028b6c6fed1f46018defdca53 100644 (file)
@@ -74,10 +74,10 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
        private Keyring keyring;
        private Repository repository;
 
+       // RElevant default node indexers 
        private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
        private JarFileIndexer jarFileIndexer = new JarFileIndexer();
        private DistributionBundleIndexer distBundleIndexer = new DistributionBundleIndexer();
-
        private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer(
                        artifactIndexer, jarFileIndexer);
 
@@ -195,7 +195,7 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                                        if (node.getSession().hasPendingChanges()) {
                                                                node.getSession().save();
                                                                if (log.isDebugEnabled())
-                                                                       log.debug("Processed artifact "
+                                                                       log.debug("Processed jar artifact "
                                                                                        + node.getPath());
                                                        }
                                                        monitor.worked(1);
@@ -205,7 +205,7 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames {
                                        if (node.getSession().hasPendingChanges()) {
                                                node.getSession().save();
                                                if (log.isDebugEnabled())
-                                                       log.debug("Processed artifact " + node.getPath());
+                                                       log.debug("Processed pom artifact " + node.getPath());
                                        }
                                        monitor.worked(1);
                                } else {
index fab28ff379e54974ea3dc6fd1b33c96a9657e6bf..54fdf107054c38aa083b3d760d3f479c93733dc5 100644 (file)
@@ -16,8 +16,8 @@ import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 
 /**
- * Abstract the base a given modular distribution set that is the parent all
- * versions of the same distribution
+ * Abstract the base of a given modular distribution set i.e. the parent of all
+ * versions of a given modular distribution
  */
 public class ModularDistBaseElem extends DistParentElem {
 
@@ -25,31 +25,31 @@ public class ModularDistBaseElem extends DistParentElem {
        final static public String AETHER_BINARIES_TYPE = "binaries";
        final static public String AETHER_DEP_TYPE = "dep";
        private String type;
-       private Node artifactBase;
+       private Node modularDistBase;
 
        public ModularDistBaseElem(WorkspaceElem wkspElem, String name,
-                       Node artifactBase, String type) {
+                       Node modularDistBase, String type) {
                super(name, wkspElem.inHome(), wkspElem.isReadOnly());
                setParent(wkspElem);
-               this.artifactBase = artifactBase;
+               this.modularDistBase = modularDistBase;
                this.type = type;
        }
 
        public Node getCategoryBase() {
                // TODO clean this
                if (type.equals(AETHER_CATEGORY_BASE))
-                       return artifactBase;
+                       return modularDistBase;
                else
                        try {
-                               return artifactBase.getParent();
+                               return modularDistBase.getParent();
                        } catch (RepositoryException e) {
                                throw new SlcException("unable tyo get parent node for "
-                                               + artifactBase, e);
+                                               + modularDistBase, e);
                        }
        }
 
        /**
-        * Override normal behavior to initialize children only when first requested
+        * Override normal behaviour to initialise children only when first requested
         */
        @Override
        public synchronized boolean hasChildren() {
@@ -61,14 +61,13 @@ public class ModularDistBaseElem extends DistParentElem {
        };
 
        /**
-        * Override normal behavior to initialize children only when first requested
+        * Override normal behaviour to initialise children only when first requested
         */
        @Override
        public synchronized Object[] getChildren() {
                if (isLoaded()) {
                        return super.getChildren();
                } else {
-                       // initialize current object
                        try {
                                NodeIterator ni = getDistVersions();
                                while (ni != null && ni.hasNext()) {
@@ -80,8 +79,8 @@ public class ModularDistBaseElem extends DistParentElem {
                                return super.getChildren();
                        } catch (RepositoryException re) {
                                throw new ArgeoException(
-                                               "Unexcpected error while initializing children SingleJcrNode",
-                                               re);
+                                               "Unable to retrieve children for "
+                                                               + modularDistBase, re);
                        }
                }
        }
@@ -91,14 +90,14 @@ public class ModularDistBaseElem extends DistParentElem {
                        if (AETHER_CATEGORY_BASE.equals(type))
                                return null;
 
-                       QueryManager queryManager = artifactBase.getSession()
+                       QueryManager queryManager = modularDistBase.getSession()
                                        .getWorkspace().getQueryManager();
                        QueryObjectModelFactory factory = queryManager.getQOMFactory();
                        Selector source = factory.selector(
                                        SlcTypes.SLC_MODULAR_DISTRIBUTION,
                                        SlcTypes.SLC_MODULAR_DISTRIBUTION);
                        Constraint constraint = factory.descendantNode(
-                                       source.getSelectorName(), artifactBase.getPath());
+                                       source.getSelectorName(), modularDistBase.getPath());
                        // Ordering order = factory.descending(factory.propertyValue(
                        // source.getSelectorName(), SlcNames.SLC_ARTIFACT_VERSION));
                        // Ordering[] orderings = { order };
index 7eb57a2d4e747608e62a7a275c677284b0de41fd..4bdda83cf6eb02e2da4460e8ded1c1540581cd2a 100644 (file)
@@ -76,8 +76,9 @@ abstract class AbstractJcrRepoManager {
        }
 
        protected void workspaceInit(String workspaceName) {
+               Session workspaceAdminSession = null;
                try {
-                       Session workspaceAdminSession = jcrRepository.login(workspaceName);
+                       workspaceAdminSession = jcrRepository.login(workspaceName);
                        workspaceSessions.put(workspaceName, adminSession);
                        JcrUtils.addPrivilege(workspaceAdminSession, "/",
                                        SlcConstants.ROLE_SLC, "jcr:all");
@@ -86,6 +87,8 @@ abstract class AbstractJcrRepoManager {
                        workspaceIndexers.put(workspaceName, workspaceIndexer);
                } catch (RepositoryException e) {
                        log.error("Cannot initialize workspace " + workspaceName, e);
+               } finally {
+                       JcrUtils.logoutQuietly(workspaceAdminSession);
                }
        }
 
@@ -100,5 +103,4 @@ abstract class AbstractJcrRepoManager {
        public void setSecurityWorkspace(String securityWorkspace) {
                this.securityWorkspace = securityWorkspace;
        }
-
-}
+}
\ No newline at end of file