/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.core.session;

import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.apache.jackrabbit.core.id.NodeId;

/**
 * Operation to persist transient changes in a session.
 */
public class SessionSaveOperation implements SessionWriteOperation<Object> {

    /**
     * Persists transient changes by delegating to the save() method of the
     * root node (or the parent of transient changes if access to the root
     * node is not available to this session).
     */
    public Object perform(SessionContext context) throws RepositoryException {
        NodeId id;
        // JCR-2425: check whether session is allowed to read root node
        if (context.getSessionImpl().hasPermission("/", Session.ACTION_READ)) {
            id = context.getRootNodeId();
        } else {
            id = context.getItemStateManager().getIdOfRootTransientNodeState();
        }
        context.getItemManager().getItem(id).save();
        return this;
    }

    //--------------------------------------------------------------< Object >

    /**
     * Returns a string representation of this operation.
     */
    public String toString() {
        return "session.save()";
    }

}
@@ -944,17 +944,118 @@
 ore.
-id.NodeId
+ItemImpl;%0Aimport org.apache.jackrabbit.core.id.NodeId;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
 ;%0A%0A/
@@ -1195,16 +1195,219 @@
 ect%3E %7B%0A%0A
+    private static final Logger LOG = LoggerFactory.getLogger(SessionSaveOperation.class);%0A    private static final boolean LOG_WITH_STACKTRACE = Boolean.getBoolean(%22org.jackrabbit.logWithStackTrace%22);%0A%0A
     /**%0A
@@ -1921,16 +1921,16 @@
  else %7B%0A
-
         
@@ -2011,16 +2011,466 @@
       %7D%0A
+        if (LOG.isDebugEnabled()) %7B%0A            NodeId transientRoot = context.getItemStateManager().getIdOfRootTransientNodeState();%0A            ItemImpl item = context.getItemManager().getItem(transientRoot);%0A            if (LOG_WITH_STACKTRACE) %7B%0A                LOG.debug(%22Saving changes under %22 + item.getPath(), new Exception());%0A            %7D else %7B%0A                LOG.debug(%22Saving changes under %22 + item.getPath());%0A            %7D%0A        %7D%0A
         

Improve logging of Session.save() to trace back root cause of externally modified nodes