001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/io/sdeapi/SDEConnection.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2006 by: M.O.S.S. Computer Grafik Systeme GmbH
006: Hohenbrunner Weg 13
007: D-82024 Taufkirchen
008: http://www.moss.de/
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014:
015: This library is distributed in the hope that it will be useful,
016: but WITHOUT ANY WARRANTY; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: Lesser General Public License for more details.
019:
020: You should have received a copy of the GNU Lesser General Public
021: License along with this library; if not, write to the Free Software
022: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023:
024: ---------------------------------------------------------------------------*/
025: package org.deegree.io.sdeapi;
026:
027: import com.esri.sde.sdk.client.SeConnection;
028: import com.esri.sde.sdk.client.SeException;
029: import com.esri.sde.sdk.client.SeState;
030: import com.esri.sde.sdk.client.SeVersion;
031:
032: public class SDEConnection {
033:
034: private SeConnection connection;
035:
036: private SeVersion version;
037:
038: private SeState state;
039:
040: public SDEConnection(final String sdeServer, final int sdeInstance,
041: final String sdeDatabase, final String sdeVersion,
042: final String sdeUser, final String sdePassword) {
043:
044: try {
045: connection = new SeConnection(sdeServer, sdeInstance,
046: sdeDatabase, sdeUser, sdePassword);
047: if (null == sdeVersion || 0 == sdeVersion.length()) {
048: version = new SeVersion(connection);
049: } else {
050: try {
051: version = new SeVersion(connection, sdeVersion);
052: } catch (SeException dne) {
053: version = new SeVersion(connection,
054: SeVersion.SE_QUALIFIED_DEFAULT_VERSION_NAME);
055: version.setDescription(sdeVersion);
056: version.setName(sdeVersion);
057: version
058: .setParentName(SeVersion.SE_QUALIFIED_DEFAULT_VERSION_NAME);
059: version.create(false, version);
060: }
061: }
062: reserve();
063: } catch (Exception e) {
064: e.printStackTrace();
065: }
066: }
067:
068: public SeConnection getConnection() {
069: return connection;
070: }
071:
072: public SeVersion getVersion() {
073: return version;
074: }
075:
076: public SeState getState() {
077: return state;
078: }
079:
080: public boolean isClosed() {
081: if (null == connection) {
082: return true;
083: }
084: return connection.isClosed();
085: }
086:
087: public void close() {
088: if (!isClosed()) {
089: release();
090: try {
091: connection.close();
092: } catch (Exception e) {
093: }
094: connection = null;
095: }
096: }
097:
098: private void reserve() {
099: try {
100: SeState verState = new SeState(connection, version
101: .getStateId());
102: state = new SeState(connection);
103: if (verState.isOpen()) {
104: verState.close();
105: }
106: state.create(verState.getId());
107: } catch (Exception e) {
108: e.printStackTrace();
109: }
110: ;
111: }
112:
113: private void release() {
114: try {
115: version.changeState(state.getId());
116: state.close();
117: } catch (Exception e) {
118: e.printStackTrace();
119: }
120: ;
121: }
122: }
|