jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angela Schreiber <anch...@adobe.com>
Subject Re: value conversions, and relative paths in Oak
Date Thu, 10 May 2012 06:46:49 GMT
hi julian

> 1) missing Date->long/double/decimal value conversions. I have added
> those for now in ValueImpl (not core); is this correct, Angela?

as long as we don't need it in the core, i would add it in oak-jcr.
we can still push i down to the CoreValue later on.
the basic question is again what part of the validation should be
in which layer... that's a matter of definition rather than right
or wrong.

> 2) we didn't round-trip a relative path of ".". Now we do, but I'm not
> sure I got the mapping correct. What is a same-node reference in Oak
> path syntax? "." or empty string?

well, i would expect "."

> I also fear that we need to be able to
> round-trip relative paths like "../foo/bar" in path values, which we
> currently do not. Do we need a "normalize" flag???

i would expect that we need it sooner or later.

> 3) Node.getNode(".") failed because it looked for a child called ".". If
> have added a hack to make this work, but I'm wondering how to do this
> properly.

imo oak paths should always be normalized except for path values.

kind regards
angela

> Best regards, Julian
>
>
>
> On 2012-05-09 17:52, reschke@apache.org wrote:
>> Author: reschke
>> Date: Wed May  9 15:52:35 2012
>> New Revision: 1336250
>>
>> URL: http://svn.apache.org/viewvc?rev=1336250&view=rev
>> Log:
>> OAK-6: add test content for property tests; add value conversion for dates, handle
"." paths in path-typed properties
>>
>> Modified:
>>       jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
>>       jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
>>       jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
>>       jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
>>
>> Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
>> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1336250&r1=1336249&r2=1336250&view=diff
>> ==============================================================================
>> --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
>> +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Wed May  9 15:52:35 2012
>> @@ -143,6 +143,11 @@ public class NamePathMapperImpl implemen
>>                }
>>            }
>>
>> +        // empty path: map to "."
>> +        if (oakPath.length() == 0) {
>> +            return ".";
>> +        }
>> +
>>            // root path is special-cased early on so it does not need to
>>            // be considered here
>>            oakPath.deleteCharAt(oakPath.length() - 1);
>> @@ -228,6 +233,11 @@ public class NamePathMapperImpl implemen
>>                }
>>            }
>>
>> +        // empty path: map to "."
>> +        if (jcrPath.length() == 0) {
>> +            return ".";
>> +        }
>> +
>>            jcrPath.deleteCharAt(jcrPath.length() - 1);
>>            return jcrPath.toString();
>>        }
>>
>> Modified: jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
>> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java?rev=1336250&r1=1336249&r2=1336250&view=diff
>> ==============================================================================
>> --- jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
(original)
>> +++ jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
Wed May  9 15:52:35 2012
>> @@ -16,16 +16,22 @@
>>     */
>>    package org.apache.jackrabbit.oak.jcr;
>>
>> +import java.util.Calendar;
>> +
>>    import javax.jcr.Node;
>>    import javax.jcr.PathNotFoundException;
>> +import javax.jcr.PropertyType;
>>    import javax.jcr.RepositoryException;
>>    import javax.jcr.Session;
>> +import javax.jcr.ValueFactory;
>>
>>    public class TestContentLoader {
>>
>>        public void loadTestContent(Session session) throws RepositoryException {
>>
>> -        getOrAddNode(session.getRootNode(), "testdata");
>> +        Node data = getOrAddNode(session.getRootNode(), "testdata");
>> +        addPropertyTestData(getOrAddNode(data, "property"));
>> +
>>            session.save();
>>        }
>>
>> @@ -36,4 +42,20 @@ public class TestContentLoader {
>>                return node.addNode(name);
>>            }
>>        }
>> +
>> +    /**
>> +     * Creates a boolean, double, long, calendar and a path property at the
>> +     * given node.
>> +     */
>> +    private  void addPropertyTestData(Node node) throws RepositoryException {
>> +        node.setProperty("boolean", true);
>> +        node.setProperty("double", Math.PI);
>> +        node.setProperty("long", 90834953485278298l);
>> +        Calendar c = Calendar.getInstance();
>> +        c.set(2005, 6, 18, 17, 30);
>> +        node.setProperty("calendar", c);
>> +        ValueFactory factory = node.getSession().getValueFactory();
>> +        node.setProperty("path", factory.createValue("/", PropertyType.PATH));
>> +        node.setProperty("multi", new String[] { "one", "two", "three" });
>> +    }
>>    }
>>
>> 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=1336250&r1=1336249&r2=1336250&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 May  9 15:52:35 2012
>> @@ -365,6 +365,12 @@ public class NodeImpl extends ItemImpl i
>>            checkStatus();
>>
>>            String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
>> +
>> +        // TODO: hack
>> +        if (".".equals(oakPath)) {
>> +            return this;
>> +        }
>> +
>>            NodeDelegate nd = dlg.getChild(oakPath);
>>            if (nd == null) {
>>                throw new PathNotFoundException(relPath);
>>
>> Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
>> URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java?rev=1336250&r1=1336249&r2=1336250&view=diff
>> ==============================================================================
>> --- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
(original)
>> +++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
Wed May  9 15:52:35 2012
>> @@ -113,7 +113,13 @@ class ValueImpl implements Value {
>>        @Override
>>        public BigDecimal getDecimal() throws RepositoryException {
>>            try {
>> -            return value.getDecimal();
>> +            switch (getType()) {
>> +                case PropertyType.DATE:
>> +                    Calendar cal = getDate();
>> +                    return BigDecimal.valueOf(cal.getTimeInMillis());
>> +                default:
>> +                    return value.getDecimal();
>> +            }
>>            } catch (NumberFormatException e) {
>>                throw new ValueFormatException("Incompatible type " + PropertyType.nameFromValue(getType()));
>>            }
>> @@ -125,7 +131,13 @@ class ValueImpl implements Value {
>>        @Override
>>        public double getDouble() throws RepositoryException {
>>            try {
>> -            return value.getDouble();
>> +            switch (getType()) {
>> +                case PropertyType.DATE:
>> +                    Calendar cal = getDate();
>> +                    return cal.getTimeInMillis();
>> +                default:
>> +                    return value.getDouble();
>> +            }
>>            } catch (NumberFormatException e) {
>>                throw new ValueFormatException("Incompatible type " + PropertyType.nameFromValue(getType()));
>>            }
>> @@ -137,7 +149,13 @@ class ValueImpl implements Value {
>>        @Override
>>        public long getLong() throws RepositoryException {
>>            try {
>> -            return value.getLong();
>> +            switch (getType()) {
>> +                case PropertyType.DATE:
>> +                    Calendar cal = getDate();
>> +                    return cal.getTimeInMillis();
>> +                default:
>> +                    return value.getLong();
>> +            }
>>            } catch (NumberFormatException e) {
>>                throw new ValueFormatException("Incompatible type " + PropertyType.nameFromValue(getType()));
>>            }
>>
>>
>>
>

Mime
View raw message