use of org.apache.jackrabbit.core.id.NodeId 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.id.NodeId in project jackrabbit by apache.
the class BundleReader method readBundleOld.
private void readBundleOld(NodePropBundle bundle) throws IOException {
// read primary type...special handling
int a = in.readUnsignedByte();
int b = in.readUnsignedByte();
int c = in.readUnsignedByte();
String uri = binding.nsIndex.indexToString(a << 16 | b << 8 | c);
String local = binding.nameIndex.indexToString(in.readInt());
bundle.setNodeTypeName(NameFactoryImpl.getInstance().create(uri, local));
// parentUUID
bundle.setParentId(readNodeId());
// definitionId
in.readUTF();
// mixin types
Name name = readIndexedQName();
if (name != null) {
Set<Name> mixinTypeNames = new HashSet<Name>();
do {
mixinTypeNames.add(name);
name = readIndexedQName();
} while (name != null);
bundle.setMixinTypeNames(mixinTypeNames);
} else {
bundle.setMixinTypeNames(Collections.<Name>emptySet());
}
// properties
name = readIndexedQName();
while (name != null) {
PropertyId pId = new PropertyId(bundle.getId(), name);
NodePropBundle.PropertyEntry pState = readPropertyEntry(pId);
// skip redundant primaryType, mixinTypes and uuid properties
if (!name.equals(NameConstants.JCR_PRIMARYTYPE) && !name.equals(NameConstants.JCR_UUID)) {
bundle.addProperty(pState);
}
name = readIndexedQName();
}
// set referenceable flag
bundle.setReferenceable(in.readBoolean());
// child nodes (list of uuid/name pairs)
NodeId childId = readNodeId();
while (childId != null) {
bundle.addChildNodeEntry(readQName(), childId);
childId = readNodeId();
}
// read modcount, since version 1.0
if (version >= BundleBinding.VERSION_1) {
bundle.setModCount(in.readShort());
}
// read shared set, since version 2.0
if (version >= BundleBinding.VERSION_2) {
// shared set (list of parent uuids)
NodeId parentId = readNodeId();
if (parentId != null) {
Set<NodeId> shared = new HashSet<NodeId>();
do {
shared.add(parentId);
parentId = readNodeId();
} while (parentId != null);
bundle.setSharedSet(shared);
} else {
bundle.setSharedSet(Collections.<NodeId>emptySet());
}
} else {
bundle.setSharedSet(Collections.<NodeId>emptySet());
}
}
use of org.apache.jackrabbit.core.id.NodeId 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);
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class Serializer method deserialize.
/**
* Deserializes a <code>NodeState</code> object from the given binary
* <code>stream</code>.
*
* @param state <code>state</code> to deserialize
* @param stream the stream where the <code>state</code> should be deserialized from
* @throws Exception if an error occurs during the deserialization
* @see #serialize(NodeState, OutputStream)
*/
public static void deserialize(NodeState state, InputStream stream) throws Exception {
DataInputStream in = new DataInputStream(stream);
// primaryType
String s = in.readUTF();
state.setNodeTypeName(NameFactoryImpl.getInstance().create(s));
// parentUUID (may be null)
byte[] uuidBytes = new byte[NodeId.UUID_BYTE_LENGTH];
in.readFully(uuidBytes);
if (!Arrays.equals(uuidBytes, NULL_UUID_PLACEHOLDER_BYTES)) {
state.setParentId(new NodeId(uuidBytes));
}
// definitionId
in.readUTF();
// mixin types
// count
int count = in.readInt();
Set<Name> set = new HashSet<Name>(count);
for (int i = 0; i < count; i++) {
set.add(NameFactoryImpl.getInstance().create(in.readUTF()));
}
if (set.size() > 0) {
state.setMixinTypeNames(set);
}
// modCount
short modCount = in.readShort();
state.setModCount(modCount);
// properties (names)
// count
count = in.readInt();
for (int i = 0; i < count; i++) {
// name
state.addPropertyName(NameFactoryImpl.getInstance().create(in.readUTF()));
}
// child nodes (list of name/uuid pairs)
// count
count = in.readInt();
for (int i = 0; i < count; i++) {
// name
Name name = NameFactoryImpl.getInstance().create(in.readUTF());
// uuid
in.readFully(uuidBytes);
state.addChildNodeEntry(name, new NodeId(uuidBytes));
}
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class NodePropBundle method createNodeState.
/**
* Creates a node state from the values of this bundle
* @param pMgr the persistence manager
* @return the new nodestate
*/
public NodeState createNodeState(PersistenceManager pMgr) {
NodeState state = pMgr.createNew(id);
state.setParentId(parentId);
state.setNodeTypeName(nodeTypeName);
state.setMixinTypeNames(mixinTypeNames);
state.setModCount(modCount);
for (ChildNodeEntry e : childNodeEntries) {
state.addChildNodeEntry(e.getName(), e.getId());
}
state.setPropertyNames(properties.keySet());
// add fake property entries
state.addPropertyName(NameConstants.JCR_PRIMARYTYPE);
if (mixinTypeNames.size() > 0) {
state.addPropertyName(NameConstants.JCR_MIXINTYPES);
}
// uuid is special...only if 'referenceable'
if (isReferenceable) {
state.addPropertyName(NameConstants.JCR_UUID);
}
for (NodeId nodeId : sharedSet) {
state.addShare(nodeId);
}
return state;
}
Aggregations