Search in sources :

Example 26 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class NodeCounterEditor method leaveOld.

private void leaveOld(NodeState before, NodeState after) throws CommitFailedException {
    long offset = ApproximateCounter.calculateOffset(countOffset, root.resolution);
    if (offset == 0) {
        return;
    }
    // only read the value of the property if really needed
    NodeBuilder builder = getBuilder();
    PropertyState p = builder.getProperty(COUNT_PROPERTY_NAME);
    long count = p == null ? 0 : p.getValue(Type.LONG);
    offset = ApproximateCounter.adjustOffset(count, offset, root.resolution);
    if (offset == 0) {
        return;
    }
    count += offset;
    root.callback.indexUpdate();
    if (count == 0) {
        if (builder.getChildNodeCount(1) >= 0) {
            builder.removeProperty(COUNT_PROPERTY_NAME);
        } else {
            builder.remove();
        }
    } else {
        builder.setProperty(COUNT_PROPERTY_NAME, count);
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 27 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class NodeCounter method getEstimatedNodeCountOld.

private static long getEstimatedNodeCountOld(NodeState root, NodeState s, String path, boolean max) {
    // old code from here
    PropertyState p = s.getProperty(NodeCounterEditor.COUNT_PROPERTY_NAME);
    if (p != null) {
        long x = p.getValue(Type.LONG);
        if (max) {
            // in the node itself, we just add the resolution
            x += ApproximateCounter.COUNT_RESOLUTION;
        }
        return x;
    }
    // check in the counter index (if it exists)
    s = child(root, IndexConstants.INDEX_DEFINITIONS_NAME, "counter");
    if (s == null || !s.exists()) {
        // no index
        return -1;
    }
    s = child(s, NodeCounterEditor.DATA_NODE_NAME);
    if (!s.exists()) {
        // no index data (not yet indexed, or very few nodes)
        return -1;
    }
    s = child(s, PathUtils.elements(path));
    if (s == null || !s.exists()) {
        // we have an index, but no data
        long x = 0;
        if (max) {
            // in the index, the resolution is lower
            x += ApproximateCounter.COUNT_RESOLUTION * 20;
        }
        return x;
    }
    p = s.getProperty(NodeCounterEditor.COUNT_PROPERTY_NAME);
    if (p == null) {
        // we have an index, but no data
        long x = 0;
        if (max) {
            // in the index, the resolution is lower
            x += ApproximateCounter.COUNT_RESOLUTION * 20;
        }
        return x;
    }
    long x = p.getValue(Type.LONG);
    if (max) {
        x += ApproximateCounter.COUNT_RESOLUTION;
    }
    return x;
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 28 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class PrivilegeUtil method readDefinition.

/**
     * Reads the privilege definition stored in the specified definition tree.
     * Note, that this utility does not check the existence nor the node type
     * of the specified tree.
     *
     * @param definitionTree An existing tree storing a privilege definition.
     * @return A new instance of {@code PrivilegeDefinition}.
     */
@Nonnull
public static PrivilegeDefinition readDefinition(@Nonnull Tree definitionTree) {
    String name = definitionTree.getName();
    boolean isAbstract = TreeUtil.getBoolean(definitionTree, REP_IS_ABSTRACT);
    Iterable<String> declAggrNames = null;
    PropertyState property = definitionTree.getProperty(REP_AGGREGATES);
    if (property != null) {
        declAggrNames = property.getValue(Type.NAMES);
    }
    return new ImmutablePrivilegeDefinition(name, isAbstract, declAggrNames);
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

Example 29 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class AbstractRestrictionProvider method getRestrictionProperties.

@Nonnull
private Map<String, PropertyState> getRestrictionProperties(Tree aceTree) {
    Tree rTree = getRestrictionsTree(aceTree);
    Map<String, PropertyState> restrictionProperties = new HashMap<String, PropertyState>();
    for (PropertyState property : rTree.getProperties()) {
        String name = property.getName();
        if (isRestrictionProperty(name)) {
            restrictionProperties.put(name, property);
        }
    }
    return restrictionProperties;
}
Also used : HashMap(java.util.HashMap) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

Example 30 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class UserPrincipalProvider method getPrincipalName.

@CheckForNull
private static String getPrincipalName(@Nonnull Tree tree) {
    PropertyState principalName = tree.getProperty(UserConstants.REP_PRINCIPAL_NAME);
    if (principalName != null) {
        return principalName.getValue(STRING);
    } else {
        String msg = "Authorizable without principal name " + UserUtil.getAuthorizableId(tree);
        log.warn(msg);
        return null;
    }
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState) CheckForNull(javax.annotation.CheckForNull)

Aggregations

PropertyState (org.apache.jackrabbit.oak.api.PropertyState)404 Test (org.junit.Test)189 Tree (org.apache.jackrabbit.oak.api.Tree)138 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)49 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 Nonnull (javax.annotation.Nonnull)31 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)29 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)28 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)28 Blob (org.apache.jackrabbit.oak.api.Blob)21 ArrayList (java.util.ArrayList)20 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)17 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)16 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)13 CheckForNull (javax.annotation.CheckForNull)12 RepositoryException (javax.jcr.RepositoryException)10 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 Map (java.util.Map)9 Value (javax.jcr.Value)9