@Test @FixFor( "MODE-1900" ) public void shouldSelectDistinctNodesWhenJoiningMultiValueReferenceProperties() throws Exception { Node nodeA = session.getRootNode().addNode("A", "test:node"); nodeA.setProperty("test:name", "A"); Node nodeB = session.getRootNode().addNode("B", "test:node"); nodeB.setProperty("test:name", "B"); JcrValue nodeBRef = session.getValueFactory().createValue(nodeB); Node nodeC = session.getRootNode().addNode("C", "test:node"); nodeC.setProperty("test:name", "C"); JcrValue nodeCRef = session.getValueFactory().createValue(nodeC); try { Node relationship = nodeA.addNode("relationship", "test:relationship"); relationship.setProperty("test:target", new JcrValue[] {nodeBRef, nodeCRef}); session.save(); QueryManager queryManager = session.getWorkspace().getQueryManager(); String queryString = "SELECT relationship.[test:target] FROM [test:relationship] AS relationship"; Query query = queryManager.createQuery(queryString, Query.JCR_SQL2); validateQuery().rowCount(1).validate(query, query.execute()); queryString = "SELECT [jcr:uuid], [jcr:path] FROM [test:node]"; query = queryManager.createQuery(queryString, Query.JCR_SQL2); validateQuery().rowCount(3).onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertNotNull(row.getValue("jcr:uuid")); } }).validate(query, query.execute()); queryString = "SELECT relationship.[test:target], target.[jcr:path] " + " FROM [test:relationship] AS relationship " + " JOIN [test:node] AS target ON relationship.[test:target] = target.[jcr:uuid] "; query = queryManager.createQuery(queryString, Query.JCR_SQL2); validateQuery().rowCount(2).validate(query, query.execute()); queryString = "SELECT node.[jcr:path], relationship.[test:target], target.[jcr:path] FROM [test:node] AS node " + " JOIN [test:relationship] AS relationship ON ISCHILDNODE(relationship, node) " + " JOIN [test:node] AS target ON relationship.[test:target] = target.[jcr:uuid] " + " WHERE node.[test:name] = 'A'"; query = queryManager.createQuery(queryString, Query.JCR_SQL2); validateQuery().rowCount(2).validate(query, query.execute()); queryString = "SELECT DISTINCT target.* FROM [test:node] AS node " + " JOIN [test:relationship] AS relationship ON ISCHILDNODE(relationship, node) " + " JOIN [test:node] AS target ON relationship.[test:target] = target.[jcr:uuid] " + " WHERE node.[test:name] = 'A'"; query = queryManager.createQuery(queryString, Query.JCR_SQL2); validateQuery().rowCount(2).validate(query, query.execute()); } finally { nodeA.remove(); nodeB.remove(); nodeC.remove(); session.save(); } }
@Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } JcrQueryManager( JcrSession session ); }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } JcrQueryManager( JcrSession session ); @Override org.modeshape.jcr.api.query.qom.QueryObjectModelFactory getQOMFactory(); @Override org.modeshape.jcr.api.query.Query createQuery( String statement,
                                                          String language ); @Override org.modeshape.jcr.api.query.Query createQuery( String statement, 
                                                          String language,
                                                          Locale locale ); org.modeshape.jcr.api.query.Query createQuery( String expression,
                                                          String language,
                                                          Path storedAtPath, 
                                                          Locale locale ); Query createQuery( QueryCommand command ); @Override org.modeshape.jcr.api.query.Query getQuery( Node node ); @Override String[] getSupportedQueryLanguages(); }
JcrQueryManager implements QueryManager { @Override public org.modeshape.jcr.api.query.Query createQuery( String statement, String language ) throws InvalidQueryException, RepositoryException { CheckArg.isNotNull(statement, "statement"); CheckArg.isNotNull(language, "language"); return createQuery(statement, language, null, null); } JcrQueryManager( JcrSession session ); @Override org.modeshape.jcr.api.query.qom.QueryObjectModelFactory getQOMFactory(); @Override org.modeshape.jcr.api.query.Query createQuery( String statement,
                                                          String language ); @Override org.modeshape.jcr.api.query.Query createQuery( String statement, 
                                                          String language,
                                                          Locale locale ); org.modeshape.jcr.api.query.Query createQuery( String expression,
                                                          String language,
                                                          Path storedAtPath, 
                                                          Locale locale ); Query createQuery( QueryCommand command ); @Override org.modeshape.jcr.api.query.Query getQuery( Node node ); @Override String[] getSupportedQueryLanguages();  }