use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.
the class GarbageCollector method scanNodeIdList.
private void scanNodeIdList(int split, List<NodeId> nodeList, PersistenceManager pm, int pmCount) throws RepositoryException, ItemStateException {
int count = 0;
for (NodeId id : nodeList) {
count++;
if (count % 1000 == 0) {
if (split > 0) {
LOG.debug("[Split " + split + "] " + pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
} else {
LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
}
}
if (callback != null) {
callback.beforeScanning(null);
}
try {
NodeState state = pm.load(id);
Set<Name> propertyNames = state.getPropertyNames();
for (Name name : propertyNames) {
PropertyId pid = new PropertyId(id, name);
PropertyState ps = pm.load(pid);
if (ps.getType() == PropertyType.BINARY) {
for (InternalValue v : ps.getValues()) {
// getLength will update the last modified date
// if the persistence manager scan is running
v.getLength();
}
}
}
} catch (NoSuchItemStateException e) {
// the node may have been deleted or moved in the meantime
// ignore it
}
}
}
use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.
the class BundleReader method readBundleNew.
private void readBundleNew(NodePropBundle bundle) throws IOException {
// node type
bundle.setNodeTypeName(readName());
// parentUUID
NodeId parentId = readNodeId();
if (BundleBinding.NULL_PARENT_ID.equals(parentId)) {
parentId = null;
}
bundle.setParentId(parentId);
// read modcount
bundle.setModCount((short) readVarInt());
int b = in.readUnsignedByte();
bundle.setReferenceable((b & 1) != 0);
// mixin types
int mn = readVarInt((b >> 7) & 1, 1);
if (mn == 0) {
bundle.setMixinTypeNames(Collections.<Name>emptySet());
} else if (mn == 1) {
bundle.setMixinTypeNames(Collections.singleton(readName()));
} else {
Set<Name> mixins = new HashSet<Name>(mn * 2);
for (int i = 0; i < mn; i++) {
mixins.add(readName());
}
bundle.setMixinTypeNames(mixins);
}
// properties
int pn = readVarInt((b >> 4) & 7, 7);
for (int i = 0; i < pn; i++) {
PropertyId id = new PropertyId(bundle.getId(), readName());
bundle.addProperty(readPropertyEntry(id));
}
// child nodes (list of name/uuid pairs)
int nn = readVarInt((b >> 2) & 3, 3);
for (int i = 0; i < nn; i++) {
Name name = readQName();
NodeId id = readNodeId();
bundle.addChildNodeEntry(name, id);
}
// read shared set
int sn = readVarInt((b >> 1) & 1, 1);
if (sn == 0) {
bundle.setSharedSet(Collections.<NodeId>emptySet());
} else if (sn == 1) {
bundle.setSharedSet(Collections.singleton(readNodeId()));
} else {
Set<NodeId> shared = new HashSet<NodeId>();
for (int i = 0; i < sn; i++) {
shared.add(readNodeId());
}
bundle.setSharedSet(shared);
}
}
use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.
the class XMLPersistenceManager method store.
/**
* {@inheritDoc}
*/
protected void store(NodeReferences refs) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
try {
refsFile.makeParentDirs();
OutputStream os = refsFile.getOutputStream();
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(os, DEFAULT_ENCODING));
writer.write("<?xml version=\"1.0\" encoding=\"" + DEFAULT_ENCODING.name() + "\"?>\n");
writer.write("<" + NODEREFERENCES_ELEMENT + " " + TARGETID_ATTRIBUTE + "=\"" + refs.getTargetId() + "\">\n");
// write references (i.e. the id's of the REFERENCE properties)
for (PropertyId propId : refs.getReferences()) {
writer.write("\t<" + NODEREFERENCE_ELEMENT + " " + PROPERTYID_ATTRIBUTE + "=\"" + propId + "\"/>\n");
}
writer.write("</" + NODEREFERENCES_ELEMENT + ">\n");
} finally {
writer.close();
}
} catch (Exception e) {
String msg = "failed to store " + refs;
log.debug(msg);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.
the class PersistenceCopier method copy.
/**
* Copies the given node state and all associated property states
* to the target persistence manager.
*
* @param sourceNode source node state
* @throws RepositoryException if the copy operation fails
*/
private void copy(NodeState sourceNode) throws RepositoryException {
try {
ChangeLog changes = new ChangeLog();
// Copy the node state
NodeState targetNode = target.createNew(sourceNode.getNodeId());
targetNode.setParentId(sourceNode.getParentId());
targetNode.setNodeTypeName(sourceNode.getNodeTypeName());
targetNode.setMixinTypeNames(sourceNode.getMixinTypeNames());
targetNode.setPropertyNames(sourceNode.getPropertyNames());
targetNode.setChildNodeEntries(sourceNode.getChildNodeEntries());
if (target.exists(targetNode.getNodeId())) {
changes.modified(targetNode);
} else {
changes.added(targetNode);
}
// Copy all associated property states
for (Name name : sourceNode.getPropertyNames()) {
PropertyId id = new PropertyId(sourceNode.getNodeId(), name);
PropertyState sourceState = source.load(id);
PropertyState targetState = target.createNew(id);
targetState.setType(sourceState.getType());
targetState.setMultiValued(sourceState.isMultiValued());
InternalValue[] values = sourceState.getValues();
// special case copy of binary values
if (sourceState.getType() == PropertyType.BINARY) {
InternalValue[] convertedValues = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
try (InputStream stream = values[i].getStream()) {
convertedValues[i] = InternalValue.create(stream, store);
}
}
targetState.setValues(convertedValues);
} else {
targetState.setValues(values);
}
if (target.exists(targetState.getPropertyId())) {
changes.modified(targetState);
} else {
changes.added(targetState);
}
}
// Copy all node references
if (source.existsReferencesTo(sourceNode.getNodeId())) {
changes.modified(source.loadReferencesTo(sourceNode.getNodeId()));
} else if (target.existsReferencesTo(sourceNode.getNodeId())) {
NodeReferences references = target.loadReferencesTo(sourceNode.getNodeId());
references.clearAllReferences();
changes.modified(references);
}
// Persist the copied states
target.store(changes);
} catch (IOException e) {
throw new RepositoryException("Unable to copy binary values of " + sourceNode, e);
} catch (ItemStateException e) {
throw new RepositoryException("Unable to copy " + sourceNode, e);
}
}
use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.
the class AbstractBundlePersistenceManager method storeInternal.
/**
* Stores the given changelog and updates the bundle cache.
*
* @param changeLog the changelog to store
* @throws ItemStateException on failure
*/
private void storeInternal(ChangeLog changeLog) throws ItemStateException {
// delete bundles
HashSet<ItemId> deleted = new HashSet<ItemId>();
for (ItemState state : changeLog.deletedStates()) {
if (state.isNode()) {
NodePropBundle bundle = getBundle((NodeId) state.getId());
if (bundle == null) {
throw new NoSuchItemStateException(state.getId().toString());
}
deleteBundle(bundle);
deleted.add(state.getId());
}
}
// gather added node states
HashMap<ItemId, NodePropBundle> modified = new HashMap<ItemId, NodePropBundle>();
for (ItemState state : changeLog.addedStates()) {
if (state.isNode()) {
NodePropBundle bundle = new NodePropBundle((NodeState) state);
modified.put(state.getId(), bundle);
}
}
// gather modified node states
for (ItemState state : changeLog.modifiedStates()) {
if (state.isNode()) {
NodeId nodeId = (NodeId) state.getId();
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.update((NodeState) state);
} else {
PropertyId id = (PropertyId) state.getId();
// skip redundant primaryType and uuid properties
if (id.getName().equals(JCR_PRIMARYTYPE) || id.getName().equals(JCR_UUID)) {
continue;
}
NodeId nodeId = id.getParentId();
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.addProperty((PropertyState) state, getBlobStore());
}
}
// add removed properties
for (ItemState state : changeLog.deletedStates()) {
if (state.isNode()) {
// check consistency
NodeId parentId = state.getParentId();
if (!modified.containsKey(parentId) && !deleted.contains(parentId)) {
log.warn("Deleted node state's parent is not modified or deleted: " + parentId + "/" + state.getId());
}
} else {
PropertyId id = (PropertyId) state.getId();
NodeId nodeId = id.getParentId();
if (!deleted.contains(nodeId)) {
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
// should actually not happen
log.warn("deleted property state's parent not modified!");
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.removeProperty(id.getName(), getBlobStore());
}
}
}
// add added properties
for (ItemState state : changeLog.addedStates()) {
if (!state.isNode()) {
PropertyId id = (PropertyId) state.getId();
// skip primaryType and uuid properties
if (id.getName().equals(JCR_PRIMARYTYPE) || id.getName().equals(JCR_UUID)) {
continue;
}
NodeId nodeId = id.getParentId();
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
// should actually not happen
log.warn("added property state's parent not modified!");
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.addProperty((PropertyState) state, getBlobStore());
}
}
// now store all modified bundles
long updateSize = 0;
for (NodePropBundle bundle : modified.values()) {
putBundle(bundle);
updateSize += bundle.getSize();
}
changeLog.setUpdateSize(updateSize);
// store the refs
for (NodeReferences refs : changeLog.modifiedRefs()) {
if (refs.hasReferences()) {
store(refs);
} else {
destroy(refs);
}
}
}
Aggregations