use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class VersionGCQueryTest method noQueryForFirstLevelPrevDocs.
@Test
public void noQueryForFirstLevelPrevDocs() throws Exception {
// create some garbage
NodeBuilder builder = ns.getRoot().builder();
for (int i = 0; i < 10; i++) {
InputStream s = new RandomStream(10 * 1024, 42);
PropertyState p = new BinaryPropertyState("p", ns.createBlob(s));
builder.child("test").child("node-" + i).setProperty(p);
}
merge(builder);
// overwrite with other binaries to force document splits
builder = ns.getRoot().builder();
for (int i = 0; i < 10; i++) {
InputStream s = new RandomStream(10 * 1024, 17);
PropertyState p = new BinaryPropertyState("p", ns.createBlob(s));
builder.child("test").child("node-" + i).setProperty(p);
}
merge(builder);
ns.runBackgroundOperations();
builder = ns.getRoot().builder();
builder.child("test").remove();
merge(builder);
ns.runBackgroundOperations();
clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
VersionGarbageCollector gc = new VersionGarbageCollector(ns, new VersionGCSupport(store));
prevDocIds.clear();
VersionGCStats stats = gc.gc(30, TimeUnit.MINUTES);
assertEquals(11, stats.deletedDocGCCount);
assertEquals(10, stats.splitDocGCCount);
assertEquals(0, prevDocIds.size());
assertEquals(1, Iterables.size(Utils.getAllDocuments(store)));
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class AbstractCompositeProviderTest method testIsGrantedNone.
@Test
public void testIsGrantedNone() throws Exception {
PermissionProvider pp = createPermissionProvider();
for (String p : NODE_PATHS) {
Tree tree = readOnlyRoot.getTree(p);
PropertyState ps = tree.getProperty(JcrConstants.JCR_PRIMARYTYPE);
assertFalse(p, pp.isGranted(tree, null, Permissions.NO_PERMISSION));
assertFalse(PathUtils.concat(p, JcrConstants.JCR_PRIMARYTYPE), pp.isGranted(tree, ps, Permissions.NO_PERMISSION));
}
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class RestrictionProviderImplTest method testGetPatternForAllSupported.
@Test
public void testGetPatternForAllSupported() throws Exception {
Map<PropertyState, RestrictionPattern> map = newHashMap();
map.put(PropertyStates.createProperty(REP_GLOB, "/*/jcr:content"), GlobPattern.create("/testPath", "/*/jcr:content"));
List<String> ntNames = ImmutableList.of(JcrConstants.NT_FOLDER, JcrConstants.NT_LINKEDFILE);
map.put(PropertyStates.createProperty(REP_NT_NAMES, ntNames, Type.NAMES), new NodeTypePattern(ntNames));
List<String> prefixes = ImmutableList.of("rep", "jcr");
map.put(PropertyStates.createProperty(REP_PREFIXES, prefixes, Type.STRINGS), new PrefixPattern(prefixes));
List<String> itemNames = ImmutableList.of("abc", "jcr:primaryType");
map.put(PropertyStates.createProperty(REP_ITEM_NAMES, prefixes, Type.NAMES), new ItemNamePattern(itemNames));
NodeUtil tree = new NodeUtil(root.getTree("/")).getOrAddTree("testPath", JcrConstants.NT_UNSTRUCTURED);
Tree restrictions = tree.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS).getTree();
for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) {
restrictions.setProperty(entry.getKey());
}
RestrictionPattern pattern = provider.getPattern("/testPath", restrictions);
assertTrue(pattern instanceof CompositePattern);
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class Namespaces method addCustomMapping.
public static String addCustomMapping(NodeBuilder namespaces, String uri, String prefixHint) {
// first look for an existing mapping for the given URI
for (PropertyState property : namespaces.getProperties()) {
if (property.getType() == STRING) {
String prefix = property.getName();
if (isValidPrefix(prefix) && uri.equals(property.getValue(STRING))) {
return prefix;
}
}
}
// no existing mapping found for the URI, make sure prefix is unique
String prefix = prefixHint;
int iteration = 1;
while (namespaces.hasProperty(prefix)) {
prefix = prefixHint + ++iteration;
}
// add the new mapping with its unique prefix
namespaces.setProperty(prefix, uri);
return prefix;
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class PropertyIndexLookup method getIndexNode.
/**
* Get the node with the index definition for the given property, if there
* is an applicable index with data.
*
* @param propertyName the property name
* @param filter the filter (which contains information of all supertypes,
* unless the filter matches all types)
* @return the node where the index definition (metadata) is stored (the
* parent of ":index"), or null if no index definition or index data
* node was found
*/
@Nullable
NodeState getIndexNode(NodeState node, String propertyName, Filter filter) {
// keep a fallback to a matching index def that has *no* node type constraints
// (initially, there is no fallback)
NodeState fallback = null;
NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME);
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
NodeState index = entry.getNodeState();
PropertyState type = index.getProperty(TYPE_PROPERTY_NAME);
if (type == null || type.isArray() || !getType().equals(type.getValue(Type.STRING))) {
continue;
}
if (contains(getNames(index, PROPERTY_NAMES), propertyName)) {
NodeState indexContent = index.getChildNode(INDEX_CONTENT_NODE_NAME);
if (!indexContent.exists()) {
continue;
}
Set<String> supertypes = getSuperTypes(filter);
if (index.hasProperty(DECLARING_NODE_TYPES)) {
if (supertypes != null) {
for (String typeName : getNames(index, DECLARING_NODE_TYPES)) {
if (supertypes.contains(typeName)) {
// TODO: prefer the most specific type restriction
return index;
}
}
}
} else if (supertypes == null) {
return index;
} else if (fallback == null) {
// update the fallback
fallback = index;
}
}
}
return fallback;
}
Aggregations