nfsantos commented on code in PR #1612:
URL: https://github.com/apache/jackrabbit-oak/pull/1612#discussion_r1701428350
##########
oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonDeserializer.java:
##########
@@ -39,49 +39,67 @@
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
-import static org.apache.jackrabbit.guava.common.collect.ImmutableSet.of;
-import static java.util.Collections.emptyList;
import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
import static
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import static
org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
public class JsonDeserializer {
- public static final String OAK_CHILD_ORDER = ":childOrder";
- private final BlobDeserializer blobHandler;
- private final NodeBuilder builder;
- private final DeserializationSupport deserializationSupport;
+ /**
+ * Provides support for inferring types for some common property name and
types
+ */
+ private static final Set<String> NAME_PROPS = Set.of(JCR_PRIMARYTYPE,
JCR_MIXINTYPES);
+ private static final String ORDERABLE_TYPE = NT_UNSTRUCTURED;
+ private static final String OAK_CHILD_ORDER = ":childOrder";
- private JsonDeserializer(BlobDeserializer blobHandler, NodeBuilder
builder, DeserializationSupport support) {
- this.blobHandler = blobHandler;
- this.builder = builder;
- this.deserializationSupport = support;
+ private static Type<?> inferPropertyType(String propertyName, String
jsonString) {
+ if (NAME_PROPS.contains(propertyName) && hasSingleColon(jsonString)) {
+ return Type.NAME;
+ }
+ return Type.UNDEFINED;
}
- public JsonDeserializer(BlobDeserializer blobHandler) {
- this(blobHandler, EMPTY_NODE.builder(),
DeserializationSupport.INSTANCE);
+ private static boolean hasOrderableChildren(NodeBuilder builder) {
+ PropertyState primaryType = builder.getProperty(JCR_PRIMARYTYPE);
+ return primaryType != null &&
ORDERABLE_TYPE.equals(primaryType.getValue(Type.NAME));
+ }
+
+ private static boolean hasSingleColon(String jsonString) {
+ // In case the primaryType was encoded then it would be like
Review Comment:
Yes, I moved it from the bottom of the class to be at the top, as is the
convention for static code.
Your proposed solution might indeed be faster, given that `indexOf()` is
intrinsified, so it is executed with native code, likely using vector
instructions. This should be faster than a loop on `charAt()`. Might be worth
to explore, although the gains might not be large because property names are
usually small.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]