Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1011 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / DBLayerDefinition.java @ 12904

History | View | Annotate | Download (7.8 KB)

1
/*
2
 * Created on 26-oct-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * 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
 *
13
 * 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
 *
18
 * 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
 *
22
 * 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
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.cit.gvsig.fmap.drivers;
45

    
46
import java.awt.geom.Rectangle2D;
47
//import java.sql.Connection;
48
import java.sql.Types;
49

    
50
public class DBLayerDefinition extends LayerDefinition {
51
        private IConnection conn;
52
    private String catalogName;
53
    private String schema;
54
    private String tableName;
55
    // private String[] fieldNames; // GeometryField not included
56
    private String fieldID; // Estos 2 campos en PostGIS los sabremos
57
    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
    private String classToInstantiate;
62

    
63
    // private int idFieldGeometry = -1;
64
    private int idFieldID = -1;
65
        private int dimension = 2;
66
        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
    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
    /**
89
     * @param fieldID
90
     */
91
    public void setFieldID(String fieldID) {
92
        this.fieldID = fieldID;
93
        // 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
    }
110
    /**
111
     * @return GeometryField is not included in this list
112
     */
113
    public String[] getFieldNames() {
114
            String[] fieldNames = new String[fieldsDesc.length];
115
            for (int i=0; i< fieldsDesc.length; i++)
116
            {
117
                    fieldNames[i] = fieldsDesc[i].getFieldName();
118
            }
119
        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
        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
        {
134
                fieldsDesc[i] = new FieldDescription();
135
                fieldsDesc[i].setFieldName(fieldNames[i]);
136
        }
137
    }
138
    /**
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
    public String getTableName() {
144
                   return tableName;
145
    }
146
    public void setTableName(String tableName) {
147
        this.tableName = tableName;
148
    }
149
    /**
150
     * The returned string must contain "WHERE " clause
151
     * @return
152
     */
153
    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

    
166
    /**
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
        for (int i=0; i < fieldsDesc.length; i++)
174
        {
175
            if (fieldName.equalsIgnoreCase(fieldsDesc[i].getFieldName()))
176
            {
177
                result = i;
178
                break;
179
            }
180
        }
181
        return result;
182
    }
183

    
184
    /**
185
     * 0 based index of the ID field
186
     * @return Returns the idFieldID.
187
     */
188
    public int getIdFieldID() {
189
        if (idFieldID == -1)
190
            idFieldID = getIdField(fieldID);
191
        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
    /**
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

    
218
    public int getFieldIdByName(String name)
219
    {
220
        int resul = -1;
221
        for (int i=0; i<fieldsDesc.length; i++)
222
        {
223
            if (fieldsDesc[i].getFieldName().equalsIgnoreCase(name))
224
            {
225
                resul = i;
226
                break;
227
            }
228
        }
229
        return resul;
230
    }
231
        public IConnection getConnection() {
232
                return conn;
233
        }
234

    
235
        public void setConnection(IConnection connection) {
236
                conn = connection;
237
        }
238
        public int getDimension() {
239
                return dimension;
240
        }
241

    
242
        public void setDimension(int dim) {
243
                dimension = dim;
244
        }
245
        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
        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
                String compoundTable = "";
292
                if (getSchema()!=null && !getSchema().equals("")){
293
                        compoundTable = getSchema()+ ".";
294
                }
295
                compoundTable = compoundTable+ getTableName();
296
                return compoundTable;
297
        }
298
}