📄 geodatabasecastororacle.java
字号:
/*
* This file is part of the GeOxygene project source files.
*
* GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
* the development and deployment of geographic (GIS) applications. It is a open source
* contribution of the COGIT laboratory at the Institut G閛graphique National (the French
* National Mapping Agency).
*
* See: http://oxygene-project.sourceforge.net
*
* Copyright (C) 2005 Institut G閛graphique National
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this library (see file LICENSE if present); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package fr.ign.cogit.geoxygene.datatools.castor;
//import feature.FT_Feature;
//import feature.FT_FeatureCollection;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import fr.ign.cogit.geoxygene.datatools.Metadata;
//import datatools.oracle.SpatialQuery;
/** NON MAINTENU.
* Implementation d'une Geodatabase utilisant Castor comme mappeur et Oracle comme SGBDR geographique.
* N'EST PLUS MAINTENU DEPUIS LE PASSAGE A OJB.
*
* @author Thierry Badard & Arnaud Braun
* @version 1.0
*/
public class GeodatabaseCastorOracle/* implements Geodatabase */{
/////////////////////////////////////////////////////////////////////////////////////////
///// attributs /////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
private String _oxygeneMapping; // variable d'environnememt GEOXYGENE_MAPPING
private Connection _conn; // connection JDBC
// private JDO _jdo; // JDO Castor
// private Database _db; // Database Castor
private PrintWriter _writer; // destination des messages de sortie
private List _metadataList; // liste des metadonnnees pour les classes persistantes.
private static String _databaseName="cogit"; // nom de la base qui apparait dans le fichier database.xml
/////////////////////////////////////////////////////////////////////////////////////////
///// constructeurs /////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/** Constructeur, avec un writer pour l'affichage des messages Castor. */
public GeodatabaseCastorOracle(PrintWriter writer) {
try {
initWriter(writer);
initEnv();
if (writer != null) writer.println("Convertisseur de g?om?trie pour Oracle initialis?.");
initJDO(_databaseName, writer);
if (writer != null) writer.println("Moteur JDO de Castor initialis?.");
initDatabase();
if (writer != null) writer.println("Geodatabase initialis?e.");
initConnection();
if (writer != null) writer.println("Connection JDBC initialis?e.");
initMetadata();
if (writer != null) writer.println("M?tadonn?es initialis?es.");
} catch (Exception e) {_writer.println(e.getMessage());}
}
/** Constructeur, sans writer donc sans affichage des messages Castor. */
public GeodatabaseCastorOracle() {
this(null);
}
/** Constructeur sans initialiser la Geodatabase si le boolean en param?tre vaut false.
Utilise uniquement dans EasyLoader pour creer le fichier de mapping. */
public GeodatabaseCastorOracle(boolean Castor) {
try {
initWriter(null);
initEnv();
initJDO(_databaseName, null);
if (Castor == true) {
initDatabase();
initConnection();
initMetadata();
} else {
initConnectionWithoutJDO();
}
} catch (Exception e) {
System.out.println(e.getMessage());}
}
/////////////////////////////////////////////////////////////////////////////////////
/// initialisation des attributs ////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/** Initialise le Writer. Si on avait passe null en parametre du constructeur de DataSource, alors
initialise un writer sur la sortie standard qui est utilise uniquement pour afficher les messages de cette classe. */
private void initWriter (PrintWriter writer) {
if (writer != null) {
_writer = writer;
} else {
_writer = new PrintWriter(System.out,true);
}
}
/** Recupere la valeur de la variable d'environnement GEOXYGENE_MAPPING */
// on essaie d'assurer l'independance vis a vis du systeme d'exploitation
private void initEnv() {
try { // ceci est pour Windows
String[] command = {"cmd.exe","/c","set"};
Process pr = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader( (InputStream)pr.getInputStream()));
String ligne = br.readLine();
while (ligne != null) {
if ((ligne.length() >= 15) && (ligne.substring(0,15).compareTo("GEOXYGENE_MAPPING") == 0)) {
_oxygeneMapping = ligne.substring(16);
break;
}
ligne = br.readLine();
}
} catch (Exception e1) {
try { // ceci est pour Solaris / Linux
String command = "env";
Process pr = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader( (InputStream)pr.getInputStream()));
String ligne = br.readLine();
while (ligne != null) {
if ((ligne.length() >= 15) && (ligne.substring(0,15).compareTo("GEOXYGENE_MAPPING") == 0)) {
_oxygeneMapping = ligne.substring(16);
break;
}
ligne = br.readLine();
}
} catch (Exception e2) {
try { // ceci est pour Windows
String[] command = {"command.com","/c","set"};
Process pr = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader( (InputStream)pr.getInputStream()));
String ligne = br.readLine();
while (ligne != null) {
if ((ligne.length() >= 15) && (ligne.substring(0,15).compareTo("GEOXYGENE_MAPPING") == 0)) {
_oxygeneMapping = ligne.substring(16);
break;
}
ligne = br.readLine();
}
} catch (Exception e3) {
System.out.println("GeOxygene : env, cmd ou command ne sont pas reconnus");
e1.printStackTrace();
e2.printStackTrace();
e3.printStackTrace();
}
}
}
if (_oxygeneMapping == null)
_writer.println(" ### La variable d'environnement GEOXYGENE_MAPPING n'est pas renseign閑 ###");
}
/** Initialise le JDO (moteur utilis? par Castor pour se connecter ? la base). */
private void initJDO (String databaseName, PrintWriter writer) {
/* try {
File databasePath = new File(_oxygeneMapping);
File databaseFile = new File(databasePath,"database.xml");
URL databaseURL = databaseFile.toURL();
_jdo = new JDO();
if (writer != null) {_jdo.setLogWriter( writer );}
_jdo.setConfiguration( databaseURL.toString());
_jdo.setDatabaseName( databaseName );
} catch ( Exception except ) {
except.printStackTrace( _writer );
}
*/ }
/** Ouvre une Database Castor (repr?sente une connection ouverte au SGBD) */
private void initDatabase() {
/* try {
_db = _jdo.getDatabase();
} catch ( Exception except ) {
except.printStackTrace( _writer );
}
*/ }
/** Initialise la connection JDBC. */
// On cree une connection JDBC avec les parametres Castor
private void initConnection() {
/* try {
_conn = DatabaseRegistry.getDatabaseRegistry(_jdo.getDatabaseName()).createConnection();
} catch(Exception e) {
e.printStackTrace();
}
*/ }
/** Initialise la connection JDBC sans passer par JDO. */
// On parse la fichier "database.xml" a l'aide des fonctionnalites XML de Castor.
private void initConnectionWithoutJDO() {
/* try {
File databasePath = new File(_oxygeneMapping);
File databaseFile = new File(databasePath,"database.xml");
FileReader reader = new FileReader(databaseFile);
datatools.castor.conf.Database _db = (datatools.castor.conf.Database)Unmarshaller.unmarshal(datatools.castor.conf.Database.class,reader);
java.lang.Class.forName(_db.getDriver().getClassName()).newInstance();
_conn = DriverManager.getConnection(_db.getDriver().getUrl(), _db.getDriver().getUserName(),
_db.getDriver().getPassword());
} catch(Exception e) {
e.printStackTrace();
}
*/ }
/** Renseigne l'attribut _metadataList. */
private void initMetadata() {
/* try {
MappingResolver mr = DatabaseRegistry.getDatabaseRegistry(_jdo.getDatabaseName()).getMappingResolver();
Enumeration listDesc = mr.listDescriptors();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -