public int compare(Object left, Object right) throws QueryException { if (!(right instanceof Boolean)) throw new QueryException("Type Error: Cannot compare a boolean to a: " + right.getClass()); return ((Boolean)left).compareTo((Boolean)right); } public ValueLiteral newLiteral(Object data) { return new Bool((Boolean)data); }
public int compare(Object left, Object right) throws QueryException { if (!(right instanceof Number)) throw new QueryException("Type Error: Cannot compare a double to a: " + right.getClass()); return ((Double)left).compareTo(((Number)right).doubleValue()); } public ValueLiteral newLiteral(Object data) { return new NumericLiteral((Double)data); }
public int compare(Object left, Object right) throws QueryException { Float fleft = (Float)left; if (!(right instanceof Number)) throw new QueryException("Type Error: Cannot compare a float to a: " + right.getClass()); // if right has more precision, then promote lfloat, and compare the other way around if (right instanceof Double) return -((Double)right).compareTo(fleft.doubleValue()); return fleft.compareTo(((Number)right).floatValue()); } public ValueLiteral newLiteral(Object data) { return new NumericLiteral((Float)data); }
private void assertExternallyManagedXA() throws QueryException { if (transactionFactory == null) { transactionFactory = externalFactory = transactionManager.getExternalFactory(); } else if (externalFactory == null) { throw new QueryException("Attempt to use external transaction control in internally managed session"); } }
/** * Resolve this variable in its current context * @return An expression value wrapping the data bound to this point * @throws QueryException Indicates an error getting data out of the context, or globalizing. */ public ComparableExpression resolveComparable() throws QueryException { RDFTerm v = resolve(); if (!(v instanceof ComparableExpression)) throw new QueryException("Type Error: Cannot compare against a: " + v.getClass().getSimpleName()); return (ComparableExpression)v; }
/** * 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.getColumnValue(columnNumber) != Tuples.UNBOUND; } catch (Exception te) { // TuplesException throw new QueryException("Error resolving column", te); } }
/** {@inheritDoc} */ public boolean test(Context context) throws QueryException { if (type == null) return ((String)value).length() != 0; TypeInfo test = infoMap.get(type); if (test == null) throw new QueryException("Type Error: no effective boolean value for: " + toString()); return test.ebv(value.toString()); }
/** * Applies this function to its operands to get back a result. * @return A language code for the operand. * @throws QueryException If the operand was not a literal. */ protected RDFTerm resolve() throws QueryException { if (!operand.isLiteral()) throw new QueryException("Disallowed type in LANG function. Expected a Literal. Got a : " + operand.getClass().getSimpleName()); return ((ValueLiteral)operand).getLang(); } }
public void setAutoCommit(boolean autoCommit) throws QueryException { if (logger.isDebugEnabled()) { logger.debug("setAutoCommit(" + autoCommit + ") called."); } assertInternallyManagedXA(); try { internalFactory.setAutoCommit(this, autoCommit); } catch (MulgaraTransactionException em) { throw new QueryException("Error setting autocommit", em); } }
/** * Tests a value to see if it is a simple literal, and throws an exception if it is. * Simple literals do a similar test when compared with a ComparableExpression. * @param v The comparable expression to test. * @throws QueryException If the comparable expression resolves to a {@link SimpleLiteral}. */ private void compatibilityTest(ComparableExpression v) throws QueryException { if (v.isLiteral() && ((ValueLiteral)v).isSimple()) throw new QueryException("Type Error: cannot compare a simple literal with a: " + getClass().getSimpleName()); }
/** * Get the type from the underlying operand * @return The operands type IRI * @throws QueryException If there was an error resolving the operand */ protected RDFTerm resolve() throws QueryException { if (!operand.isLiteral()) throw new QueryException("Disallowed type in DATATYPE function. Expected a Literal. Got a : " + operand.getClass().getSimpleName()); return ((ValueLiteral)operand).getType(); }
public void rollback() throws QueryException { logger.debug("Rollback transaction"); assertInternallyManagedXA(); try { internalFactory.rollback(this); } catch (MulgaraTransactionException em) { throw new QueryException("Error performing rollback", em); } }
/** * @see org.mulgara.query.filter.value.ValueLiteral#getLexical() * @throws QueryException if the operand does not resolve */ public String getLexical() throws QueryException { Object value = operand.getValue(); // Works fine without this test, but the SPARQL spec wants to prevent it if (value instanceof BNode) throw new QueryException("Not permitted to convert a blank node to a String in SPARQL"); return operand.getValue().toString(); }
/** * @see org.mulgara.query.filter.value.ValueLiteral#getType() * @throws QueryException if this function does not resolve to a literal. */ public IRI getType() throws QueryException { RDFTerm result = resolve(); if (result.isLiteral()) return ((ValueLiteral)result).getType(); throw new QueryException("Not valid to ask the type of a: " + result.getClass().getSimpleName()); }
/** @see org.mulgara.query.filter.value.ComparableExpression#lessThan(org.mulgara.query.filter.value.ComparableExpression) */ public boolean lessThan(ComparableExpression v) throws QueryException { if (!isLiteral()) throw new QueryException("Type Error: cannot compare a: " + getClass().getSimpleName()); return ((ValueLiteral)resolve()).lessThan(v); }
/** * @see org.mulgara.query.filter.value.ValueLiteral#getLang() * @throws QueryException if this function does not resolve to a literal. */ public SimpleLiteral getLang() throws QueryException { RDFTerm result = resolve(); if (result.isLiteral()) return ((ValueLiteral)result).getLang(); throw new QueryException("Not valid to ask the language of a: " + result.getClass().getSimpleName()); }
/** * Tests if the parameter is a {@link org.mulgara.query.filter.value.SimpleLiteral}. * Throws an exception if it is not. * @param v The parameter to test * @throws QueryException Thrown if v is not a simple literal. */ private void testSimple(RDFTerm v) throws QueryException { if (!v.isLiteral() || !((ValueLiteral)v).isSimple()) throw new QueryException("Type Error: LangMatches requires simple literals"); }
/** * Extended numerical comparison function. Currently unused. * @param v The term to compare against. * @return <code>true</code> if this compares against v with semantic equivalence, regardless of lexical equivalence * @throws QueryException Thrown when a value cannot be resolved, or if the types are no numbers. */ @SuppressWarnings("unused") private boolean numberCompare(RDFTerm v) throws QueryException { if (!(value instanceof Number) || !(v.getValue() instanceof Number)) throw new QueryException("Terms are not equal"); return compare(value, v) == 0; }
public boolean test(Context context) throws QueryException { setCurrentContext(context); RDFTerm term = resolve(); if (!term.isLiteral()) throw new QueryException("Cannot get an effective boolean value for a non-literal: " + term.getClass().getSimpleName()); return ((ComparableExpression)term).test(context); }
/** @see org.mulgara.query.filter.value.ValueLiteral#test(org.mulgara.query.filter.Context) */ public boolean test(Context context) throws QueryException { setCurrentContext(context); RDFTerm term = resolve(); if (term.isLiteral()) { return ((ValueLiteral)term).test(context); } else if (term instanceof Filter) { return ((Filter)term).test(context); } throw new QueryException("Type error. Cannot get a boolean from a: " + term.getClass().getSimpleName()); }