Statistics
| Revision:

root / trunk / libraries / libFMap_dataDB / src / org / gvsig / data / datastores / vectorial / db / sde / SDEResource.java @ 20855

History | View | Annotate | Download (5.41 KB)

1 20802 vcaballero
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program 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
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I   {{Task}}
26
*/
27
28
/**
29
 *
30
 */
31
package org.gvsig.data.datastores.vectorial.db.sde;
32
33
import org.gvsig.data.Resource;
34
import org.gvsig.data.exception.CloseException;
35
import org.gvsig.data.exception.DataException;
36
import org.gvsig.data.exception.InitializeException;
37
import org.gvsig.data.exception.OpenException;
38
import org.gvsig.data.exception.ReadException;
39
import org.gvsig.data.exception.ResourceChangedException;
40
41
import com.esri.sde.sdk.client.SeConnection;
42
import com.esri.sde.sdk.client.SeException;
43
44
/**
45
 * @author jmvivo
46
 *
47
 */
48
public class SDEResource extends Resource {
49
        protected SeConnection connection = null;
50
51
        private String user;
52
        private String password;
53
        private String server;
54
        private String port;
55
56
        private String database;
57
58
59
60
        /* (non-Javadoc)
61
         * @see org.gvsig.data.Resource#doDispose()
62
         */
63
        protected void doDispose() throws DataException {
64
                this.connection = this.createConnection();
65
                this.setOpened();
66
67
        }
68
69
        /* (non-Javadoc)
70
         * @see org.gvsig.data.Resource#doOpen()
71
         */
72
        protected boolean doOpen() throws OpenException {
73
                try {
74
                        this.connection = this.createConnection();
75
                } catch (ReadException e) {
76
                        throw new OpenException(this.getName(),e);
77
                }
78
                this.setOpened();
79
                return true;
80
        }
81
82
        SDEResource(SDEStoreParameters params){
83
                this.loadParamsData(params);
84
        }
85
86
        SDEResource(SDEExplorerParameters params){
87
                this.loadParamsData(params);
88
        }
89
90
        /* (non-Javadoc)
91
         * @see org.gvsig.data.Resource#doClose()
92
         */
93
        protected boolean doClose() throws CloseException {
94
                try {
95
                        connection.close();
96
                } catch (SeException e) {
97
                        throw new CloseException(this.getName(),e);
98
                }
99
                return super.doClose();
100
        }
101
102
        protected void loadParamsData(SDEStoreParameters params){
103
                this.user = params.getUser();
104
                this.password = params.getPassw();
105
                this.server=params.getHost();
106
                this.port=params.getPort();
107
                this.database=params.getDb();
108
        }
109
110
        protected void loadParamsData(SDEExplorerParameters params){
111
                this.user = params.getUser();
112
                this.password = params.getPassw();
113
                this.server=params.getHost();
114
                this.port=params.getPort();
115
                this.database=params.getDb();
116
        }
117
118
119
        protected SeConnection createConnection() throws ReadException{
120
                try {
121
                        return new SeConnection(server, Integer.parseInt(port), database,
122
                                        user, password);
123
                } catch (SeException e) {
124
                        throw new ReadException("SDE Connection", e);
125
                } catch (Exception e) {
126
                        throw new ReadException("SDE Connection", e);
127
                }
128
        }
129
130
131
        /* (non-Javadoc)
132
         * @see org.gvsig.data.Resource#description()
133
         */
134
        public String description() {
135
                return this.getName()+" SDE Connection Resource: server='"+this.getServer()+"' port='"+this.getPort()+"' db='"+this.getDatabase()+"' user='"+this.getUser()+"'";
136
        }
137
138
        /* (non-Javadoc)
139
         * @see org.gvsig.data.Resource#doChanged()
140
         */
141
        protected void doChanged() {
142
                // No Operation
143
        }
144
145
        /**
146
         * @return the password
147
         */
148
        public String getPassword() {
149
                return password;
150
        }
151
152
        /**
153
         * @param password the password to set
154
         * @throws InitializeException
155
         */
156
        public void setPassword(String password) throws InitializeException {
157
                if (this.getRefencesCount() > 0){
158
                        throw new InitializeException("Resource in use",this.description());
159
                }
160
                this.password = password;
161
        }
162
163
        /**
164
         * @return the user
165
         */
166
        public String getUser() {
167
                return user;
168
        }
169
170
        /**
171
         * @param user the user to set
172
         * @throws InitializeException
173
         */
174
        public void setUser(String user) throws InitializeException {
175
                if (this.getRefencesCount() > 0){
176
                        throw new InitializeException("Resource in use",this.description());
177
                }
178
                this.user = user;
179
        }
180
181
        protected SeConnection getConnection() throws ReadException{
182
                this.checkOpen();
183
                return this.connection;
184
        }
185
186
        protected SeConnection getWriterConnection() throws ReadException{
187
                return this.createConnection();
188
        }
189
190
        /* (non-Javadoc)
191
         * @see org.gvsig.data.Resource#checkChanged()
192
         */
193
        protected void checkChanged() throws ResourceChangedException {
194
                // NO Operation
195
196
        }
197
198
        public String getDatabase() {
199
                return database;
200
        }
201
202
        public void setDatabase(String database) {
203
                this.database = database;
204
        }
205
206
        public String getPort() {
207
                return port;
208
        }
209
210
        public void setPort(String port) {
211
                this.port = port;
212
        }
213
214
        public String getServer() {
215
                return server;
216
        }
217
218
        public void setServer(String server) {
219
                this.server = server;
220
        }
221
        /* (non-Javadoc)
222
         * @see org.gvsig.data.Resource#generateKey()
223
         */
224
        protected String generateKey() {
225
                return this.getName()+";"+this.getServer()+";"+this.getPort()+";"+this.getDatabase()+";"+this.getUser();
226
        }
227
228
        /* (non-Javadoc)
229
         * @see org.gvsig.data.Resource#getName()
230
         */
231
        public String getName() {
232
                return "sde";
233
        }
234
235
}