use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class BatchedItemOperations method copyPropertyState.
/**
* Copies the specified property state.
*
* @param srcState the property state to copy.
* @param parentId the id of the parent node.
* @param propName the name of the property.
* @param def the definition of the property.
* @return a copy of the property state.
* @throws RepositoryException if an error occurs while copying.
*/
private PropertyState copyPropertyState(PropertyState srcState, NodeId parentId, Name propName, QPropertyDefinition def) throws RepositoryException {
PropertyState newState = stateMgr.createNew(propName, parentId);
newState.setType(srcState.getType());
newState.setMultiValued(srcState.isMultiValued());
InternalValue[] values = srcState.getValues();
if (values != null) {
/**
* special handling required for properties with special semantics
* (e.g. those defined by mix:referenceable, mix:versionable,
* mix:lockable, et.al.)
*
* todo FIXME delegate to 'node type instance handler'
*/
if (propName.equals(NameConstants.JCR_UUID) && def.getDeclaringNodeType().equals(NameConstants.MIX_REFERENCEABLE)) {
// set correct value of jcr:uuid property
newState.setValues(new InternalValue[] { InternalValue.create(parentId.toString()) });
} else {
InternalValue[] newValues = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
newValues[i] = values[i].createCopy();
}
newState.setValues(newValues);
}
}
return newState;
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class BatchedItemOperations method createPropertyState.
/**
* Creates a new property based on the given definition.
* <p>
* Note that access rights are <b><i>not</i></b> enforced!
* <p>
* <b>Precondition:</b> the state manager needs to be in edit mode.
*
* @param parent
* @param propName
* @param type
* @param def
* @return
* @throws ItemExistsException
* @throws RepositoryException
*/
public PropertyState createPropertyState(NodeState parent, Name propName, int type, QPropertyDefinition def) throws ItemExistsException, RepositoryException {
// check for name collisions with existing properties
if (parent.hasPropertyName(propName)) {
PropertyId errorId = new PropertyId(parent.getNodeId(), propName);
throw new ItemExistsException(safeGetJCRPath(errorId));
}
// create property
PropertyState prop = stateMgr.createNew(propName, parent.getNodeId());
if (def.getRequiredType() != PropertyType.UNDEFINED) {
prop.setType(def.getRequiredType());
} else if (type != PropertyType.UNDEFINED) {
prop.setType(type);
} else {
prop.setType(PropertyType.STRING);
}
prop.setMultiValued(def.isMultiple());
// compute system generated values if necessary
new NodeTypeInstanceHandler(session.getUserID()).setDefaultValues(prop, parent, def);
// now add new property entry to parent
parent.addPropertyName(propName);
// store parent
stateMgr.store(parent);
return prop;
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class NodeIndexer method createDoc.
/**
* Creates a lucene Document.
*
* @return the lucene Document with the index layout.
* @throws RepositoryException if an error occurs while reading property
* values from the <code>ItemStateProvider</code>.
*/
public Document createDoc() throws RepositoryException {
doNotUseInExcerpt.clear();
Document doc = new Document();
doc.setBoost(getNodeBoost());
// special fields
// UUID
doc.add(new IDField(node.getNodeId()));
try {
// parent UUID
if (node.getParentId() == null) {
// root node
Field parent = new Field(FieldNames.PARENT, false, "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO);
parent.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY);
doc.add(parent);
addNodeName(doc, "", "");
} else if (node.getSharedSet().isEmpty()) {
addParentChildRelation(doc, node.getParentId());
} else {
// shareable node
for (NodeId id : node.getSharedSet()) {
addParentChildRelation(doc, id);
}
// mark shareable nodes
doc.add(new Field(FieldNames.SHAREABLE_NODE, false, "", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
}
} catch (NoSuchItemStateException e) {
throwRepositoryException(e);
} catch (ItemStateException e) {
throwRepositoryException(e);
} catch (NamespaceException e) {
// will never happen, because this.mappings will dynamically add
// unknown uri<->prefix mappings
}
Set<Name> props = node.getPropertyNames();
for (Name propName : props) {
if (isIndexed(propName)) {
PropertyId id = new PropertyId(node.getNodeId(), propName);
try {
PropertyState propState = (PropertyState) stateProvider.getItemState(id);
// beginning with V2
if (indexFormatVersion.getVersion() >= IndexFormatVersion.V2.getVersion()) {
addPropertyName(doc, propState.getName());
}
InternalValue[] values = propState.getValues();
for (InternalValue value : values) {
addValue(doc, value, propState.getName());
}
if (values.length > 1) {
// real multi-valued
addMVPName(doc, propState.getName());
}
} catch (NoSuchItemStateException e) {
throwRepositoryException(e);
} catch (ItemStateException e) {
throwRepositoryException(e);
}
}
}
// now add fields that are not used in excerpt (must go at the end)
for (Fieldable field : doNotUseInExcerpt) {
doc.add(field);
}
return doc;
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class LockManagerImpl method removeLockProperties.
/**
*
* @param node
* @throws RepositoryException
*/
protected void removeLockProperties(NodeImpl node) throws RepositoryException {
boolean success = false;
SessionImpl editingSession = (SessionImpl) node.getSession();
WorkspaceImpl wsp = (WorkspaceImpl) editingSession.getWorkspace();
UpdatableItemStateManager stateMgr = wsp.getItemStateManager();
try {
acquireLockPropertiesLock();
// add properties to content
if (stateMgr.inEditMode()) {
throw new RepositoryException("Unable to remove lock properties.");
}
stateMgr.edit();
try {
NodeId nodeId = node.getNodeId();
NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
if (nodeState.hasPropertyName(NameConstants.JCR_LOCKOWNER)) {
PropertyState propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKOWNER));
nodeState.removePropertyName(NameConstants.JCR_LOCKOWNER);
stateMgr.destroy(propState);
stateMgr.store(nodeState);
}
if (nodeState.hasPropertyName(NameConstants.JCR_LOCKISDEEP)) {
PropertyState propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKISDEEP));
nodeState.removePropertyName(NameConstants.JCR_LOCKISDEEP);
stateMgr.destroy(propState);
stateMgr.store(nodeState);
}
stateMgr.update();
success = true;
} catch (ItemStateException e) {
throw new RepositoryException("Error while removing lock.", e);
} finally {
if (!success) {
// failed to set lock meta-data content, cleanup
stateMgr.cancel();
}
}
} finally {
releaseLockPropertiesLock();
}
}
use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.
the class LockManagerImpl method writeLockProperties.
/**
* Add the lock related properties to the target node.
*
* @param node
* @param lockOwner
* @param isDeep
*/
protected void writeLockProperties(NodeImpl node, String lockOwner, boolean isDeep) throws RepositoryException {
boolean success = false;
SessionImpl editingSession = (SessionImpl) node.getSession();
WorkspaceImpl wsp = (WorkspaceImpl) editingSession.getWorkspace();
UpdatableItemStateManager stateMgr = wsp.getItemStateManager();
try {
acquireLockPropertiesLock();
if (stateMgr.inEditMode()) {
throw new RepositoryException("Unable to write lock properties.");
}
stateMgr.edit();
try {
// add properties to content
NodeId nodeId = node.getNodeId();
NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
PropertyState propState;
if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKOWNER)) {
propState = stateMgr.createNew(NameConstants.JCR_LOCKOWNER, nodeId);
propState.setType(PropertyType.STRING);
propState.setMultiValued(false);
} else {
propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKOWNER));
}
propState.setValues(new InternalValue[] { InternalValue.create(lockOwner) });
nodeState.addPropertyName(NameConstants.JCR_LOCKOWNER);
stateMgr.store(nodeState);
if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKISDEEP)) {
propState = stateMgr.createNew(NameConstants.JCR_LOCKISDEEP, nodeId);
propState.setType(PropertyType.BOOLEAN);
propState.setMultiValued(false);
} else {
propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKISDEEP));
}
propState.setValues(new InternalValue[] { InternalValue.create(isDeep) });
nodeState.addPropertyName(NameConstants.JCR_LOCKISDEEP);
stateMgr.store(nodeState);
stateMgr.update();
success = true;
} catch (ItemStateException e) {
throw new RepositoryException("Error while creating lock.", e);
} finally {
if (!success) {
// failed to set lock meta-data content, cleanup
stateMgr.cancel();
try {
unlock(node);
} catch (RepositoryException e) {
// cleanup failed
log.error("error while cleaning up after failed lock attempt", e);
}
}
}
} finally {
releaseLockPropertiesLock();
}
}
Aggregations