2121 */
2222package net .sf .jsqlparser .schema ;
2323
24- import net .sf .jsqlparser .expression .Expression ;
25- import net .sf .jsqlparser .expression .ExpressionVisitor ;
24+ import net .sf .jsqlparser .expression .*;
2625
2726/**
2827 * A column. It can have the table name it belongs to.
2928 */
30- public class Column implements Expression {
31-
32- private String columnName = "" ;
33- private Table table ;
34-
35- public Column () {
36- }
37-
38- public Column (Table table , String columnName ) {
39- this .table = table ;
40- this .columnName = columnName ;
41- }
42-
43- public Column (String columnName ) {
44- this (null , columnName );
45- }
46-
47- public String getColumnName () {
48- return columnName ;
49- }
50-
51- public Table getTable () {
52- return table ;
53- }
54-
55- public void setColumnName (String string ) {
56- columnName = string ;
57- }
58-
59- public void setTable (Table table ) {
60- this .table = table ;
61- }
62-
63- /**
64- * @return the name of the column, prefixed with 'tableName' and '.'
65- */
66- public String getWholeColumnName () {
67-
68- String columnWholeName ;
69- String tableWholeName = null ;
70-
71- if (table != null ) {
72- tableWholeName = table .getWholeTableName ();
73- }
74- if (tableWholeName != null && tableWholeName .length () != 0 ) {
75- columnWholeName = tableWholeName + "." + columnName ;
76- } else {
77- columnWholeName = columnName ;
78- }
79-
80- return columnWholeName ;
81-
82- }
83-
84- @ Override
85- public void accept (ExpressionVisitor expressionVisitor ) {
86- expressionVisitor .visit (this );
87- }
88-
89- @ Override
90- public String toString () {
91- return getWholeColumnName ();
92- }
93- }
29+ public final class Column implements Expression , MultiPartName {
30+
31+ private Table table ;
32+ private String columnName ;
33+
34+ public Column () {
35+ }
36+
37+ public Column (Table table , String columnName ) {
38+ setTable (table );
39+ setColumnName (columnName );
40+ }
41+
42+ public Column (String columnName ) {
43+ this (null , columnName );
44+ }
45+
46+ public Table getTable () {
47+ return table ;
48+ }
49+
50+ public void setTable (Table table ) {
51+ this .table = table ;
52+ }
53+
54+ public String getColumnName () {
55+ return columnName ;
56+ }
57+
58+ public void setColumnName (String string ) {
59+ columnName = string ;
60+ }
61+
62+ @ Override
63+ public String getFullyQualifiedName () {
64+ StringBuilder fqn = new StringBuilder ();
65+
66+ if (table != null ) {
67+ fqn .append (table .getFullyQualifiedName ());
68+ }
69+ if (fqn .length ()>0 ) {
70+ fqn .append ('.' );
71+ }
72+ if (columnName != null ) {
73+ fqn .append (columnName );
74+ }
75+ return fqn .toString ();
76+ }
77+
78+ @ Override
79+ public void accept (ExpressionVisitor expressionVisitor ) {
80+ expressionVisitor .visit (this );
81+ }
82+
83+ @ Override
84+ public String toString () {
85+ return getFullyQualifiedName ();
86+ }
87+ }
0 commit comments