001package gudusoft.gsqlparser.nodes;
002
003
004import gudusoft.gsqlparser.EDbObjectType;
005import gudusoft.gsqlparser.ESqlClause;
006import gudusoft.gsqlparser.TCustomSqlStatement;
007
008/**
009 * SQL Server table hint:
010 * <p>Syntax 1:
011 * <pre>
012 *    WITH  ( &lt;table_hint&gt; [ [, ]...n ] )
013 *
014 *    &lt;table_hint&gt; ::=  FORCESCAN
015 *    use {@link #getHint()} method get this hint:FORCESCAN
016 *
017 *    &lt;table_hint&gt; ::= INDEX =  ( index_value )
018 *    {@link #isIndex() } return true, {@link #getHint()} return index_value.
019 *
020 *    &lt;table_hint&gt; ::= INDEX  ( index_value [ ,...n ] )
021 *    {@link #isIndex() } return true, {@link #getExprList()} return index_value list.
022 *  </pre>
023 *
024 */
025public class TTableHint extends TParseTreeNode {
026    public void setHint(TObjectName hint) {
027        this.hint = hint;
028    }
029
030    private TObjectName hint;
031    private TExpressionList exprList; //TPTNodeList <TExpression>
032    private boolean isIndex;
033    private TConstant hintValue;
034    private TTable ownerTable;
035
036    public void setOwnerTable(TTable ownerTable) {
037        this.ownerTable = ownerTable;
038    }
039
040    public TConstant getHintValue() {
041        return hintValue;
042    }
043
044    public TExpressionList getExprList() {
045        return exprList;
046    }
047
048    public TObjectName getHint() {
049        return hint;
050    }
051
052    public boolean isIndex() {
053        return isIndex;
054    }
055
056    public void setIndex(boolean index) {
057
058        isIndex = index;
059    }
060
061    public void init  (Object arg1){
062        if (arg1 instanceof TObjectName){
063            hint = (TObjectName)arg1;
064            hint.setDbObjectType(EDbObjectType.hint);
065        }else if (arg1 instanceof TExpressionList){
066            exprList = (TExpressionList)arg1;
067            isIndex = true;
068        }else if (arg1 instanceof TConstant){
069            hintValue = (TConstant)arg1;
070        }
071    }
072
073     public void doParse(TCustomSqlStatement psql, ESqlClause plocation){
074          if (hint != null){
075              //psql.linkColumnReferenceToTable(hint,plocation);
076              hint.setLocation(plocation);
077              hint.setDbObjectType(EDbObjectType.hint);
078             // ownerTable.getObjectNameReferences().addObjectName(hint);
079             // ownerTable.getLinkedColumns().addObjectName(hint);
080             // hint.setSourceTable(ownerTable);
081          }else if (exprList != null){
082              exprList.doParse(psql,plocation);
083          }
084    }
085
086    public void accept(TParseTreeVisitor v){
087        v.preVisit(this);
088        v.postVisit(this);
089    }
090
091    public void acceptChildren(TParseTreeVisitor v){
092        v.preVisit(this);
093        v.postVisit(this);
094    }
095
096    public void setExprList(TExpressionList exprList) {
097        this.exprList = exprList;
098    }
099
100    public void setHintValue(TConstant hintValue) {
101        this.hintValue = hintValue;
102    }
103}