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.unsupported;
09:
10: import org.openrdf.model.Value;
11: import org.openrdf.query.algebra.QueryModelNode;
12: import org.openrdf.query.algebra.ValueConstant;
13: import org.openrdf.query.algebra.ValueExpr;
14: import org.openrdf.query.algebra.Var;
15: import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
16: import org.openrdf.sail.rdbms.RdbmsValueFactory;
17: import org.openrdf.sail.rdbms.algebra.NumberValue;
18: import org.openrdf.sail.rdbms.algebra.RefIdColumn;
19: import org.openrdf.sail.rdbms.algebra.SqlNull;
20: import org.openrdf.sail.rdbms.algebra.base.SqlExpr;
21: import org.openrdf.sail.rdbms.exceptions.RdbmsException;
22: import org.openrdf.sail.rdbms.exceptions.RdbmsRuntimeException;
23: import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
24:
25: /**
26: *
27: * @author James Leigh
28: */
29: public class HashExprFactory extends
30: QueryModelVisitorBase<UnsupportedRdbmsOperatorException> {
31: protected SqlExpr result;
32: private RdbmsValueFactory vf;
33:
34: public HashExprFactory(RdbmsValueFactory vf) {
35: super ();
36: this .vf = vf;
37: }
38:
39: public SqlExpr createHashExpr(ValueExpr expr)
40: throws UnsupportedRdbmsOperatorException {
41: result = null;
42: if (expr == null)
43: return new SqlNull();
44: expr.visit(this );
45: if (result == null)
46: return new SqlNull();
47: return result;
48: }
49:
50: @Override
51: public void meet(ValueConstant vc) {
52: result = valueOf(vc.getValue());
53: }
54:
55: @Override
56: public void meet(Var var) {
57: if (var.getValue() == null) {
58: result = new RefIdColumn(var);
59: } else {
60: result = valueOf(var.getValue());
61: }
62: }
63:
64: @Override
65: protected void meetNode(QueryModelNode arg)
66: throws UnsupportedRdbmsOperatorException {
67: throw unsupported(arg);
68: }
69:
70: public SqlExpr valueOf(Value value) {
71: try {
72: return new NumberValue(vf.getInternalId(value));
73: } catch (RdbmsException e) {
74: throw new RdbmsRuntimeException(e);
75: }
76: }
77:
78: }
|