use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class MemoryNodeState method compareAgainstBaseState.
/**
* We don't keep track of a separate base node state for
* {@link MemoryNodeState} instances, so this method will just do
* a generic diff against the given state.
*/
@Override
public boolean compareAgainstBaseState(NodeState base, NodeStateDiff diff) {
if (base == EMPTY_NODE || !base.exists()) {
return EmptyNodeState.compareAgainstEmptyState(this, diff);
}
Map<String, PropertyState> newProperties = new HashMap<String, PropertyState>(properties);
for (PropertyState before : base.getProperties()) {
PropertyState after = newProperties.remove(before.getName());
if (after == null) {
if (!diff.propertyDeleted(before)) {
return false;
}
} else if (!after.equals(before)) {
if (!diff.propertyChanged(before, after)) {
return false;
}
}
}
for (PropertyState after : newProperties.values()) {
if (!diff.propertyAdded(after)) {
return false;
}
}
Map<String, NodeState> newNodes = new HashMap<String, NodeState>(nodes);
for (ChildNodeEntry entry : base.getChildNodeEntries()) {
String name = entry.getName();
NodeState before = entry.getNodeState();
NodeState after = newNodes.remove(name);
if (after == null) {
if (!diff.childNodeDeleted(name, before)) {
return false;
}
} else if (after != before) {
if (!diff.childNodeChanged(name, before, after)) {
return false;
}
}
}
for (Map.Entry<String, NodeState> entry : newNodes.entrySet()) {
if (!diff.childNodeAdded(entry.getKey(), entry.getValue())) {
return false;
}
}
return true;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class EffectiveType method getDefinition.
/**
* Finds a matching definition for a property with the given name and type.
*
* @param property modified property
* @return matching property definition, or {@code null}
*/
@CheckForNull
NodeState getDefinition(@Nonnull PropertyState property) {
String propertyName = property.getName();
Type<?> propertyType = property.getType();
String escapedName;
if (JCR_PRIMARYTYPE.equals(propertyName)) {
escapedName = NodeTypeConstants.REP_PRIMARY_TYPE;
} else if (JCR_MIXINTYPES.equals(propertyName)) {
escapedName = NodeTypeConstants.REP_MIXIN_TYPES;
} else if (JCR_UUID.equals(propertyName)) {
escapedName = NodeTypeConstants.REP_UUID;
} else {
escapedName = propertyName;
}
String definedType = propertyType.toString();
String undefinedType;
if (propertyType.isArray()) {
undefinedType = UNDEFINEDS.toString();
} else {
undefinedType = UNDEFINED.toString();
}
// Find matching named property definition
for (NodeState type : types) {
NodeState definitions = type.getChildNode(REP_NAMED_PROPERTY_DEFINITIONS).getChildNode(escapedName);
NodeState definition = definitions.getChildNode(definedType);
if (definition.exists()) {
return definition;
}
definition = definitions.getChildNode(undefinedType);
if (definition.exists()) {
return definition;
}
// TODO: unnecessary if the OAK-713 fallback wasn't needed below
for (ChildNodeEntry entry : definitions.getChildNodeEntries()) {
definition = entry.getNodeState();
if (definition.getBoolean(JCR_MANDATORY)) {
return definition;
}
}
// TODO: Fall back to residual definitions until we have consensus on OAK-713
// throw new ConstraintViolationException(
// "No matching definition found for property " + propertyName);
}
// Find matching residual property definition
for (NodeState type : types) {
NodeState residual = type.getChildNode(REP_RESIDUAL_PROPERTY_DEFINITIONS);
NodeState definition = residual.getChildNode(definedType);
if (!definition.exists()) {
definition = residual.getChildNode(undefinedType);
}
if (definition.exists()) {
return definition;
}
}
return null;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class EffectiveType method isValidChildNode.
/**
* Finds a matching definition for a child node with the given name and
* types.
*
* @param nameWithIndex child node name, possibly with an SNS index
* @param effective effective types of the child node
* @return {@code true} if there's a matching child node definition,
* {@code false} otherwise
*/
boolean isValidChildNode(@Nonnull String nameWithIndex, @Nonnull EffectiveType effective) {
String name = dropIndexFromName(nameWithIndex);
boolean sns = !name.equals(nameWithIndex);
Set<String> typeNames = effective.getTypeNames();
// Find matching named child node definition
for (NodeState type : types) {
NodeState definitions = type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).getChildNode(name);
for (String typeName : typeNames) {
NodeState definition = definitions.getChildNode(typeName);
if (definition.exists() && snsMatch(sns, definition)) {
return true;
}
}
// TODO: unnecessary if the OAK-713 fallback wasn't needed below
for (ChildNodeEntry entry : definitions.getChildNodeEntries()) {
NodeState definition = entry.getNodeState();
if (definition.getBoolean(JCR_MANDATORY)) {
return false;
}
}
// TODO: Fall back to residual definitions until we have consensus on OAK-713
// throw new ConstraintViolationException(
// "Incorrect node type of child node " + nodeName);
}
// Find matching residual child node definition
for (NodeState type : types) {
NodeState residual = type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
for (String typeName : typeNames) {
NodeState definition = residual.getChildNode(typeName);
if (definition.exists() && snsMatch(sns, definition)) {
return true;
}
}
}
return false;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class PropertyIndexInfoProvider method computeCountEstimate.
private void computeCountEstimate(PropertyIndexInfo info, NodeState idxState) {
long count = -1;
for (ChildNodeEntry cne : idxState.getChildNodeEntries()) {
// In multiplexing setups there can be multiple index nodes
if (NodeStateUtils.isHidden(cne.getName())) {
NodeState indexData = cne.getNodeState();
long estimate = ApproximateCounter.getCountSync(indexData);
if (estimate > 0) {
if (count < 0) {
count = 0;
}
count += estimate;
} else if (count < 0 && indexData.getChildNodeCount(1) == 0) {
// If we cannot get estimate then at least try to see if any index data is there or not
count = 0;
}
}
}
info.estimatedCount = count;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class CheckpointCompactorTest method checkGeneration.
private static void checkGeneration(NodeState node, GCGeneration gcGeneration) {
assertTrue(node instanceof SegmentNodeState);
assertEquals(gcGeneration, ((SegmentNodeState) node).getRecordId().getSegmentId().getGcGeneration());
for (ChildNodeEntry cne : node.getChildNodeEntries()) {
checkGeneration(cne.getNodeState(), gcGeneration);
}
}
Aggregations