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.sqlNull;
009: import static org.openrdf.sail.rdbms.algebra.base.SqlExprSupport.str;
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.LanguageColumn;
024: import org.openrdf.sail.rdbms.algebra.SqlNull;
025: import org.openrdf.sail.rdbms.algebra.base.SqlExpr;
026: import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
027:
028: /**
029: * Creates an SQL expression of a literal's language.
030: *
031: * @author James Leigh
032: *
033: */
034: public class LanguageExprFactory extends
035: QueryModelVisitorBase<UnsupportedRdbmsOperatorException> {
036: protected SqlExpr result;
037:
038: public SqlExpr createLanguageExpr(ValueExpr expr)
039: throws UnsupportedRdbmsOperatorException {
040: result = null;
041: if (expr == null)
042: return new SqlNull();
043: expr.visit(this );
044: if (result == null)
045: return new SqlNull();
046: return result;
047: }
048:
049: @Override
050: public void meet(Datatype node)
051: throws UnsupportedRdbmsOperatorException {
052: result = sqlNull();
053: }
054:
055: @Override
056: public void meet(Lang node)
057: throws UnsupportedRdbmsOperatorException {
058: result = sqlNull();
059: }
060:
061: @Override
062: public void meet(MathExpr node)
063: throws UnsupportedRdbmsOperatorException {
064: result = sqlNull();
065: }
066:
067: @Override
068: public void meet(Str node) throws UnsupportedRdbmsOperatorException {
069: result = sqlNull();
070: }
071:
072: @Override
073: public void meet(ValueConstant vc) {
074: result = valueOf(vc.getValue());
075: }
076:
077: @Override
078: public void meet(Var var) {
079: if (var.getValue() == null) {
080: result = new LanguageColumn(var);
081: } else {
082: result = valueOf(var.getValue());
083: }
084: }
085:
086: @Override
087: protected void meetNode(QueryModelNode arg)
088: throws UnsupportedRdbmsOperatorException {
089: throw unsupported(arg);
090: }
091:
092: private SqlExpr valueOf(Value value) {
093: if (value instanceof Literal) {
094: Literal lit = (Literal) value;
095: return str(lit.getLanguage());
096: }
097: return sqlNull();
098: }
099:
100: }
|