jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1506551 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: SessionImpl.java WorkspaceImpl.java xml/ImportHandler.java xml/ImporterImpl.java
Date Wed, 24 Jul 2013 13:45:45 GMT
Author: angela
Date: Wed Jul 24 13:45:45 2013
New Revision: 1506551

URL: http://svn.apache.org/r1506551
Log:
OAK-773 : Workspace Import 

- simplify import code
- abort workspace import if the editing session has pending changes

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1506551&r1=1506550&r2=1506551&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Wed Jul 24 13:45:45 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -65,6 +63,8 @@ import org.slf4j.LoggerFactory;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
+import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
+
 /**
  * TODO document
  */
@@ -100,6 +100,7 @@ public class SessionImpl implements Jack
         protected void checkPreconditions() throws RepositoryException {
             sd.checkAlive();
         }
+
         @Override
         public boolean isUpdate() {
             return true;
@@ -144,7 +145,7 @@ public class SessionImpl implements Jack
      *
      * @param absPath An absolute path.
      * @return the specified {@code Node} or {@code null}.
-     * @throws RepositoryException   If another error occurs.
+     * @throws RepositoryException If another error occurs.
      */
     @CheckForNull
     public Node getNodeOrNull(final String absPath) throws RepositoryException {
@@ -162,7 +163,7 @@ public class SessionImpl implements Jack
      *
      * @param absPath An absolute path.
      * @return the specified {@code Property} or {@code null}.
-     * @throws RepositoryException   if another error occurs.
+     * @throws RepositoryException if another error occurs.
      */
     @CheckForNull
     public Property getPropertyOrNull(final String absPath) throws RepositoryException {
@@ -191,7 +192,7 @@ public class SessionImpl implements Jack
      *
      * @param absPath An absolute path.
      * @return the specified {@code Item} or {@code null}.
-     * @throws RepositoryException   if another error occurs.
+     * @throws RepositoryException if another error occurs.
      */
     @CheckForNull
     public Item getItemOrNull(final String absPath) throws RepositoryException {
@@ -428,7 +429,7 @@ public class SessionImpl implements Jack
     @Nonnull
     public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior)
             throws RepositoryException {
-        return new ImportHandler(parentAbsPath, sessionContext, sd.getRoot(), uuidBehavior,
false);
+        return new ImportHandler(parentAbsPath, sessionContext, uuidBehavior, false);
     }
 
     @Override
@@ -449,7 +450,10 @@ public class SessionImpl implements Jack
         } finally {
             // JCR-2903
             if (in != null) {
-                try { in.close(); } catch (IOException ignore) {}
+                try {
+                    in.close();
+                } catch (IOException ignore) {
+                }
             }
         }
     }
@@ -457,9 +461,9 @@ public class SessionImpl implements Jack
     /**
      * Exports content at the given path using the given exporter.
      *
-     * @param path of the node to be exported
+     * @param path     of the node to be exported
      * @param exporter document or system view exporter
-     * @throws SAXException if the SAX event handler failed
+     * @throws SAXException        if the SAX event handler failed
      * @throws RepositoryException if another error occurs
      */
     private synchronized void export(String path, Exporter exporter)
@@ -498,7 +502,7 @@ public class SessionImpl implements Jack
 
     @Override
     public void exportDocumentView(String absPath, ContentHandler contentHandler, boolean
skipBinary,
-            boolean noRecurse) throws SAXException, RepositoryException {
+                                   boolean noRecurse) throws SAXException, RepositoryException
{
         export(absPath, new DocumentViewExporter(this, contentHandler, !noRecurse, !skipBinary));
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1506551&r1=1506550&r2=1506551&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Wed Jul 24 13:45:45 2013
@@ -243,8 +243,7 @@ public class WorkspaceImpl implements Ja
     public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior)
throws RepositoryException {
         ensureIsAlive();
 
-        Root writeRoot = sessionContext.getSessionDelegate().getContentSession().getLatestRoot();
-        return new ImportHandler(parentAbsPath, sessionContext, writeRoot, uuidBehavior,
true);
+        return new ImportHandler(parentAbsPath, sessionContext, uuidBehavior, true);
     }
 
     @Override
@@ -268,7 +267,10 @@ public class WorkspaceImpl implements Ja
         } finally {
             // JCR-2903
             if (in != null) {
-                try { in.close(); } catch (IOException ignore) {}
+                try {
+                    in.close();
+                } catch (IOException ignore) {
+                }
             }
         }
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java?rev=1506551&r1=1506550&r2=1506551&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
Wed Jul 24 13:45:45 2013
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.commons.Nam
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.jcr.SessionContext;
+import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,7 +58,6 @@ public class ImportHandler extends Defau
     private final SessionContext sessionContext;
     private final Importer importer;
     private final NamespaceHelper helper;
-    private final ValueFactory valueFactory;
     private final boolean isWorkspaceImport;
 
     protected Locator locator;
@@ -65,14 +65,14 @@ public class ImportHandler extends Defau
     private final Map<String, String> tempPrefixMap = new HashMap<String, String>();
 
     public ImportHandler(String absPath, SessionContext sessionContext,
-                         Root root, int uuidBehavior, boolean isWorkspaceImport)
-            throws RepositoryException {
-        this.root = root;
+                         int uuidBehavior, boolean isWorkspaceImport) throws RepositoryException
{
         this.sessionContext = sessionContext;
-        this.helper = new NamespaceHelper(sessionContext.getSession());
-        this.importer = new ImporterImpl(absPath, sessionContext, root, uuidBehavior, isWorkspaceImport);
-        this.valueFactory = sessionContext.getValueFactory();
         this.isWorkspaceImport = isWorkspaceImport;
+
+        SessionDelegate sd = sessionContext.getSessionDelegate();
+        root = (isWorkspaceImport) ? sd.getContentSession().getLatestRoot() : sd.getRoot();
+        helper = new NamespaceHelper(sessionContext.getSession());
+        importer = new ImporterImpl(absPath, sessionContext, root, uuidBehavior, isWorkspaceImport);
     }
 
     //---------------------------------------------------------< ErrorHandler >
@@ -162,10 +162,11 @@ public class ImportHandler extends Defau
         if (targetHandler == null) {
             // the namespace of the first element determines the type of XML
             // (system view/document view)
+            ValueFactory vf = sessionContext.getValueFactory();
             if (NamespaceConstants.NAMESPACE_SV.equals(namespaceURI)) {
-                targetHandler = new SysViewImportHandler(importer, valueFactory, helper);
+                targetHandler = new SysViewImportHandler(importer, vf, helper);
             } else {
-                targetHandler = new DocViewImportHandler(importer, valueFactory, helper);
+                targetHandler = new DocViewImportHandler(importer, vf, helper);
             }
 
             targetHandler.startDocument();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?rev=1506551&r1=1506550&r2=1506551&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
Wed Jul 24 13:45:45 2013
@@ -105,12 +105,17 @@ public class ImporterImpl implements Imp
         if (oakPath == null) {
             throw new RepositoryException("Invalid name or path: " + absPath);
         }
+
+        if (isWorkspaceImport && sessionContext.getSessionDelegate().hasPendingChanges())
{
+            throw new RepositoryException("Pending changes on session. Cannot run workspace
import.");
+        }
+
         importTargetTree = root.getTree(absPath);
         if (!importTargetTree.exists()) {
             throw new PathNotFoundException(absPath);
         }
 
-        VersionManager vMgr =  sessionContext.getVersionManager();
+        VersionManager vMgr = sessionContext.getVersionManager();
         if (!vMgr.isCheckedOut(absPath)) {
             throw new VersionException("Target node is checked in.");
         }
@@ -142,7 +147,7 @@ public class ImporterImpl implements Imp
         }
     }
 
-    protected Tree createTree(@Nonnull Tree parent, @Nonnull NodeInfo nInfo, @CheckForNull
String uuid) throws RepositoryException {
+    private Tree createTree(@Nonnull Tree parent, @Nonnull NodeInfo nInfo, @CheckForNull
String uuid) throws RepositoryException {
         String ntName = nInfo.getPrimaryTypeName();
         String value = (ntName != null) ? ntName : TreeUtil.getDefaultChildType(ntTypesRoot,
parent, nInfo.getName());
         Tree child = TreeUtil.addChild(parent, nInfo.getName(), value, ntTypesRoot, userID);
@@ -158,8 +163,7 @@ public class ImporterImpl implements Imp
         return child;
     }
 
-    protected void
-    createProperty(Tree tree, PropInfo pInfo, PropertyDefinition def) throws RepositoryException
{
+    private void createProperty(Tree tree, PropInfo pInfo, PropertyDefinition def) throws
RepositoryException {
         List<Value> values = pInfo.getValues(pInfo.getTargetType(def));
         PropertyState propertyState;
         String name = pInfo.getName();
@@ -176,10 +180,9 @@ public class ImporterImpl implements Imp
         }
     }
 
-    protected Tree resolveUUIDConflict(Tree parent,
-                                       String conflictingId,
-                                       NodeInfo nodeInfo)
-            throws RepositoryException {
+    private Tree resolveUUIDConflict(Tree parent,
+                                     String conflictingId,
+                                     NodeInfo nodeInfo) throws RepositoryException {
         Tree tree;
         Tree conflicting = idManager.getTree(conflictingId);
         if (conflicting != null && !conflicting.exists()) {



Mime
View raw message