jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r628156 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/NodeImpl.java main/java/org/apache/jackrabbit/core/PropertyImpl.java test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java
Date Fri, 15 Feb 2008 20:10:02 GMT
Author: jukka
Date: Fri Feb 15 12:10:01 2008
New Revision: 628156

URL: http://svn.apache.org/viewvc?rev=628156&view=rev
Log:
JCR-1389: setProperty("name", new Value[0], PropertyType.LONG) loses property type

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java

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=628156&r1=628155&r2=628156&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 Feb 15 12:10:01 2008
@@ -2085,12 +2085,7 @@
         BitSet status = new BitSet();
         PropertyImpl prop = getOrCreateProperty(name, type, true, true, status);
         try {
-            if (prop.getDefinition().getRequiredType() == PropertyType.UNDEFINED
-                    && type != PropertyType.UNDEFINED) {
-                prop.setValue(ValueHelper.convert(values, type, session.getValueFactory()));
-            } else {
-                prop.setValue(values);
-            }
+            prop.setValue(values, type);
         } catch (RepositoryException re) {
             if (status.get(CREATED)) {
                 // setting value failed, get rid of newly created property

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=628156&r1=628155&r2=628156&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Fri Feb 15 12:10:01 2008
@@ -615,6 +615,19 @@
             throws ValueFormatException, VersionException,
             LockException, ConstraintViolationException,
             RepositoryException {
+        setValue(values, PropertyType.UNDEFINED);
+    }
+
+    /**
+     * Sets the values of this property.
+     *
+     * @param values property values (possibly <code>null</code>)
+     * @param valueType default value type if not set in the node type,
+     *                  may be {@link PropertyType#UNDEFINED}
+     * @throws RepositoryException if the property values could not be set
+     */
+    public void setValue(Value[] values, int valueType)
+            throws RepositoryException {
         // check state of this instance
         sanityCheck();
 
@@ -623,50 +636,46 @@
 
         if (values != null) {
             // check type of values
-            int valueType = PropertyType.UNDEFINED;
+            int firstValueType = PropertyType.UNDEFINED;
             for (int i = 0; i < values.length; i++) {
-                if (values[i] == null) {
-                    // skip null values as those will be purged later
-                    continue;
-                }
-                if (valueType == PropertyType.UNDEFINED) {
-                    valueType = values[i].getType();
-                } else if (valueType != values[i].getType()) {
-                    // inhomogeneous types
-                    String msg = "inhomogeneous type of values";
-                    log.debug(msg);
-                    throw new ValueFormatException(msg);
+                if (values[i] != null) {
+                    if (firstValueType == PropertyType.UNDEFINED) {
+                        firstValueType = values[i].getType();
+                    } else if (firstValueType != values[i].getType()) {
+                        throw new ValueFormatException(
+                                "inhomogeneous type of values");
+                    }
                 }
             }
         }
 
         int reqType = definition.getRequiredType();
+        if (reqType == PropertyType.UNDEFINED) {
+            reqType = valueType; // use the given type as property type
+        }
 
         InternalValue[] internalValues = null;
         // convert to internal values of correct type
         if (values != null) {
             internalValues = new InternalValue[values.length];
+
+            // check type of values
             for (int i = 0; i < values.length; i++) {
                 Value value = values[i];
-                InternalValue internalValue = null;
                 if (value != null) {
-                    // check type according to definition of this property
                     if (reqType == PropertyType.UNDEFINED) {
-                        // use the value's type as property type
+                        // Use the type of the fist value as the type
                         reqType = value.getType();
                     }
                     if (reqType != value.getType()) {
-                        // type conversion required
-                        Value targetVal = ValueHelper.convert(
-                                value, reqType,
-                                ValueFactoryImpl.getInstance());
-                        internalValue = InternalValue.create(targetVal, session.getNamePathResolver(),
rep.getDataStore());
-                    } else {
-                        // no type conversion required
-                        internalValue = InternalValue.create(value, session.getNamePathResolver(),
rep.getDataStore());
+                        value = ValueHelper.convert(
+                                value, reqType, session.getValueFactory());
                     }
+                    internalValues[i] = InternalValue.create(
+                            value, session, rep.getDataStore());
+                } else {
+                    internalValues[i] = null;
                 }
-                internalValues[i] = internalValue;
             }
         }
 

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java?rev=628156&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/NodeImplTest.java
Fri Feb 15 12:10:01 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.integration;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Integration tests for the Node implementation in Jackrabbit core.
+ */
+public class NodeImplTest extends AbstractJCRTest {
+
+    private Node node;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        node = testRootNode.addNode("testNodeImpl", "nt:unstructured");
+        testRootNode.save();
+    }
+
+    protected void tearDown() throws Exception {
+        node.remove();
+        testRootNode.save();
+    }
+
+    /**
+     * Test case for JCR-1389.
+     * 
+     * @see https://issues.apache.org/jira/browse/JCR-1389
+     */
+    public void testSetEmptyMultiValueProperty() throws RepositoryException {
+        Property property =
+            node.setProperty("test", new Value[0], PropertyType.LONG);
+        assertEquals(
+                "JCR-1389: setProperty(name, new Value[0], PropertyType.LONG)"
+                + " loses property type",
+                PropertyType.LONG, property.getType());
+    }
+
+}



Mime
View raw message