use of org.apache.jackrabbit.core.state.ItemStateManager in project jackrabbit by apache.
the class NodeImpl method removeChildNode.
protected void removeChildNode(NodeId childId) throws RepositoryException {
// modify the state of 'this', i.e. the parent node
NodeState thisState = (NodeState) getOrCreateTransientItemState();
ChildNodeEntry entry = thisState.getChildNodeEntry(childId);
if (entry == null) {
String msg = "failed to remove child " + childId + " of " + this;
log.debug(msg);
throw new RepositoryException(msg);
}
// notify target of removal
try {
NodeImpl childNode = itemMgr.getNode(childId, getNodeId());
childNode.onRemove(getNodeId());
} catch (ItemNotFoundException e) {
boolean ignoreError = false;
if (sessionContext.getSessionImpl().autoFixCorruptions()) {
// it might be an access right problem
// we need to check if the item doesn't exist in the ism
ItemStateManager ism = sessionContext.getItemStateManager();
if (!ism.hasItemState(childId)) {
log.warn("Node " + childId + " not found, ignore", e);
ignoreError = true;
}
}
if (!ignoreError) {
throw e;
}
}
// remove the child node entry
if (!thisState.removeChildNodeEntry(childId)) {
String msg = "failed to remove child " + childId + " of " + this;
log.debug(msg);
throw new RepositoryException(msg);
}
}
use of org.apache.jackrabbit.core.state.ItemStateManager in project jackrabbit by apache.
the class SearchIndex method retrieveAggregateRoot.
/**
* Retrieves the root of the indexing aggregate for <code>removedIds</code>
* and puts it into <code>map</code>.
*
* @param removedIds the ids of removed nodes.
* @param aggregates aggregate roots are collected in this map
*/
protected void retrieveAggregateRoot(Set<NodeId> removedIds, Map<NodeId, NodeState> aggregates) {
if (removedIds.isEmpty() || indexingConfig == null) {
return;
}
AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
if (aggregateRules == null) {
return;
}
int found = 0;
long time = System.currentTimeMillis();
try {
CachingMultiIndexReader reader = index.getIndexReader();
try {
Term aggregateIds = new Term(FieldNames.AGGREGATED_NODE_UUID, "");
TermDocs tDocs = reader.termDocs();
try {
ItemStateManager ism = getContext().getItemStateManager();
for (NodeId id : removedIds) {
aggregateIds = aggregateIds.createTerm(id.toString());
tDocs.seek(aggregateIds);
while (tDocs.next()) {
Document doc = reader.document(tDocs.doc(), FieldSelectors.UUID);
NodeId nId = new NodeId(doc.get(FieldNames.UUID));
NodeState nodeState = (NodeState) ism.getItemState(nId);
aggregates.put(nId, nodeState);
found++;
// JCR-2989 Support for embedded index aggregates
int sizeBefore = aggregates.size();
retrieveAggregateRoot(nodeState, aggregates);
found += aggregates.size() - sizeBefore;
}
}
} finally {
tDocs.close();
}
} finally {
reader.release();
}
} catch (NoSuchItemStateException e) {
log.info("Exception while retrieving aggregate roots. Node is not available {}.", e.getMessage());
} catch (Exception e) {
log.warn("Exception while retrieving aggregate roots", e);
}
time = System.currentTimeMillis() - time;
log.debug("Retrieved {} aggregate roots in {} ms.", found, time);
}
use of org.apache.jackrabbit.core.state.ItemStateManager in project jackrabbit by apache.
the class PropertyValueOperand method getPropertyState.
/**
* Returns the property state for the given score node or <code>null</code>
* if none exists.
*
* @param sn the current score node.
* @param context the evaluation context.
* @return the property state or <code>null</code>.
* @throws RepositoryException if an error occurs while reading.
*/
public final PropertyState getPropertyState(ScoreNode sn, EvaluationContext context) throws RepositoryException {
ItemStateManager ism = context.getItemStateManager();
PropertyId propId = new PropertyId(sn.getNodeId(), operand.getPropertyQName());
try {
return (PropertyState) ism.getItemState(propId);
} catch (NoSuchItemStateException e) {
return null;
} catch (ItemStateException e) {
throw new RepositoryException(e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateManager in project jackrabbit by apache.
the class NodeImpl method onRemove.
protected void onRemove(NodeId parentId) throws RepositoryException {
// modify the state of 'this', i.e. the target node
NodeState thisState = (NodeState) getOrCreateTransientItemState();
// remove this node from its shared set
if (thisState.isShareable()) {
if (thisState.removeShare(parentId) > 0) {
// this state is still connected to some parents, so
// leave the child node entries and properties
// set state of this instance to 'invalid'
data.setStatus(STATUS_INVALIDATED);
// notify the item manager that this instance has been
// temporarily invalidated
itemMgr.itemInvalidated(id, data);
return;
}
}
if (thisState.hasChildNodeEntries()) {
// remove child nodes
// use temp array to avoid ConcurrentModificationException
ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(thisState.getChildNodeEntries());
// remove from tail to avoid problems with same-name siblings
for (int i = tmp.size() - 1; i >= 0; i--) {
ChildNodeEntry entry = tmp.get(i);
// recursively remove child node
NodeId childId = entry.getId();
//NodeImpl childNode = (NodeImpl) itemMgr.getItem(childId);
try {
/* omit the read-permission check upon retrieving the
child item as this is an internal call to remove the
subtree which may contain (protected) child items which
are not visible to the caller of the removal. the actual
validation of the remove permission however is only
executed during Item.save().
*/
NodeImpl childNode = itemMgr.getNode(childId, getNodeId(), false);
childNode.onRemove(thisState.getNodeId());
// remove the child node entry
} catch (ItemNotFoundException e) {
boolean ignoreError = false;
if (parentId != null && sessionContext.getSessionImpl().autoFixCorruptions()) {
// it might be an access right problem
// we need to check if the item doesn't exist in the ism
ItemStateManager ism = sessionContext.getItemStateManager();
if (!ism.hasItemState(childId)) {
log.warn("Child named " + entry.getName() + " (index " + entry.getIndex() + ", " + "node id " + childId + ") " + "not found when trying to remove " + getPath() + " " + "(node id " + getNodeId() + ") - ignored", e);
ignoreError = true;
}
}
if (!ignoreError) {
throw e;
}
}
thisState.removeChildNodeEntry(childId);
}
}
// remove properties
// use temp set to avoid ConcurrentModificationException
HashSet<Name> tmp = new HashSet<Name>(thisState.getPropertyNames());
for (Name propName : tmp) {
// remove the property entry
thisState.removePropertyName(propName);
// remove property
PropertyId propId = new PropertyId(thisState.getNodeId(), propName);
/* omit the read-permission check upon retrieving the
child item as this is an internal call to remove the
subtree which may contain (protected) child items which
are not visible to the caller of the removal. the actual
validation of the remove permission however is only
executed during Item.save().
*/
itemMgr.getItem(propId, false).setRemoved();
}
// finally remove this node
thisState.setParentId(null);
setRemoved();
}
use of org.apache.jackrabbit.core.state.ItemStateManager in project jackrabbit by apache.
the class SearchIndex method mergeAggregatedNodeIndexes.
/**
* Merges the fulltext indexed fields of the aggregated node states into
* <code>doc</code>.
*
* @param state the node state on which <code>doc</code> was created.
* @param doc the lucene document with index fields from <code>state</code>.
* @param ifv the current index format version.
*/
protected void mergeAggregatedNodeIndexes(NodeState state, Document doc, IndexFormatVersion ifv) {
if (indexingConfig != null) {
AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
if (aggregateRules == null) {
return;
}
try {
ItemStateManager ism = getContext().getItemStateManager();
for (AggregateRule aggregateRule : aggregateRules) {
boolean ruleMatched = false;
// node includes
NodeState[] aggregates = aggregateRule.getAggregatedNodeStates(state);
if (aggregates != null) {
ruleMatched = true;
for (NodeState aggregate : aggregates) {
Document aDoc = createDocument(aggregate, getNamespaceMappings(), ifv);
// transfer fields to doc if there are any
Fieldable[] fulltextFields = aDoc.getFieldables(FieldNames.FULLTEXT);
if (fulltextFields != null) {
for (Fieldable fulltextField : fulltextFields) {
doc.add(fulltextField);
}
doc.add(new Field(FieldNames.AGGREGATED_NODE_UUID, false, aggregate.getNodeId().toString(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
}
}
// make sure that fulltext fields are aligned properly
// first all stored fields, then remaining
Fieldable[] fulltextFields = doc.getFieldables(FieldNames.FULLTEXT);
doc.removeFields(FieldNames.FULLTEXT);
Arrays.sort(fulltextFields, FIELDS_COMPARATOR_STORED);
for (Fieldable f : fulltextFields) {
doc.add(f);
}
}
// property includes
PropertyState[] propStates = aggregateRule.getAggregatedPropertyStates(state);
if (propStates != null) {
ruleMatched = true;
for (PropertyState propState : propStates) {
String namePrefix = FieldNames.createNamedValue(getNamespaceMappings().translateName(propState.getName()), "");
NodeState parent = (NodeState) ism.getItemState(propState.getParentId());
Document aDoc = createDocument(parent, getNamespaceMappings(), ifv);
try {
// find the right fields to transfer
Fieldable[] fields = aDoc.getFieldables(FieldNames.PROPERTIES);
for (Fieldable field : fields) {
// assume properties fields use SingleTokenStream
TokenStream tokenStream = field.tokenStreamValue();
TermAttribute termAttribute = tokenStream.addAttribute(TermAttribute.class);
PayloadAttribute payloadAttribute = tokenStream.addAttribute(PayloadAttribute.class);
tokenStream.incrementToken();
tokenStream.end();
tokenStream.close();
String value = new String(termAttribute.termBuffer(), 0, termAttribute.termLength());
if (value.startsWith(namePrefix)) {
// extract value
String rawValue = value.substring(namePrefix.length());
// create new named value
Path p = getRelativePath(state, propState);
String path = getNamespaceMappings().translatePath(p);
value = FieldNames.createNamedValue(path, rawValue);
termAttribute.setTermBuffer(value);
PropertyMetaData pdm = PropertyMetaData.fromByteArray(payloadAttribute.getPayload().getData());
doc.add(new Field(field.name(), new SingletonTokenStream(value, pdm.getPropertyType())));
doc.add(new Field(FieldNames.AGGREGATED_NODE_UUID, false, parent.getNodeId().toString(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
if (pdm.getPropertyType() == PropertyType.STRING) {
// add to fulltext index
Field ft = new Field(FieldNames.FULLTEXT, false, rawValue, Field.Store.YES, Field.Index.ANALYZED_NO_NORMS, Field.TermVector.NO);
doc.add(ft);
}
}
}
} finally {
Util.disposeDocument(aDoc);
}
}
}
// only use first aggregate definition that matches
if (ruleMatched) {
break;
}
}
} catch (NoSuchItemStateException e) {
// do not fail if aggregate cannot be created
log.info("Exception while building indexing aggregate for {}. Node is not available {}.", state.getNodeId(), e.getMessage());
} catch (Exception e) {
// do not fail if aggregate cannot be created
log.warn("Exception while building indexing aggregate for " + state.getNodeId(), e);
}
}
}
Aggregations