/** * Alipay.com Inc. * Copyright (c) 2004-2012 All Rights Reserved. */ package com.alipay.zdal.parser.sql.ast.expr; import com.alipay.zdal.parser.sql.ast.SQLDataType; import com.alipay.zdal.parser.sql.ast.SQLExpr; import com.alipay.zdal.parser.sql.ast.SQLExprImpl; import com.alipay.zdal.parser.sql.visitor.SQLASTVisitor; /** * * @author xiaoqing.zhouxq * @version $Id: SQLCastExpr.java, v 0.1 2012-11-17 ����3:16:21 xiaoqing.zhouxq Exp $ */ public class SQLCastExpr extends SQLExprImpl { private static final long serialVersionUID = 1L; private SQLExpr expr; private SQLDataType dataType; public SQLCastExpr() { } public SQLExpr getExpr() { return this.expr; } public void setExpr(SQLExpr expr) { this.expr = expr; } public SQLDataType getDataType() { return this.dataType; } public void setDataType(SQLDataType dataType) { this.dataType = dataType; } public void output(StringBuffer buf) { buf.append("CAST("); this.expr.output(buf); buf.append(" AS "); this.dataType.output(buf); buf.append(")"); } protected void accept0(SQLASTVisitor visitor) { if (visitor.visit(this)) { acceptChild(visitor, this.expr); acceptChild(visitor, this.dataType); } visitor.endVisit(this); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((dataType == null) ? 0 : dataType.hashCode()); result = prime * result + ((expr == null) ? 0 : expr.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } SQLCastExpr other = (SQLCastExpr) obj; if (dataType == null) { if (other.dataType != null) { return false; } } else if (!dataType.equals(other.dataType)) { return false; } if (expr == null) { if (other.expr != null) { return false; } } else if (!expr.equals(other.expr)) { return false; } return true; } }