/** * Gets the internal column number for a column with the given name * * @param name The name of the column to search for. * @return The column number for the column with the given name. */ public int getInternalColumnIndex(String name) { try { return tuples.getColumnIndex(new Variable(name)); } catch (Exception te) { // TuplesException return NOT_BOUND; } }
/** * Gets the current binding to a local value (a long) for a given internal column number. * * @return the value in the column number specified in the current context. */ public long getColumnValue(int columnNumber) throws QueryException { try { return tuples.getRawColumnValue(columnNumber); } catch (Exception te) { // TuplesException throw new QueryException("Error resolving value", te); } }
/** * Tests if a given column is bound in the current context. * * @return <code>true</code> iff the column exists and is bound. */ public boolean isBound(int columnNumber) throws QueryException { try { return columnNumber != NOT_BOUND && tuples.getRawColumnValue(columnNumber) != Tuples.UNBOUND; } catch (Exception te) { // TuplesException logger.error("Exception getting column value", te); throw new QueryException("Error resolving column", te); } }
/** * Resolve a constraint against an RDF/XML document. * * <p>Resolution is by filtration of a URL stream, and thus very slow. */ public Resolution resolve(Constraint constraint) throws QueryException { if (logger.isDebugEnabled()) { logger.debug("Resolve " + constraint); } // Validate "constraint" parameter if (constraint == null) { throw new IllegalArgumentException("Null \"constraint\" parameter"); } if (!(constraint.getModel() instanceof LocalNode)) { if (logger.isDebugEnabled()) logger.debug("Ignoring solutions for " + constraint); return new EmptyResolution(constraint, false); } if (!(constraint.getElement(1) instanceof LocalNode) || !(constraint.getElement(2) instanceof LocalNode)) { throw new QueryException( "Prefix resolver can only be used for fixed prefixes: " + constraint); } try { long property = ((LocalNode) constraint.getElement(1)).getValue(); LocalNode object = (LocalNode) constraint.getElement(2); Node prefixNode = resolverSession.globalize(object.getValue()); // check the constraint for consistency if ((property != mulgaraPrefix && property != mulgaraStringPrefix) || !(prefixNode instanceof Literal || prefixNode instanceof URIReference)) { logger.debug("property = " + property + ", mulgaraPrefix = " + mulgaraPrefix); logger.debug("element(2): " + prefixNode + " [" + prefixNode.getClass().getName() + "]"); throw new QueryException( "Prefix resolver can only be used for prefix constraints: " + constraint); } if (logger.isDebugEnabled()) { logger.debug( "Evaluating " + constraint.getElement(0) + " has prefix " + constraint.getElement(2)); } ConstraintElement node = constraint.getElement(0); assert node != null; Tuples tuples; if (node instanceof Variable) { // convert the prefix into a string pool object SPObjectFactory spoFact = SPObjectFactoryImpl.getInstance(); SPObject startPrefixObj = getStartObject(spoFact, prefixNode, property); SPObject endPrefixObj = getEndObject(spoFact, prefixNode, property); // get the extents of the prefix from the string pool tuples = resolverSession.findStringPoolRange(startPrefixObj, true, endPrefixObj, false); assert tuples != null; // rename variables away from subject, predicate and object tuples.renameVariables(constraint); long resultSize; try { // Get the size of the final result. resultSize = tuples.getRowCount(); } catch (TuplesException e) { throw new QueryException("Unable to build result", e); } if (logger.isDebugEnabled()) { try { logger.debug( "tuples size = " + tuples.getRowCount() + " (should be " + resultSize + ")"); } catch (TuplesException e) { logger.debug("Error getting the length of the tuples object"); } } return new TuplesWrapperResolution(tuples, constraint); } else { // if (node instanceof Variable) // node must therefore be an instanceof LocalNode // we can shortcut the process here assert node instanceof LocalNode; LocalNode n = (LocalNode) node; // get the node out of the string pool SPObject spo = resolverSession.findStringPoolObject(n.getValue()); // check that the node exists if (spo == null) { tuples = TuplesOperations.empty(); } else { // see if the node starts with the required prefix String prefix; // extract the string from the literal if (prefixNode instanceof Literal) { prefix = ((Literal) prefixNode).getLexicalForm(); } else { prefix = ((URIReference) prefixNode).getURI().toString(); } if (spo.getLexicalForm().startsWith(prefix)) { tuples = TuplesOperations.unconstrained(); } else { tuples = TuplesOperations.empty(); } } } // convert the tuples to a resolution return new TuplesWrapperResolution(tuples, constraint); } catch (GlobalizeException ge) { throw new QueryException("Couldn't convert internal data into a string", ge); } catch (StringPoolException e) { throw new QueryException("Couldn't query constraint", e); } }