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.statement.select.ColumnIndex;
23: import net.sf.jsqlparser.statement.select.ColumnReference;
24: import net.sf.jsqlparser.statement.select.ColumnReferenceVisitor;
25:
26: import com.esri.sde.sdk.client.SeConnection;
27:
28: /**
29: * Qualifies a column reference (aliased) the ArcSDE "table.user." prefix as
30: * required by the ArcSDE java api to not get confused when using joined tables.
31: *
32: * @author Gabriel Roldan, Axios Engineering
33: * @version $Id: ColumnReferenceQualifier.java 18656 2006-03-14 18:05:11Z
34: * groldan $
35: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/main/java/org/geotools/arcsde/data/view/ColumnReferenceQualifier.java $
36: * @since 2.3.x
37: */
38: public class ColumnReferenceQualifier implements ColumnReferenceVisitor {
39: /** DOCUMENT ME! */
40: private ColumnReference qualifiedReference;
41:
42: /** DOCUMENT ME! */
43: private SeConnection conn;
44:
45: private Map tableAliases;
46:
47: /**
48: * Creates a new ColumnReferenceQualifier object.
49: *
50: * @param conn DOCUMENT ME!
51: */
52: private ColumnReferenceQualifier(SeConnection conn, Map tableAliases) {
53: this .conn = conn;
54: this .tableAliases = tableAliases;
55: }
56:
57: /**
58: * DOCUMENT ME!
59: *
60: * @param conn DOCUMENT ME!
61: * @param colRef DOCUMENT ME!
62: *
63: * @return DOCUMENT ME!
64: */
65: public static ColumnReference qualify(SeConnection conn,
66: Map tableAliases, ColumnReference colRef) {
67: if (colRef == null) {
68: return null;
69: }
70:
71: ColumnReferenceQualifier qualifier = new ColumnReferenceQualifier(
72: conn, tableAliases);
73: colRef.accept(qualifier);
74:
75: return qualifier.qualifiedReference;
76: }
77:
78: /**
79: * DOCUMENT ME!
80: *
81: * @param columnIndex DOCUMENT ME!
82: */
83: public void visit(ColumnIndex columnIndex) {
84: qualifiedReference = columnIndex;
85: }
86:
87: /**
88: * DOCUMENT ME!
89: *
90: * @param column DOCUMENT ME!
91: */
92: public void visit(Column column) {
93: this.qualifiedReference = ColumnQualifier.qualify(conn,
94: tableAliases, column);
95: }
96: }
|