Search in sources :

Example 1 with PropertyEntry

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit-oak by apache.

the class JackrabbitNodeState method createProperties.

private Map<String, PropertyState> createProperties(NodePropBundle bundle) {
    Map<String, PropertyState> properties = newHashMap();
    String primary;
    if (bundle.getNodeTypeName() != null) {
        primary = createName(bundle.getNodeTypeName());
    } else {
        warn("Missing primary node type; defaulting to nt:unstructured");
        primary = NT_UNSTRUCTURED;
    }
    properties.put(JCR_PRIMARYTYPE, PropertyStates.createProperty(JCR_PRIMARYTYPE, primary, Type.NAME));
    for (PropertyEntry property : bundle.getPropertyEntries()) {
        String name = createName(property.getName());
        try {
            int type = property.getType();
            if (property.isMultiValued()) {
                properties.put(name, createProperty(name, type, property.getValues()));
            } else {
                properties.put(name, createProperty(name, type, property.getValues()[0]));
            }
        } catch (Exception e) {
            warn("Skipping broken property entry " + name, e);
        }
    }
    Set<String> mixins = newLinkedHashSet();
    if (bundle.getMixinTypeNames() != null) {
        for (Name mixin : bundle.getMixinTypeNames()) {
            mixins.add(createName(mixin));
        }
    }
    if (mixins.remove("mix:simpleVersionable")) {
        mixins.add(MIX_VERSIONABLE);
    }
    if (!mixins.isEmpty()) {
        properties.put(JCR_MIXINTYPES, PropertyStates.createProperty(JCR_MIXINTYPES, mixins, Type.NAMES));
    }
    if (bundle.isReferenceable() || isReferenceable.apply(primary, mixins)) {
        properties.put(JCR_UUID, PropertyStates.createProperty(JCR_UUID, bundle.getId().toString()));
    }
    return properties;
}
Also used : PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Name(org.apache.jackrabbit.spi.Name)

Example 2 with PropertyEntry

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit-oak by apache.

the class BundleLoader method loadBundle.

NodePropBundle loadBundle(NodeId id) throws ItemStateException {
    if (loadBundle != null) {
        try {
            return checkNotNull((NodePropBundle) loadBundle.invoke(pm, id), "Could not load NodePropBundle for id [%s]", id);
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof ItemStateException) {
                throw (ItemStateException) e.getCause();
            }
        // fall through
        } catch (IllegalArgumentException e) {
        // fall through
        } catch (IllegalAccessException e) {
        // fall through
        }
    }
    NodeState state = pm.load(id);
    checkNotNull(state, "Could not load NodeState for id [%s]", id);
    NodePropBundle bundle = new NodePropBundle(state);
    for (Name name : state.getPropertyNames()) {
        if (NameConstants.JCR_UUID.equals(name)) {
            bundle.setReferenceable(true);
        } else if (!NameConstants.JCR_PRIMARYTYPE.equals(name) && !NameConstants.JCR_MIXINTYPES.equals(name)) {
            bundle.addProperty(new PropertyEntry(pm.load(new PropertyId(id, name))));
        }
    }
    return bundle;
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) InvocationTargetException(java.lang.reflect.InvocationTargetException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 3 with PropertyEntry

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit by apache.

the class BundleWriter method writeBundle.

/**
 * Serializes a <code>NodePropBundle</code> to a data output stream
 *
 * @param bundle the bundle to serialize
 * @throws IOException if an I/O error occurs.
 */
public void writeBundle(NodePropBundle bundle) throws IOException {
    long size = out.size();
    // primaryType
    writeName(bundle.getNodeTypeName());
    // parentUUID
    NodeId parentId = bundle.getParentId();
    if (parentId == null) {
        parentId = BundleBinding.NULL_PARENT_ID;
    }
    writeNodeId(parentId);
    // write mod count
    writeVarInt(bundle.getModCount());
    Collection<Name> mixins = bundle.getMixinTypeNames();
    Collection<PropertyEntry> properties = bundle.getPropertyEntries();
    Collection<ChildNodeEntry> nodes = bundle.getChildNodeEntries();
    Collection<NodeId> shared = bundle.getSharedSet();
    int mn = mixins.size();
    int pn = properties.size();
    int nn = nodes.size();
    int sn = shared.size();
    int referenceable = 0;
    if (bundle.isReferenceable()) {
        referenceable = 1;
    }
    out.writeByte(Math.min(mn, 1) << 7 | Math.min(pn, 7) << 4 | Math.min(nn, 3) << 2 | Math.min(sn, 1) << 1 | referenceable);
    // mixin types
    writeVarInt(mn, 1);
    for (Name name : mixins) {
        writeName(name);
    }
    // properties
    writeVarInt(pn, 7);
    for (PropertyEntry property : properties) {
        writeState(property);
    }
    // child nodes (list of name/uuid pairs)
    writeVarInt(nn, 3);
    for (ChildNodeEntry child : nodes) {
        // name
        writeName(child.getName());
        // uuid
        writeNodeId(child.getId());
    }
    // write shared set
    writeVarInt(sn, 1);
    for (NodeId nodeId : shared) {
        writeNodeId(nodeId);
    }
    // set size of bundle
    bundle.setSize(out.size() - size);
}
Also used : PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) ChildNodeEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) Name(org.apache.jackrabbit.spi.Name)

Example 4 with PropertyEntry

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit by apache.

the class BundleBindingTest method testComplexBundle.

/**
 * Tests serialization of a complex bundle.
 */
public void testComplexBundle() throws Exception {
    NodeId id = new NodeId(1, 2);
    NodePropBundle bundle = new NodePropBundle(id);
    bundle.setParentId(new NodeId(3, 4));
    bundle.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);
    bundle.setMixinTypeNames(Collections.singleton(NameConstants.MIX_CREATED));
    bundle.setReferenceable(true);
    bundle.setSharedSet(new HashSet<NodeId>(Arrays.asList(new NodeId(5, 6), new NodeId(7, 8), new NodeId(9, 10))));
    PropertyEntry property;
    property = new PropertyEntry(new PropertyId(id, NameConstants.JCR_CREATED));
    property.setType(PropertyType.DATE);
    property.setMultiValued(false);
    Calendar date = Calendar.getInstance();
    date.setTimeInMillis(1234567890);
    property.setValues(new InternalValue[] { InternalValue.create(date) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, NameConstants.JCR_CREATEDBY));
    property.setType(PropertyType.STRING);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create("test") });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "binary")));
    property.setType(PropertyType.BINARY);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "boolean")));
    property.setType(PropertyType.BOOLEAN);
    property.setMultiValued(true);
    property.setValues(new InternalValue[] { InternalValue.create(true), InternalValue.create(false) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "date")));
    property.setType(PropertyType.DATE);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(date) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "decimal")));
    property.setType(PropertyType.DECIMAL);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(new BigDecimal("1234567890.0987654321")) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "double")));
    property.setType(PropertyType.DOUBLE);
    property.setMultiValued(true);
    property.setValues(new InternalValue[] { InternalValue.create(1.0), InternalValue.create(Math.PI) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "long")));
    property.setType(PropertyType.LONG);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(1234567890) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "name")));
    property.setType(PropertyType.NAME);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(NameConstants.JCR_MIMETYPE) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "path")));
    property.setType(PropertyType.PATH);
    property.setMultiValued(true);
    PathFactory pathFactory = PathFactoryImpl.getInstance();
    Path root = pathFactory.getRootPath();
    Path path = pathFactory.create(root, NameConstants.JCR_SYSTEM, false);
    property.setValues(new InternalValue[] { InternalValue.create(root), InternalValue.create(path) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "reference")));
    property.setType(PropertyType.REFERENCE);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(new NodeId(11, 12)) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "string")));
    property.setType(PropertyType.STRING);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create("test") });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "uri")));
    property.setType(PropertyType.URI);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(new URI("http://jackrabbit.apache.org/")) });
    bundle.addProperty(property);
    property = new PropertyEntry(new PropertyId(id, factory.create("", "weakreference")));
    property.setType(PropertyType.WEAKREFERENCE);
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { InternalValue.create(new NodeId(13, 14), true) });
    bundle.addProperty(property);
    bundle.addChildNodeEntry(NameConstants.JCR_SYSTEM, new NodeId(15, 16));
    bundle.addChildNodeEntry(NameConstants.JCR_VERSIONSTORAGE, new NodeId(17, 18));
    assertBundleRoundtrip(bundle);
    assertBundleSerialization(bundle, new byte[] { 2, 0, 0, 1, 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 2, 0, 0, 0, 4, -1, -1, -1, -1, 0, 0, 0, 6, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 73, -106, 2, -46, 0, 0, 0, 6, 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 116, 101, 115, 116, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0, 6, 1, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 6, 0, 0, 0, 13, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 109, 105, 109, 101, 84, 121, 112, 101, 0, 0, 0, 6, 0, 0, 0, 15, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 6, 0, 0, 0, 18, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 9, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 29, 49, 57, 55, 48, 45, 48, 49, 45, 49, 53, 84, 48, 55, 58, 53, 54, 58, 48, 55, 46, 56, 57, 48, 43, 48, 49, 58, 48, 48, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 6, 0, 0, 0, 17, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 29, 104, 116, 116, 112, 58, 47, 47, 106, 97, 99, 107, 114, 97, 98, 98, 105, 116, 46, 97, 112, 97, 99, 104, 101, 46, 111, 114, 103, 47, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 116, 101, 115, 116, 0, 0, 0, 6, 0, 0, 0, 11, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 2, 63, -16, 0, 0, 0, 0, 0, 0, 64, 9, 33, -5, 84, 68, 45, 24, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 29, 49, 57, 55, 48, 45, 48, 49, 45, 49, 53, 84, 48, 55, 58, 53, 54, 58, 48, 55, 46, 56, 57, 48, 43, 48, 49, 58, 48, 48, 0, 0, 0, 6, 0, 0, 0, 10, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 1, 1, 0, 21, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 46, 48, 57, 56, 55, 54, 53, 52, 51, 50, 49, 0, 0, 0, 6, 0, 0, 0, 14, 0, 0, 0, 8, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 123, 125, 0, 0, 0, 37, 123, 125, 9, 123, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 106, 99, 112, 46, 111, 114, 103, 47, 106, 99, 114, 47, 49, 46, 48, 125, 115, 121, 115, 116, 101, 109, -1, -1, -1, -1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 6, 115, 121, 115, 116, 101, 109, 1, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 14, 118, 101, 114, 115, 105, 111, 110, 83, 116, 111, 114, 97, 103, 101, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 8, 1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 10, 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0 });
}
Also used : Path(org.apache.jackrabbit.spi.Path) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) Calendar(java.util.Calendar) NodeId(org.apache.jackrabbit.core.id.NodeId) PathFactory(org.apache.jackrabbit.spi.PathFactory) URI(java.net.URI) BigDecimal(java.math.BigDecimal) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 5 with PropertyEntry

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit by apache.

the class BundleBindingTest method assertValueSerialization.

private void assertValueSerialization(InternalValue value) throws Exception {
    NodePropBundle bundle = new NodePropBundle(NodeId.randomId());
    bundle.setParentId(NodeId.randomId());
    bundle.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);
    bundle.setMixinTypeNames(Collections.<Name>emptySet());
    bundle.setSharedSet(Collections.<NodeId>emptySet());
    Name name = factory.create("", "test");
    PropertyEntry property = new PropertyEntry(new PropertyId(bundle.getId(), name));
    property.setType(value.getType());
    property.setMultiValued(false);
    property.setValues(new InternalValue[] { value });
    bundle.addProperty(property);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    binding.writeBundle(buffer, bundle);
    byte[] bytes = buffer.toByteArray();
    NodePropBundle result = binding.readBundle(new ByteArrayInputStream(bytes), bundle.getId());
    assertEquals(value, result.getPropertyEntry(name).getValues()[0]);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Aggregations

PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)9 Name (org.apache.jackrabbit.spi.Name)5 PropertyId (org.apache.jackrabbit.core.id.PropertyId)4 NodeId (org.apache.jackrabbit.core.id.NodeId)3 InternalValue (org.apache.jackrabbit.core.value.InternalValue)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)2 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 RepositoryException (javax.jcr.RepositoryException)1 ChildNodeEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.ChildNodeEntry)1 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)1 NodeState (org.apache.jackrabbit.core.state.NodeState)1