protected final Value[] getJcrValues() throws RepositoryException { Value[] values = new Value[this.values.size()]; ValueFactory factory = session.getValueFactory(); int i = 0; for (String value : this.values) { values[i++] = factory.createValue(value); } this.values = new LinkedHashSet<String>(); return values; }
protected final Value[] getJcrValues() throws RepositoryException { Value[] values = new Value[this.values.size()]; ValueFactory factory = session.getValueFactory(); int i = 0; for (String value : this.values) { values[i++] = factory.createValue(value); } this.values = new LinkedHashSet<String>(); return values; }
protected Value[] valuesFrom( String... values ) throws RepositoryException { Value[] result = new Value[values.length]; int i = 0; for (String value : values) { result[i++] = session.getValueFactory().createValue(value); } return result; }
protected Value[] values( double[] values ) throws Exception { Value[] result = new Value[values.length]; for (int i = 0; i != values.length; ++i) { result[i] = session.getValueFactory().createValue(values[i]); } return result; }
protected Value[] values( byte[][] values ) throws Exception { Value[] result = new Value[values.length]; for (int i = 0; i != values.length; ++i) { Binary binary = session.getValueFactory().createBinary(values[i]); result[i] = session.getValueFactory().createValue(binary); } return result; }
protected Value[] values( long[] values ) throws Exception { Value[] result = new Value[values.length]; for (int i = 0; i != values.length; ++i) { result[i] = session.getValueFactory().createValue(values[i]); } return result; }
protected Value[] values( int type, String[] values ) throws Exception { Value[] result = new Value[values.length]; for (int i = 0; i != values.length; ++i) { result[i] = session.getValueFactory().createValue(values[i]); } return result; }
protected Value[] values( Node[] values ) throws Exception { Value[] result = new Value[values.length]; for (int i = 0; i != values.length; ++i) { result[i] = session.getValueFactory().createValue(values[i]); } return result; }
protected Value[] values( boolean[] values ) throws Exception { Value[] result = new Value[values.length]; for (int i = 0; i != values.length; ++i) { result[i] = session.getValueFactory().createValue(values[i]); } return result; }
private void setCreatedByIfNecessary( JcrSession outputSession, List<AbstractJcrNode> outputNodes ) throws RepositoryException { // if the mix:created mixin is on any of the new nodes, we need to set the createdBy here, otherwise it will be // set by the system session when it saves and it will default to "modeshape-worker" for (AbstractJcrNode node : outputNodes) { if (node.isNodeType(JcrMixLexicon.CREATED)) { node.setProperty(JcrLexicon.CREATED_BY, outputSession.getValueFactory().createValue(work.getUserId()), true, true, false, false); } } }
private void setCreatedByIfNecessary( JcrSession outputSession, List<AbstractJcrNode> outputNodes ) throws RepositoryException { // if the mix:created mixin is on any of the new nodes, we need to set the createdBy here, otherwise it will be // set by the system session when it saves and it will default to "modeshape-worker" for (AbstractJcrNode node : outputNodes) { if (node.isNodeType(JcrMixLexicon.CREATED)) { node.setProperty(JcrLexicon.CREATED_BY, outputSession.getValueFactory().createValue(work.getUserId()), true, true, false, false); } } }
@SuppressWarnings( "deprecation" ) @Test( expected = RepositoryException.class ) public void shouldNotCreateValueForNonReferenceableNode() throws Exception { ValueFactory factory = session.getValueFactory(); Node node = Mockito.mock(Node.class); String uuid = UUID.randomUUID().toString(); when(node.getUUID()).thenReturn(uuid); when(node.getIdentifier()).thenReturn(uuid); when(node.isNodeType("mix:referenceable")).thenReturn(false); factory.createValue(node); }
protected Value[] values( DateTime[] values ) throws Exception { Value[] result = new Value[values.length]; for (int i = 0; i != values.length; ++i) { result[i] = session.getValueFactory().createValue(values[i].toCalendar()); } return result; }
private InputStream storeBinaryProperty( byte[] data, String nodeName ) throws RepositoryException { Node testRoot = jcrSession().getRootNode().addNode(nodeName); testRoot.setProperty("binary", session.getValueFactory().createValue(new ByteArrayInputStream(data))); jcrSession().save(); Property binary = jcrSession().getNode("/" + nodeName).getProperty("binary"); Assert.assertNotNull(binary); return binary.getBinary().getStream(); }
@Test public void shouldAllowValidReferenceValue() throws Exception { NodeType constrainedType = validateTypeDefinition(); JcrPropertyDefinition prop = propertyDefinitionFor(constrainedType, TestLexicon.CONSTRAINED_REFERENCE); Value value = session.getValueFactory().createValue(session.getRootNode()); assertThat(prop.satisfiesConstraints(value, session), is(true)); }
@Test public void shouldAllowValidReferenceValues() throws Exception { NodeType constrainedType = validateTypeDefinition(); JcrPropertyDefinition prop = propertyDefinitionFor(constrainedType, TestLexicon.CONSTRAINED_REFERENCE); Value value = session.getValueFactory().createValue(session.getRootNode()); assertThat(satisfiesConstraints(prop, new Value[] {}), is(true)); assertThat(satisfiesConstraints(prop, new Value[] {value}), is(true)); }
@FixFor( "MODE-1685" ) @Test public void shouldNotEnforceReferentialIntegrityOfWeakReferenceWhenRemovingNodes() throws Exception { JcrValueFactory valueFactory = session.getValueFactory(); Node targetNode = session.getRootNode().addNode("target"); targetNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString()); Node parentNode = session.getRootNode().addNode("parent"); Node childNode = parentNode.addNode("child"); childNode.setProperty("ref1", valueFactory.createValue(targetNode, true)); session.save(); // Delete the target - there should be no strong references, but the weak is okay and won't prevent removal ... targetNode.remove(); session.save(); }
@Test public void shouldNotAllowInvalidReferenceValue() throws Exception { NodeType constrainedType = validateTypeDefinition(); JcrPropertyDefinition prop = propertyDefinitionFor(constrainedType, TestLexicon.CONSTRAINED_REFERENCE); Value value = session.getValueFactory().createValue(session.getRootNode().getNode("a")); assertThat(prop.satisfiesConstraints(value, session), is(false)); }
@Test public void shouldNotAllowInvalidReferenceValues() throws Exception { NodeType constrainedType = validateTypeDefinition(); JcrPropertyDefinition prop = propertyDefinitionFor(constrainedType, TestLexicon.CONSTRAINED_REFERENCE); Value value = session.getValueFactory().createValue(session.getRootNode().getNode("a")); assertThat(satisfiesConstraints(prop, new Value[] {value}), is(false)); }
@FixFor( "MODE-1840" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithBindVariableInsideContains() throws RepositoryException { String sql = "select [jcr:path] from [nt:unstructured] as n where contains(n.something, $expression)"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); query.bindValue("expression", session.getValueFactory().createValue("cat wearing")); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("jcr:path").hasNodesAtPaths("/Other/NodeA[2]").validate(query, result); }