Skip to content

Commit

Permalink
MODE-838 Fixed the XPathQueryResult class in a similar way to what wa…
Browse files Browse the repository at this point in the history
…s done to the JcrSqlQueryResult class for MODE-773: simply keep a list of the types (like the names) in the subclass. Added a new unit test to verify the desired behavior, and all unit and integration tests pass.

git-svn-id: https://svn.jboss.org/repos/modeshape/trunk@2072 76366958-4244-0410-ad5e-bbfabb93f86b
  • Loading branch information
Randall Hauch committed Jul 31, 2010
1 parent 8a25404 commit 142e1f8
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,28 @@ public class XPathQueryResult extends JcrQueryResult {

public static final String JCR_SCORE_COLUMN_NAME = "jcr:score";
public static final String JCR_PATH_COLUMN_NAME = "jcr:path";
/* The TypeFactory.getTypeName() always returns an uppercased type */
public static final String JCR_SCORE_COLUMN_TYPE = PropertyType.nameFromValue(PropertyType.DOUBLE).toUpperCase();
public static final String JCR_PATH_COLUMN_TYPE = PropertyType.nameFromValue(PropertyType.STRING).toUpperCase();

private final List<String> columnNames;
private final List<String> columnTypes;

public XPathQueryResult( JcrQueryContext context,
String query,
QueryResults graphResults,
Schemata schemata ) {
super(context, query, graphResults, schemata);
List<String> columnNames = new LinkedList<String>(graphResults.getColumns().getColumnNames());
List<String> columnTypes = new LinkedList<String>(graphResults.getColumns().getColumnTypes());
if (graphResults.getColumns().hasFullTextSearchScores() && !columnNames.contains(JCR_SCORE_COLUMN_NAME)) {
columnNames.add(0, JCR_SCORE_COLUMN_NAME);
columnTypes.add(0, JCR_SCORE_COLUMN_TYPE);
}
columnNames.add(0, JCR_PATH_COLUMN_NAME);
columnTypes.add(0, JCR_PATH_COLUMN_TYPE);
this.columnNames = Collections.unmodifiableList(columnNames);
this.columnTypes = Collections.unmodifiableList(columnTypes);
}

/**
Expand All @@ -73,6 +81,16 @@ public List<String> getColumnNameList() {
return columnNames;
}

/**
* {@inheritDoc}
*
* @see org.modeshape.jcr.query.JcrQueryResult#getColumnTypeList()
*/
@Override
public java.util.List<String> getColumnTypeList() {
return columnTypes;
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* ModeShape (http://www.modeshape.org)
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
* See the AUTHORS.txt file in the distribution for a full listing of
* individual contributors.
*
* ModeShape is free software. Unless otherwise indicated, all code in ModeShape
* is licensed to you under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* ModeShape is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.modeshape.jcr.query;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.modeshape.graph.query.QueryResults;
import org.modeshape.graph.query.QueryResults.Columns;
import org.modeshape.graph.query.model.Column;
import org.modeshape.graph.query.model.SelectorName;
import org.modeshape.graph.query.process.QueryResultColumns;
import org.modeshape.graph.query.validate.Schemata;

public class XPathQueryResultTest {

private XPathQueryResult result;
private JcrQueryContext context;
private String query;
private QueryResults graphResult;
private Schemata schemata;
private Columns resultColumns;
private List<String> columnTypes;
private List<String> columnNames;
private List<Column> columns;

@Before
public void beforeEach() {
schemata = mock(Schemata.class);
context = mock(JcrQueryContext.class);
query = "SELECT jcr:primaryType, foo:bar FROM nt:unstructured";
graphResult = mock(QueryResults.class);
columnTypes = Arrays.asList("STRING", "LONG");
columnNames = Arrays.asList("jcr:primaryType", "foo:bar");
SelectorName tableName = new SelectorName("nt:unstructured");
columns = Arrays.asList(new Column(tableName, columnNames.get(0), columnNames.get(0)), new Column(tableName,
columnNames.get(1),
columnNames.get(1)));
resultColumns = new QueryResultColumns(columns, columnTypes, true);
when(graphResult.getColumns()).thenReturn(resultColumns);

result = new XPathQueryResult(context, query, graphResult, schemata);
}

@Test
public void shouldHaveSameNumberOfColumnNamesAsTypes() {
assertThat(result.getColumnNames(), is(new String[] {"jcr:path", "jcr:score", "jcr:primaryType", "foo:bar"}));
assertThat(result.getColumnTypes(), is(new String[] {"STRING", "DOUBLE", "STRING", "LONG"}));
}
}

0 comments on commit 142e1f8

Please sign in to comment.