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.statement.select.ColumnReference;
22: import net.sf.jsqlparser.statement.select.OrderByElement;
23: import net.sf.jsqlparser.statement.select.OrderByVisitor;
24:
25: import com.esri.sde.sdk.client.SeConnection;
26:
27: /**
28: * Qualifies a column reference in an order by clause
29: *
30: * @author Gabriel Roldan, Axios Engineering
31: * @version $Id: OrderByElementQualifier.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/OrderByElementQualifier.java $
33: * @since 2.3.x
34: */
35: public class OrderByElementQualifier implements OrderByVisitor {
36: /** DOCUMENT ME! */
37: private OrderByElement qualifiedOrderBy;
38:
39: /** DOCUMENT ME! */
40: private SeConnection conn;
41:
42: private Map tableAliases;
43:
44: /**
45: * Creates a new OrderByElementQualifier object.
46: *
47: * @param conn DOCUMENT ME!
48: */
49: private OrderByElementQualifier(SeConnection conn, Map tableAliases) {
50: this .conn = conn;
51: this .tableAliases = tableAliases;
52: }
53:
54: /**
55: * DOCUMENT ME!
56: *
57: * @param conn DOCUMENT ME!
58: * @param orderBy DOCUMENT ME!
59: *
60: * @return DOCUMENT ME!
61: */
62: public static OrderByElement qualify(SeConnection conn,
63: Map tableAliases, OrderByElement orderBy) {
64: if (orderBy == null) {
65: return null;
66: }
67:
68: OrderByElementQualifier qualifier = new OrderByElementQualifier(
69: conn, tableAliases);
70: orderBy.accept(qualifier);
71:
72: return qualifier.qualifiedOrderBy;
73: }
74:
75: /**
76: * DOCUMENT ME!
77: *
78: * @param orderBy DOCUMENT ME!
79: */
80: public void visit(OrderByElement orderBy) {
81: OrderByElement qualifiedOrderBy = new OrderByElement();
82: qualifiedOrderBy.setAsc(orderBy.isAsc());
83:
84: ColumnReference colRef = orderBy.getColumnReference();
85:
86: ColumnReference qualifiedColRef = ColumnReferenceQualifier
87: .qualify(conn, tableAliases, colRef);
88:
89: qualifiedOrderBy.setColumnReference(qualifiedColRef);
90:
91: this.qualifiedOrderBy = qualifiedOrderBy;
92: }
93: }
|