use of org.apache.jackrabbit.core.state.ChangeLog in project jackrabbit by apache.
the class VersionItemStateManager method setNodeReferences.
/**
* Sets the
* @param references
* @return
*/
public boolean setNodeReferences(ChangeLog references) {
try {
ChangeLog log = new ChangeLog();
for (NodeReferences source : references.modifiedRefs()) {
// filter out version storage intern ones
NodeReferences target = new NodeReferences(source.getTargetId());
for (PropertyId id : source.getReferences()) {
if (!hasNonVirtualItemState(id.getParentId())) {
target.addReference(id);
}
}
log.modified(target);
}
if (log.hasUpdates()) {
pMgr.store(log);
}
return true;
} catch (ItemStateException e) {
log.error("Error while setting references: " + e.toString());
return false;
}
}
use of org.apache.jackrabbit.core.state.ChangeLog in project jackrabbit by apache.
the class ConsistencyCheckerImpl method repair.
/**
* Repair any errors found during a {@link #check}. Should be run after a {#check} and
* (if needed) {@link #doubleCheckErrors}.
*
* @throws RepositoryException
*/
public void repair() throws RepositoryException {
checkLostNFound();
bundles = new HashMap<NodeId, NodePropBundle>();
if (hasRepairableErrors()) {
boolean successful = false;
final CheckerUpdate update = new CheckerUpdate();
try {
eventChannel.updateCreated(update);
for (ConsistencyCheckerError error : errors) {
if (error.isRepairable()) {
try {
error.repair(update.getChanges());
info(null, "Repairing " + error);
} catch (ItemStateException e) {
error(null, "Failed to repair error: " + error, e);
}
}
}
final ChangeLog changes = update.getChanges();
if (changes.hasUpdates()) {
eventChannel.updatePrepared(update);
for (NodePropBundle bundle : bundles.values()) {
storeBundle(bundle);
}
update.setAttribute(ATTRIBUTE_UPDATE_SIZE, changes.getUpdateSize());
successful = true;
}
} catch (ClusterException e) {
throw new RepositoryException("Cannot create update", e);
} finally {
if (successful) {
eventChannel.updateCommitted(update, "checker@");
} else {
eventChannel.updateCancelled(update);
}
}
}
}
use of org.apache.jackrabbit.core.state.ChangeLog in project jackrabbit by apache.
the class UpdateEventFactory method createUpdateOperationWithNullUserId.
/**
* Create an update operation.
*
* @return update operation
*/
public UpdateEvent createUpdateOperationWithNullUserId() {
NodeState n1 = createNodeState();
NodeState n2 = createNodeState();
NodeState n3 = createNodeState();
PropertyState p1 = createPropertyState(n1.getNodeId(), "{}a");
PropertyState p2 = createPropertyState(n2.getNodeId(), "{}b");
ChangeLog changes = new ChangeLog();
changes.added(n1);
changes.added(p1);
changes.deleted(p2);
changes.modified(n2);
changes.deleted(n3);
Session s = new ClusterSession(null);
List events = new ArrayList();
events.add(createEventState(n1, Event.NODE_ADDED, "{}n1", s));
events.add(createEventState(p1, n1, Event.PROPERTY_ADDED, s));
events.add(createEventState(p2, n2, Event.PROPERTY_REMOVED, s));
events.add(createEventState(n3, Event.NODE_REMOVED, "{}n3", s));
return new UpdateEvent(changes, events, System.currentTimeMillis(), "user-data");
}
use of org.apache.jackrabbit.core.state.ChangeLog in project jackrabbit by apache.
the class UpdateEventFactory method createUpdateOperation.
/**
* Create an update operation.
*
* @return update operation
*/
public UpdateEvent createUpdateOperation() {
NodeState n1 = createNodeState();
NodeState n2 = createNodeState();
NodeState n3 = createNodeState();
PropertyState p1 = createPropertyState(n1.getNodeId(), "{}a");
PropertyState p2 = createPropertyState(n2.getNodeId(), "{}b");
ChangeLog changes = new ChangeLog();
changes.added(n1);
changes.added(p1);
changes.deleted(p2);
changes.modified(n2);
changes.deleted(n3);
List events = new ArrayList();
events.add(createEventState(n1, Event.NODE_ADDED, "{}n1", session));
events.add(createEventState(p1, n1, Event.PROPERTY_ADDED, session));
events.add(createEventState(p2, n2, Event.PROPERTY_REMOVED, session));
events.add(createEventState(n3, Event.NODE_REMOVED, "{}n3", session));
return new UpdateEvent(changes, events, System.currentTimeMillis(), "user-data");
}
use of org.apache.jackrabbit.core.state.ChangeLog in project jackrabbit by apache.
the class PersistenceManagerTest method assertCreateUpdateDelete.
private void assertCreateUpdateDelete(PersistenceManager manager) throws Exception {
NodeState node = new NodeState(NODE_ID, TEST, RepositoryImpl.ROOT_NODE_ID, ItemState.STATUS_NEW, true);
node.addChildNodeEntry(TEST, CHILD_ID);
node.addPropertyName(NameConstants.JCR_PRIMARYTYPE);
node.addPropertyName(TEST);
NodeState child = new NodeState(CHILD_ID, TEST, NODE_ID, ItemState.STATUS_NEW, true);
child.addPropertyName(NameConstants.JCR_PRIMARYTYPE);
PropertyState property = new PropertyState(PROPERTY_ID, ItemState.STATUS_NEW, true);
property.setType(PropertyType.REFERENCE);
property.setValues(new InternalValue[] { InternalValue.create(CHILD_ID) });
NodeReferences references = new NodeReferences(CHILD_ID);
references.addReference(PROPERTY_ID);
ChangeLog create = new ChangeLog();
create.added(node);
create.added(child);
create.added(property);
create.modified(references);
manager.store(create);
assertTrue(manager.exists(NODE_ID));
assertTrue(manager.exists(CHILD_ID));
assertTrue(manager.exists(PROPERTY_ID));
assertTrue(manager.existsReferencesTo(CHILD_ID));
assertEquals(node, manager.load(NODE_ID));
assertEquals(child, manager.load(CHILD_ID));
assertEquals(property, manager.load(PROPERTY_ID));
assertEquals(references, manager.loadReferencesTo(CHILD_ID));
references.removeReference(PROPERTY_ID);
node.setStatus(ItemState.STATUS_EXISTING);
ChangeLog update = new ChangeLog();
update.modified(references);
node.removePropertyName(TEST);
update.deleted(property);
update.modified(node);
manager.store(update);
assertTrue(manager.exists(NODE_ID));
assertTrue(manager.exists(CHILD_ID));
assertFalse(manager.exists(PROPERTY_ID));
assertFalse(manager.existsReferencesTo(CHILD_ID));
assertEquals(node, manager.load(NODE_ID));
assertEquals(child, manager.load(CHILD_ID));
ChangeLog delete = new ChangeLog();
delete.deleted(child);
delete.deleted(node);
manager.store(delete);
assertFalse(manager.exists(NODE_ID));
assertFalse(manager.exists(CHILD_ID));
assertFalse(manager.exists(PROPERTY_ID));
assertFalse(manager.existsReferencesTo(CHILD_ID));
}
Aggregations