001package gudusoft.gsqlparser.nodes;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.compiler.TVariable;
005import gudusoft.gsqlparser.resolver.TColumnTableMatch;
006import gudusoft.gsqlparser.sqlenv.*;
007import gudusoft.gsqlparser.stmt.TSelectSqlStatement;
008import gudusoft.gsqlparser.util.keywordChecker;
009
010import java.util.ArrayList;
011
012/**
013 * The qualified or unqualified name that identifies a database object.
014 * The qualified name may includes those parts: server,database,schema,object,part and dblink.
015 * This class represents database object in different database vendors such as Oracle, SQL Server in a uniform way.
016 * <p>
017 * The general syntax of database object in Oracle: [schema.]object[.part][@dblink]
018 * <p>
019 * The general syntax of database object in SQL Server: [server.][database.][schema.]object
020 * <p>
021 * The meaning of {@link #getObjectToken()} and {@link #getPartToken()} depends on the {@link #getDbObjectType()}.
022 * If this database object is a schema object such as table, index, then the objectToken represents this
023 * database object and partToken is null.
024 * <p><p>
025 * If this TObjectName represents a column, the partToken represents the column name, the objectToken is table/view
026 * name of this column if this column is qualified like <code>table.column</code>, otherwise, the objectToken is
027 * null.
028 * <p>
029 * schemaToken, databaseToken, serverToken is the qualified part of a database object name.
030 * If this objectName represents a database name in the create database statement like this
031 * <code>CREATE DATABASE menagerie</code>, then, the objectToken is menagerie and databaseToken is null.
032 *
033 * @see gudusoft.gsqlparser.EDbObjectType
034 **/
035
036public class TObjectName extends TParseTreeNode implements Cloneable{
037
038
039    private TExceptReplaceClause exceptReplaceClause;
040
041    public TExceptReplaceClause getExceptReplaceClause() {
042        return exceptReplaceClause;
043    }
044
045    public void setExceptReplaceClause(TExceptReplaceClause exceptReplaceClause) {
046        this.exceptReplaceClause = exceptReplaceClause;
047    }
048        
049    private ETableKind tableKind = ETableKind.etkBase;
050
051    public void setTableKind(ETableKind tableKind) {
052        this.tableKind = tableKind;
053    }
054
055    public ETableKind getTableKind() {
056        return tableKind;
057    }
058
059    TVariable linkedVariable = null;
060
061    public void setLinkedVariable(TVariable linkedVariable) {
062        this.linkedVariable = linkedVariable;
063        this.dbObjectType = EDbObjectType.variable;
064    }
065
066    public TVariable getLinkedVariable() {
067        return linkedVariable;
068    }
069
070    // 如果该对象表示一个字段,那么本属性表示该字段的数据来自那个源字段
071    private TAttributeNode sourceAttributeNode;
072
073    public void setSourceAttributeNode(TAttributeNode sourceAttributeNode) {
074        this.sourceAttributeNode = sourceAttributeNode;
075    }
076
077    public TAttributeNode getSourceAttributeNode() {
078        return sourceAttributeNode;
079    }
080//    private boolean isResolved = false;
081//
082//    public void setResolved(boolean resolved) {
083//        isResolved = resolved;
084//    }
085//
086//    public void setResolvedRelation(TTable resolvedRelation) {
087//        this.resolvedRelation = resolvedRelation;
088//        this.isResolved = true;
089//    }
090//
091//    public boolean isResolved() {
092//        return isResolved;
093//    }
094//
095//    public TTable getResolvedRelation() {
096//        return resolvedRelation;
097//    }
098//
099//    private TTable resolvedRelation = null;
100
101    public TObjectName clone(){
102        TObjectName cloneObject = new TObjectName();
103        cloneObject.dbObjectType = this.dbObjectType;
104        cloneObject.dbvendor = this.dbvendor;
105
106        if (this.partToken != null){
107            cloneObject.partToken = this.partToken.clone();
108        }
109        if (this.objectToken != null){
110            cloneObject.objectToken = this.objectToken.clone();
111        }
112        if (this.schemaToken != null){
113        cloneObject.schemaToken = this.schemaToken.clone();
114        }
115
116        if (this.databaseToken != null){
117            cloneObject.databaseToken = this.databaseToken.clone();
118        }
119
120        if (this.serverToken != null){
121            cloneObject.serverToken = this.serverToken.clone();
122        }
123
124        if (this.propertyToken != null){
125            cloneObject.propertyToken = this.propertyToken.clone();
126        }
127
128        if (this.methodToken != null){
129            cloneObject.methodToken = this.methodToken.clone();
130        }
131
132        if (this.packageToken != null){
133            cloneObject.packageToken = this.packageToken.clone();
134        }
135
136        cloneObject.numberOfPart = this.numberOfPart;
137
138        return cloneObject;
139    }
140
141    private TObjectName parentObjectName;
142
143    public void setParentObjectName(TObjectName parentObjectName) {
144        this.parentObjectName = parentObjectName;
145    }
146
147    @Override
148    public TObjectName getParentObjectName() {
149        return parentObjectName;
150    }
151
152    public void setPath(TPathSqlNode path) {
153        this.path = path;
154        this.setEndToken(path.getEndToken());
155    }
156
157    /**
158     *  stage path
159     *
160     * @return
161     */
162    public TPathSqlNode getPath() {
163        return path;
164    }
165
166    private TPathSqlNode path;
167
168//    private TObjectName cursorName;
169//
170//    public void setCursorName(TObjectName cursorName) {
171//        this.cursorName = cursorName;
172//    }
173//
174//    /**
175//     * related cursor name if oracle for statement
176//     * like: FOR emp_rec IN emp_cur
177//     * @return
178//     */
179//    public TObjectName getCursorName() {
180//        return cursorName;
181//    }
182
183    private ArrayList<TTable> sourceTableList = new ArrayList<>();
184
185    /**
186     * source table list for star column,
187     * <br>select * from emp,dept
188     * <br> * column will be list to both emp and dept table.
189     * <br>
190     * @return
191     */
192    public ArrayList<TTable> getSourceTableList() {
193        return sourceTableList;
194    }
195
196    private boolean isImplicitSchema = false;
197    private boolean isImplicitDatabase = false;
198
199    public boolean isImplicitSchema() {
200        return isImplicitSchema;
201    }
202
203    public boolean isImplicitDatabase() {
204        return isImplicitDatabase;
205    }
206
207//    public void setOriginalQuery(TSelectSqlStatement originalQuery) {
208//        this.originalQuery = originalQuery;
209//    }
210//
211//    public TSelectSqlStatement getOriginalQuery() {
212//        return originalQuery;
213//    }
214//
215//    private TSelectSqlStatement originalQuery = null;
216
217    private ArrayList<TAttributeNode> attributeNodesDerivedFromFromClause;
218
219    /**
220     * 这个属性只有当 column 为 * 时有效
221     * 当 column 为 * 时, 本属性包含该 * 展开后对应的 attributeNode 列表,来源是 FROM CLAUSE中的 tables, 在 resolve star column
222     * 时给本属性赋值, TStmtScope.resolve(TObjectName objectName)
223     *
224     * 当 table 有metadata或DDL给出了明确的字段时,每table个展开的 attributeNode 包含明确的字段名,such as t.c
225     * 当 table 没有 metadata 和 DDL 时,每table个只展开的 一个 attributeNode,内容为 t.*
226     *
227     *
228     * @return
229     */
230    public ArrayList<TAttributeNode> getAttributeNodesDerivedFromFromClause() {
231        if (attributeNodesDerivedFromFromClause == null){
232            attributeNodesDerivedFromFromClause = new ArrayList<TAttributeNode>();
233        }
234        return attributeNodesDerivedFromFromClause;
235    }
236
237    private ArrayList<TColumnTableMatch> candidateAttributeNodes;
238
239    /**
240     * 非 star column 使用该属性存放可能包含该 column 的 attributeNode
241     * star column 使用 {@link #getAttributeNodesDerivedFromFromClause()}
242     *
243     * @return
244     */
245    public ArrayList<TColumnTableMatch> getCandidateAttributeNodes() {
246        if (candidateAttributeNodes == null){
247            candidateAttributeNodes = new ArrayList<TColumnTableMatch>();
248        }
249        return candidateAttributeNodes;
250    }
251
252    private TTableList candidateTables = null;
253
254    public TTableList getCandidateTables() {
255        if (candidateTables == null){
256            candidateTables = new TTableList();
257        }
258        return candidateTables;
259    }
260
261    private boolean isOrphanColumn = false;
262
263    public void setOrphanColumn(boolean orphanColumn) {
264        isOrphanColumn = orphanColumn;
265    }
266
267    public boolean isOrphanColumn() {
268        return isOrphanColumn;
269    }
270
271    private boolean isReservedKeyword = false;
272
273    public boolean isReservedKeyword() {
274        return isReservedKeyword;
275    }
276
277    private TColumnDefinition linkedColumnDef = null;
278
279    public void setLinkedColumnDef(TColumnDefinition linkedColumnDef) {
280        this.linkedColumnDef = linkedColumnDef;
281    }
282
283    /**
284     * The column definition in create/alter table statement that include this column name object.
285     * <pre>
286     *     CREATE TABLE table_name (
287     *       column1 datatype,
288     *       column2 datatype
289     *    );
290     * </pre>
291     * In above SQL, <code>column1 datatype</code> is the column definition while <code>column1</code> is this
292     * object name.
293     * @return column definition in create/alter table statement
294     */
295    public TColumnDefinition getLinkedColumnDef() {
296
297        return linkedColumnDef;
298    }
299
300    private TObjectName namespace;
301
302    public void setNamespace(TObjectName namespace) {
303        this.namespace = namespace;
304    }
305
306    /**
307     * The Couchbase namespace before keyspace
308     * @return the namespace
309     */
310    public TObjectName getNamespace() {
311
312        return namespace;
313    }
314
315    public String toString() {
316        String ret = super.toString();
317
318        if (ret != null) {
319            if ((dbvendor == EDbVendor.dbvsnowflake) && (ret.toString().toLowerCase().startsWith("identifier("))){
320                // snowflake identifier name: IDENTIFIER( { string_literal | session_variable | bind_variable | snowflake_scripting_variable } )
321                // only return the string_literal part
322                // https://www.sqlparser.com/bugs/mantisbt/view.php?id=3566
323                return TBaseType.removeQuoteChar(getObjectString());
324            }
325            return ret;
326        }
327
328        if (getPartToken() != null) return getPartString();
329        if (getObjectToken() != null ) return getObjectString();
330
331        return  null;
332    }
333
334    public void setQuoteType(EQuoteType quoteType) {
335        this.quoteType = quoteType;
336    }
337
338    /**
339     * Tell whether this is a quoted objectName.
340     * @return EQuoteType.squareBracket or EQuoteType.doubleQuote if this objectName is quoted.
341     */
342    public EQuoteType getQuoteType() {
343        if (toString().startsWith("[")){
344            return EQuoteType.squareBracket;
345        }else if (toString().startsWith("\"")){
346            return EQuoteType.doubleQuote;
347        }else if (toString().startsWith("`")){
348            return EQuoteType.backtick;
349        }else
350            return quoteType;
351    }
352
353    private EQuoteType quoteType = EQuoteType.notQuoted;
354//    private String stringValue;
355
356
357
358    /**
359     * Internal use only
360     */
361    public int searchLevel = 0;
362
363    public boolean isContinueToSearch(){
364        // if column is in where clause, we can search 10 levels up
365
366        // if column is in select list, only select one level up.
367        // only search one level up, c:\prg\gsp_sqlfiles\TestCases\java\oracle\dbobject\berger_sqltest_04.sql
368
369        if (this.getLocation() == ESqlClause.where) return (searchLevel < 10);
370        else return (searchLevel < 1);
371    }
372    private TResultColumn sourceColumn;
373
374    /**
375     * Set the result column which include this column name. Used by parser internally.
376     *
377     * @param sourceColumn the result column includes this column name
378     */
379    public void setSourceColumn(TResultColumn sourceColumn) {
380        this.sourceColumn = sourceColumn;
381        this.setDbObjectTypeDirectly(EDbObjectType.column);
382    }
383
384    /**
385     * The result column which include this column
386     * <pre>
387     *     select salary + 1000 from emp
388     * </pre>
389     * In the above SQL, <code>salary + 1000</code> is the result column while <code>salary</code> is this column name.
390     *
391     * @return the result column includes this column name
392     */
393    public TResultColumn getSourceColumn() {
394
395        return sourceColumn;
396    }
397
398    private TTable sourceTable;
399
400    /**
401     * This column must be in this syntax: table.column, otherwise, this method always return false.
402     * Match tableToken with the input pTable, compare the alias of pTable to tableToken at first,
403     * If not the same, then compare the table name directly. This method can handle quoted name correctly.
404     *
405     * This method is used by parser internally.
406     *
407     * @param pTable table used to match {@link #getTableToken()} of this column object
408     * @return true if input table is matched with tableToken of this column object
409     */
410    public boolean resolveWithThisTable(TTable pTable){
411        boolean lcResult = false;
412        if (getTableString().length() == 0) return false;
413        if (pTable.getAliasName().length() > 0) {
414            lcResult = pTable.checkTableByName(getTableString().toString()); //pTable.getAliasName().toString().equalsIgnoreCase(getTableString().toString());
415            if ((!lcResult)&&(getSchemaString().length()>0)){
416                lcResult = pTable.getAliasName().toString().equalsIgnoreCase(getSchemaString().toString());
417                if (lcResult){
418                    // table.column.field, table was recognized as schema in the parser, change the part token to property token
419                    this.columnToProperty();
420                }
421            }
422        }
423        if (lcResult) return true;
424
425        if (((pTable.isBaseTable()||(pTable.isCTEName()))&&(getTableToken() != null)&&(pTable.getTableName().getTableToken() != null))) {
426            // lcResult = getTableToken().toUnQuotedString().equalsIgnoreCase(pTable.getTableName().getTableToken().toUnQuotedString());
427            String s1 = TBaseType.getTextWithoutQuoted(getTableToken().toString());
428            String s2 = TBaseType.getTextWithoutQuoted(pTable.getTableName().getTableToken().toString());
429//            System.out.println("table1: "+s1);
430//            System.out.println("table1: "+s2);
431            lcResult = s1.equalsIgnoreCase(s2);
432
433            if (lcResult && (!pTable.getPrefixDatabase().isEmpty()) && (!this.getDatabaseString().isEmpty()) && (!pTable.getPrefixDatabase().equalsIgnoreCase(this.getDatabaseString().toString()))) {
434                // teradata: UPDATE foodmart.STRTOK_TIME A SET SYSTEM_DESK = testdatabase.STRTOK_TIME.SYSTEM_DESK
435                // table STRTOK_TIME in testdatabase should be treat as the same one in foodmart
436                lcResult = false;
437            }
438
439
440            if ((!lcResult)&&(getSchemaString().length()>0)){
441               // lcResult = pTable.getTableName().getTableToken().toUnQuotedString().equalsIgnoreCase(getSchemaString().toString());
442                lcResult = TBaseType.getTextWithoutQuoted(pTable.getTableName().getTableToken().toString()).equalsIgnoreCase(getSchemaString().toString());
443                if (lcResult){
444                    // table.column.field, table was recognized as schema in the parser, change the part token to property token
445                    this.columnToProperty();
446                }
447            }
448        }
449        return lcResult;
450    }
451
452    /**
453     * Check whether a column is prefixed by a table like this: <code>table.column</code>
454     *
455     * @return true if this column is in syntax like this: <code>table.column</code>
456     */
457    public boolean isQualified(){
458        return (getTableString().length() > 0);
459    }
460
461    public int getValidate_column_status() {
462        return validate_column_status;
463    }
464
465    public void setValidate_column_status(int validate_column_status) {
466        this.validate_column_status = validate_column_status;
467    }
468
469    private int validate_column_status = TBaseType.CAN_BE_COLUMN_NOT_VALIDATE_YET;
470    /**
471     * Check whether a column name is syntax valid in a specific database vendor.
472     * For example, in Oracle, <code>rowid</code> is not a valid column name.
473     *
474     * @param pDBVendor in which the database vendor the syntax of this column is checked
475     * @return true if this objectName can be used as a column name in the specified database
476     */
477    public boolean isValidColumnName(EDbVendor pDBVendor){
478       boolean lcResult = true;
479       if (validate_column_status == TBaseType.VALIDATED_CAN_BE_A_COLUMN_NAME) return true;
480       if (validate_column_status == TBaseType.VALIDATED_CAN_NOT_BE_A_COLUMN_NAME) return false;
481       if (validate_column_status == TBaseType.MARKED_NOT_A_COLUMN_IN_COLUMN_RESOLVER) return false;
482       if (validate_column_status == TBaseType.COLUMN_LINKED_TO_COLUMN_ALIAS_IN_OLD_ALGORITHM) return false;
483
484
485
486       if ((getObjectType() == TObjectName.ttobjVariable)
487               ||(getDbObjectType() == EDbObjectType.variable)
488               ||(getObjectType() == TObjectName.ttobjColumnAlias)
489               || (getDbObjectType() == EDbObjectType.xmlElement)
490               || (getDbObjectType() == EDbObjectType.date_time_part)
491               || (getDbObjectType() == EDbObjectType.constant)
492               || (getDbObjectType() == EDbObjectType.function)
493       ) {
494            validate_column_status = TBaseType.VALIDATED_CAN_NOT_BE_A_COLUMN_NAME;
495            return false;
496        }
497
498        if (pDBVendor == EDbVendor.dbvsybase){
499            TSourceToken pt = getPartToken();
500            if ( pt != null){
501                if (pt.tokentype == ETokenType.ttdqstring){
502                    //"0123", quoted string start with a number can't a column
503                    if ((pt.toString().charAt(1) >= '0')
504                            &&(pt.toString().charAt(1) <= '9')){
505                        lcResult = false;
506                    }else if (pt.toString().length() == 2){
507                        //"", empty
508                        lcResult = false;
509                    }else if (pt.toString().substring(1,pt.toString().length()-1).trim().length() == 0){
510                        //"  "
511                        lcResult = false;
512                    }
513                }
514            }
515        }
516
517        if (getPartToken() != null){
518            if (getPartToken().tokentype == ETokenType.ttkeyword){
519
520                switch (pDBVendor){
521                    case dbvmssql:
522                        //lcResult = this.getGsqlparser().getFlexer().canBeColumnName(getPartToken().tokencode);
523                        lcResult = TLexerMssql.canBeColumnName(getPartToken().tokencode);
524                        break;
525                    case dbvsybase:
526                        lcResult = !keywordChecker.isKeyword(getPartToken().toString(), EDbVendor.dbvsybase, "15.7", true);
527                        break;
528                    default:
529                        break;
530                }
531            }
532        }
533
534        if ((toString().startsWith("@"))||((toString().startsWith(":"))&&(toString().indexOf(".")==-1)))
535        {
536            setObjectType(TObjectName.ttobjNotAObject);
537            lcResult = false;
538        }
539
540        switch (pDBVendor){
541            case dbvoracle:
542                if ( //(getColumnNameOnly().compareToIgnoreCase ("rowid") == 0)||
543                         (getColumnNameOnly().compareToIgnoreCase ("sysdate") == 0)
544                        || (getColumnNameOnly().compareToIgnoreCase ("nextval") == 0)
545                        || (getColumnNameOnly().compareToIgnoreCase ("rownum") == 0)
546                        || (getColumnNameOnly().compareToIgnoreCase ("level") == 0)
547                        || (getColumnNameOnly().compareToIgnoreCase ("user") == 0)
548                ){
549                    setObjectType(TObjectName.ttobjNotAObject);
550                    lcResult = false;
551                }
552                if ((toString().startsWith(":"))&&(toString().indexOf(".") == -1))
553                { // :bindv, but :new.column should not be enter here
554                    setObjectType(TObjectName.ttobjNotAObject);
555                    lcResult = false;
556                }
557                break;
558            case dbvmssql:
559                if ((getColumnNameOnly().compareToIgnoreCase ("system_user") == 0)
560                ){
561                    //setObjectType(TObjectName.ttobjNotAObject);
562                    lcResult = false;
563                }
564                break;
565            case dbvmysql:
566                if (toString().startsWith("\"")){
567                    // "X" is a string literal
568                    lcResult = false;
569                }
570                if (keywordChecker.isKeyword(toString(),EDbVendor.dbvmysql,"6.0",true)){
571                    isReservedKeyword = true;
572                    lcResult = false;
573                }
574                break;
575            case dbvteradata:
576                if ((getObjectString().length() == 0)&&((getColumnNameOnly().compareToIgnoreCase ("account") == 0)
577                        ||(getColumnNameOnly().compareToIgnoreCase ("current_date") == 0)
578                        ||(getColumnNameOnly().compareToIgnoreCase ("current_role") == 0)
579                        ||(getColumnNameOnly().compareToIgnoreCase ("current_time") == 0)
580                        ||(getColumnNameOnly().compareToIgnoreCase ("current_timestamp") == 0)
581                        ||(getColumnNameOnly().compareToIgnoreCase ("current_user") == 0)
582                        ||(getColumnNameOnly().compareToIgnoreCase ("database") == 0)
583                        ||((getColumnNameOnly().compareToIgnoreCase ("date") == 0)&&( this.getDbObjectType() != EDbObjectType.column ))
584                        ||(getColumnNameOnly().compareToIgnoreCase ("profile") == 0)
585                        ||(getColumnNameOnly().compareToIgnoreCase ("role") == 0)
586                        ||(getColumnNameOnly().compareToIgnoreCase ("session") == 0)
587                        ||(getColumnNameOnly().compareToIgnoreCase ("time") == 0)
588                        ||(getColumnNameOnly().compareToIgnoreCase ("user") == 0)
589                        ||(getColumnNameOnly().compareToIgnoreCase ("sysdate") == 0)
590                )){
591                    lcResult = false;
592                }
593                break;
594            case dbvpostgresql:
595                if (toString().startsWith("$")){
596                    if ((toString().charAt(1) >= '0')
597                            &&(toString().charAt(1) <= '9')){
598                        this.setDbObjectType(EDbObjectType.variable);
599                        lcResult = false;
600                    }
601                }
602                break;
603            case dbvbigquery:
604                if ((getColumnNameOnly().compareToIgnoreCase ("CURRENT_DATE") == 0)
605                         ||(getColumnNameOnly().compareToIgnoreCase ("CURRENT_TIME") == 0)
606                        ||(getColumnNameOnly().compareToIgnoreCase ("CURRENT_TIMESTAMP") == 0)
607                ){
608                    //setObjectType(TObjectName.ttobjNotAObject);
609                    lcResult = false;
610                }
611                break;
612        }
613
614       if(lcResult){
615           validate_column_status = TBaseType.VALIDATED_CAN_BE_A_COLUMN_NAME;
616       }else{
617           validate_column_status = TBaseType.VALIDATED_CAN_NOT_BE_A_COLUMN_NAME;
618       }
619
620       return lcResult;
621
622    }
623
624    private boolean expandStarColumns = false;
625    ArrayList<String> expandedStarColumns = new ArrayList<>();
626
627    public ArrayList<String> getColumnsLinkedToStarColumn() {
628        if (expandStarColumns) return expandedStarColumns;
629
630        //TTable sourceTable = this.getSourceTable();
631        if (getSourceTableList().size() > 0){
632            for( int i = 0;i < getSourceTableList().size();i++){
633                for(String c:getSourceTableList().get(i).getExpandedStarColumns()){
634                    expandedStarColumns.add(c);
635                }
636            }
637        }
638
639        expandStarColumns = true;
640        return expandedStarColumns;
641
642    }
643
644    private ArrayList<String> columnsLinkedToStarColumn = new ArrayList<String>();
645
646    private TResultColumnList columnsLinkedToStar;
647
648    public void setColumnsLinkedToStar(TResultColumnList columnsLinkedToStar) {
649        this.columnsLinkedToStar = columnsLinkedToStar;
650        for(TResultColumn rc:columnsLinkedToStar){
651            if (rc.getColumnAlias()!= ""){
652                columnsLinkedToStarColumn.add(rc.getColumnAlias());
653            }else{
654                columnsLinkedToStarColumn.add(rc.getColumnNameOnly());
655            }
656        }
657
658        this.setDbObjectTypeDirectly(EDbObjectType.column);
659    }
660
661    /**
662     * if this is a star column(column name is *), and the value of this star column
663     * is derived from a subquery, then, this field points to the select list in the subquery
664     *
665     * @return the select list in the subquery
666     */
667    public TResultColumnList getColumnsLinkedToStar() {
668        return columnsLinkedToStar;
669    }
670
671    /**
672     * Set the table this column belongs to. Used by parser internally.
673     *
674     * @param sourceTable table contains this column
675     */
676    public void setSourceTable(TTable sourceTable) {
677        this.sourceTable = sourceTable;
678
679        // 如果 column token 的 tokentype 为 ETokenType.ttkeyword, 那么调整为 ETokenType.ttidentifier
680        if ((this.getPartToken() != null)&&(this.getPartToken().tokentype == ETokenType.ttkeyword)){
681            if ((this.getPartToken().getDbObjectType() == EDbObjectType.column)||(this.getPartToken().getDbObjectType() == EDbObjectType.unknown)){
682                this.getPartToken().tokentype = ETokenType.ttidentifier;
683            }
684        }
685        this.setDbObjectTypeDirectly(EDbObjectType.column);
686    }
687
688    public void setSourceTable2(TCustomSqlStatement sqlStatement, TAttributeNode attributeNode, TTable newSourceTable) {
689        // 如果 column token 的 tokentype 为 ETokenType.ttkeyword, 那么调整为 ETokenType.ttidentifier
690        if ((this.getPartToken() != null)&&(this.getPartToken().tokentype == ETokenType.ttkeyword)){
691            if ((this.getPartToken().getDbObjectType() == EDbObjectType.column)||(this.getPartToken().getDbObjectType() == EDbObjectType.unknown)){
692                this.getPartToken().tokentype = ETokenType.ttidentifier;
693            }
694        }
695
696        if ((this.sourceTable != null) && (this.sourceTable.equals(newSourceTable))) return;
697
698        if ((this.getResolveStatus() == TBaseType.RESOLVED_AND_FOUND ) 
699                || (newSourceTable.getTableType() != ETableSource.subquery)){// 关联到 subquery 的 column 本能算真正找到 table,因此还不能去掉 orphan column
700            if (sqlStatement.getOrphanColumns().removeElement(this)){
701                if (TBaseType.DUMP_RESOLVER_LOG_TO_CONSOLE){
702                    TBaseType.log(String.format("Remove orphan column <%s> find in old algorithm",this.toString()),TLog.WARNING,this);
703                }
704                // remove the waring in sql statement's error syntax list
705                TCustomSqlStatement currentStatement = sqlStatement;
706                while (currentStatement != null) {
707                    if (currentStatement.getSyntaxHints() != null) {
708                        for(int i=0; i<currentStatement.getSyntaxHints().size(); i++) {
709                            TSyntaxError syntaxError = currentStatement.getSyntaxHints().get(i);
710                            if (syntaxError.errortype == EErrorType.sphint) {
711                                if ((syntaxError.lineNo == this.getStartToken().lineNo)||(syntaxError.columnNo == this.getStartToken().columnNo)) {
712                                    currentStatement.getSyntaxHints().remove(i);
713                                    if (TBaseType.DUMP_RESOLVER_LOG_TO_CONSOLE){
714                                        TBaseType.log(String.format("Remove orphan column <%s> warning message in old algorithm", this.toString()), TLog.WARNING, this);
715                                    }
716                                    break;
717                                }
718                            }
719                        }
720                    }
721                    currentStatement = currentStatement.getParentStmt();
722                }
723            }
724        }else{
725            TBaseType.log(String.format("Found orphan column <%s> find in old algorithm in subquery %s, but NOT remove it from orphan list",this.toString(),newSourceTable.getAliasName()),TLog.WARNING,this);
726        }
727
728        if (this.sourceTable != null){
729            if (this.sourceTable.getLinkedColumns().removeElement(this)){
730                if (TBaseType.DUMP_RESOLVER_LOG_TO_CONSOLE){
731                    TBaseType.log(String.format("Remove <%s> at addr: %s from table <%s> that found in old algorithm, new linked table is: %s"
732                            ,this.toString(),Integer.toHexString(this.hashCode()),this.sourceTable.toString(),newSourceTable.toString())
733                            ,TLog.WARNING,this);
734                }
735            }
736        }
737        this.sourceTable = newSourceTable;
738        this.sourceTable.getLinkedColumns().addObjectName(this);
739
740        if (this.getSourceColumn() == null){
741           // if (attributeNode.isAttributeCreatedFromAliasColumn()){
742                this.setSourceColumn(attributeNode.getSubLevelResultColumn());
743           // }
744        }
745
746        this.setDbObjectTypeDirectly(EDbObjectType.column);
747    }
748
749    /**
750     * The table this column belongs to. Only valid when this objectName represents a column.
751     * <p>
752     * Please check getTableColumn demo shipped together with this library to find out more information
753     * such as column impact and data lineage of the table and column in the SQL script.
754     *
755     * @return table this column belongs to
756     */
757    public TTable getSourceTable() {
758        return sourceTable;
759    }
760
761    public void setResolveStatus(int resolveStatus) {
762        this.resolveStatus = resolveStatus;
763
764        if (this.resolveStatus == TBaseType.RESOLVED_AND_FOUND){
765            this.setDbObjectTypeDirectly(EDbObjectType.column);
766        }
767
768    }
769
770    private int resolveStatus = TBaseType.NOT_RESOLVED_YET;
771
772    public int getResolveStatus() {
773        return resolveStatus;
774    }
775
776    public void   TObjectName(){
777
778    }
779
780    private TObjectNameList columnAttributes = null;
781
782    private boolean  subscripts;
783    private  TIndirection indirection;
784
785    /**
786     * PostgreSQL column with array types
787     * <pre>
788     *     CREATE TABLE sal_emp (
789     *          name            text,
790     *          pay_by_quarter  integer[],
791     *          schedule        text[][]
792     *     );
793     * </pre>
794     * In the above SQL, this method returns true for <code>pay_by_quarter</code> column.
795     *
796     * @return true if this objectName is array type
797     */
798    public boolean isSubscripts() {
799        return subscripts;
800    }
801
802    public void setIndirection(TIndirection indirection) {
803        if(indirection == null) return;
804
805        this.indirection = indirection;
806        // setup the exceptReplaceClause of the last indirection to the parent object which is set in the .y bnf file
807        if (indirection.getIndices() != null){
808            if (indirection.getIndices().getElement(indirection.getIndices().size()-1).getAttributeName() != null){
809                setExceptReplaceClause(indirection.getIndices().getElement(indirection.getIndices().size()-1).getAttributeName().getExceptReplaceClause());
810
811            }
812        }
813
814        // possible syntax, support in postgresql only in current version:
815        // [ indirection ], list in [] was indirection
816        //
817        // tablename[.column]
818        // tablename[.*]
819        // $1[.somecolumn]
820        //
821        // mytable[.arraycolumn[4]]
822        // mytable[.two_d_column[17][34]]
823        // $1[[10:42]]
824        //
825
826        if (this.getObjectType() == TObjectName.ttobjPositionalParameters){
827            if(indirection.isRealIndices()){
828                //$1[10:42]
829                this.subscripts = true;
830            }else{
831                //$1.somecolumn
832               this.setColumnTokenOfPositionalParameters(indirection.getIndices().getElement(0).getAttributeName().getPartToken());
833            }
834        }else{
835            if(indirection.isRealIndices()){
836                if (indirection.getIndices().size() == 1){
837                    // arraycolumn[4]
838                    this.subscripts = true;
839                }else if (indirection.getIndices().size() >= 2){
840                   if (!indirection.getIndices().getElement(0).isRealIndices()){
841                        // mytable[.arraycolumn[4]]
842                        // mytable[.two_d_column[17][34]]
843                     //  this.setPartTokenOfIndirection(indirection.getIndices().getElement(0).getAttributeName().getPartToken());
844                       this.subscripts = true;
845                     //  this.indirection.getIndices().remove(0);
846                   }
847                }
848            }
849
850            //else{
851                // 首先查找 : 和 [ 分隔符,如果找到,在该分隔符前的是 column,如果没有找到按照一般 qualified name 规则处理
852                // https://docs.snowflake.com/en/user-guide/querying-semistructured.html
853                int elementIndex = -1;
854                for(int i=0;i<indirection.getIndices().size();i++){
855                    TIndices tmp = indirection.getIndices().getElement(i);
856                    if ((tmp.getStartToken().tokencode == ':')||(tmp.getStartToken().tokencode == '[')||(tmp.getStartToken().tokencode == TBaseType.bind_v)){
857                        elementIndex = i;
858                        break;
859                    }
860                }
861                if (elementIndex >= 0){
862                    // 找到了 : 和 [ 分隔符
863                    if (elementIndex == 0){
864                        // snowflake, <column>:<level1_element>
865                        // everything already perfect, nothing need to be changed
866                        partToken.setDbObjectType(EDbObjectType.column);
867                    }else if (elementIndex == 1){
868                        // snowflake, table.column:<level1_element>
869                        objectToken = partToken;
870                        objectToken.setDbObjectType(EDbObjectType.table);
871                        partToken = indirection.getIndices().getElement(elementIndex-1).getAttributeName().getPartToken();
872                        partToken.setDbObjectType(EDbObjectType.column);
873                    }else if (elementIndex == 2){
874                        // snowflake, schema.table.column:<level1_element>
875                        schemaToken = partToken;
876                        schemaToken.setDbObjectType(EDbObjectType.schema);
877                        objectToken = indirection.getIndices().getElement(elementIndex-2).getAttributeName().getPartToken();
878                        objectToken.setDbObjectType(EDbObjectType.table);
879                        partToken = indirection.getIndices().getElement(elementIndex-1).getAttributeName().getPartToken();
880                        partToken.setDbObjectType(EDbObjectType.column);
881                    }
882                }else{
883                    // 一般 qualified name 规则处理
884                    if (indirection.getIndices().size() == 1){
885                        this.setPartTokenOfIndirection(indirection.getIndices().getElement(0).getAttributeName().getPartToken());
886                    }else if (indirection.getIndices().size() == 2){
887                        schemaToken = partToken;
888                        schemaToken.setDbObjType(TObjectName.ttobjSchemaName);
889                        objectToken = indirection.getIndices().getElement(0).getAttributeName().getPartToken();
890                        objectToken.setDbObjType(ttobjTable);
891                        partToken = indirection.getIndices().getElement(1).getAttributeName().getPartToken();
892                        partToken.setDbObjType(ttobjColumn);
893                    }else if (indirection.getIndices().size() == 3){
894                        // db.schema.tablename.column
895                        databaseToken = partToken;
896                        databaseToken.setDbObjectType(EDbObjectType.database);
897                        partToken = indirection.getIndices().getElement(2).getAttributeName().getPartToken();
898                        partToken.setDbObjectType(EDbObjectType.column);
899                        objectToken = indirection.getIndices().getElement(1).getAttributeName().getPartToken();
900                        objectToken.setDbObjectType(EDbObjectType.table);
901                        schemaToken = indirection.getIndices().getElement(0).getAttributeName().getPartToken();
902                        schemaToken.setDbObjectType(EDbObjectType.schema);
903                    }
904                }
905
906//                if (indirection.getIndices().size() == 1){
907//                    if ((indirection.getIndices().getElement(0).getStartToken().tokencode == ':')
908//                        ||(indirection.getIndices().getElement(0).getStartToken().tokencode == TBaseType.bind_v))
909//                    {
910//                        // snowflake, <column>:<level1_element>
911//
912//                    }else{
913//                        // tablename[.column]
914//                        // tablename[.*]
915//                        this.setPartTokenOfIndirection(indirection.getIndices().getElement(0).getAttributeName().getPartToken());
916//                    }
917//                }else if (indirection.getIndices().size() == 2){
918//                    if ((indirection.getIndices().getElement(0).getStartToken().tokencode == ':')
919//                            ||(indirection.getIndices().getElement(0).getStartToken().tokencode == TBaseType.bind_v))
920//                    {
921//                        // snowflake, <column>:<level1_element>
922//
923//                    }else {
924//                        // schema.tablename.column
925//                        schemaToken = partToken;
926//                        schemaToken.setDbObjType(TObjectName.ttobjSchemaName);
927//                        objectToken = indirection.getIndices().getElement(0).getAttributeName().getPartToken();
928//                        objectToken.setDbObjType(ttobjTable);
929//                        partToken = indirection.getIndices().getElement(1).getAttributeName().getPartToken();
930//                        partToken.setDbObjType(ttobjColumn);
931//                    }
932//                }else if (indirection.getIndices().size() == 3){
933//                    // db.schema.tablename.column
934//                    databaseToken = partToken;
935//                    databaseToken.setDbObjectType(EDbObjectType.database);
936//                    partToken = indirection.getIndices().getElement(2).getAttributeName().getPartToken();
937//                    partToken.setDbObjectType(EDbObjectType.column);
938//                    objectToken = indirection.getIndices().getElement(1).getAttributeName().getPartToken();
939//                    objectToken.setDbObjectType(EDbObjectType.table);
940//                    schemaToken = indirection.getIndices().getElement(0).getAttributeName().getPartToken();
941//                    schemaToken.setDbObjectType(EDbObjectType.schema);
942//                }
943
944          //  }
945
946        }
947
948    }
949
950    /**
951     * Array element of this objectName
952     * <pre>
953     *     select arraycolumn[4] from t;
954     * </pre>
955     * In the above SQL, this method returns <code>[4]</code> of this objectName.
956     *
957     * @return array element of this objectName
958     * @see gudusoft.gsqlparser.nodes.TIndirection
959     */
960    public TIndirection getIndirection() {
961        return indirection;
962    }
963
964    private void setPartTokenOfIndirection(TSourceToken column){
965        parseTablename();
966        this.partToken = column;
967        this.partToken.setDbObjType(ttobjColumn);
968    }
969
970    public void setPropertyToken(TSourceToken propertyToken) {
971        this.propertyToken = propertyToken;
972    }
973
974    public TSourceToken getAtsign() {
975        return atsign;
976    }
977
978    public TSourceToken getMethodToken() {
979
980        return methodToken;
981    }
982
983    public TSourceToken getPropertyToken() {
984        return propertyToken;
985    }
986
987    /**
988     *  The server part of this objectName: [server.][database.][schema.]object
989     *
990     * @return server part of the objectName
991     */
992    public TSourceToken getServerToken() {
993        return serverToken;
994    }
995
996    public TSourceToken getExclamationmark() {
997
998        return exclamationmark;
999    }
1000
1001    /**
1002     *
1003     * The database link part <code>remoreserver</code> in this objectName: scott.emp@remoreserver
1004     *
1005     * @return database link
1006     */
1007    public TObjectName getDblink() {
1008
1009        return dblink;
1010    }
1011
1012    /**
1013     *  The database part of this objectName: [server.][database.][schema.]object
1014     *
1015     * @return database part of the objectName
1016     */
1017    public TSourceToken getDatabaseToken() {
1018        return databaseToken;
1019    }
1020
1021
1022    private boolean tableDetermined = true;
1023
1024    public void setTableDetermined(boolean tableDetermined) {
1025        this.tableDetermined = tableDetermined;
1026    }
1027
1028
1029    /**
1030     * Sometime, a non-qualified column can't be linked to a table without additional metadata from database.
1031     * <pre>
1032     *     select name from emp, dept
1033     * </pre>
1034     * In the above SQL, the <code>name</code> column can't be determined which table it belongs to.
1035     *
1036     * Below is a more complicated SQL that shows the relationship between column and table.
1037     * <pre>
1038     *   select
1039     *          s2.s2t1a1,
1040     *          s3.s3t1a1
1041     *   from
1042     *       (
1043     *         select *
1044     *           from subselect2table1 s2t1
1045     *       ) s2,
1046     *       (
1047     *          select *
1048     *             from  subselect3table1, subselect3table2
1049     *       ) s3
1050     * </pre>
1051     *
1052     * column s2t1a1 was linked to subselect2table1, {@link #isTableDetermined()} returns true for this column.
1053     * <br> column s3t1a1 was linked to both subselect3table1 and subselect3table2
1054     * due to lack of meta information from database, {@link #isTableDetermined()} returns false for this column.
1055     * <p>
1056     * Provide database metadata will help GSP links the column to the table correctly.
1057     *
1058     * @return true if this column can be linked to a table without doubt.
1059     * @see gudusoft.gsqlparser.TGSqlParser#setMetaDatabase
1060     */
1061    public boolean isTableDetermined() {
1062        return tableDetermined;
1063    }
1064
1065    /**
1066     * used in Oracle and teradata SQL syntax
1067     * <p>teradata:
1068     * <p>column.attribute()
1069     * <p>column.attribute().attribute() 
1070     * @param attributes
1071     */
1072    public void attributesToPropertyToken(TObjectNameList attributes){
1073        if (attributes.size() == 1){
1074            this.propertyToken = attributes.getObjectName(0).getPartToken();
1075        }
1076    }
1077
1078    public void setColumnAttributes(TObjectNameList columnAttributes) {
1079        this.columnAttributes = columnAttributes;
1080    }
1081
1082    /**
1083     * The data type of this column is structured UDT, this method returns the column's attributes.
1084     * Below is the sample SQL from <a href="https://info.teradata.com/HTMLPubs/DB_TTU_16_00/index.html#page/SQL_Reference/B035-1146-160K/fyj1472240813334.html">teradata</a>.
1085     * <pre>
1086     *
1087     *          CREATE TYPE school_record AS (
1088     *           school_name VARCHAR(20),
1089     *           GPA         FLOAT);
1090     *
1091     *          CREATE TYPE college_record AS (
1092     *           school school_record,
1093     *           major  VARCHAR(20),
1094     *           minor  VARCHAR(20));
1095     *
1096     *          CREATE TABLE student_record (
1097     *           student_id  INTEGER,
1098     *           Last_name   VARCHAR(20),
1099     *           First_name  VARCHAR(20),
1100     *           high_school school_record,
1101     *           college     college_record);
1102     *
1103     *          SELECT student_id, last_name, first_name,
1104     *           high_school.school_name(), high_school.GPA(),
1105     *           college.school().school_name(), college.school().GPA(),
1106     *           college.major(), college.minor()
1107     *          FROM student_record;
1108     *
1109     *          SELECT *.ALL FROM student_record;
1110     *          SELECT student_record.*.ALL;
1111     * </pre>
1112     * Take this column <code>college.school().school_name()</code> for example, the partToken of this objectName
1113     * should be <code>college</code>, and the value returned by this method should be
1114     * <code>school().school_name()</code>
1115     * <p>
1116     * PLEASE NOTE THAT CURRENT VERSION CAN'T HANDLE THE ABOVE SQL CORRECTLY.
1117     *
1118     * @return attributes of this structured UDT column
1119     */
1120    public TObjectNameList getColumnAttributes() {
1121        return columnAttributes;
1122    }
1123
1124    /**
1125     * Used internally.
1126     * @deprecated use {@link #setDbObjectType} instead
1127     *
1128     * @param objectType object type of this objectName
1129     */
1130    public void setObjectType(int objectType) {
1131        if (this.objectType == objectType) return;
1132        this.objectType = objectType;
1133        // set this object type to source token
1134        switch(this.getObjectType()){
1135            case TObjectName.ttobjTable:
1136           // case TObjectName.ttobjTableTemp:
1137            //    case TObjectName.ttobjTableVar:
1138                this.parseTablename();
1139                this.objectToken.setDbObjType(this.objectType);
1140                if (dbObjectType != EDbObjectType.stage){ // not already set to stage
1141                    dbObjectType = EDbObjectType.table;
1142                }
1143
1144                if ((!TSQLEnv.supportSchema(this.dbvendor))&&(this.schemaToken != null)){
1145                    this.databaseToken = this.schemaToken;
1146                    this.schemaToken = null;
1147                }
1148                break;
1149//            case TObjectName.ttobjTableCTE:
1150//                this.parseTablename();
1151//                this.objectToken.setDbObjType(this.objectType);
1152//                dbObjectType = EDbObjectType.cte;
1153//                break;
1154//            case ttObjLibrary:
1155//                this.parseTablename();
1156//                this.objectToken.setDbObjType(this.objectType);
1157//                dbObjectType = EDbObjectType.library;
1158//                break;
1159            case TObjectName.ttobjColumn:
1160                this.partToken.setDbObjType(this.objectType);
1161                dbObjectType = EDbObjectType.column;
1162                break;
1163            case TObjectName.ttobjColumnAlias:
1164                if ((this.objectToken == null) && (this.partToken != null)){
1165                   this.parseObjectName();
1166                }
1167                this.objectToken.setDbObjType(this.objectType);
1168                dbObjectType = EDbObjectType.column_alias;
1169                break;
1170//            case TObjectName.ttObjTableAlias:
1171//                this.parseObjectName();
1172//                this.objectToken.setDbObjType(this.objectType);
1173//                dbObjectType = EDbObjectType.table_alias;
1174//                break;
1175            case TObjectName.ttobjParameter:
1176                this.parseObjectName();
1177                this.objectToken.setDbObjType(this.objectType);
1178                dbObjectType = EDbObjectType.parameter;
1179                break;
1180            case TObjectName.ttobjVariable:
1181                this.parseVariableName();
1182                this.objectToken.setDbObjType(this.objectType);
1183                dbObjectType = EDbObjectType.variable;
1184                break;
1185            case TObjectName.ttobjColumnMethod:
1186                if (dbObjectType != EDbObjectType.method){
1187                    this.parseColumnMethodName();
1188                    this.partToken.setDbObjType(this.ttobjColumn);
1189                    this.methodToken.setDbObjType(this.ttobjColumnMethod);
1190                    dbObjectType = EDbObjectType.method;
1191                }
1192                break;
1193//            case TObjectName.ttobjProcedureName:
1194//                this.parseFunctionName();
1195//                this.objectToken.setDbObjType(this.objectType);
1196//                dbObjectType = EDbObjectType.procedure;
1197//                break;
1198            case TObjectName.ttobjFunctionName:
1199                this.parseFunctionName();
1200                this.objectToken.setDbObjType(this.objectType);
1201                dbObjectType = EDbObjectType.function;
1202                break;
1203//            case TObjectName.ttobjLabelName:
1204//                this.parseObjectName();
1205//                this.objectToken.setDbObjType(this.objectType);
1206//                dbObjectType = EDbObjectType.label;
1207//                break;
1208//            case TObjectName.ttobjIndexName:
1209//                this.parseObjectName();
1210//                this.objectToken.setDbObjType(this.objectType);
1211//                dbObjectType = EDbObjectType.index;
1212//                break;
1213//            case TObjectName.ttobjMaterializedViewName:
1214//                this.parseObjectName();
1215//                this.objectToken.setDbObjType(this.objectType);
1216//                dbObjectType = EDbObjectType.materializedView;
1217//                break;
1218//            case TObjectName.ttobjViewName:
1219//                this.parseObjectName();
1220//                this.objectToken.setDbObjType(this.objectType);
1221//                dbObjectType = EDbObjectType.view;
1222//                break;
1223//            case TObjectName.ttobjCursorName:
1224//                this.parseObjectName();
1225//                this.objectToken.setDbObjType(this.objectType);
1226//                dbObjectType = EDbObjectType.cursor;
1227//                break;
1228            case TObjectName.ttobjConstraintName:
1229                this.parseObjectName();
1230                this.objectToken.setDbObjType(this.objectType);
1231                dbObjectType = EDbObjectType.constraint;
1232                break;
1233//            case TObjectName.ttobjPropertyName:
1234//                this.propertyToken.setDbObjType(this.objectType);
1235//                dbObjectType = EDbObjectType.property;
1236//                break;
1237//            case TObjectName.ttobjTransactionName:
1238//                this.parseObjectName();
1239//                this.objectToken.setDbObjType(this.objectType);
1240//                dbObjectType = EDbObjectType.transaction;
1241//                break;
1242//            case TObjectName.ttobjDatabaseName:
1243//                this.parseObjectName();
1244//                this.objectToken.setDbObjType(this.objectType);
1245//                dbObjectType = EDbObjectType.database;
1246//                break;
1247            case TObjectName.ttobjStringConstant:
1248                this.parseObjectName();
1249                this.objectToken.setDbObjType(this.objectType);
1250                break;
1251//            case TObjectName.ttobjAliasName:
1252//                this.parseObjectName();
1253//                this.objectToken.setDbObjType(this.objectType);
1254//                dbObjectType = EDbObjectType.alias;
1255//                break;
1256            case TObjectName.ttobjAttribute:
1257                this.partToken.setDbObjType(this.objectType);
1258                dbObjectType = EDbObjectType.attribute;
1259                break;
1260//           case TObjectName.ttobjTypeName:
1261//               this.parseObjectName();
1262//               this.objectToken.setDbObjType(this.objectType);
1263//               dbObjectType = EDbObjectType.user_defined_type;
1264//               break;
1265//            case TObjectName.ttobjPackage:
1266//                this.parseObjectName();
1267//                this.objectToken.setDbObjType(this.objectType);
1268//                dbObjectType = EDbObjectType.plsql_package;
1269//                break;
1270//            case TObjectName.ttobjSequence:
1271//                this.parseObjectName();
1272//                this.objectToken.setDbObjType(this.objectType);
1273//                dbObjectType = EDbObjectType.sequence;
1274//                break;
1275//            case TObjectName.ttobjTrigger:
1276//                this.parseObjectName();
1277//                this.objectToken.setDbObjType(this.objectType);
1278//                dbObjectType = EDbObjectType.trigger;
1279//                break;
1280            default:
1281                break;
1282        }
1283    }
1284
1285    public void setDbObjectType(EDbVendor dbVendor, EDbObjectType dbObjectType) {
1286        this.dbvendor = dbVendor;
1287        this.setDbObjectType(dbObjectType);
1288    }
1289
1290    public void setDbObjectTypeDirectly(EDbObjectType dbObjectType) {
1291        this.dbObjectType = dbObjectType;
1292    }
1293    /**
1294     * Set object type of this objectName
1295     *
1296     * @param dbObjectType database object type
1297     */
1298    public void setDbObjectType(EDbObjectType dbObjectType) {
1299        if (this.dbObjectType == dbObjectType) return;
1300        if (this.dbObjectType == EDbObjectType.stage) return;
1301        // TODO, 如果已经被设定为某个对象类型,不应该再次设置,但如果下面的语句执行,会导致部分测试用例失败,需要查具体原因
1302        // if (this.dbObjectType != EDbObjectType.unknown) return;
1303
1304        EDbObjectType prev = this.dbObjectType;
1305        this.dbObjectType = dbObjectType;
1306        if (prev == EDbObjectType.unknown){
1307            switch (dbObjectType){
1308                case column:
1309                    parseColumnName();
1310                    break;
1311                case table:
1312                case index:
1313                case synonym:
1314                case macro:
1315                case view:
1316                case stage:
1317                case task:
1318                case stream:
1319                case TEMP_TABLE:
1320                case pipe:
1321                case security_policy:
1322
1323                case plsql_package:
1324                case trigger:
1325                case transaction:
1326                case user_defined_type:
1327                case property:
1328                case cursor:
1329                case label:
1330                case table_alias:
1331                case partitionScheme:
1332                    parseTablename();
1333                    break;
1334                case library:
1335                    parseTablename();
1336                    break;
1337                case function:
1338                    parseFunctionName();
1339                    break;
1340                case procedure:
1341                case materializedView:
1342                    parseFunctionName();
1343                    break;
1344                case alias:
1345                case module:
1346                case sequence:
1347                    parseTablename();
1348                    break;
1349                case database:
1350                    this.objectToken = this.partToken;
1351                    this.databaseToken = null;
1352                    this.partToken = null;
1353                    break;
1354                case variable:
1355                    parseVariableName();
1356                    break;
1357                case schema:
1358                    this.databaseToken = this.objectToken;
1359                    this.objectToken = this.partToken;
1360                    this.schemaToken = this.partToken;
1361                    break;
1362                case method:
1363                    this.parseColumnMethodName();
1364                    this.partToken.setDbObjType(this.ttobjColumn);
1365                    //this.methodToken.setDbObjType(this.ttobjColumnMethod);
1366                    this.methodToken.setDbObjectType(EDbObjectType.method);
1367                    break;
1368                case cte:
1369                    parseObjectName();
1370                    break;
1371                default:
1372                    break;
1373            }
1374        }
1375    }
1376
1377    private EDbObjectType dbObjectType = EDbObjectType.unknown;
1378
1379    /**
1380     * The database object type of this objectName such as table, view, column for example.
1381     * If object type is {@link gudusoft.gsqlparser.EDbObjectType#column}, {@link #getPartToken} represents
1382     * the column name, for all other object type, the name of this database object is stored in {@link #getObjectToken}
1383     *
1384     * @return database object type
1385     */
1386    public EDbObjectType getDbObjectType() {
1387        return dbObjectType;
1388    }
1389
1390    /**
1391     * @deprecated use {@link #getDbObjectType()} instead.
1392     *
1393     * @return the type of database object or variable this objectName represents for.
1394     */
1395    public int getObjectType() {
1396
1397        return objectType;
1398    }
1399
1400
1401    public void setAtsign(TSourceToken atsign) {
1402        this.atsign = atsign;
1403    }
1404
1405    public void setDblink(TObjectName dblink) {
1406        dblink.setDbObjectType(EDbObjectType.dblink);
1407        this.dblink = dblink;
1408    }
1409
1410    public void setDblink(TObjectName dblink, boolean linkToDB) {
1411        setDblink(dblink);
1412
1413        if (linkToDB){
1414            if (dblink.numberOfPart == 1){
1415                this.databaseToken = dblink.getPartToken();
1416            }
1417        }
1418    }
1419
1420    private TSourceToken serverToken = null; //sql server
1421    private TSourceToken databaseToken = null; //sql server
1422    // schemaToken.objectToken.partToken@dblink, schemaToken, partToken, and dblink is optional
1423    private TSourceToken schemaToken;
1424    private TSourceToken objectToken;
1425
1426    /*
1427     * part is a part of the object. This identifier lets you refer to a part of a schema object,
1428     * such as a column or a partition of a table. Not all types of objects have parts.
1429     */
1430    private TSourceToken partToken;
1431    private TSourceToken propertyToken = null;
1432    private TSourceToken methodToken = null;
1433    private TSourceToken atsign; //@
1434    private TObjectName dblink;
1435
1436    public void setServerToken(TSourceToken serverToken) {
1437        this.serverToken = serverToken;
1438    }
1439
1440    public void setDatabaseToken(TSourceToken databaseToken, boolean implicit) {
1441        this.isImplicitDatabase = implicit;
1442        setDatabaseToken(databaseToken);
1443    }
1444
1445    public void setDatabaseToken(TSourceToken databaseToken) {
1446        this.databaseToken = databaseToken;
1447    }
1448
1449    public void setObjectToken(TSourceToken objectToken) {
1450        this.objectToken = objectToken;
1451    }
1452
1453    public void setPartToken(TSourceToken partToken) {
1454        this.partToken = partToken;
1455    }
1456
1457    public void setMethodToken(TSourceToken methodToken) {
1458        this.methodToken = methodToken;
1459    }
1460
1461    public void setSchemaToken(TSourceToken schemaToken, boolean implicit) {
1462        this.isImplicitSchema = implicit;
1463        setSchemaToken(schemaToken);
1464    }
1465
1466    public void setSchemaToken(TSourceToken schemaToken) {
1467
1468        this.schemaToken = schemaToken;
1469    }
1470
1471    public void setPackageToken(TSourceToken packageToken) {
1472        this.packageToken = packageToken;
1473    }
1474
1475    /**
1476     * Oracle package name
1477     *
1478     * @return the source token of Oracle package name.
1479     */
1480    public TSourceToken getPackageToken() {
1481        return packageToken;
1482    }
1483
1484    private TSourceToken packageToken = null;
1485
1486
1487    /**
1488     * The object part of this objectName such as table name, view name.
1489     *
1490     * @return object part of this objectName
1491     */
1492    public TSourceToken getObjectToken() {
1493        return objectToken;
1494    }
1495
1496    /**
1497     * The column name of this objectName if {@link #getDbObjectType} is {@link EDbObjectType#column}.
1498     * {@link #getColumnToken} returns the same value.
1499     *
1500     * @return the column name
1501     */
1502    public TSourceToken getPartToken() {
1503        return partToken;
1504    }
1505
1506    /**
1507     * The schema name of this objectName.
1508     *
1509     * @return schema name
1510     */
1511    public TSourceToken getSchemaToken() {
1512        return schemaToken;
1513    }
1514
1515
1516    private String schemaString;
1517    private String objectString;
1518    private String partString;
1519
1520    /**
1521     * String text of the package name.
1522     *
1523     * @return string of the package name,return null if empty.
1524     */
1525    public String getPackageString(){
1526        if (getPackageToken() != null) return  getPackageToken().toString();
1527        else return "";
1528    }
1529
1530    /**
1531     * String text of the server name
1532     *
1533     * @return string of the server name,return null if empty.
1534     */
1535    public String getServerString(){
1536        if (getServerToken() != null) return  getServerToken().toString();
1537        else return "";
1538    }
1539
1540    /**
1541     * String text of the database name
1542     *
1543     * @return string of the database name,return null if empty.
1544     */
1545    public String getDatabaseString(){
1546        if (isImplicitDatabase ) return "";
1547        else if (getDatabaseToken() != null) return getDatabaseToken().toString();
1548        else if ((this.dbObjectType == EDbObjectType.database) && (getObjectToken() != null)){
1549            return getObjectToken().toString();
1550        }
1551        else return "";
1552    }
1553
1554    /**
1555     * String text of schema name in a qualified name of a schema object.
1556     *
1557     *
1558     * @return string of schema name, return null if empty.
1559     */
1560    public String getSchemaString() {
1561        if (isImplicitSchema) return "";
1562        else if (schemaToken != null)
1563            return schemaToken.astext;
1564        else
1565            return "" ;
1566    }
1567
1568    private TSQLEnv sqlEnv = null;
1569
1570    public void setSqlEnv(TSQLEnv sqlEnv) {
1571        this.sqlEnv = sqlEnv;
1572    }
1573
1574
1575
1576    /**
1577     * This is the schema fetched from the SQLEnv. Not the direct qualified schema name of this object
1578     * search this table in the current default database and schema.
1579     *
1580     * If this is a qualified schema object, then return {@link #getSchemaString()}
1581     *
1582     * This method is only valid when the {@link #dbObjectType} is a schema object.
1583     *
1584     * @return schema name fetched from the SQLEnv
1585     */
1586    public String getImplictSchemaString() {
1587        String implictSchema = null;
1588        if (this.implictSchemaName != null) return this.implictSchemaName;
1589
1590        if (schemaToken != null) return schemaToken.toString();
1591        if (getSchemaString().length() > 0) return  getSchemaString();
1592
1593        if (sqlEnv == null) return null;
1594
1595        TSQLSchema s = searchImplicitSchema();
1596        if (s != null){
1597            implictSchema = s.getName();
1598        }
1599
1600        return implictSchema;
1601    }
1602
1603    private String implictDatabaseName;
1604    private String implictSchemaName;
1605
1606    public void setImplictDatabaseName(String implictDatabaseName) {
1607        this.isImplicitDatabase = true;
1608        this.implictDatabaseName = implictDatabaseName;
1609    }
1610
1611    public void setImplictSchemaName(String implictSchemaName) {
1612        this.isImplicitSchema = true;
1613        this.implictSchemaName = implictSchemaName;
1614    }
1615
1616    public String getImplictDatabaseString() {
1617        String implictDatabase = null;
1618        if (implictDatabaseName != null) return implictDatabaseName;
1619
1620        if (getDatabaseString().length() > 0) return  getDatabaseString();
1621
1622        if (sqlEnv == null) return null;
1623        TSQLSchema s = searchImplicitSchema();
1624        if (s != null){
1625            TSQLCatalog c = s.getCatalog();
1626            if (c != null){
1627                implictDatabase = c.getName();
1628            }
1629        }
1630
1631        return implictDatabase;
1632    }
1633
1634    protected TSQLSchema searchImplicitSchema(){
1635        TSQLSchema s = null;
1636        if (sqlEnv == null) return null;
1637        switch (dbObjectType){
1638            case table:
1639            case view:
1640                TSQLTable t = sqlEnv.searchTable(".."+this.getObjectString());
1641                if (t != null){
1642                    s = t.getSchema();
1643                }
1644
1645                break;
1646            case function:
1647            case procedure:
1648                TSQLFunction f = sqlEnv.searchFunction(".."+this.getObjectString());
1649                if (f != null){
1650                    s = f.getSchema();
1651                }
1652                break;
1653            default:
1654                break;
1655        }
1656
1657        return s;
1658    }
1659
1660    /**
1661     * The table name of this objectName, it's the same value as {@link #getObjectToken} if {@link #getDbObjectType}
1662     * is {@link gudusoft.gsqlparser.EDbObjectType#table}
1663     *
1664     * @return table name
1665     */
1666    public  TSourceToken getTableToken(){
1667        if (objectToken == null) return  null;
1668        else return objectToken;
1669    }
1670
1671    /**
1672     * String text of the table name
1673     *
1674     * @return string of the table name, return null if empty.
1675     */
1676    public String getTableString(){
1677        if (objectToken == null) return  "";
1678//        else if (!((dbObjectType == EDbObjectType.table)||(dbObjectType == EDbObjectType.view))){
1679//            return "";
1680//        }
1681        else return objectToken.toString();
1682    }
1683
1684    /**
1685     * String text of the object name
1686     *
1687     * @return string of the object name, return null if empty.
1688     */
1689    public String getObjectString() {
1690        if (objectToken != null)
1691            return objectToken.astext;
1692        else
1693            return "" ;
1694    }
1695
1696    /**
1697     * String text of the part name
1698     *
1699     * @return string of the part name, return null if empty.
1700     */
1701    public String getPartString() {
1702        if (partToken != null)
1703            return partToken.astext;
1704        else
1705            return "" ;
1706    }
1707
1708
1709    public void setExclamationmark(TSourceToken exclamationmark) {
1710        this.exclamationmark = exclamationmark;
1711    }
1712
1713    private TSourceToken exclamationmark; // objectToken@!, ! is dblink
1714
1715    private Boolean isParsed = false;
1716
1717    private void parseObjectName(){
1718        parseTablename();
1719    }
1720
1721   private void parseTablename(){
1722       if ((this.dbObjectType == EDbObjectType.variable) ||(this.dbObjectType == EDbObjectType.stage))return;
1723
1724       switch (this.dbvendor){
1725           case dbvteradata:
1726           case dbvhive:
1727               if (objectToken != null){
1728                   databaseToken = objectToken;
1729                   //databaseToken.setDbObjType(TObjectName.ttobjDatabaseName);
1730                   databaseToken.setDbObjectType(EDbObjectType.database);
1731               }
1732               objectToken = partToken;
1733               partToken = null;
1734
1735               break;
1736           default:
1737               if (databaseToken != null){
1738                   serverToken = databaseToken;
1739                   //serverToken.setDbObjType(TObjectName.ttobjServerName);
1740                   serverToken.setDbObjectType(EDbObjectType.server);
1741               }
1742
1743               if (schemaToken != null){
1744                   databaseToken = schemaToken;
1745                   //databaseToken.setDbObjType(TObjectName.ttobjDatabaseName);
1746                   databaseToken.setDbObjectType(EDbObjectType.database);
1747               }
1748
1749               if (objectToken != null){
1750                   schemaToken = objectToken;
1751                   schemaToken.setDbObjType(TObjectName.ttobjSchemaName);
1752               }
1753
1754               objectToken = partToken;
1755               partToken = null;
1756               break;
1757       }
1758
1759       if (objectToken != null){
1760           objectToken.setDbObjectType(this.dbObjectType);
1761       }
1762    }
1763
1764    private void parseVariableName(){
1765        if (databaseToken != null){
1766            serverToken = databaseToken;
1767            //serverToken.setDbObjType(TObjectName.ttobjServerName);
1768            serverToken.setDbObjectType(EDbObjectType.server);
1769        }
1770
1771        if (schemaToken != null){
1772            databaseToken = schemaToken;
1773           // databaseToken.setDbObjType(TObjectName.ttobjDatabaseName);
1774            databaseToken.setDbObjectType(EDbObjectType.database);
1775        }
1776
1777        if (objectToken != null){
1778            if (partToken != null){
1779                schemaToken = objectToken;
1780                schemaToken.setDbObjType(TObjectName.ttobjSchemaName);
1781                objectToken = partToken;
1782                partToken = null;
1783            }else{
1784
1785            }
1786        }else{
1787            objectToken = partToken;
1788            partToken = null;
1789        }
1790    }
1791
1792    private String ansiSchemaName;
1793    private String ansiCatalogName;
1794
1795
1796    /**
1797     *  In this SQL: select * from part1.part2,
1798     *  In Hive, MySQL and Teradata, part1 will be treated as a database name, returned in getDatabaseString(),
1799     *  while getSchemaString() return empty string.
1800     *
1801     *  However, TObjectName.getAnsiSchemaName() will return part1, which means it's a schema name.
1802     *
1803     *  If a table name is not qualified with a schema name, but GSP detect the schema for this table in the metadata
1804     *  then, this method will return this detected schema name.
1805     *
1806     * @return schema name
1807     */
1808    public String getAnsiSchemaName(){
1809        String ret = this.getSchemaString();
1810        if ((ret.length() == 0) && ((this.getImplictSchemaString() != null) && (!this.getImplictSchemaString().equalsIgnoreCase("default")))){
1811            ret = this.getImplictSchemaString();
1812        }
1813
1814        switch (dbvendor){
1815            case dbvmysql:
1816            case dbvhive:
1817            case dbvteradata:
1818                ret = this.getDatabaseString();
1819                break;
1820        }
1821        return ret;
1822    }
1823
1824    /**
1825     *   If a table name is not qualified with a database name, but GSP detect the database  for this table in the metadata
1826     *   then, this method will return this detected database name.
1827     *
1828     * @return
1829     */
1830    public String getAnsiCatalogName(){
1831        String ret = this.getDatabaseString();
1832        if (( ret.length() == 0) && (this.getImplictDatabaseString() != null) && (!this.getImplictDatabaseString().equalsIgnoreCase("default"))){
1833            ret = this.getImplictDatabaseString();
1834        }
1835
1836        switch (dbvendor){
1837            case dbvmysql:
1838            case dbvhive:
1839            case dbvteradata:
1840                ret = "";
1841                break;
1842        }
1843
1844        return  ret;
1845    }
1846
1847    private void parseFunctionName(){
1848        this.parseTablename();
1849     }
1850
1851    private void parseColumnMethodName(){
1852       // objectType = ttobjColumnMethod;
1853
1854        methodToken = objectToken;
1855        partToken = schemaToken;
1856
1857        objectToken = null;//;
1858        schemaToken = null;
1859     }
1860
1861    private void parseColumnName(){
1862        assert(partToken != null);
1863     }
1864
1865    public TObjectName(){
1866    }
1867
1868    /**
1869     *  List the number of parts made up this objectName
1870     *
1871     * @return the number of parts that made up this objectName
1872     */
1873    public int getNumberOfPart() {
1874        return numberOfPart;
1875    }
1876
1877    private int numberOfPart = 1;
1878
1879    public static TObjectName createObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType){
1880        return new TObjectName(dbVendor,dbObjectType);
1881    }
1882
1883
1884    public static TObjectName createObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token1){
1885        return new TObjectName(dbVendor,dbObjectType,token1);
1886    }
1887
1888    public static TObjectName createObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType, String str) {
1889        String[] parts = str.split("\\.");
1890        if (parts.length == 1) {
1891            return new TObjectName(dbVendor, dbObjectType, new TSourceToken(parts[0]));
1892        } else if (parts.length == 2) {
1893            return new TObjectName(dbVendor, dbObjectType, new TSourceToken(parts[0]), new TSourceToken(parts[1]));
1894        } else if (parts.length == 3) {
1895            return new TObjectName(dbVendor, dbObjectType, new TSourceToken(parts[0]), new TSourceToken(parts[1]), new TSourceToken(parts[2]));
1896        } else if (parts.length == 4) {
1897            return new TObjectName(dbVendor, dbObjectType, new TSourceToken(parts[0]), new TSourceToken(parts[1]), new TSourceToken(parts[2]), new TSourceToken(parts[3]));
1898        }
1899        return new TObjectName(dbVendor, dbObjectType, new TSourceToken(str));
1900    }
1901
1902
1903    public static TObjectName createObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token1,TSourceToken token2){
1904        return new TObjectName(dbVendor,dbObjectType,token1,token2);
1905    }
1906
1907    public static TObjectName createObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token1,TSourceToken token2,TSourceToken token3){
1908        return new TObjectName(dbVendor,dbObjectType,token1,token2,token3);
1909    }
1910
1911    public static TObjectName createObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token1,TSourceToken token2,TSourceToken token3,TSourceToken token4){
1912        return new TObjectName(dbVendor,dbObjectType,token1,token2,token3,token4);
1913    }
1914
1915    /**
1916     * @deprecated As of v2.0.7.1, please use {@link #TObjectName(EDbObjectType, TSourceToken)} instead.
1917     *
1918     * Class constructor specifying object name and object type.
1919     * <p>
1920     * Use {@link gudusoft.gsqlparser.TGSqlParser#parseObjectName} to create an objectName more than 2 parts.
1921     *
1922     * @param token           name of this object
1923     * @param dbObjectType   type of this object
1924     */
1925    private TObjectName(TSourceToken token,EDbObjectType dbObjectType){
1926        this(dbObjectType,token);
1927    }
1928
1929    public void splitNameInQuotedIdentifier(){
1930        if (this.dbvendor != EDbVendor.dbvbigquery) return;
1931        if (getQuoteType() == EQuoteType.notQuoted) return;
1932//        if ((this.dbvendor != EDbVendor.dbvbigquery)
1933//                &&(getQuoteType() == EQuoteType.doubleQuote)) return;
1934        if (this.objectToken == null) return;
1935        TSourceToken token = this.objectToken;
1936
1937        String s = TBaseType.getTextWithoutQuoted(token.toString());
1938        String[] a = s.split("[.]");
1939        if (a.length == 1){
1940            // this.objectToken = token;
1941        }else if (a.length == 2){
1942            this.objectToken = new TSourceToken(token.toString().charAt(0)+a[1]+token.toString().charAt(0));
1943            this.schemaToken = new TSourceToken(token.toString().charAt(0)+a[0]+token.toString().charAt(0));
1944        }else if (a.length == 3){
1945            this.objectToken = new TSourceToken(token.toString().charAt(0)+a[2]+token.toString().charAt(0));
1946            this.schemaToken = new TSourceToken(token.toString().charAt(0)+a[1]+token.toString().charAt(0));
1947            this.databaseToken = new TSourceToken(token.toString().charAt(0)+a[0]+token.toString().charAt(0));
1948        }
1949
1950    }
1951
1952    private TObjectName(EDbVendor dbVendor){
1953        this.dbvendor = dbVendor;
1954    }
1955
1956    private TObjectName(EDbVendor dbVendor,EDbObjectType dbObjectType){
1957        this.dbvendor = dbVendor;
1958        this.dbObjectType = dbObjectType;
1959    }
1960
1961    private TObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token){
1962        this.dbvendor = dbVendor;
1963        numberOfPart = 1;
1964        this.setStartToken(token);
1965        this.setEndToken(token);
1966
1967        this.dbObjectType = dbObjectType;
1968        switch (dbObjectType){
1969            case column:
1970                this.partToken = token;
1971                break;
1972            case method:
1973                this.methodToken = token;
1974                break;
1975            case table:
1976            case function:
1977            case procedure:
1978            case materializedView:
1979            case alias:
1980            case module:
1981            case sequence:
1982            case collation:
1983                this.objectToken = token;
1984                splitNameInQuotedIdentifier();
1985                break;
1986            default:
1987                this.objectToken = token;
1988                break;
1989        }
1990    }
1991
1992    private void initWithOneToken(EDbObjectType dbObjectType,TSourceToken token){
1993        numberOfPart = 1;
1994        this.setStartToken(token);
1995        this.setEndToken(token);
1996
1997        this.dbObjectType = dbObjectType;
1998        switch (dbObjectType){
1999            case column:
2000                this.partToken = token;
2001                break;
2002            case method:
2003                this.methodToken = token;
2004                break;
2005            case table:
2006            case function:
2007            case procedure:
2008            case materializedView:
2009            case alias:
2010            case module:
2011            case sequence:
2012            case collation:
2013            case stage:
2014                this.objectToken = token;
2015                splitNameInQuotedIdentifier();
2016                break;
2017            case namespace:
2018                this.schemaToken = token;
2019                break;
2020            default:
2021                this.objectToken = token;
2022                break;
2023        }
2024    }
2025
2026    private void initWithTwoTokens(EDbObjectType dbObjectType,TSourceToken token2,TSourceToken token1){
2027        initWithOneToken(dbObjectType,token1);
2028        numberOfPart = 2;
2029        this.setStartToken(token2);
2030        this.setEndToken(token1);
2031
2032        switch (dbObjectType){
2033            case column:
2034                this.objectToken = token2;
2035                break;
2036            case method:
2037                this.partToken = token2;
2038                break;
2039            case table:
2040            case function:
2041            case procedure:
2042            case materializedView:
2043            case alias:
2044            case module:
2045            case sequence:
2046            case collation:
2047            case stage:
2048                this.schemaToken = token2;
2049                break;
2050            case namespace:
2051                this.databaseToken = token2;
2052                break;
2053            default:
2054                this.schemaToken = token2;
2055                break;
2056        }
2057
2058    }
2059
2060    private void initWithThreeTokens(EDbObjectType dbObjectType,TSourceToken token3,TSourceToken token2,TSourceToken token1){
2061        initWithTwoTokens(dbObjectType,token2,token1);
2062        numberOfPart = 3;
2063        this.setStartToken(token3);
2064        this.setEndToken(token1);
2065
2066        switch (dbObjectType){
2067            case column:
2068                this.schemaToken = token3;
2069                break;
2070            case method:
2071                this.objectToken = token3;
2072                break;
2073            case table:
2074            case function:
2075            case procedure:
2076            case materializedView:
2077            case alias:
2078            case module:
2079            case sequence:
2080            case collation:
2081            case stage:
2082                this.databaseToken = token3;
2083                break;
2084            default:
2085                this.databaseToken = token3;
2086                break;
2087        }
2088
2089    }
2090
2091    private void initWithFourTokens(EDbObjectType dbObjectType,TSourceToken token4,TSourceToken token3,TSourceToken token2,TSourceToken token1){
2092        initWithThreeTokens(dbObjectType,token3,token2,token1);
2093        numberOfPart = 4;
2094        this.setStartToken(token4);
2095        this.setEndToken(token1);
2096
2097        switch (dbObjectType){
2098            case column:
2099                this.databaseToken = token4;
2100                break;
2101            case method:
2102                this.schemaToken = token4;
2103                break;
2104            case table:
2105            case function:
2106            case procedure:
2107            case materializedView:
2108            case alias:
2109            case module:
2110            case sequence:
2111            case collation:
2112                this.serverToken = token4;
2113                break;
2114            default:
2115                this.serverToken = token4;
2116                break;
2117        }
2118
2119    }
2120
2121    /**
2122     * @deprecated As of v2.0.7.1, please use {@link TObjectName#createObjectName(EDbVendor, EDbObjectType, TSourceToken)} instead.
2123     * 
2124     * @param dbObjectType
2125     * @param token
2126     */
2127    private TObjectName(EDbObjectType dbObjectType,TSourceToken token){
2128        initWithOneToken(dbObjectType,token);
2129    }
2130
2131    private TObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token2,TSourceToken token1){
2132        this(dbVendor,dbObjectType,token1);
2133        numberOfPart = 2;
2134        this.setStartToken(token2);
2135        this.setEndToken(token1);
2136
2137        switch (dbObjectType){
2138            case column:
2139                this.objectToken = token2;
2140                break;
2141            case method:
2142                this.partToken = token2;
2143                break;
2144            case table:
2145            case function:
2146            case procedure:
2147            case materializedView:
2148            case alias:
2149            case module:
2150            case sequence:
2151            case collation:
2152                if (dbVendor == EDbVendor.dbvteradata){
2153                    this.databaseToken = token2;
2154                }else{
2155                    this.schemaToken = token2;
2156                }
2157
2158                break;
2159            default:
2160                this.schemaToken = token2;
2161                break;
2162        }
2163
2164    }
2165
2166
2167    /**
2168     * @deprecated since ver 2.5.9.8
2169     *
2170     * @param dbObjectType
2171     * @param token2
2172     * @param token1
2173     */
2174    private TObjectName(EDbObjectType dbObjectType,TSourceToken token2,TSourceToken token1){
2175        this(dbObjectType,token1);
2176        numberOfPart = 2;
2177        this.setStartToken(token2);
2178        this.setEndToken(token1);
2179
2180        switch (dbObjectType){
2181            case column:
2182                this.objectToken = token2;
2183                break;
2184            case method:
2185                this.partToken = token2;
2186                break;
2187            case table:
2188            case function:
2189            case procedure:
2190            case materializedView:
2191            case alias:
2192            case module:
2193            case sequence:
2194            case collation:
2195                this.schemaToken = token2;
2196                break;
2197            default:
2198                this.schemaToken = token2;
2199                break;
2200        }
2201    }
2202    private TObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token3,TSourceToken token2,TSourceToken token1){
2203        this(dbVendor,dbObjectType,token2,token1);
2204        numberOfPart = 3;
2205        this.setStartToken(token3);
2206        this.setEndToken(token1);
2207
2208        switch (dbObjectType){
2209            case column:
2210                this.schemaToken = token3;
2211                break;
2212            case method:
2213                this.objectToken = token3;
2214                break;
2215            case table:
2216            case function:
2217            case procedure:
2218            case materializedView:
2219            case alias:
2220            case module:
2221            case sequence:
2222            case collation:
2223                this.databaseToken = token3;
2224                break;
2225            default:
2226                this.databaseToken = token3;
2227                break;
2228        }
2229
2230    }
2231
2232
2233    /**
2234     * @deprecated since ver 2.5.9.8
2235     *
2236     * @param dbObjectType
2237     * @param token3
2238     * @param token2
2239     * @param token1
2240     */
2241    private TObjectName(EDbObjectType dbObjectType,TSourceToken token3,TSourceToken token2,TSourceToken token1){
2242        this(dbObjectType,token2,token1);
2243        numberOfPart = 3;
2244        this.setStartToken(token3);
2245        this.setEndToken(token1);
2246
2247        switch (dbObjectType){
2248            case column:
2249                this.schemaToken = token3;
2250                break;
2251            case method:
2252                this.objectToken = token3;
2253                break;
2254            case table:
2255            case function:
2256            case procedure:
2257            case materializedView:
2258            case alias:
2259            case module:
2260            case sequence:
2261            case collation:
2262                this.databaseToken = token3;
2263                break;
2264            default:
2265                this.databaseToken = token3;
2266                break;
2267        }
2268    }
2269
2270    private TObjectName(EDbVendor dbVendor, EDbObjectType dbObjectType,TSourceToken token4,TSourceToken token3,TSourceToken token2,TSourceToken token1){
2271        this(dbVendor,dbObjectType,token3,token2,token1);
2272        numberOfPart = 4;
2273        this.setStartToken(token4);
2274        this.setEndToken(token1);
2275
2276        switch (dbObjectType){
2277            case column:
2278                this.databaseToken = token4;
2279                break;
2280            case method:
2281                this.schemaToken = token4;
2282                break;
2283            case table:
2284            case function:
2285            case procedure:
2286            case materializedView:
2287            case alias:
2288            case module:
2289            case sequence:
2290            case collation:
2291                this.serverToken = token4;
2292                break;
2293            default:
2294                this.serverToken = token4;
2295                break;
2296        }
2297
2298    }
2299
2300    /**
2301     * @deprecated since ver 2.5.9.8
2302     *
2303     * @param dbObjectType
2304     * @param token4
2305     * @param token3
2306     * @param token2
2307     * @param token1
2308     */
2309    private TObjectName(EDbObjectType dbObjectType,TSourceToken token4,TSourceToken token3,TSourceToken token2,TSourceToken token1){
2310        this(dbObjectType,token3,token2,token1);
2311        numberOfPart = 4;
2312        this.setStartToken(token4);
2313        this.setEndToken(token1);
2314
2315        switch (dbObjectType){
2316            case column:
2317                this.databaseToken = token4;
2318                break;
2319            case method:
2320                this.schemaToken = token4;
2321                break;
2322            case table:
2323            case function:
2324            case procedure:
2325            case materializedView:
2326            case alias:
2327            case module:
2328            case sequence:
2329            case collation:
2330                this.serverToken = token4;
2331                break;
2332            default:
2333                this.serverToken = token4;
2334                break;
2335        }
2336    }
2337
2338    /**
2339     * @deprecated As of v2.0.7.1, please use {@link #TObjectName(EDbObjectType, TSourceToken, TSourceToken)} instead.
2340     *
2341     * Class constructor specifying object, part name and object type.
2342     * Use this constructor to create a <code>table.column</code> objectName.
2343     * Use {@link gudusoft.gsqlparser.TGSqlParser#parseObjectName} to create an objectName more than 2 parts.
2344     *
2345     * @param pObjectToken    name of this object, usually it's the table name
2346     * @param pPartToken      name of the column
2347     * @param dbObjectType    type of this object, usually it's {@link gudusoft.gsqlparser.EDbObjectType#column}
2348     */
2349    private TObjectName(TSourceToken pObjectToken,TSourceToken pPartToken,EDbObjectType dbObjectType){
2350        this(dbObjectType,pObjectToken,pPartToken);
2351    }
2352
2353    public void init(Object arg1)
2354    {
2355        partToken = (TSourceToken)arg1;
2356        numberOfPart = 1;
2357        this.setStartToken(partToken);
2358        this.setEndToken(partToken);
2359    }
2360
2361    public void init(Object arg1, Object arg2)
2362    {
2363        if (arg1 instanceof EDbObjectType){
2364            initWithOneToken((EDbObjectType)arg1,(TSourceToken) arg2);
2365
2366        }else{
2367            numberOfPart = 0;
2368            objectToken = (TSourceToken)arg1;
2369            partToken = (TSourceToken)arg2;
2370            if (partToken != null) numberOfPart++;
2371            if (objectToken != null) numberOfPart++;
2372
2373
2374            if(objectToken != null){
2375                this.setStartToken(objectToken);
2376            }else{
2377                this.setStartToken(partToken);
2378            }
2379
2380            if (partToken != null){
2381                this.setEndToken(partToken);
2382            }else{
2383                this.setEndToken(objectToken);
2384            }
2385        }
2386    }
2387
2388    public void init(EDbObjectType dbObjectType, Object arg1, Object arg2, Object arg3){
2389        numberOfPart = 0;
2390        if (arg1 != null) numberOfPart++;
2391        if (arg2 != null) numberOfPart++;
2392        if (arg3 != null) numberOfPart++;
2393
2394        this.dbObjectType = dbObjectType;
2395        this.setStartToken((TSourceToken)arg1);
2396        this.setEndToken((TSourceToken)arg3);
2397        switch (this.dbObjectType){
2398            case column:
2399                schemaToken = (TSourceToken)arg1;
2400                objectToken = (TSourceToken)arg2;
2401                partToken = (TSourceToken)arg3;
2402                break;
2403            case table:
2404            case function:
2405            case procedure:
2406            case materializedView:
2407            case module:
2408            case sequence:
2409                databaseToken = (TSourceToken) arg1;
2410                schemaToken = (TSourceToken)arg2;
2411                objectToken = (TSourceToken)arg3;
2412                break;
2413            case alias:
2414                break;
2415            default:
2416                break;
2417        }
2418
2419    }
2420
2421    public void init(Object arg1, Object arg2, Object arg3)
2422    {
2423        if (arg1 instanceof EDbObjectType){
2424            initWithTwoTokens((EDbObjectType)arg1,(TSourceToken) arg2,(TSourceToken) arg3);
2425        }else{
2426            numberOfPart = 0;
2427            if (arg1 != null) numberOfPart++;
2428            if (arg2 != null) numberOfPart++;
2429            if (arg3 != null) numberOfPart++;
2430
2431            if (dbvendor == EDbVendor.dbvteradata){
2432                databaseToken = (TSourceToken) arg1;
2433                this.setStartToken(databaseToken);
2434            }else{
2435                schemaToken = (TSourceToken)arg1;
2436                this.setStartToken(schemaToken);
2437                if (schemaToken != null)
2438                   {schemaToken.setDbObjType(TObjectName.ttobjSchemaName);}
2439            }
2440
2441            objectToken = (TSourceToken)arg2;
2442            partToken = (TSourceToken)arg3;
2443            this.setEndToken(partToken);
2444        }
2445    }
2446
2447    public void init(Object arg1, Object arg2, Object arg3, Object arg4)
2448    {
2449        if (arg1 instanceof EDbObjectType){
2450            //this.dbObjectType = (EDbObjectType)arg1;
2451            //init(arg2,arg3,arg4);
2452            initWithThreeTokens((EDbObjectType)arg1,(TSourceToken)arg2,(TSourceToken)arg3,(TSourceToken)arg4);
2453        }else{
2454            numberOfPart = 0;
2455            if (arg1 != null) numberOfPart++;
2456            if (arg2 != null) numberOfPart++;
2457            if (arg3 != null) numberOfPart++;
2458            if (arg4 != null) numberOfPart++;
2459
2460            //serverToken = (TSourceToken)arg1;
2461            databaseToken = (TSourceToken)arg1;
2462            schemaToken = (TSourceToken)arg2;
2463            objectToken = (TSourceToken)arg3;
2464            partToken = (TSourceToken)arg4;
2465            this.setStartToken(databaseToken);
2466            this.setEndToken(partToken);
2467            if (databaseToken != null){
2468                //databaseToken.setDbObjType(TObjectName.ttobjDatabaseName);
2469                databaseToken.setDbObjectType(EDbObjectType.database);
2470            }else {
2471            }
2472            if (schemaToken != null){
2473                schemaToken.setDbObjType(TObjectName.ttobjSchemaName);
2474            }else {
2475            }
2476        }
2477    }
2478
2479    public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
2480    {
2481        numberOfPart = 0;
2482        if (arg1 != null) numberOfPart++;
2483        if (arg2 != null) numberOfPart++;
2484        if (arg3 != null) numberOfPart++;
2485        if (arg4 != null) numberOfPart++;
2486        if (arg5 != null) numberOfPart++;
2487
2488        serverToken = (TSourceToken)arg1;
2489        databaseToken = (TSourceToken)arg2;
2490        schemaToken = (TSourceToken)arg3;
2491        objectToken = (TSourceToken)arg4;
2492        partToken = (TSourceToken)arg5;
2493
2494        this.setStartToken(serverToken);
2495        this.setEndToken(partToken);
2496
2497        if (serverToken != null){
2498            //serverToken.setDbObjType(TObjectName.ttobjServerName);
2499            serverToken.setDbObjectType(EDbObjectType.server);
2500        }else{
2501        }
2502        if (databaseToken != null){
2503            //databaseToken.setDbObjType(TObjectName.ttobjDatabaseName);
2504            databaseToken.setDbObjectType(EDbObjectType.database);
2505        }else{
2506        }
2507        if (schemaToken != null){
2508            schemaToken.setDbObjType(TObjectName.ttobjSchemaName);
2509        }else{
2510        }
2511    }
2512
2513    public void init(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6)
2514    {
2515        numberOfPart = 0;
2516        if (arg1 != null) numberOfPart++;
2517        if (arg2 != null) numberOfPart++;
2518        if (arg3 != null) numberOfPart++;
2519        if (arg4 != null) numberOfPart++;
2520        if (arg5 != null) numberOfPart++;
2521        if (arg6 != null) numberOfPart++;
2522
2523        serverToken = (TSourceToken)arg1;
2524        databaseToken = (TSourceToken)arg2;
2525        schemaToken = (TSourceToken)arg3;
2526        objectToken = (TSourceToken)arg4;
2527        partToken = (TSourceToken)arg5;
2528        propertyToken = (TSourceToken)arg6;
2529
2530        this.setStartToken(serverToken);
2531        this.setEndToken(propertyToken);
2532
2533        if (serverToken != null){
2534            //serverToken.setDbObjType(TObjectName.ttobjServerName);
2535            serverToken.setDbObjectType(EDbObjectType.server);
2536        }else{
2537        }
2538        if (databaseToken != null){
2539           // databaseToken.setDbObjType(TObjectName.ttobjDatabaseName);
2540            databaseToken.setDbObjectType(EDbObjectType.database);
2541        }else{
2542        }
2543        if (schemaToken != null){
2544            schemaToken.setDbObjType(TObjectName.ttobjSchemaName);
2545        }else{
2546        }
2547    }
2548
2549    /**
2550     * The column position of this objectName in the SQL
2551     *
2552     * @return column position
2553     */
2554    @Override
2555    public long getColumnNo() {
2556        long retval = -1;
2557        if (partToken != null) { retval = partToken.columnNo;}
2558        if (objectToken != null) {
2559              retval = objectToken.columnNo;
2560        }
2561        if (schemaToken != null) {
2562              retval = schemaToken.columnNo;
2563        }
2564        if (databaseToken != null) {
2565              retval = databaseToken.columnNo;
2566        }
2567        if (serverToken != null) {
2568              retval = serverToken.columnNo;
2569        }
2570        return retval;
2571    }
2572
2573    /**
2574     * The line number of this objectName in SQL
2575     *
2576     * @return the line number
2577     */
2578    @Override
2579    public long getLineNo() {
2580        long retval = -1;
2581        if (partToken != null) { retval = partToken.lineNo;}
2582        if (objectToken != null) {
2583              retval = objectToken.lineNo;
2584        }
2585        if (schemaToken != null) {
2586              retval = schemaToken.lineNo;
2587        }
2588        if (databaseToken != null) {
2589              retval = databaseToken.lineNo;
2590        }
2591        if (serverToken != null) {
2592              retval = serverToken.lineNo;
2593        }
2594        return retval;
2595    }
2596
2597   private TObjectNameList referencedObjects = null;
2598
2599    public TObjectNameList getReferencedObjects() {
2600        if (referencedObjects == null){
2601            referencedObjects = new TObjectNameList();
2602        }
2603        return referencedObjects;
2604    }
2605
2606    /**
2607     * Returns only the column name if it's prefixed with a table name
2608     *
2609     * @return only the column name if it's prefixed with a table name
2610     */
2611    public String getColumnNameOnly(){
2612
2613        if (getPartToken() == null) return "";
2614        else  return getPartToken().toString();
2615    }
2616
2617    public void accept(TParseTreeVisitor v){
2618        v.preVisit(this);
2619        v.postVisit(this);
2620    }
2621
2622    public void acceptChildren(TParseTreeVisitor v){
2623        v.preVisit(this);
2624        v.postVisit(this);
2625    }
2626
2627//    private TSourceToken sortType = null;
2628//
2629//    public void setSortType(TSourceToken sortType) {
2630//        this.sortType = sortType;
2631//    }
2632//
2633//    /**
2634//     * When this object is column in primary key(column,...), unique key(column,...) in sql server
2635//     * there maybe sort information like column asc, column desc
2636//     * this token represents for ASC, DESC if specified.
2637//     *
2638//     * @return ASC, DESC or null
2639//     */
2640//
2641//    public TSourceToken getSortType() {
2642//        return sortType;
2643//    }
2644
2645    /**
2646     * It's the same as {@link #getPartToken} if {@link #getDbObjectType} is {@link gudusoft.gsqlparser.EDbObjectType#column}
2647     *
2648     * @return source token that represents column, return null if this objectName is not type of column
2649     *
2650     */
2651    public TSourceToken getColumnToken(){
2652        TSourceToken ret = null;
2653        if (this.getObjectType() == ttobjColumn){
2654            ret = this.getPartToken();
2655        }
2656        return ret;
2657    }
2658
2659    /*
2660     *  re-arranage objectname to make it a valid name includes attribute name
2661      * used by teradata yacc file only.
2662      * valid syntax:
2663       * column.attr1().attr2().
2664       * column.attr1().attr2().attr3()
2665       * table.column.attr1().attr2().
2666       * table.column.attr1().attr2().attr3()
2667       *
2668     *   @return
2669     */
2670   public boolean isAttributeNameInObjectName(TSourceToken leftparen,TSourceToken rightparen){
2671        boolean ret = false;
2672        if ((this.partToken == null) || (this.objectToken == null)){
2673            return ret;
2674        }
2675        this.objectType = TObjectName.ttobjColumn;
2676        this.columnAttributes = new TObjectNameList();
2677        TObjectName attr1 = new TObjectName();
2678        attr1.objectType = TObjectName.ttobjAttribute;
2679        attr1.init(this.partToken);
2680        attr1.setEndToken(rightparen);
2681        this.columnAttributes.addObjectName(attr1);
2682
2683        this.partToken = this.objectToken;
2684
2685        if (this.schemaToken != null){
2686            this.objectToken = this.schemaToken;
2687        }
2688
2689        return true;
2690   }
2691
2692    /**
2693     * Used internally in hive .y file to merge two objectNames
2694     */
2695    public void mergeObjectName(TObjectName objectName){
2696        this.objectToken = this.partToken;
2697        this.partToken = objectName.getPartToken();
2698        this.setStartToken(objectToken);
2699        this.setEndToken(partToken);
2700    }
2701
2702    public void mergeObjectName(TObjectName objectName,TObjectName objectName2){
2703        this.schemaToken = this.partToken;
2704        this.objectToken = objectName.getPartToken();
2705        this.partToken = objectName2.getPartToken();
2706        this.setStartToken(schemaToken);
2707        this.setEndToken(partToken);
2708    }
2709
2710
2711    public void columnToProperty(){
2712        // if (numberOfPart == 1) return;
2713        if (this.propertyToken != null) return; // columnToProperty() already called
2714        if (! ((this.partToken != null) && (this.objectToken != null))) return; // 既然是 column.property , 那么 partToken and objectToken 不能为空
2715
2716        this.propertyToken = this.partToken;
2717        this.partToken = this.objectToken;
2718        this.objectToken = this.schemaToken;
2719
2720        this.setDbObjectTypeDirectly(EDbObjectType.column);
2721    }
2722
2723    public void appendObjectName(TObjectName objectName){
2724        if (this.databaseToken != null){
2725            this.serverToken = this.databaseToken;
2726        }
2727        if (this.schemaToken != null){
2728            this.databaseToken = this.schemaToken;
2729        }
2730        if (this.objectToken != null){
2731            this.schemaToken = this.objectToken;
2732        }
2733        this.objectToken = this.partToken;
2734        this.partToken = objectName.getPartToken();
2735        this.setEndTokenDirectly(this.partToken);
2736    }
2737
2738    private TSourceToken commentString;
2739
2740    public void setCommentString(TSourceToken commentString) {
2741        this.commentString = commentString;
2742    }
2743
2744    public TSourceToken getCommentString() {
2745
2746        return commentString;
2747    }
2748
2749
2750    /**
2751     * The X and Y position of this objectName in the SQL
2752     *
2753     * @return coordinate in string text
2754     */
2755    public String coordinate(){
2756        return this.getStartToken().lineNo+","+this.getEndToken().columnNo;
2757    }
2758
2759
2760    /**
2761     * @deprecated replaced by {@link EDbObjectType}.
2762     *
2763     * this is not an object, like sysdate function in oracle database
2764     */
2765    public final static int ttobjNotAObject = -1;
2766
2767    /**
2768     * @deprecated replaced by {@link EDbObjectType}.
2769     * object type can't be determined.
2770     */
2771    public final static int ttobjUnknown = 0;
2772
2773    /**
2774     * @deprecated replaced by {@link EDbObjectType}.
2775     * column in table, objectToken is table if specified, and partToken is column name.
2776     */
2777    public final static int ttobjColumn = 1;
2778
2779    /**
2780     * @deprecated replaced by {@link EDbObjectType}.
2781     * column alias in objectToken.
2782     */
2783    public final static int ttobjColumnAlias = 2;
2784
2785    /**
2786     * @deprecated replaced by {@link EDbObjectType}.
2787     * table name in objectToken.
2788     */
2789    public final static int ttobjTable = 3;
2790
2791
2792    /**
2793     * @deprecated replaced by {@link EDbObjectType}.
2794     * parameter name in objectToken.
2795     */
2796    public final static int ttobjParameter = 9;
2797
2798    /**
2799     * @deprecated replaced by {@link EDbObjectType}.
2800     * variable name in objectToken.
2801     */
2802    public final static int ttobjVariable = 10;
2803
2804
2805    /**
2806     * @deprecated replaced by {@link EDbObjectType#method}.
2807     *  column method like SetXY below, column method in {@link #methodToken}, and colomn name in {@link #partToken}.
2808     *<p>   UPDATE Cities
2809     *<p>   SET Location.SetXY(23.5, 23.5)
2810     *
2811     *
2812     */
2813    public final static int ttobjColumnMethod = 11;
2814
2815
2816
2817    /**
2818     * @deprecated replaced by {@link EDbObjectType}.
2819     * function name in {@link #objectToken}
2820     */
2821    public final static int ttobjFunctionName = 13;
2822
2823
2824    /**
2825     * @deprecated replaced by {@link EDbObjectType#constraint}.
2826     * constraint name in {@link #objectToken}
2827     */
2828    public final static int ttobjConstraintName = 19;
2829
2830    /**
2831     * @deprecated replaced by {@link EDbObjectType}.
2832     * string constant in {@link #objectToken}
2833     */
2834    public final static int ttobjStringConstant = 23;
2835
2836
2837    /**
2838     * @deprecated replaced by {@link EDbObjectType}.
2839     * attribute name is in {@link #partToken}
2840     */
2841    public final static int ttobjAttribute = 26;
2842
2843
2844    /**
2845     * @deprecated replaced by {@link EDbObjectType}.
2846     * datatype was not represented by a TObjectName object, this constant was used in source tokens that consist of  TTypeName.
2847     */
2848    public final static int ttobjDatatype = 30;
2849
2850    /**
2851     * @deprecated replaced by {@link EDbObjectType}.
2852     *  schema name in {@link #schemaToken}
2853     */
2854    public final static int ttobjSchemaName = 31;
2855
2856
2857    /**
2858     * @deprecated replaced by {@link EDbObjectType}.
2859     * postgresql
2860     * Positional Parameters, $1, $1[1], $1[1,10]
2861     * parameter name is in {@link #partToken} of $1,
2862     * and parameter name is in {@link #objectToken} of $1.columnName,
2863     * and column name is in {@link #partToken}
2864     */
2865
2866    public final static int ttobjPositionalParameters = 61;
2867
2868
2869
2870    private void setColumnTokenOfPositionalParameters(TSourceToken column){
2871        this.objectToken = this.partToken;
2872        this.partToken = column;
2873    }
2874
2875    private int objectType = ttobjUnknown;
2876
2877
2878    /**
2879     * @deprecated replaced by {@link EDbObjectType}.
2880     * this type is used in TObjectNameList, when objects in TObjectNameList includes more than
2881     * one type, objtype of that TObjectNameList was set to ttobjMixed.
2882     *
2883     * removed since v2.9.2.5
2884     */
2885   // public final static int ttobjMixed = 100;
2886
2887    /**
2888     * @deprecated replaced by {@link EDbObjectType#library}.
2889     * removed since v2.9.2.5
2890     */
2891   // public final static  int ttObjLibrary = 72;
2892
2893    /**
2894     * @deprecated replaced by {@link EDbObjectType#oracleHint}.
2895     * removed since v2.9.2.5
2896     */
2897   // public final static  int ttObjOracleHint = 70;
2898
2899    /**
2900     * @deprecated replaced by {@link EDbObjectType#fieldName}.
2901     * check {@link gudusoft.gsqlparser.nodes.TExpression#getFieldName()} for more
2902     * removed since v2.9.2.5
2903     */
2904   // public final static int ttobjFieldName = 51;
2905
2906    /**
2907     * @deprecated replaced by {@link EDbObjectType#miningModel}.
2908     * removed since v2.9.2.5
2909     */
2910    // public final static int ttobjMiningModel = 46;
2911
2912    /**
2913     * @deprecated replaced by {@link EDbObjectType#materializedView}.
2914     * removed since v2.9.2.5
2915     */
2916    // public final static int ttobjMaterializedView = 44;
2917
2918    /**
2919     * @deprecated replaced by {@link EDbObjectType#indextype}.
2920     * removed since v2.9.2.5
2921     */
2922   // public final static int ttobjIndexType = 42;
2923
2924    /**
2925     * @deprecated replaced by {@link EDbObjectType#operator}.
2926     * removed since v2.9.2.5
2927     */
2928    // public final static int ttobjOperator = 40;
2929
2930    /**
2931     * @deprecated replaced by {@link EDbObjectType#server}.
2932     * server name in {@link #serverToken}
2933     *
2934     * removed since v2.9.2.5
2935     */
2936  //  public final static int ttobjServerName = 32;
2937
2938    /**
2939     * @deprecated replaced by {@link EDbObjectType#sequence}.
2940     * Sequence name in {@link #objectToken}
2941     *
2942     * removed since v2.9.2.5
2943     */
2944   // public final static int ttobjSequence = 29;
2945
2946    /**
2947     * @deprecated replaced by {@link EDbObjectType#plsql_package}.
2948     * package name in {@link #objectToken}
2949     *
2950     * removed since v2.9.2.5
2951     */
2952   // public final static int ttobjPackage = 28;
2953
2954    /**
2955     * @deprecated replaced by {@link EDbObjectType#alias}.
2956     * alias name in {@link #objectToken}
2957     *
2958     * removed since v2.9.2.5
2959     */
2960   // public final static int ttobjAliasName = 25;
2961
2962
2963    /**
2964     * @deprecated replaced by {@link EDbObjectType#trigger}.
2965     * Trigger name in {@link #objectToken}
2966     *
2967     * removed since v2.9.2.5
2968     */
2969   // public final static int ttobjTrigger = 24;
2970
2971    /**
2972     * @deprecated replaced by {@link EDbObjectType#database}.
2973     * Database name in {@link #objectToken}
2974     *
2975     * removed since v2.9.2.5
2976     */
2977   // public final static int ttobjDatabaseName = 22;
2978
2979    /**
2980     * @deprecated replaced by {@link EDbObjectType#transaction}.
2981     * Transaction name in {@link #objectToken}
2982     *
2983     * removed since v2.9.2.5
2984     */
2985    // public final static int ttobjTransactionName = 21;
2986
2987
2988    /**
2989     * @deprecated replaced by {@link EDbObjectType#user_defined_type}.
2990     * type name in {@link #objectToken}
2991     *
2992     * removed since v2.9.2.5
2993     */
2994   // public final static int ttobjTypeName = 27;
2995
2996    /**
2997     * @deprecated replaced by {@link EDbObjectType#property}.
2998     * property name in {@link #propertyToken}
2999     *
3000     * removed since v2.9.2.5
3001     */
3002   // public final static int ttobjPropertyName = 20;
3003
3004    /**
3005     * @deprecated replaced by {@link EDbObjectType#view}.
3006     * view name in {@link #objectToken}
3007     *
3008     * removed since v2.9.2.5
3009     */
3010   // public final static int ttobjViewName = 18;
3011
3012    /**
3013     * @deprecated replaced by {@link EDbObjectType#cursor}.
3014     * cursor name in {@link #objectToken}
3015     *
3016     * removed since v2.9.2.5
3017     */
3018  //  public final static int ttobjCursorName = 17;
3019
3020    /**
3021     * @deprecated replaced by {@link EDbObjectType#materializedView}.
3022     * materialized view name in {@link #objectToken}
3023     *
3024     * removed since v2.9.2.5
3025     */
3026   // public final static int ttobjMaterializedViewName = 16;
3027
3028    /**
3029     * @deprecated replaced by {@link EDbObjectType#index}.
3030     * index name in {@link #objectToken}
3031     *
3032     * removed since v2.9.2.5
3033     */
3034   // public final static int ttobjIndexName = 15;
3035
3036    /**
3037     * @deprecated replaced by {@link EDbObjectType#label}.
3038     * label name in {@link #objectToken}
3039     *
3040     * removed since v2.9.2.5
3041     */
3042   // public final static int ttobjLabelName = 14;
3043
3044    /**
3045     * @deprecated replaced by {@link EDbObjectType#procedure}.
3046     * procedure name in {@link #objectToken}
3047     *
3048     * removed since v2.9.2.5
3049     */
3050   // public final static int ttobjProcedureName = 12;
3051
3052    /**
3053     * @deprecated replaced by {@link EDbObjectType#variable}.
3054     * table variable in objectToken.
3055     *
3056     * removed since v2.9.2.5
3057     */
3058   // public final static int ttobjTableVar = 8;
3059
3060    /**
3061     * @deprecated replaced by {@link EDbObjectType#cte}.
3062     * table name in objectToken.
3063     *
3064     * removed since v2.9.2.5
3065     */
3066    // public final static int ttobjTableCTE = 5;
3067
3068    /**
3069     * @deprecated replaced by {@link EDbObjectType}.
3070     * table name in objectToken.
3071     */
3072    // public final static int ttobjTableTemp = 6;
3073
3074    /**
3075     * @deprecated replaced by {@link EDbObjectType}.
3076     */
3077    //  public final static int ttobjTablePivot = 7;
3078
3079    /**
3080     * @deprecated replaced by {@link EDbObjectType#table_alias}.
3081     * table alias in objectToken
3082     *
3083     * removed since v2.9.2.5
3084     */
3085   // public final static int ttObjTableAlias = 4;
3086}