jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Bocanegra <tobias.bocane...@day.com>
Subject Re: svn commit: r985273 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ state/ version/
Date Mon, 16 Aug 2010 08:24:25 GMT
i agree with stefan, further should the "computeGeneratedValues" be
extensible in the future - so adding them to the state is imo wrong,
too. i would rather have a more generic approach to this.
regards, toby

On Mon, Aug 16, 2010 at 10:12 AM, Stefan Guggisberg
<stefan.guggisberg@day.com> wrote:
> sorry, but i don't agree with these changes.
> ItemState classes IMO shouldn't have any
> knowledge of node type semantics. in general
> they're only bean-like objects with simple setters
> and getters.
>
> a method like
>
> public void PropertyState#setDefaultValues(
>            NodeState parent, QPropertyDefinition def, String userId)
>            throws RepositoryException
>
> doesn't look right to me.
>
> cheers
> stefan
>
>
> On Fri, Aug 13, 2010 at 6:36 PM,  <jukka@apache.org> wrote:
>> 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