@NotNull public static PropertyValue newBinary(@NotNull byte[] value) { return new PropertyStateValue(BinaryPropertyState.binaryProperty("", value)); }
@Nonnull public static PropertyValue newBinary(@Nonnull Blob value) { return new PropertyStateValue(BinaryPropertyState.binaryProperty("", value)); }
@NotNull public static PropertyValue newBinary(@NotNull Blob value) { return new PropertyStateValue(BinaryPropertyState.binaryProperty("", value)); }
@Nonnull public static PropertyValue newBinary(@Nonnull byte[] value) { return new PropertyStateValue(BinaryPropertyState.binaryProperty("", value)); }
private ValueImpl createBinaryValue(Blob blob) throws RepositoryException { return new ValueImpl(BinaryPropertyState.binaryProperty("", blob), namePathMapper); }
@NotNull private ValueImpl createBinaryValue(@NotNull Blob blob) throws RepositoryException { return new ValueImpl(BinaryPropertyState.binaryProperty("", blob), getNamePathMapper(), getBlobAccessProvider()); }
return StringPropertyState.stringProperty(name, (String) value); } else if (value instanceof Blob) { return BinaryPropertyState.binaryProperty(name, (Blob) value); } else if (value instanceof byte[]) { return BinaryPropertyState.binaryProperty(name, (byte[]) value); } else if (value instanceof Long) { return LongPropertyState.createLongProperty(name, (Long) value);
return StringPropertyState.stringProperty(name, (String) value); } else if (value instanceof Blob) { return BinaryPropertyState.binaryProperty(name, (Blob) value); } else if (value instanceof byte[]) { return BinaryPropertyState.binaryProperty(name, (byte[]) value); } else if (value instanceof Long) { return LongPropertyState.createLongProperty(name, (Long) value);
@NotNull private PropertyState compact(@NotNull PropertyState property) { compactionMonitor.onProperty(); String name = property.getName(); Type<?> type = property.getType(); if (type == BINARY) { compactionMonitor.onBinary(); return binaryProperty(name, property.getValue(Type.BINARY)); } else if (type == BINARIES) { List<Blob> blobs = newArrayList(); for (Blob blob : property.getValue(BINARIES)) { compactionMonitor.onBinary(); blobs.add(blob); } return binaryPropertyFromBlob(name, blobs); } else { return createProperty(name, property.getValue(type), type); } }
private static void file(Tree parent, String name) { Tree file = parent.addChild(name); file.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME); Tree resource = file.addChild(JCR_CONTENT); resource.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME); resource.setProperty("jcr:lastModified", Calendar.getInstance()); resource.setProperty("jcr:encoding", "UTF-8"); resource.setProperty("jcr:mimeType", "text/plain"); resource.setProperty(binaryProperty(JCR_DATA, "the quick brown fox jumps over the lazy dog.")); }
@Test public void testChildNodeWithOr() throws Exception { Tree file = root.getTree("/").addChild("myFile"); file.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME); Tree resource = file.addChild(JCR_CONTENT); resource.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME); resource.setProperty("jcr:lastModified", Calendar.getInstance()); resource.setProperty("jcr:encoding", "UTF-8"); resource.setProperty("jcr:mimeType", "text/plain"); resource.setProperty(binaryProperty(JCR_DATA, "the quick brown fox jumps over the lazy dog.")); resource.setProperty("jcr:title", "title"); resource.setProperty("jcr:description", "description"); root.commit(); String matchContentSimple = "//element(*, nt:file)[(jcr:contains(jcr:content, 'dog'))]"; assertQuery(matchContentSimple, "xpath", ImmutableList.of("/myFile")); String matchContent = " //element(*, nt:file)[(jcr:contains(jcr:content, 'dog') or jcr:contains(jcr:content/@jcr:title, 'invalid') or jcr:contains(jcr:content/@jcr:description, 'invalid'))]"; assertQuery(matchContent, "xpath", ImmutableList.of("/myFile")); String matchTitle = " //element(*, nt:file)[(jcr:contains(jcr:content, 'invalid') or jcr:contains(jcr:content/@jcr:title, 'title') or jcr:contains(jcr:content/@jcr:description, 'invalid'))]"; assertQuery(matchTitle, "xpath", ImmutableList.of("/myFile")); String matchDesc = " //element(*, nt:file)[(jcr:contains(jcr:content, 'invalid') or jcr:contains(jcr:content/@jcr:title, 'invalid') or jcr:contains(jcr:content/@jcr:description, 'description'))]"; assertQuery(matchDesc, "xpath", ImmutableList.of("/myFile")); String matchNone = " //element(*, nt:file)[(jcr:contains(jcr:content, 'invalid') or jcr:contains(jcr:content/@jcr:title, 'invalid') or jcr:contains(jcr:content/@jcr:description, 'invalid'))]"; assertQuery(matchNone, "xpath", new ArrayList<String>()); }
/** * Create a {@code PropertyState} from a string. * @param name The name of the property state * @param value The value of the property state * @param type The type of the property state * @return The new property state */ @Nonnull public static PropertyState createProperty(String name, String value, int type) { switch (type) { case PropertyType.STRING: return StringPropertyState.stringProperty(name, value); case PropertyType.BINARY: return BinaryPropertyState.binaryProperty(name, Conversions.convert(value).toBinary()); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, Conversions.convert(value).toLong()); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, Conversions.convert(value).toDouble()); case PropertyType.BOOLEAN: return BooleanPropertyState.booleanProperty(name, Conversions.convert(value).toBoolean()); case PropertyType.DECIMAL: return DecimalPropertyState.decimalProperty(name, Conversions.convert(value).toDecimal()); default: return new GenericPropertyState(name, value, Type.fromTag(type, false)); } }
/** * Create a {@code PropertyState} from a string. * @param name The name of the property state * @param value The value of the property state * @param type The type of the property state * @return The new property state */ @NotNull public static PropertyState createProperty(String name, String value, int type) { switch (type) { case PropertyType.STRING: return StringPropertyState.stringProperty(name, value); case PropertyType.BINARY: return BinaryPropertyState.binaryProperty(name, Conversions.convert(value).toBinary()); case PropertyType.LONG: return LongPropertyState.createLongProperty(name, Conversions.convert(value).toLong()); case PropertyType.DOUBLE: return DoublePropertyState.doubleProperty(name, Conversions.convert(value).toDouble()); case PropertyType.BOOLEAN: return BooleanPropertyState.booleanProperty(name, Conversions.convert(value).toBoolean()); case PropertyType.DECIMAL: return DecimalPropertyState.decimalProperty(name, Conversions.convert(value).toDecimal()); default: return new GenericPropertyState(name, value, Type.fromTag(type, false)); } }
@Test public void testChildNodeProperty() throws Exception { Tree file = root.getTree("/").addChild("myFile"); file.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME); Tree resource = file.addChild(JCR_CONTENT); resource.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME); resource.setProperty("jcr:lastModified", Calendar.getInstance()); resource.setProperty("jcr:encoding", "UTF-8"); resource.setProperty("jcr:mimeType", "text/plain"); resource.setProperty(binaryProperty(JCR_DATA, "the quick brown fox jumps over the lazy dog.")); resource.setProperty("jcr:title", "title"); resource.setProperty("jcr:description", "description"); root.commit(); String matchChildSimple = "//*[( jcr:contains(@jcr:title, 'title') )]"; assertQuery(matchChildSimple, "xpath", ImmutableList.of("/myFile/jcr:content")); String matchChildWithStar = "//*[( jcr:contains(., 'dog') and jcr:contains(@jcr:title, 'title') )]"; assertQuery(matchChildWithStar, "xpath", ImmutableList.of("/myFile/jcr:content")); }
@Test public void testPreventDoubleAggregation() throws Exception { Tree file = root.getTree("/").addChild("myFile"); file.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME); file.setProperty("jcr:title", "fox"); Tree resource = file.addChild(JCR_CONTENT); resource.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME); resource.setProperty("jcr:lastModified", Calendar.getInstance()); resource.setProperty("jcr:encoding", "UTF-8"); resource.setProperty("jcr:mimeType", "text/plain"); resource.setProperty(binaryProperty(JCR_DATA, "the quick brown fox jumps over the lazy dog.")); root.commit(); String matchChildSimple = "//element(*, nt:file)[( jcr:contains(., 'fox') )]"; assertQuery(matchChildSimple, "xpath", ImmutableList.of("/myFile")); }
@Test public void testNodeTypes() throws Exception { Tree folder = root.getTree("/").addChild("myFolder"); folder.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME); Tree file = folder.addChild("myFile"); file.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME); file.setProperty("jcr:title", "title"); file.setProperty("jcr:description", "description"); Tree resource = file.addChild(JCR_CONTENT); resource.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME); resource.setProperty("jcr:lastModified", Calendar.getInstance()); resource.setProperty("jcr:encoding", "UTF-8"); resource.setProperty("jcr:mimeType", "text/plain"); resource.setProperty(binaryProperty(JCR_DATA, "the quick brown fox jumps over the lazy dog.")); root.commit(); String matchContentSimple = "//*[( jcr:contains(., 'dog') and @jcr:primaryType = 'nt:file' )]"; assertQuery(matchContentSimple, "xpath", ImmutableList.of("/myFolder/myFile")); String matchContentDouble = "//*[( jcr:contains(., 'dog') and (@jcr:primaryType = 'nt:file' or @jcr:primaryType = 'nt:folder') )]"; assertQuery(matchContentDouble, "xpath", ImmutableList.of("/myFolder", "/myFolder/myFile")); }
@Test public void noSplitForSmallBinary() throws Exception { DocumentStore store = mk.getDocumentStore(); DocumentNodeStore ns = mk.getNodeStore(); NodeBuilder builder = ns.getRoot().builder(); builder.child("foo"); merge(ns, builder); for (int i = 0; i < 10; i++) { builder = ns.getRoot().builder(); builder.child("foo").setProperty( binaryProperty("p", ("value" + i).getBytes())); merge(ns, builder); ns.runBackgroundOperations(); } NodeDocument foo = store.find(NODES, Utils.getIdFromPath("/foo")); assertNotNull(foo); List<NodeDocument> prevDocs = copyOf(foo.getAllPreviousDocs()); // must not create split documents for small binaries less 4k assertEquals(0, prevDocs.size()); }
@Test public void testChildNodeProperty2() throws Exception { Tree file = root.getTree("/").addChild("myFile"); file.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME); Tree resource = file.addChild(JCR_CONTENT); resource.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME); resource.setProperty(binaryProperty(JCR_DATA, "the quick brown fox jumps over the lazy dog.")); resource.setProperty("jcr:title", "title"); resource.setProperty("jcr:description", "description"); Tree file2 = root.getTree("/").addChild("myFile2"); file2.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME); Tree resource2 = file2.addChild(JCR_CONTENT); resource2.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME); resource2.setProperty(binaryProperty(JCR_DATA, "the quick brown fox jumps over the lazy dog.")); resource2.setProperty("jcr:title", "other"); resource.setProperty("jcr:description", "title"); root.commit(); String matchChildSimple = "//*[( jcr:contains(jcr:content/@jcr:title, 'title') )]"; assertQuery(matchChildSimple, "xpath", ImmutableList.of("/myFile")); }
@Test public void splitDocumentWithBinary() throws Exception { DocumentStore store = mk.getDocumentStore(); DocumentNodeStore ns = mk.getNodeStore(); NodeBuilder builder = ns.getRoot().builder(); builder.child("foo"); merge(ns, builder); // use more than 4k of binary data (OAK-5205) PropertyState binary = binaryProperty("p", randomBytes(5 * 1024)); for (int i = 0; i < 10; i++) { builder = ns.getRoot().builder(); builder.child("foo").setProperty(binary); merge(ns, builder); ns.runBackgroundOperations(); } NodeDocument foo = store.find(NODES, Utils.getIdFromPath("/foo")); assertNotNull(foo); List<NodeDocument> prevDocs = copyOf(foo.getAllPreviousDocs()); // all but most recent value are moved to individual previous docs assertEquals(9, prevDocs.size()); }
@Test public void noBinarySplitWhenRemoved() throws Exception { DocumentStore store = mk.getDocumentStore(); DocumentNodeStore ns = mk.getNodeStore(); NodeBuilder builder = ns.getRoot().builder(); // use more than 4k of binary data (OAK-5205) PropertyState binary = binaryProperty("p", randomBytes(5 * 1024)); builder.child("foo").setProperty(binary); merge(ns, builder); builder = ns.getRoot().builder(); builder.child("foo").remove(); merge(ns, builder); ns.runBackgroundOperations(); // must not create split document in this case. See OAK-5010 NodeDocument foo = store.find(NODES, Utils.getIdFromPath("/foo")); assertNotNull(foo); assertEquals(0, foo.getPreviousRanges().size()); // re-create it builder = ns.getRoot().builder(); builder.child("foo"); merge(ns, builder); ns.runBackgroundOperations(); // now the old binary value must be moved to a previous document foo = store.find(NODES, Utils.getIdFromPath("/foo")); assertNotNull(foo); List<NodeDocument> prevDocs = copyOf(foo.getAllPreviousDocs()); assertEquals(1, prevDocs.size()); }