jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1444676 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
Date Mon, 11 Feb 2013 08:14:50 GMT
Author: jukka
Date: Mon Feb 11 08:14:49 2013
New Revision: 1444676

URL: http://svn.apache.org/r1444676
Log:
OAK-593: Segment-based MK

Improved SegmentPropertyState

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java?rev=1444676&r1=1444675&r2=1444676&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentPropertyState.java
Mon Feb 11 08:14:49 2013
@@ -25,16 +25,15 @@ import java.util.NoSuchElementException;
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyPropertyState;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
-class SegmentPropertyState implements PropertyState {
+class SegmentPropertyState extends EmptyPropertyState {
 
     private final SegmentReader reader;
 
-    private final String name;
-
     private final int tag;
 
     private final int count;
@@ -42,8 +41,9 @@ class SegmentPropertyState implements Pr
     private final ListRecord values;
 
     SegmentPropertyState(SegmentReader reader, String name, RecordId id) {
+        super(name);
+
         this.reader = checkNotNull(reader);
-        this.name = checkNotNull(name);
 
         checkNotNull(id);
         this.tag = reader.readInt(id, 0);
@@ -51,11 +51,6 @@ class SegmentPropertyState implements Pr
         this.values = new ListRecord(reader.readRecordId(id, 8), count());
     }
 
-    @Override @Nonnull
-    public String getName() {
-        return name;
-    }
-
     @Override
     public boolean isArray() {
         return count != -1;
@@ -123,28 +118,35 @@ class SegmentPropertyState implements Pr
             return (T) new SegmentBlob(reader, valueId);
         } else {
             String value = reader.readString(valueId);
-            switch (type.tag()) {
-            case PropertyType.BOOLEAN:
-                return (T) Boolean.valueOf(Conversions.convert(value).toBoolean());
-            case PropertyType.DATE:
-                return (T) Conversions.convert(value).toDate();
-            case PropertyType.DECIMAL:
-                return (T) Conversions.convert(value).toDecimal();
-            case PropertyType.DOUBLE:
-                return (T) Double.valueOf(Conversions.convert(value).toDouble());
-            case PropertyType.LONG:
-                return (T) Long.valueOf(Conversions.convert(value).toLong());
-            case PropertyType.NAME:
-            case PropertyType.PATH:
-            case PropertyType.REFERENCE:
-            case PropertyType.STRING:
-            case PropertyType.URI:
-            case PropertyType.WEAKREFERENCE:
+            if (type == Type.STRING || type == Type.URI
+                    || type == Type.NAME || type == Type.PATH
+                    || type == Type.REFERENCE || type == Type.WEAKREFERENCE) {
                 return (T) value;
-            case PropertyType.UNDEFINED:
-                throw new IllegalArgumentException("Undefined type");
-            default:
-                throw new UnsupportedOperationException("Unknown type: " + type);
+            } else {
+                Converter converter = Conversions.convert(value);
+                if (tag == PropertyType.DATE) {
+                    converter = Conversions.convert(converter.toCalendar());
+                } else if (tag == PropertyType.DECIMAL) {
+                    converter = Conversions.convert(converter.toDecimal());
+                } else if (tag == PropertyType.DOUBLE) {
+                    converter = Conversions.convert(converter.toDouble());
+                } else if (tag == PropertyType.LONG) {
+                    converter = Conversions.convert(converter.toLong());
+                }
+                if (type == Type.BOOLEAN) {
+                    return (T) Boolean.valueOf(converter.toBoolean());
+                } else if (type == Type.DATE) {
+                    return (T) converter.toDate();
+                } else if (type == Type.DECIMAL) {
+                    return (T) converter.toDecimal();
+                } else if (type == Type.DOUBLE) {
+                    return (T) Double.valueOf(converter.toDouble());
+                } else if (type == Type.LONG) {
+                    return (T) Long.valueOf(converter.toLong());
+                } else {
+                    throw new UnsupportedOperationException(
+                            "Unknown type: " + type);
+                }
             }
         }
     }



Mime
View raw message