Search in sources :

Example 21 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId 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)

Example 22 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class ChangeLogTest method testPreserveOrder.

/**
 * Add some item states. Retrieve them again and make sure the order is
 * preserved.
 */
public void testPreserveOrder() throws Exception {
    ItemState[] states = new ItemState[10];
    for (int i = 0; i < states.length; i++) {
        PropertyId id = new PropertyId(NodeId.randomId(), factory.create("", "a" + i));
        states[i] = new PropertyState(id, ItemState.STATUS_NEW, false);
    }
    ChangeLog log = new ChangeLog();
    for (int i = 0; i < states.length; i++) {
        log.added(states[i]);
    }
    int i = 0;
    for (ItemState state : log.addedStates()) {
        assertTrue("Added states preserve order.", state.equals(states[i++]));
    }
}
Also used : PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 23 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeStateEx method getProperties.

/**
 * Returns the properties of this node
 *
 * @return the properties of this node
 * @throws ItemStateException if an error occurs
 */
public PropertyState[] getProperties() throws ItemStateException {
    Set<Name> set = nodeState.getPropertyNames();
    PropertyState[] props = new PropertyState[set.size()];
    int i = 0;
    for (Name propName : set) {
        PropertyId propId = new PropertyId(nodeState.getNodeId(), propName);
        props[i++] = (PropertyState) stateMgr.getItemState(propId);
    }
    return props;
}
Also used : Name(org.apache.jackrabbit.spi.Name) PropertyState(org.apache.jackrabbit.core.state.PropertyState) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 24 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeStateEx method setPropertyValues.

/**
 * Sets the property values
 *
 * @param name name of the property
 * @param type type of the values
 * @param values values to set
 * @param multiple <code>true</code>for MV properties
 * @return the modified property state
 * @throws RepositoryException if an error occurs
 */
public PropertyState setPropertyValues(Name name, int type, InternalValue[] values, boolean multiple) throws RepositoryException {
    PropertyId propId = new PropertyId(nodeState.getNodeId(), name);
    if (stateMgr.hasItemState(propId)) {
        try {
            PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
            if (propState.getStatus() == ItemState.STATUS_EXISTING) {
                propState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
            }
            // although this is not quite correct, we mark node as modified as well
            if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
                nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
            }
            propState.setType(type);
            propState.setMultiValued(multiple);
            propState.setValues(values);
            return propState;
        } catch (ItemStateException e) {
            throw new RepositoryException("Unable to create property: " + e.toString());
        }
    } else {
        PropertyState propState = stateMgr.createNew(name, nodeState.getNodeId());
        propState.setType(type);
        propState.setMultiValued(multiple);
        propState.setValues(values);
        // need to store node state
        nodeState.addPropertyName(name);
        if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        return propState;
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 25 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeStateEx method removeNode.

/**
 * removes recursively the node with the given id
 *
 * @param id node id
 * @throws ItemStateException if an error occurs
 */
private void removeNode(NodeId id) throws ItemStateException {
    NodeState state = (NodeState) stateMgr.getItemState(id);
    // remove properties
    for (Name name : state.getPropertyNames()) {
        PropertyId propId = new PropertyId(id, name);
        PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
        stateMgr.destroy(propState);
    }
    state.removeAllPropertyNames();
    // remove child nodes
    for (ChildNodeEntry entry : state.getChildNodeEntries()) {
        removeNode(entry.getId());
    }
    state.removeAllChildNodeEntries();
    // destroy the state itself
    stateMgr.destroy(state);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Aggregations

PropertyId (org.apache.jackrabbit.core.id.PropertyId)59 Name (org.apache.jackrabbit.spi.Name)29 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 NodeState (org.apache.jackrabbit.core.state.NodeState)23 RepositoryException (javax.jcr.RepositoryException)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)16 InternalValue (org.apache.jackrabbit.core.value.InternalValue)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 HashSet (java.util.HashSet)10 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)7 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ItemId (org.apache.jackrabbit.core.id.ItemId)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)4