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;
007:
008: import org.openrdf.query.algebra.QueryModelNode;
009: import org.openrdf.query.algebra.QueryModelVisitor;
010: import org.openrdf.sail.rdbms.algebra.base.RdbmsQueryModelNodeBase;
011: import org.openrdf.sail.rdbms.algebra.base.RdbmsQueryModelVisitorBase;
012: import org.openrdf.sail.rdbms.algebra.base.SqlExpr;
013:
014: /**
015: * A collection of SQL expressions that form an RDF value binding.
016: *
017: * @author James Leigh
018: *
019: */
020: public class SelectProjection extends RdbmsQueryModelNodeBase {
021: private ColumnVar var;
022: private RefIdColumn id;
023: private SqlExpr stringValue;
024: private SqlExpr datatype;
025: private SqlExpr language;
026:
027: public ColumnVar getVar() {
028: return var;
029: }
030:
031: public void setVar(ColumnVar var) {
032: this .var = var;
033: }
034:
035: public RefIdColumn getId() {
036: return id;
037: }
038:
039: public void setId(RefIdColumn id) {
040: this .id = id;
041: id.setParentNode(this );
042: }
043:
044: public SqlExpr getStringValue() {
045: return stringValue;
046: }
047:
048: public void setStringValue(SqlExpr stringValue) {
049: this .stringValue = stringValue;
050: stringValue.setParentNode(this );
051: }
052:
053: public SqlExpr getDatatype() {
054: return datatype;
055: }
056:
057: public void setDatatype(SqlExpr datatype) {
058: this .datatype = datatype;
059: datatype.setParentNode(this );
060: }
061:
062: public SqlExpr getLanguage() {
063: return language;
064: }
065:
066: public void setLanguage(SqlExpr language) {
067: this .language = language;
068: language.setParentNode(this );
069: }
070:
071: @Override
072: public <X extends Exception> void visit(
073: RdbmsQueryModelVisitorBase<X> visitor) throws X {
074: visitor.meet(this );
075: }
076:
077: @Override
078: public <X extends Exception> void visitChildren(
079: QueryModelVisitor<X> visitor) throws X {
080: id.visit(visitor);
081: stringValue.visit(visitor);
082: datatype.visit(visitor);
083: language.visit(visitor);
084: }
085:
086: @Override
087: public void replaceChildNode(QueryModelNode current,
088: QueryModelNode replacement) {
089: if (id == current) {
090: setId((RefIdColumn) replacement);
091: } else if (stringValue == current) {
092: setStringValue((SqlExpr) replacement);
093: } else if (datatype == current) {
094: setDatatype((SqlExpr) replacement);
095: } else if (language == current) {
096: setLanguage((SqlExpr) replacement);
097: } else {
098: super .replaceChildNode(current, replacement);
099: }
100: }
101:
102: @Override
103: public SelectProjection clone() {
104: SelectProjection clone = (SelectProjection) super .clone();
105: clone.setId(getId().clone());
106: clone.setStringValue(getStringValue().clone());
107: clone.setDatatype(getDatatype().clone());
108: clone.setLanguage(getLanguage().clone());
109: return clone;
110: }
111:
112: @Override
113: public int hashCode() {
114: final int prime = 31;
115: int result = 1;
116: result = prime * result
117: + ((datatype == null) ? 0 : datatype.hashCode());
118: result = prime * result + ((id == null) ? 0 : id.hashCode());
119: result = prime * result
120: + ((language == null) ? 0 : language.hashCode());
121: result = prime * result
122: + ((stringValue == null) ? 0 : stringValue.hashCode());
123: result = prime * result + ((var == null) ? 0 : var.hashCode());
124: return result;
125: }
126:
127: @Override
128: public boolean equals(Object obj) {
129: if (this == obj)
130: return true;
131: if (obj == null)
132: return false;
133: if (getClass() != obj.getClass())
134: return false;
135: final SelectProjection other = (SelectProjection) obj;
136: if (datatype == null) {
137: if (other.datatype != null)
138: return false;
139: } else if (!datatype.equals(other.datatype))
140: return false;
141: if (id == null) {
142: if (other.id != null)
143: return false;
144: } else if (!id.equals(other.id))
145: return false;
146: if (language == null) {
147: if (other.language != null)
148: return false;
149: } else if (!language.equals(other.language))
150: return false;
151: if (stringValue == null) {
152: if (other.stringValue != null)
153: return false;
154: } else if (!stringValue.equals(other.stringValue))
155: return false;
156: if (var == null) {
157: if (other.var != null)
158: return false;
159: } else if (!var.equals(other.var))
160: return false;
161: return true;
162: }
163:
164: }
|