jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1409405 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Wed, 14 Nov 2012 21:15:23 GMT
Author: jukka
Date: Wed Nov 14 21:15:18 2012
New Revision: 1409405

URL: http://svn.apache.org/viewvc?rev=1409405&view=rev
Log:
OAK-249: Add support for auto created properties and nodes

Degrade gracefully when user id is null.
Also add @Nonnull annotations to various property classes to proactively avoid more problems
like this.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
Wed Nov 14 21:15:18 2012
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Nonnull;
 import javax.jcr.Value;
 
 import org.apache.jackrabbit.oak.api.Blob;
@@ -27,9 +30,9 @@ import org.apache.jackrabbit.oak.plugins
 public class BinaryPropertyState extends SinglePropertyState<Blob> {
     private final Blob value;
 
-    public BinaryPropertyState(String name, Blob value) {
+    public BinaryPropertyState(@Nonnull String name, @Nonnull Blob value) {
         super(name);
-        this.value = value;
+        this.value = checkNotNull(value);
     }
 
     /**
@@ -38,8 +41,10 @@ public class BinaryPropertyState extends
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#BINARY}
      */
-    public static PropertyState binaryProperty(String name, byte[] value) {
-        return new BinaryPropertyState(name, new ArrayBasedBlob(value));
+    public static PropertyState binaryProperty(
+            @Nonnull String name, @Nonnull byte[] value) {
+        return new BinaryPropertyState(
+                name, new ArrayBasedBlob(checkNotNull(value)));
     }
 
     /**
@@ -48,8 +53,10 @@ public class BinaryPropertyState extends
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#BINARY}
      */
-    public static PropertyState binaryProperty(String name, String value) {
-        return new BinaryPropertyState(name, new StringBasedBlob(value));
+    public static PropertyState binaryProperty(
+            @Nonnull String name, @Nonnull String value) {
+        return new BinaryPropertyState(
+                name, new StringBasedBlob(checkNotNull(value)));
     }
 
     /**
@@ -58,7 +65,8 @@ public class BinaryPropertyState extends
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#BINARY}
      */
-    public static PropertyState binaryProperty(String name, Blob value) {
+    public static PropertyState binaryProperty(
+            @Nonnull String name, @Nonnull Blob value) {
         return new BinaryPropertyState(name, value);
     }
 
@@ -68,8 +76,10 @@ public class BinaryPropertyState extends
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#BINARY}
      */
-    public static PropertyState binaryProperty(String name, Value value) {
-        return new BinaryPropertyState(name, new ValueBasedBlob(value));
+    public static PropertyState binaryProperty(
+            @Nonnull String name, @Nonnull Value value) {
+        return new BinaryPropertyState(
+                name, new ValueBasedBlob(checkNotNull(value)));
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
Wed Nov 14 21:15:18 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
@@ -28,7 +30,7 @@ import static org.apache.jackrabbit.oak.
 public class BooleanPropertyState extends SinglePropertyState<Boolean> {
     private final boolean value;
 
-    public BooleanPropertyState(String name, boolean value) {
+    public BooleanPropertyState(@Nonnull String name, boolean value) {
         super(name);
         this.value = value;
     }
@@ -39,7 +41,8 @@ public class BooleanPropertyState extend
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#BOOLEAN}
      */
-    public static PropertyState booleanProperty(String name, boolean value) {
+    public static PropertyState booleanProperty(
+            @Nonnull String name, boolean value) {
         return new BooleanPropertyState(name, value);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
Wed Nov 14 21:15:18 2012
@@ -18,19 +18,22 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.math.BigDecimal;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
 import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.api.Type.DECIMAL;
 
 public class DecimalPropertyState extends SinglePropertyState<BigDecimal> {
     private final BigDecimal value;
 
-    public DecimalPropertyState(String name, BigDecimal value) {
+    public DecimalPropertyState(@Nonnull String name, @Nonnull BigDecimal value) {
         super(name);
-        this.value = value;
+        this.value = checkNotNull(value);
     }
 
     /**
@@ -39,7 +42,8 @@ public class DecimalPropertyState extend
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#DECIMAL}
      */
-    public static PropertyState decimalProperty(String name, BigDecimal value) {
+    public static PropertyState decimalProperty(
+            @Nonnull String name, @Nonnull BigDecimal value) {
         return new DecimalPropertyState(name, value);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
Wed Nov 14 21:15:18 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
@@ -28,7 +30,7 @@ import static org.apache.jackrabbit.oak.
 public class DoublePropertyState extends SinglePropertyState<Double> {
     private final double value;
 
-    public DoublePropertyState(String name, double value) {
+    public DoublePropertyState(@Nonnull String name, double value) {
         super(name);
         this.value = value;
     }
@@ -39,7 +41,8 @@ public class DoublePropertyState extends
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#DOUBLE}
      */
-    public static PropertyState doubleProperty(String name, double value) {
+    public static PropertyState doubleProperty(
+            @Nonnull String name, double value) {
         return new DoublePropertyState(name, value);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
Wed Nov 14 21:15:18 2012
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Type;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.api.Type.BINARIES;
 import static org.apache.jackrabbit.oak.api.Type.STRING;
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
@@ -44,8 +45,8 @@ public abstract class EmptyPropertyState
      * Create a new property state with the given {@code name}
      * @param name  The name of the property state.
      */
-    protected EmptyPropertyState(String name) {
-        this.name = name;
+    protected EmptyPropertyState(@Nonnull String name) {
+        this.name = checkNotNull(name);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java
Wed Nov 14 21:15:18 2012
@@ -16,12 +16,15 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
 import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.api.Type.NAME;
 import static org.apache.jackrabbit.oak.api.Type.PATH;
 import static org.apache.jackrabbit.oak.api.Type.REFERENCE;
@@ -35,11 +38,12 @@ public class GenericPropertyState extend
     /**
      * @throws IllegalArgumentException if {@code type.isArray()} is {@code true}
      */
-    public GenericPropertyState(String name, String value, Type<?> type) {
+    public GenericPropertyState(
+            @Nonnull String name, @Nonnull String value, @Nonnull Type<?> type) {
         super(name);
+        this.value = checkNotNull(value);
+        this.type = checkNotNull(type);
         checkArgument(!type.isArray());
-        this.value = value;
-        this.type = type;
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
Wed Nov 14 21:15:18 2012
@@ -18,8 +18,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.value.Conversions.convert;
+
 import java.util.Calendar;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
@@ -29,7 +34,7 @@ public class LongPropertyState extends S
     private final long value;
     private final Type<?> type;
 
-    public LongPropertyState(String name, long value, Type<?> type) {
+    public LongPropertyState(@Nonnull String name, long value, Type<?> type) {
         super(name);
         this.value = value;
         this.type = type;
@@ -41,7 +46,8 @@ public class LongPropertyState extends S
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#LONG}
      */
-    public static PropertyState createLongProperty(String name, long value) {
+    public static PropertyState createLongProperty(
+            @Nonnull String name, long value) {
         return new LongPropertyState(name, value, Type.LONG);
     }
 
@@ -51,7 +57,8 @@ public class LongPropertyState extends S
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#DATE}
      */
-    public static PropertyState createDateProperty(String name, long value) {
+    public static PropertyState createDateProperty(
+            @Nonnull String name, long value) {
         return new LongPropertyState(name, value, Type.DATE);
     }
 
@@ -61,8 +68,10 @@ public class LongPropertyState extends S
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#DATE}
      */
-    public static PropertyState createDateProperty(String name, Calendar value) {
-        return new LongPropertyState(name, Conversions.convert(value).toLong(), Type.DATE);
+    public static PropertyState createDateProperty(
+            @Nonnull String name, @Nonnull Calendar value) {
+        return new LongPropertyState(
+                name, convert(checkNotNull(value)).toLong(), Type.DATE);
     }
 
     /**
@@ -72,8 +81,10 @@ public class LongPropertyState extends S
      * @return  The new property state of type {@link Type#DATE}
      * @throws IllegalArgumentException if {@code value} is not a parseable to a date.
      */
-    public static PropertyState createDateProperty(String name, String value) {
-        return createDateProperty(name, Conversions.convert(value).toCalendar());
+    public static PropertyState createDateProperty(
+            @Nonnull String name, @Nonnull String value) {
+        return createDateProperty(
+                name, convert(checkNotNull(value)).toCalendar());
     }
 
     @Override
@@ -84,7 +95,7 @@ public class LongPropertyState extends S
     @Override
     public Converter getConverter() {
         if (type == Type.DATE) {
-            return Conversions.convert(Conversions.convert(value).toCalendar());
+            return convert(convert(value).toCalendar());
         }
         else {
             return Conversions.convert(value);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
Wed Nov 14 21:15:18 2012
@@ -36,7 +36,7 @@ abstract class SinglePropertyState<T> ex
      * Create a new property state with the given {@code name}
      * @param name  The name of the property state.
      */
-    protected SinglePropertyState(String name) {
+    protected SinglePropertyState(@Nonnull String name) {
         super(name);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
Wed Nov 14 21:15:18 2012
@@ -18,19 +18,22 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
 import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.api.Type.STRING;
 
 public class StringPropertyState extends SinglePropertyState<String> {
     private final String value;
 
-    public StringPropertyState(String name, String value) {
+    public StringPropertyState(@Nonnull String name, @Nonnull String value) {
         super(name);
-        this.value = value;
+        this.value = checkNotNull(value);
     }
 
     /**
@@ -39,7 +42,8 @@ public class StringPropertyState extends
      * @param value  The value of the property state
      * @return  The new property state of type {@link Type#STRING}
      */
-    public static PropertyState stringProperty(String name, String value) {
+    public static PropertyState stringProperty(
+            @Nonnull String name, @Nonnull String value) {
         return new StringPropertyState(name, value);
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1409405&r1=1409404&r2=1409405&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Wed Nov 14 21:15:18 2012
@@ -1368,10 +1368,11 @@ public class NodeImpl extends ItemImpl<N
                 return getValueFactory().createValue(Calendar.getInstance());
             }
         } else if (NodeTypeConstants.JCR_CREATEDBY.equals(name)) {
+            String userID = sessionDelegate.getAuthInfo().getUserID();
             // jcr:createdBy property of a mix:created
-            if (NodeTypeConstants.MIX_CREATED.equals(declaringNT)) {
-                return getValueFactory().createValue(
-                        sessionDelegate.getAuthInfo().getUserID());
+            if (userID != null
+                    && NodeTypeConstants.MIX_CREATED.equals(declaringNT)) {
+                return getValueFactory().createValue(userID);
             }
         } else if (NodeTypeConstants.JCR_LASTMODIFIED.equals(name)) {
             // jcr:lastModified property of a mix:lastModified
@@ -1379,10 +1380,11 @@ public class NodeImpl extends ItemImpl<N
                 return getValueFactory().createValue(Calendar.getInstance());
             }
         } else if (NodeTypeConstants.JCR_LASTMODIFIEDBY.equals(name)) {
+            String userID = sessionDelegate.getAuthInfo().getUserID();
             // jcr:lastModifiedBy property of a mix:lastModified
-            if (NodeTypeConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
-                return getValueFactory().createValue(
-                        sessionDelegate.getAuthInfo().getUserID());
+            if (userID != null
+                    && NodeTypeConstants.MIX_LASTMODIFIED.equals(declaringNT)) {
+                return getValueFactory().createValue(userID);
             }
         }
         // does the definition have a default value?



Mime
View raw message