001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.rdbms.algebra.factories;
007:
008: import static org.openrdf.sail.rdbms.algebra.base.SqlExprSupport.num;
009: import static org.openrdf.sail.rdbms.algebra.base.SqlExprSupport.sqlNull;
010: import static org.openrdf.sail.rdbms.algebra.base.SqlExprSupport.unsupported;
011:
012: import org.openrdf.model.Literal;
013: import org.openrdf.model.Value;
014: import org.openrdf.query.algebra.Datatype;
015: import org.openrdf.query.algebra.Lang;
016: import org.openrdf.query.algebra.MathExpr;
017: import org.openrdf.query.algebra.QueryModelNode;
018: import org.openrdf.query.algebra.Str;
019: import org.openrdf.query.algebra.ValueConstant;
020: import org.openrdf.query.algebra.ValueExpr;
021: import org.openrdf.query.algebra.Var;
022: import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
023: import org.openrdf.sail.rdbms.algebra.RefIdColumn;
024: import org.openrdf.sail.rdbms.algebra.SqlNull;
025: import org.openrdf.sail.rdbms.algebra.SqlShift;
026: import org.openrdf.sail.rdbms.algebra.base.SqlExpr;
027: import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
028: import org.openrdf.sail.rdbms.schema.IdSequence;
029:
030: /**
031: * Creates a binary SQL expression for a dateTime zoned value.
032: *
033: * @author James Leigh
034: *
035: */
036: public class ZonedExprFactory extends
037: QueryModelVisitorBase<UnsupportedRdbmsOperatorException> {
038: protected SqlExpr result;
039: private IdSequence ids;
040:
041: public ZonedExprFactory(IdSequence ids) {
042: super ();
043: this .ids = ids;
044: }
045:
046: public SqlExpr createZonedExpr(ValueExpr expr)
047: throws UnsupportedRdbmsOperatorException {
048: result = null;
049: if (expr == null)
050: return new SqlNull();
051: expr.visit(this );
052: if (result == null)
053: return new SqlNull();
054: return result;
055: }
056:
057: @Override
058: public void meet(Datatype node) {
059: result = sqlNull();
060: }
061:
062: @Override
063: public void meet(Lang node)
064: throws UnsupportedRdbmsOperatorException {
065: result = sqlNull();
066: }
067:
068: @Override
069: public void meet(MathExpr node)
070: throws UnsupportedRdbmsOperatorException {
071: result = sqlNull();
072: }
073:
074: @Override
075: public void meet(Str node) {
076: result = sqlNull();
077: }
078:
079: @Override
080: public void meet(ValueConstant vc) {
081: result = valueOf(vc.getValue());
082: }
083:
084: @Override
085: public void meet(Var node) {
086: if (node.getValue() == null) {
087: result = new SqlShift(new RefIdColumn(node),
088: ids.getShift(), ids.getMod());
089: } else {
090: result = valueOf(node.getValue());
091: }
092: }
093:
094: @Override
095: protected void meetNode(QueryModelNode arg)
096: throws UnsupportedRdbmsOperatorException {
097: throw unsupported(arg);
098: }
099:
100: private SqlExpr valueOf(Value value) {
101: if (value instanceof Literal) {
102: return num(ids.code((Literal) value));
103: }
104: return null;
105: }
106: }
|