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 net.sf.jsqlparser.schema.Table;
20:
21: import com.esri.sde.sdk.client.SeConnection;
22: import com.esri.sde.sdk.client.SeException;
23:
24: /**
25: * Utility used to qualify table names
26: *
27: * @author Gabriel Roldan, Axios Engineering
28: * @version $Id: TableQualifier.java 29135 2008-02-07 19:49:09Z desruisseaux $
29: *
30: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/main/java/org/geotools/arcsde/data/view/TableQualifier.java $
31: * @since 2.3.x
32: */
33: class TableQualifier {
34: /**
35: * Returns a Table with the same name as the argument one but fully
36: * qualified in the ArcSDE sense.
37: *
38: * @param conn connection to obtain database and user name from
39: * @param table table whose schema name is to be qualified
40: *
41: * @return a qualified Table.
42: *
43: * @throws IllegalStateException if an SDE error is catched up while asking
44: * <code>conn</code> for the database and user name.
45: */
46: public static Table qualify(SeConnection conn, Table table)
47: throws IllegalStateException {
48: if (table == null) {
49: return null;
50: }
51:
52: final Table qualifiedTable = new Table();
53: final String databaseName;
54: final String userName;
55:
56: qualifiedTable.setName(table.getName());
57: qualifiedTable.setAlias(table.getAlias());
58:
59: String schema = table.getSchemaName(); // user name in sde land
60:
61: //if (schema != null) {
62: try {
63: databaseName = conn.getDatabaseName();
64: userName = conn.getUser();
65: } catch (SeException e) {
66: throw new IllegalStateException("getting database name: "
67: + e.getMessage());
68: }
69:
70: // we'll replace the table schema name by
71: // databaseName.userName
72: String qualifiedSchema = databaseName;
73:
74: if (schema != null) {
75: // use the "user" name provided
76: qualifiedSchema += ("." + schema);
77: } else {
78: // use this connection's user name
79: qualifiedSchema += ("." + userName);
80: }
81:
82: qualifiedTable.setSchemaName(qualifiedSchema);
83: //}
84:
85: return qualifiedTable;
86: }
87: }
|