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.math.BigDecimal;
030: import java.sql.Connection;
031: import java.sql.ResultSet;
032: import java.sql.Statement;
033:
034: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
035:
036: /**
037: * Usage interne.
038: * Remplit les tables GF_FeatureType et GF_AttributeType, quand elles existent,
039: * au moment de la generation des classes Java.
040: *
041: * @author Thierry Badard & Arnaud Braun
042: * @version 1.0
043: *
044: */
045:
046: class DicoGenerator {
047:
048: private Connection conn;
049: private int dbms;
050:
051: DicoGenerator(Geodatabase data) {
052: conn = data.getConnection();
053: dbms = data.getDBMS();
054: }
055:
056: void writeFeature(String typeName) {
057: int max = 1;
058: try {
059:
060: Statement stm = conn.createStatement();
061:
062: String query = "SELECT MAX (GF_FeatureTypeID) FROM GF_FEATURETYPE";
063: ResultSet rs = stm.executeQuery(query);
064: while (rs.next()) {
065: if (dbms == Geodatabase.ORACLE) {
066: if (rs.getObject(1) != null)
067: max = ((BigDecimal) rs.getObject(1)).intValue() + 1;
068: } else if (dbms == Geodatabase.POSTGIS) {
069: max = rs.getInt(1) + 1;
070: }
071: }
072:
073: String update = "INSERT INTO GF_FEATURETYPE VALUES (" + max
074: + ",'" + typeName + "',null,'0')";
075: stm.executeUpdate(update);
076: stm.close();
077: } catch (Exception e) {
078: // e.printStackTrace();
079: ; // mieux de pas afficher de message : si les tables n'existent pas ou s'il y a des doublons
080: }
081: }
082:
083: void writeAttribute(String featureName, String memberName,
084: String typeName) {
085: int id = 0;
086: int max = 1;
087: try {
088: Statement stm = conn.createStatement();
089:
090: String query = "SELECT GF_FEATURETYPEID FROM GF_FEATURETYPE WHERE TYPENAME = '"
091: + featureName + "'";
092: ResultSet rs = (ResultSet) stm.executeQuery(query);
093: while (rs.next()) {
094: if (dbms == Geodatabase.ORACLE) {
095: id = ((BigDecimal) rs.getObject(1)).intValue();
096: } else if (dbms == Geodatabase.POSTGIS) {
097: id = rs.getInt(1);
098: }
099: }
100:
101: query = "SELECT MAX (GF_PropertyTypeID) FROM GF_ATTRIBUTETYPE";
102: rs = stm.executeQuery(query);
103: while (rs.next()) {
104: if (dbms == Geodatabase.ORACLE) {
105: if (rs.getObject(1) != null)
106: max = ((BigDecimal) rs.getObject(1)).intValue() + 1;
107: } else if (dbms == Geodatabase.POSTGIS) {
108: max = rs.getInt(1) + 1;
109: }
110: }
111:
112: String update = "INSERT INTO GF_ATTRIBUTETYPE VALUES ("
113: + max + "," + id + ",'" + memberName + "',null,'"
114: + typeName + "',null,1,1,null)";
115: stm.executeUpdate(update);
116: stm.close();
117: } catch (Exception e) {
118: // e.printStackTrace();
119: ; // mieux de pas afficher de message : si les tables n'existent pas ou s'il y a des doublons
120: }
121: }
122:
123: }
|