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]);
}
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++]));
}
}
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;
}
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;
}
}
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);
}
Aggregations