Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / DBLayerDefinition.java @ 33286

History | View | Annotate | Download (7.94 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

    
48
public class DBLayerDefinition extends LayerDefinition {
49
        private IConnection conn;
50
    private String catalogName;
51
    private String schema;
52
    private String tableName;
53
    // private String[] fieldNames; // GeometryField not included
54
    private String fieldID; // Estos 2 campos en PostGIS los sabremos
55
    private String fieldGeometry; // (gid y the_geom), pero por si acaso se cambian
56
    private String whereClause;
57
    private Rectangle2D workingArea;
58
    private String SRID_EPSG;
59
    private String classToInstantiate;
60

    
61
    // private int idFieldGeometry = -1;
62
    private int idFieldID = -1;
63
        private int dimension = 2;
64
        private String host;
65
        private int port;
66
        private String database;
67
        private String user;
68
        private String password;
69
        private String connectionname;
70

    
71
    public String getCatalogName() {
72
        return catalogName;
73
    }
74
    public void setCatalogName(String catalogName) {
75
        this.catalogName = catalogName;
76
    }
77
    public String getFieldGeometry() {
78
        return fieldGeometry;
79
    }
80
    public void setFieldGeometry(String fieldGeometry) {
81
        this.fieldGeometry = fieldGeometry;
82
    }
83
    public String getFieldID() {
84
        return fieldID;
85
    }
86
    /**
87
     * @param fieldID
88
     */
89
    public void setFieldID(String fieldID) {
90
        this.fieldID = fieldID;
91
        // No se usa lo de a?adir el id por otro lado.
92
        // Se hace en MyFinishAction
93
        /* boolean bFound = false;
94
            for (int i=0; i< fieldsDesc.length; i++)
95
            {
96
                    if (fieldsDesc[i].getFieldName().compareToIgnoreCase(fieldID) == 0)
97
                            bFound = true;
98
            }
99
        if (bFound != true)
100
        {
101
                int length = fieldsDesc.length;
102
                FieldDescription[] aux = new FieldDescription[length+1];
103
                System.arraycopy(fieldsDesc, 0, aux, 0, length);
104
                FieldDescription f = new FieldDescription();
105
                aux[length] = field
106
        } */
107
    }
108
    /**
109
     * @return GeometryField is not included in this list
110
     */
111
    public String[] getFieldNames() {
112
            String[] fieldNames = new String[fieldsDesc.length];
113
            for (int i=0; i< fieldsDesc.length; i++)
114
            {
115
                    fieldNames[i] = fieldsDesc[i].getFieldName();
116
            }
117
        return fieldNames;
118
    }
119
    /**
120
     * Geometry field not included in this list
121
     * @param fieldNames
122
     */
123
    public void setFieldNames(String[] fieldNames) {
124
        idFieldID = -1;
125
        // idFieldGeometry = -1;
126
        if (fieldsDesc == null)
127
                fieldsDesc = new FieldDescription[fieldNames.length];
128
        if (fieldsDesc.length != fieldNames.length)
129
                fieldsDesc = new FieldDescription[fieldNames.length];
130
        for (int i=0; i < fieldNames.length; i++)
131
        {
132
                fieldsDesc[i] = new FieldDescription();
133
                fieldsDesc[i].setFieldName(fieldNames[i]);
134
        }
135
    }
136
    /**
137
     * @deprecated Better use getCompoundTableName to deal with schemas.
138
     * This method should be used only by drivers when it is necessary to distinguish between table and schema.
139
     * @return
140
     */
141
    public String getTableName() {
142
                   return tableName;
143
    }
144
    public void setTableName(String tableName) {
145
        this.tableName = tableName;
146
    }
147
    /**
148
     * The returned string must contain "WHERE " clause
149
     * @return
150
     */
151
    public String getWhereClause() {
152
        return whereClause;
153
    }
154
    public void setWhereClause(String whereClause) {
155
        this.whereClause = whereClause;
156
    }
157
    public Rectangle2D getWorkingArea() {
158
        return workingArea;
159
    }
160
    public void setWorkingArea(Rectangle2D workingArea) {
161
        this.workingArea = workingArea;
162
    }
163

    
164
    /**
165
     * @param fieldName
166
     * @return index of field (0 based). -1 if not found
167
     */
168
    public int getIdField(String fieldName)
169
    {
170
        int result = -1;
171
        for (int i=0; i < fieldsDesc.length; i++)
172
        {
173
            if (fieldName.equalsIgnoreCase(fieldsDesc[i].getFieldName()))
174
            {
175
                result = i;
176
                break;
177
            }
178
        }
179
        return result;
180
    }
181

    
182
    /**
183
     * 0 based index of the ID field
184
     * @return Returns the idFieldID.
185
     */
186
    public int getIdFieldID() {
187
        if (idFieldID == -1)
188
            idFieldID = getIdField(fieldID);
189
        return idFieldID;
190
    }
191
    /**
192
     * @return Returns the sRID_EPSG.
193
     */
194
    public String getSRID_EPSG() {
195
        return SRID_EPSG;
196
    }
197
    /**
198
     * @param srid_epsg The sRID_EPSG to set.
199
     */
200
    public void setSRID_EPSG(String srid_epsg) {
201
        SRID_EPSG = srid_epsg;
202
    }
203
    /**
204
     * @return Returns the classToInstantiate.
205
     */
206
    public String getClassToInstantiate() {
207
        return classToInstantiate;
208
    }
209
    /**
210
     * @param classToInstantiate The classToInstantiate to set.
211
     */
212
    public void setClassToInstantiate(String classToInstantiate) {
213
        this.classToInstantiate = classToInstantiate;
214
    }
215

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

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

    
240
        public void setDimension(int dim) {
241
                dimension = dim;
242
        }
243
        public String getHost() {
244
                return host;
245
        }
246
        public void setHost(String host){
247
                this.host=host;
248
        }
249
        public int getPort() {
250
                return port;
251
        }
252
        public void setPort(int port){
253
                this.port=port;
254
        }
255
        public String getDataBase() {
256
                return database;
257
        }
258
        public void setDataBase(String database){
259
                this.database=database;
260
        }
261
        public String getUser() {
262
                return user;
263
        }
264
        public void setUser(String user){
265
                this.user=user;
266
        }
267
        public String getPassword() {
268
                return password;
269
        }
270
        public void setPassword(String password){
271
                this.password=password;
272
        }
273
        public void setConnectionName(String stringProperty) {
274
                this.connectionname=stringProperty;
275
        }
276
        public String getConnectionName() {
277
                return connectionname;
278
        }
279
        public void setSchema(String schema) {
280
                this.schema = schema;
281
        }
282
        public String getSchema() {
283
                return schema;
284
        }
285
        /**
286
         * @return "schema"."tableName" or only "tableName" if schema is not defined. schema and tableName are quoted
287
         */
288
        public String getComposedTableName() {
289
                String quote = conn.getIdentifierQuoteString();
290

    
291
                String compoundTable = "";
292
                if (getSchema()!=null && !getSchema().equals("")){
293
                        compoundTable = quote + getSchema() + quote + ".";
294
                }
295
                compoundTable = compoundTable + quote + getTableName() + quote;
296
                return compoundTable;
297
        }
298
        public void setIdFieldID(int idFieldID) {
299
                this.idFieldID = idFieldID;
300
        }
301
}