01: /*
02: * Geotools2 - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package org.geotools.arcsde.data.view;
18:
19: import java.util.Map;
20:
21: import net.sf.jsqlparser.schema.Column;
22: import net.sf.jsqlparser.schema.Table;
23:
24: import com.esri.sde.sdk.client.SeConnection;
25:
26: /**
27: * Qualifies a column name with the ArcSDE "table.user." prefix as required by
28: * the ArcSDE java api to not get confused when using joined tables.
29: *
30: * @author Gabriel Roldan, Axios Engineering
31: * @version $Id: ColumnQualifier.java 29135 2008-02-07 19:49:09Z desruisseaux $
32: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/main/java/org/geotools/arcsde/data/view/ColumnQualifier.java $
33: * @since 2.3.x
34: */
35: class ColumnQualifier {
36: /**
37: * DOCUMENT ME!
38: *
39: * @param conn DOCUMENT ME!
40: * @param column DOCUMENT ME!
41: *
42: * @return DOCUMENT ME!
43: */
44: public static Column qualify(SeConnection conn, Map tableAliases,
45: Column column) {
46: Table table = column.getTable();
47:
48: String columnName = column.getColumnName();
49:
50: Table unaliasedTable = (Table) tableAliases
51: .get(table.getName());
52:
53: Table qualifiedTable;
54:
55: if (unaliasedTable == null) {
56: //not an aliased table, qualify it
57: qualifiedTable = TableQualifier.qualify(conn, table);
58: } else {
59: //AllTableColumns is refering to an aliased table in the FROM clause,
60: //replace its table by the original one to get rid of the alias
61: qualifiedTable = unaliasedTable;
62: }
63:
64: Column qualifiedColumn = new Column();
65:
66: qualifiedColumn.setColumnName(columnName);
67: qualifiedColumn.setTable(qualifiedTable);
68:
69: return qualifiedColumn;
70: }
71: }
|