001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.util.loader;
028:
029: import java.sql.Connection;
030: import java.sql.ResultSet;
031: import java.sql.Statement;
032: import java.util.ArrayList;
033: import java.util.List;
034:
035: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
036: import fr.ign.cogit.geoxygene.util.loader.gui.GUITableChoice;
037:
038: /**
039: * Usage interne.
040: * Le but est de remplir la liste des tables a charger.
041: *
042: *
043: * @author Thierry Badard & Arnaud Braun
044: * @version 1.0
045: *
046: */
047:
048: public class MetadataReader {
049:
050: private Geodatabase data;
051: private List theList = new ArrayList();
052: private String query;
053:
054: private final String ORACLE_QUERY = "SELECT TABLE_NAME FROM USER_SDO_GEOM_METADATA";
055: private final String POSTGIS_QUERY = "SELECT F_TABLE_NAME FROM GEOMETRY_COLUMNS";
056:
057: public MetadataReader(Geodatabase Data) {
058: data = Data;
059: if (data.getDBMS() == Geodatabase.ORACLE)
060: query = ORACLE_QUERY;
061: else if (data.getDBMS() == Geodatabase.POSTGIS)
062: query = POSTGIS_QUERY;
063: }
064:
065: public List getSelectedTables() {
066: getAllTables();
067: ihm();
068: return theList;
069: }
070:
071: private void getAllTables() {
072: theList.clear();
073: try {
074: Connection conn = data.getConnection();
075: Statement stm = conn.createStatement();
076: ResultSet rs = (ResultSet) stm.executeQuery(query);
077: while (rs.next()) {
078: String sqlTableName = rs.getString(1);
079: if (sqlTableName.compareToIgnoreCase("RESULT_POINT") == 0) {
080: continue;
081: }
082: if (sqlTableName.compareToIgnoreCase("RESULT_CURVE") == 0) {
083: continue;
084: }
085: if (sqlTableName.compareToIgnoreCase("RESULT_SURFACE") == 0) {
086: continue;
087: }
088: if (sqlTableName.compareToIgnoreCase("RESULTAT") == 0) {
089: continue;
090: }
091: if (sqlTableName.compareToIgnoreCase("TABLEAUX") == 0) {
092: continue;
093: }
094:
095: theList.add(sqlTableName);
096: }
097: stm.close();
098: } catch (Exception e) {
099: e.printStackTrace();
100: }
101: }
102:
103: private void ihm() {
104: String user = null;
105: try {
106: user = data.getConnection().getMetaData().getUserName();
107: } catch (Exception e) {
108: e.printStackTrace();
109: }
110: System.out.println("Selection des tables ...");
111: GUITableChoice swing = new GUITableChoice(theList.toArray(),
112: user);
113: String[] selectedTables = swing.showDialog();
114: theList = new ArrayList();
115: for (int i = 0; i < selectedTables.length; i++) {
116: System.out.println(selectedTables[i]);
117: theList.add(selectedTables[i]);
118: }
119: }
120:
121: }
|