001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.arcsde.data.view;
018:
019: import net.sf.jsqlparser.schema.Table;
020: import net.sf.jsqlparser.statement.select.FromItem;
021: import net.sf.jsqlparser.statement.select.FromItemVisitor;
022: import net.sf.jsqlparser.statement.select.SubSelect;
023:
024: import com.esri.sde.sdk.client.SeConnection;
025:
026: /**
027: * Fully qualifies a table names.
028: *
029: * <p>
030: * {@link net.sf.jsqlparser.schema.Table} has provitions only to store schema
031: * and table names, in the traditional sense. ArcSDE uses fully qualified
032: * names formed by "databaseName"."userName"."tableName". Though
033: * "databaseName" is optional in some ArcSDE systems (sql server, for
034: * example), it is required in Oracle. Schema and table stands for user and
035: * table in sde land. So this visitor will create new Tables where schema if
036: * formed by SDE's "databaseName"."userName"
037: * </p>
038: *
039: * @author Gabriel Roldan, Axios Engineering
040: * @version $Id: FromItemQualifier.java 29135 2008-02-07 19:49:09Z desruisseaux $
041: *
042: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/main/java/org/geotools/arcsde/data/view/FromItemQualifier.java $
043: * @since 2.3.x
044: */
045: class FromItemQualifier implements FromItemVisitor {
046: /** DOCUMENT ME! */
047: private SeConnection conn;
048:
049: /** DOCUMENT ME! */
050: private FromItem qualifiedFromItem;
051:
052: /**
053: * Creates a new FromItemQualifier object.
054: *
055: * @param conn DOCUMENT ME!
056: *
057: * @throws IllegalStateException DOCUMENT ME!
058: */
059: private FromItemQualifier(SeConnection conn)
060: throws IllegalStateException {
061: this .conn = conn;
062: }
063:
064: /**
065: * DOCUMENT ME!
066: *
067: * @param conn DOCUMENT ME!
068: * @param fromItem DOCUMENT ME!
069: *
070: * @return DOCUMENT ME!
071: */
072: public static FromItem qualify(SeConnection conn, FromItem fromItem) {
073: if (fromItem == null) {
074: return null;
075: }
076:
077: FromItemQualifier qualifier = new FromItemQualifier(conn);
078: fromItem.accept(qualifier);
079:
080: return qualifier.qualifiedFromItem;
081: }
082:
083: /**
084: * DOCUMENT ME!
085: *
086: * @param tableName DOCUMENT ME!
087: */
088: public void visit(Table tableName) {
089: qualifiedFromItem = TableQualifier.qualify(conn, tableName);
090: }
091:
092: /**
093: * DOCUMENT ME!
094: *
095: * @param subSelect DOCUMENT ME!
096: */
097: public void visit(SubSelect subSelect) {
098: this.qualifiedFromItem = SubSelectQualifier.qualify(conn,
099: subSelect);
100: }
101: }
|