01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.rdbms.algebra.factories;
07:
08: import static org.openrdf.sail.rdbms.algebra.base.SqlExprSupport.sqlNull;
09: import static org.openrdf.sail.rdbms.algebra.base.SqlExprSupport.str;
10: import static org.openrdf.sail.rdbms.algebra.base.SqlExprSupport.unsupported;
11:
12: import org.openrdf.model.BNode;
13: import org.openrdf.model.Value;
14: import org.openrdf.query.algebra.Datatype;
15: import org.openrdf.query.algebra.Lang;
16: import org.openrdf.query.algebra.MathExpr;
17: import org.openrdf.query.algebra.QueryModelNode;
18: import org.openrdf.query.algebra.Str;
19: import org.openrdf.query.algebra.ValueConstant;
20: import org.openrdf.query.algebra.ValueExpr;
21: import org.openrdf.query.algebra.Var;
22: import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
23: import org.openrdf.sail.rdbms.algebra.BNodeColumn;
24: import org.openrdf.sail.rdbms.algebra.SqlNull;
25: import org.openrdf.sail.rdbms.algebra.StringValue;
26: import org.openrdf.sail.rdbms.algebra.base.SqlExpr;
27: import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
28:
29: /**
30: * BNode expression factory - creates a {@link BNodeColumn} or a
31: * {@link StringValue} of the BNode ID.
32: *
33: * @author James Leigh
34: *
35: */
36: public class BNodeExprFactory extends
37: QueryModelVisitorBase<UnsupportedRdbmsOperatorException> {
38: protected SqlExpr result;
39:
40: public SqlExpr createBNodeExpr(ValueExpr expr)
41: throws UnsupportedRdbmsOperatorException {
42: result = null;
43: if (expr == null)
44: return new SqlNull();
45: expr.visit(this );
46: if (result == null)
47: return new SqlNull();
48: return result;
49: }
50:
51: @Override
52: public void meet(Datatype node) {
53: result = sqlNull();
54: }
55:
56: @Override
57: public void meet(Lang node)
58: throws UnsupportedRdbmsOperatorException {
59: result = sqlNull();
60: }
61:
62: @Override
63: public void meet(MathExpr node)
64: throws UnsupportedRdbmsOperatorException {
65: result = sqlNull();
66: }
67:
68: @Override
69: public void meet(Str node) {
70: result = sqlNull();
71: }
72:
73: @Override
74: public void meet(ValueConstant vc) {
75: result = valueOf(vc.getValue());
76: }
77:
78: @Override
79: public void meet(Var var) {
80: if (var.getValue() == null) {
81: result = new BNodeColumn(var);
82: } else {
83: result = valueOf(var.getValue());
84: }
85: }
86:
87: @Override
88: protected void meetNode(QueryModelNode arg)
89: throws UnsupportedRdbmsOperatorException {
90: throw unsupported(arg);
91: }
92:
93: private SqlExpr valueOf(Value value) {
94: if (value instanceof BNode)
95: return str(((BNode) value).stringValue());
96: return sqlNull();
97: }
98: }
|