jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r985273 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ state/ version/
Date Fri, 13 Aug 2010 16:36:57 GMT
Author: jukka
Date: Fri Aug 13 16:36:56 2010
New Revision: 985273

URL: http://svn.apache.org/viewvc?rev=985273&view=rev
Log:
JCR-890: concurrent read-only access to a session

Inline NodeTypeInstanceHandler into NodeState to avoid the extra instance variable in SessionImpl

Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeTypeInstanceHandler.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=985273&r1=985272&r2=985273&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
Fri Aug 13 16:36:56 2010
@@ -1255,13 +1255,7 @@ public class BatchedItemOperations exten
         prop.setMultiValued(def.isMultiple());
 
         // compute system generated values if necessary
-        InternalValue[] genValues = session.getNodeTypeInstanceHandler()
-                .computeSystemGeneratedPropertyValues(parent, def);
-        if (genValues != null) {
-            prop.setValues(genValues);
-        } else if (def.getDefaultValues() != null) {
-            prop.setValues(InternalValue.create(def.getDefaultValues()));
-        }
+        prop.setDefaultValues(parent, def, session.getUserID());
 
         // now add new property entry to parent
         parent.addPropertyName(propName);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=985273&r1=985272&r2=985273&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Fri Aug 13 16:36:56 2010
@@ -471,15 +471,8 @@ public class NodeImpl extends ItemImpl i
             propState.setType(type);
             propState.setMultiValued(propDef.isMultiple());
             // compute system generated values if necessary
-            InternalValue[] genValues =
-                sessionContext.getSessionImpl().getNodeTypeInstanceHandler()
-                .computeSystemGeneratedPropertyValues(data.getNodeState(), propDef);
-            if (genValues == null) {
-                genValues = InternalValue.create(propDef.getDefaultValues());
-            }
-            if (genValues != null) {
-                propState.setValues(genValues);
-            }
+            propState.setDefaultValues(
+                    data.getNodeState(), propDef, getSession().getUserID());
         } catch (ItemStateException ise) {
             String msg = "failed to add property " + name + " to " + this;
             log.debug(msg);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=985273&r1=985272&r2=985273&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Fri Aug 13 16:36:56 2010
@@ -174,11 +174,6 @@ public class SessionImpl extends Abstrac
     protected final InternalVersionManager versionMgr;
 
     /**
-     * node type instance handler
-     */
-    protected final NodeTypeInstanceHandler ntInstanceHandler;
-
-    /**
      * Listeners (weak references)
      */
     protected final Map<SessionListener, SessionListener> listeners =
@@ -253,7 +248,6 @@ public class SessionImpl extends Abstrac
                 createObservationManager(wspConfig.getName()));
 
         versionMgr = createVersionManager();
-        ntInstanceHandler = new NodeTypeInstanceHandler(userId);
     }
 
     /**
@@ -459,14 +453,6 @@ public class SessionImpl extends Abstrac
     }
 
     /**
-     * Returns the node type instance handler for this session
-     * @return the node type instance handler.
-     */
-    public NodeTypeInstanceHandler getNodeTypeInstanceHandler() {
-        return ntInstanceHandler;
-    }
-
-    /**
      * Sets the named attribute. If the value is <code>null</code>, then
      * the named attribute is removed.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java?rev=985273&r1=985272&r2=985273&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeState.java
Fri Aug 13 16:36:56 2010
@@ -18,15 +18,21 @@ package org.apache.jackrabbit.core.state
 
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.jcr.RepositoryException;
+
 /**
  * <code>NodeState</code> represents the state of a <code>Node</code>.
  */
@@ -862,6 +868,70 @@ public class NodeState extends ItemState
     //-------------------------------------------------< misc. helper methods >
 
     /**
+     * Computes the values of well-known system (i.e. protected) properties.
+     *
+     * @param def the definition of the property to compute
+     * @return the computed values
+     */
+    public InternalValue[] computeGeneratedValues(
+            QPropertyDefinition def, String userId) {
+        if (userId == null) {
+            userId = "system";
+        }
+
+        Name name = def.getName();
+        Name declaringNT = def.getDeclaringNodeType();
+
+        if (NameConstants.JCR_UUID.equals(name)) {
+            // jcr:uuid property of the mix:referenceable node type
+            if (NameConstants.MIX_REFERENCEABLE.equals(declaringNT)) {
+                return new InternalValue[]{InternalValue.create(getNodeId().toString())};
+            }
+        } else if (NameConstants.JCR_PRIMARYTYPE.equals(name)) {
+            // jcr:primaryType property (of any node type)
+            return new InternalValue[]{InternalValue.create(getNodeTypeName())};
+        } else if (NameConstants.JCR_MIXINTYPES.equals(name)) {
+            // jcr:mixinTypes property (of any node type)
+            Set<Name> mixins = getMixinTypeNames();
+            InternalValue[] values = new InternalValue[mixins.size()];
+            int i = 0;
+            for (Name n : mixins) {
+                values[i++] = InternalValue.create(n);
+            }
+            return values;
+        } else if (NameConstants.JCR_CREATED.equals(name)) {
+            // jcr:created property of a version or a mix:created
+            if (NameConstants.MIX_CREATED.equals(declaringNT)
+                    || NameConstants.NT_VERSION.equals(declaringNT)) {
+                return new InternalValue[]{InternalValue.create(Calendar.getInstance())};
+            }
+        } else if (NameConstants.JCR_CREATEDBY.equals(name)) {
+            // jcr:createdBy property of a mix:created
+            if (NameConstants.MIX_CREATED.equals(declaringNT)) {
+                return new InternalValue[]{InternalValue.create(userId)};
+            }
+        } else if (NameConstants.JCR_LASTMODIFIED.equals(name)) {
+            // jcr:lastModified property of a mix:lastModified
+            if (NameConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
+                return new InternalValue[]{InternalValue.create(Calendar.getInstance())};
+            }
+        } else if (NameConstants.JCR_LASTMODIFIEDBY.equals(name)) {
+            // jcr:lastModifiedBy property of a mix:lastModified
+            if (NameConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
+                return new InternalValue[]{InternalValue.create(userId)};
+            }
+        } else if (NameConstants.JCR_ETAG.equals(name)) {
+            // jcr:etag property of a mix:etag
+            if (NameConstants.MIX_ETAG.equals(declaringNT)) {
+                // TODO: provide real implementation
+                return new InternalValue[]{InternalValue.create("")};
+            }
+        }
+
+        return null;
+    }
+
+    /**
      * {@inheritDoc}
      */
     public long calculateMemoryFootprint() {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java?rev=985273&r1=985272&r2=985273&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
Fri Aug 13 16:36:56 2010
@@ -21,8 +21,10 @@ import org.apache.jackrabbit.core.id.Nod
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
 
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 
 /**
  * <code>PropertyState</code> represents the state of a <code>Property</code>.
@@ -185,6 +187,28 @@ public class PropertyState extends ItemS
     }
 
     /**
+     * Sets the system-generated or node type -specified default values
+     * of this property. If such values are not specified, then this property
+     * is not modified.
+     * 
+     * @param parent parent node state
+     * @param def property definition
+     * @param userId user identifier associated with the current session
+     * @throws RepositoryException if the default values could not be created 
+     */
+    public void setDefaultValues(
+            NodeState parent, QPropertyDefinition def, String userId)
+            throws RepositoryException {
+        InternalValue[] values = parent.computeGeneratedValues(def, userId);
+        if (values == null) {
+            values = InternalValue.create(def.getDefaultValues());
+        }
+        if (values != null) {
+            setValues(values);
+        }
+    }
+
+    /**
      * Returns the value(s) of this property.
      *
      * @return the value(s) of this property.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java?rev=985273&r1=985272&r2=985273&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
Fri Aug 13 16:36:56 2010
@@ -651,8 +651,8 @@ abstract public class VersionManagerImpl
                                               boolean useDefaultValues)
             throws RepositoryException {
         // compute system generated values if necessary
-        InternalValue[] values = session.getNodeTypeInstanceHandler().
-                computeSystemGeneratedPropertyValues(state.getState(), def);
+        InternalValue[] values =
+            state.getState().computeGeneratedValues(def, session.getUserID());
         if (values == null && useDefaultValues) {
             values = InternalValue.create(def.getDefaultValues());
         }



Mime
View raw message