Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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 java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.query.Row;
import javax.jcr.query.RowIterator;
import org.modeshape.common.annotation.NotThreadSafe;
import org.modeshape.common.collection.Collections;
import org.modeshape.common.collection.Problem;
import org.modeshape.common.collection.Problem.Status;
import org.modeshape.jcr.JcrI18n;
import org.modeshape.jcr.query.QueryResults.Columns;
import org.modeshape.jcr.query.QueryResults.Location;
import org.modeshape.jcr.query.model.Column;
import org.modeshape.jcr.query.model.SelectorName;
import org.modeshape.jcr.query.validate.Schemata;
import org.modeshape.jcr.value.Name;
import org.modeshape.jcr.value.Path;
/**
* The results of a query. This is not thread-safe because it relies upon JcrSession, which is not thread-safe. Also, although the
* results of a query never change, the objects returned by the iterators may vary if the session information changes.
*
* @see XPathQueryResult
* @see JcrSqlQueryResult
*/
@NotThreadSafe
public class JcrQueryResult implements org.modeshape.jcr.api.query.QueryResult {
public static final String JCR_SCORE_COLUMN_NAME = "jcr:score";
public static final String JCR_PATH_COLUMN_NAME = "jcr:path";
public static final String JCR_NAME_COLUMN_NAME = "jcr:name";
public static final String MODE_LOCALNAME_COLUMN_NAME = "mode:localName";
public static final String MODE_DEPTH_COLUMN_NAME = "mode:depth";
protected static final Set PSEUDO_COLUMNS = Collections.unmodifiableSet(JCR_SCORE_COLUMN_NAME,
JCR_PATH_COLUMN_NAME,
JCR_NAME_COLUMN_NAME,
MODE_LOCALNAME_COLUMN_NAME,
MODE_DEPTH_COLUMN_NAME);
protected final JcrQueryContext context;
protected final QueryResults results;
protected final Schemata schemata;
protected final String queryStatement;
private List columnTables;
private List warnings;
protected JcrQueryResult( JcrQueryContext context,
String query,
QueryResults graphResults,
Schemata schemata ) {
this.context = context;
this.results = graphResults;
this.schemata = schemata;
this.queryStatement = query;
assert this.context != null;
assert this.results != null;
assert this.schemata != null;
assert this.queryStatement != null;
}
protected QueryResults results() {
return results;
}
public List getColumnNameList() {
return results.getColumns().getColumnNames();
}
public List getColumnTypeList() {
return results.getColumns().getColumnTypes();
}
@Override
public String[] getColumnNames() /*throws RepositoryException*/{
List names = getColumnNameList();
return names.toArray(new String[names.size()]); // make a defensive copy ...
}
@Override
public String[] getColumnTypes() {
List types = getColumnTypeList();
return types.toArray(new String[types.size()]); // make a defensive copy ...
}
@Override
public String[] getSelectorNames() {
if (columnTables == null) {
// Discover the types ...
Columns columns = results.getColumns();
Set selectorNames = new HashSet();
List tables = new ArrayList(columns.getColumnCount());
for (Column column : columns) {
SelectorName selectorName = column.selectorName();
if (selectorNames.add(column.selectorName())) {
tables.add(selectorName.getString());
}
}
columnTables = tables;
}
return columnTables.toArray(new String[columnTables.size()]);
}
@Override
public NodeIterator getNodes() throws RepositoryException {
if (getSelectorNames().length > 1) {
throw new RepositoryException(JcrI18n.multipleSelectorsAppearInQueryUnableToCallMethod.text(queryStatement));
}
// Find all of the nodes in the results. We have to do this pre-emptively, since this
// is the only method to throw RepositoryException ...
final int numRows = results.getRowCount();
if (numRows == 0) return context.emptyNodeIterator();
final List nodes = new ArrayList(numRows);
final String selectorName = results.getColumns().getSelectorNames().get(0);
final int locationIndex = results.getColumns().getLocationIndex(selectorName);
for (Object[] tuple : results.getTuples()) {
Location location = (Location)tuple[locationIndex];
Node node = context.getNode(location);
if (node != null) {
nodes.add(node);
}
}
return new QueryResultNodeIterator(nodes);
}
@Override
public RowIterator getRows() /*throws RepositoryException*/{
// We can actually delay the loading of the nodes until the rows are accessed ...
final int numRows = results.getRowCount();
final List