final JcrValue valueFrom( String value ) { return session.valueFactory().createValue(value); }
final JcrValue valueFrom( String value ) { return session.valueFactory().createValue(value); }
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( 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( 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( 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 Value valueFor( Object value, int jcrType ) throws RepositoryException { return session.getValueFactory().createValue(value, jcrType); }
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); } } }
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(); }
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; }
@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); }