nl.topicus.jdbc.shaded.net.sf.jsqlparser.schema.Column Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spanner-jdbc Show documentation
Show all versions of spanner-jdbc Show documentation
JDBC Driver for Google Cloud Spanner
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package nl.topicus.jdbc.shaded.net.sf.jsqlparser.schema;
import java.util.List;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.*;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* A column. It can have the table name it belongs to.
*/
public final class Column extends ASTNodeAccessImpl implements Expression, MultiPartName {
private Table table;
private String columnName;
public Column() {
}
public Column(Table table, String columnName) {
setTable(table);
setColumnName(columnName);
}
public Column(List nameParts) {
this(nameParts.size() > 1
? new Table(nameParts.subList(0, nameParts.size() - 1)) : null,
nameParts.get(nameParts.size() - 1));
}
public Column(String columnName) {
this(null, columnName);
}
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
public String getColumnName() {
return columnName;
}
public void setColumnName(String string) {
columnName = string;
}
@Override
public String getFullyQualifiedName() {
return getName(false);
}
/**
* Get name with out without using aliases.
*
* @param aliases
* @return
*/
public String getName(boolean aliases) {
StringBuilder fqn = new StringBuilder();
if (table != null) {
if (table.getAlias() != null && aliases) {
fqn.append(table.getAlias().getName());
} else {
fqn.append(table.getFullyQualifiedName());
}
}
if (fqn.length() > 0) {
fqn.append('.');
}
if (columnName != null) {
fqn.append(columnName);
}
return fqn.toString();
}
@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
@Override
public String toString() {
return getName(true);
}
}