svn-gvsig-desktop / tags / v1_1_Build_1003 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / DBLayerDefinition.java @ 12271
History | View | Annotate | Download (7.8 KB)
1 | 3207 | fjp | /*
|
---|---|---|---|
2 | * Created on 26-oct-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | 11926 | caballero | *
|
6 | 3207 | fjp | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 | 11926 | caballero | *
|
8 | 3207 | fjp | * This program is free software; you can redistribute it and/or
|
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | 11926 | caballero | *
|
13 | 3207 | fjp | * This program is distributed in the hope that it will be useful,
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | 11926 | caballero | *
|
18 | 3207 | fjp | * You should have received a copy of the GNU General Public License
|
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
21 | 11926 | caballero | *
|
22 | 3207 | fjp | * For more information, contact:
|
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | 11926 | caballero | *
|
34 | 3207 | fjp | * or
|
35 | 11926 | caballero | *
|
36 | 3207 | fjp | * IVER T.I. S.A
|
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | 11926 | caballero | *
|
41 | 3207 | fjp | * +34 963163400
|
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.cit.gvsig.fmap.drivers; |
||
45 | |||
46 | import java.awt.geom.Rectangle2D; |
||
47 | 11926 | caballero | //import java.sql.Connection;
|
48 | import java.sql.Types; |
||
49 | 3207 | fjp | |
50 | public class DBLayerDefinition extends LayerDefinition { |
||
51 | 11926 | caballero | private IConnection conn;
|
52 | 3207 | fjp | private String catalogName; |
53 | 11867 | jmvivo | private String schema; |
54 | 3207 | fjp | private String tableName; |
55 | 3977 | fjp | // private String[] fieldNames; // GeometryField not included
|
56 | 11926 | caballero | private String fieldID; // Estos 2 campos en PostGIS los sabremos |
57 | 3207 | fjp | private String fieldGeometry; // (gid y the_geom), pero por si acaso se cambian |
58 | private String whereClause; |
||
59 | private Rectangle2D workingArea; |
||
60 | private String SRID_EPSG; |
||
61 | 3236 | fjp | private String classToInstantiate; |
62 | 11926 | caballero | |
63 | 3207 | fjp | // private int idFieldGeometry = -1;
|
64 | private int idFieldID = -1; |
||
65 | 4740 | fjp | private int dimension = 2; |
66 | 11926 | caballero | private String host; |
67 | private int port; |
||
68 | private String database; |
||
69 | private String user; |
||
70 | private String password; |
||
71 | private String connectionname; |
||
72 | |||
73 | 3207 | fjp | public String getCatalogName() { |
74 | return catalogName;
|
||
75 | } |
||
76 | public void setCatalogName(String catalogName) { |
||
77 | this.catalogName = catalogName;
|
||
78 | } |
||
79 | public String getFieldGeometry() { |
||
80 | return fieldGeometry;
|
||
81 | } |
||
82 | public void setFieldGeometry(String fieldGeometry) { |
||
83 | this.fieldGeometry = fieldGeometry;
|
||
84 | } |
||
85 | public String getFieldID() { |
||
86 | return fieldID;
|
||
87 | } |
||
88 | 5747 | fjp | /**
|
89 | * @param fieldID
|
||
90 | */
|
||
91 | 3207 | fjp | public void setFieldID(String fieldID) { |
92 | this.fieldID = fieldID;
|
||
93 | 5747 | fjp | // No se usa lo de a?adir el id por otro lado.
|
94 | // Se hace en MyFinishAction
|
||
95 | /* boolean bFound = false;
|
||
96 | for (int i=0; i< fieldsDesc.length; i++)
|
||
97 | {
|
||
98 | if (fieldsDesc[i].getFieldName().compareToIgnoreCase(fieldID) == 0)
|
||
99 | bFound = true;
|
||
100 | }
|
||
101 | if (bFound != true)
|
||
102 | {
|
||
103 | int length = fieldsDesc.length;
|
||
104 | FieldDescription[] aux = new FieldDescription[length+1];
|
||
105 | System.arraycopy(fieldsDesc, 0, aux, 0, length);
|
||
106 | FieldDescription f = new FieldDescription();
|
||
107 | aux[length] = field
|
||
108 | } */
|
||
109 | 3207 | fjp | } |
110 | /**
|
||
111 | * @return GeometryField is not included in this list
|
||
112 | */
|
||
113 | public String[] getFieldNames() { |
||
114 | 3977 | fjp | String[] fieldNames = new String[fieldsDesc.length]; |
115 | for (int i=0; i< fieldsDesc.length; i++) |
||
116 | { |
||
117 | fieldNames[i] = fieldsDesc[i].getFieldName(); |
||
118 | } |
||
119 | 3207 | fjp | return fieldNames;
|
120 | } |
||
121 | /**
|
||
122 | * Geometry field not included in this list
|
||
123 | * @param fieldNames
|
||
124 | */
|
||
125 | public void setFieldNames(String[] fieldNames) { |
||
126 | idFieldID = -1;
|
||
127 | // idFieldGeometry = -1;
|
||
128 | 3977 | fjp | if (fieldsDesc == null) |
129 | fieldsDesc = new FieldDescription[fieldNames.length];
|
||
130 | if (fieldsDesc.length != fieldNames.length)
|
||
131 | fieldsDesc = new FieldDescription[fieldNames.length];
|
||
132 | for (int i=0; i < fieldNames.length; i++) |
||
133 | 4096 | fjp | { |
134 | fieldsDesc[i] = new FieldDescription();
|
||
135 | 3977 | fjp | fieldsDesc[i].setFieldName(fieldNames[i]); |
136 | 4096 | fjp | } |
137 | 3207 | fjp | } |
138 | 11867 | jmvivo | /**
|
139 | * @deprecated Better use getCompoundTableName to deal with schemas.
|
||
140 | * This method should be used only by drivers when it is necessary to distinguish between table and schema.
|
||
141 | * @return
|
||
142 | */
|
||
143 | 3207 | fjp | public String getTableName() { |
144 | 11867 | jmvivo | return tableName;
|
145 | 3207 | fjp | } |
146 | public void setTableName(String tableName) { |
||
147 | this.tableName = tableName;
|
||
148 | } |
||
149 | 3236 | fjp | /**
|
150 | 3248 | fjp | * The returned string must contain "WHERE " clause
|
151 | 3236 | fjp | * @return
|
152 | */
|
||
153 | 3207 | fjp | public String getWhereClause() { |
154 | return whereClause;
|
||
155 | } |
||
156 | public void setWhereClause(String whereClause) { |
||
157 | this.whereClause = whereClause;
|
||
158 | } |
||
159 | public Rectangle2D getWorkingArea() { |
||
160 | return workingArea;
|
||
161 | } |
||
162 | public void setWorkingArea(Rectangle2D workingArea) { |
||
163 | this.workingArea = workingArea;
|
||
164 | } |
||
165 | 11926 | caballero | |
166 | 3207 | fjp | /**
|
167 | * @param fieldName
|
||
168 | * @return index of field (0 based). -1 if not found
|
||
169 | */
|
||
170 | public int getIdField(String fieldName) |
||
171 | { |
||
172 | int result = -1; |
||
173 | 3977 | fjp | for (int i=0; i < fieldsDesc.length; i++) |
174 | 3207 | fjp | { |
175 | 3977 | fjp | if (fieldName.equalsIgnoreCase(fieldsDesc[i].getFieldName()))
|
176 | 3207 | fjp | { |
177 | result = i; |
||
178 | break;
|
||
179 | } |
||
180 | } |
||
181 | return result;
|
||
182 | } |
||
183 | 11926 | caballero | |
184 | 3207 | fjp | /**
|
185 | 3248 | fjp | * 0 based index of the ID field
|
186 | 3207 | fjp | * @return Returns the idFieldID.
|
187 | */
|
||
188 | public int getIdFieldID() { |
||
189 | if (idFieldID == -1) |
||
190 | 11926 | caballero | idFieldID = getIdField(fieldID); |
191 | 3207 | fjp | return idFieldID;
|
192 | } |
||
193 | /**
|
||
194 | * @return Returns the sRID_EPSG.
|
||
195 | */
|
||
196 | public String getSRID_EPSG() { |
||
197 | return SRID_EPSG;
|
||
198 | } |
||
199 | /**
|
||
200 | * @param srid_epsg The sRID_EPSG to set.
|
||
201 | */
|
||
202 | public void setSRID_EPSG(String srid_epsg) { |
||
203 | SRID_EPSG = srid_epsg; |
||
204 | } |
||
205 | 3236 | fjp | /**
|
206 | * @return Returns the classToInstantiate.
|
||
207 | */
|
||
208 | public String getClassToInstantiate() { |
||
209 | return classToInstantiate;
|
||
210 | } |
||
211 | /**
|
||
212 | * @param classToInstantiate The classToInstantiate to set.
|
||
213 | */
|
||
214 | public void setClassToInstantiate(String classToInstantiate) { |
||
215 | this.classToInstantiate = classToInstantiate;
|
||
216 | } |
||
217 | 11926 | caballero | |
218 | 3347 | fjp | public int getFieldIdByName(String name) |
219 | { |
||
220 | int resul = -1; |
||
221 | 3977 | fjp | for (int i=0; i<fieldsDesc.length; i++) |
222 | 3347 | fjp | { |
223 | 6033 | fjp | if (fieldsDesc[i].getFieldName().equalsIgnoreCase(name))
|
224 | 3347 | fjp | { |
225 | resul = i; |
||
226 | break;
|
||
227 | } |
||
228 | } |
||
229 | return resul;
|
||
230 | } |
||
231 | 11926 | caballero | public IConnection getConnection() {
|
232 | 4748 | fjp | return conn;
|
233 | 4740 | fjp | } |
234 | 11926 | caballero | |
235 | public void setConnection(IConnection connection) { |
||
236 | 4740 | fjp | conn = connection; |
237 | } |
||
238 | public int getDimension() { |
||
239 | return dimension;
|
||
240 | } |
||
241 | |||
242 | public void setDimension(int dim) { |
||
243 | dimension = dim; |
||
244 | } |
||
245 | 11926 | caballero | public String getHost() { |
246 | return host;
|
||
247 | } |
||
248 | public void setHost(String host){ |
||
249 | this.host=host;
|
||
250 | } |
||
251 | public int getPort() { |
||
252 | return port;
|
||
253 | } |
||
254 | public void setPort(int port){ |
||
255 | this.port=port;
|
||
256 | } |
||
257 | public String getDataBase() { |
||
258 | return database;
|
||
259 | } |
||
260 | public void setDataBase(String database){ |
||
261 | this.database=database;
|
||
262 | } |
||
263 | public String getUser() { |
||
264 | return user;
|
||
265 | } |
||
266 | public void setUser(String user){ |
||
267 | this.user=user;
|
||
268 | } |
||
269 | public String getPassword() { |
||
270 | return password;
|
||
271 | } |
||
272 | public void setPassword(String password){ |
||
273 | this.password=password;
|
||
274 | } |
||
275 | public void setConnectionName(String stringProperty) { |
||
276 | this.connectionname=stringProperty;
|
||
277 | } |
||
278 | public String getConnectionName() { |
||
279 | return connectionname;
|
||
280 | } |
||
281 | 11867 | jmvivo | public void setSchema(String schema) { |
282 | this.schema = schema;
|
||
283 | } |
||
284 | public String getSchema() { |
||
285 | return schema;
|
||
286 | } |
||
287 | /**
|
||
288 | * @return schema.tableName or only tableName if schema is not defined
|
||
289 | */
|
||
290 | public String getComposedTableName() { |
||
291 | 12229 | jmvivo | String compoundTable = ""; |
292 | if (getSchema()!=null && !getSchema().equals("")){ |
||
293 | compoundTable = getSchema()+ ".";
|
||
294 | } |
||
295 | compoundTable = compoundTable+ getTableName(); |
||
296 | 11867 | jmvivo | return compoundTable;
|
297 | } |
||
298 | 3207 | fjp | } |