Statistics
| Revision:

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

History | View | Annotate | Download (6.39 KB)

1 3207 fjp
/*
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 4740 fjp
import java.sql.Connection;
48 4755 fjp
import java.sql.Types;
49 3207 fjp
50 4755 fjp
import com.hardcode.gdbms.engine.instruction.Field;
51
52 3207 fjp
public class DBLayerDefinition extends LayerDefinition {
53 4740 fjp
        private Connection conn;
54 3207 fjp
    private String catalogName;
55
    private String tableName;
56 3977 fjp
    // private String[] fieldNames; // GeometryField not included
57 3207 fjp
    private String fieldID; // Estos 2 campos en PostGIS los sabremos
58
    private String fieldGeometry; // (gid y the_geom), pero por si acaso se cambian
59
    private String whereClause;
60
    private Rectangle2D workingArea;
61
    private String SRID_EPSG;
62 3236 fjp
    private String classToInstantiate;
63
64 3207 fjp
    // private int idFieldGeometry = -1;
65
    private int idFieldID = -1;
66 4740 fjp
        private int dimension = 2;
67 3207 fjp
68
    public String getCatalogName() {
69
        return catalogName;
70
    }
71
    public void setCatalogName(String catalogName) {
72
        this.catalogName = catalogName;
73
    }
74
    public String getFieldGeometry() {
75
        return fieldGeometry;
76
    }
77
    public void setFieldGeometry(String fieldGeometry) {
78
        this.fieldGeometry = fieldGeometry;
79
    }
80
    public String getFieldID() {
81
        return fieldID;
82
    }
83 5747 fjp
    /**
84
     * @param fieldID
85
     */
86 3207 fjp
    public void setFieldID(String fieldID) {
87
        this.fieldID = fieldID;
88 5747 fjp
        // No se usa lo de a?adir el id por otro lado.
89
        // Se hace en MyFinishAction
90
        /* boolean bFound = false;
91
            for (int i=0; i< fieldsDesc.length; i++)
92
            {
93
                    if (fieldsDesc[i].getFieldName().compareToIgnoreCase(fieldID) == 0)
94
                            bFound = true;
95
            }
96
        if (bFound != true)
97
        {
98
                int length = fieldsDesc.length;
99
                FieldDescription[] aux = new FieldDescription[length+1];
100
                System.arraycopy(fieldsDesc, 0, aux, 0, length);
101
                FieldDescription f = new FieldDescription();
102
                aux[length] = field
103
        } */
104 3207 fjp
    }
105
    /**
106
     * @return GeometryField is not included in this list
107
     */
108
    public String[] getFieldNames() {
109 3977 fjp
            String[] fieldNames = new String[fieldsDesc.length];
110
            for (int i=0; i< fieldsDesc.length; i++)
111
            {
112
                    fieldNames[i] = fieldsDesc[i].getFieldName();
113
            }
114 3207 fjp
        return fieldNames;
115
    }
116
    /**
117
     * Geometry field not included in this list
118
     * @param fieldNames
119
     */
120
    public void setFieldNames(String[] fieldNames) {
121
        idFieldID = -1;
122
        // idFieldGeometry = -1;
123 3977 fjp
        if (fieldsDesc == null)
124
                fieldsDesc = new FieldDescription[fieldNames.length];
125
        if (fieldsDesc.length != fieldNames.length)
126
                fieldsDesc = new FieldDescription[fieldNames.length];
127
        for (int i=0; i < fieldNames.length; i++)
128 4096 fjp
        {
129
                fieldsDesc[i] = new FieldDescription();
130 3977 fjp
                fieldsDesc[i].setFieldName(fieldNames[i]);
131 4096 fjp
        }
132 3207 fjp
    }
133
    public String getTableName() {
134
        return tableName;
135
    }
136
    public void setTableName(String tableName) {
137
        this.tableName = tableName;
138
    }
139 3236 fjp
    /**
140 3248 fjp
     * The returned string must contain "WHERE " clause
141 3236 fjp
     * @return
142
     */
143 3207 fjp
    public String getWhereClause() {
144
        return whereClause;
145
    }
146
    public void setWhereClause(String whereClause) {
147
        this.whereClause = whereClause;
148
    }
149
    public Rectangle2D getWorkingArea() {
150
        return workingArea;
151
    }
152
    public void setWorkingArea(Rectangle2D workingArea) {
153
        this.workingArea = workingArea;
154
    }
155
156
    /**
157
     * @param fieldName
158
     * @return index of field (0 based). -1 if not found
159
     */
160
    public int getIdField(String fieldName)
161
    {
162
        int result = -1;
163 3977 fjp
        for (int i=0; i < fieldsDesc.length; i++)
164 3207 fjp
        {
165 3977 fjp
            if (fieldName.equalsIgnoreCase(fieldsDesc[i].getFieldName()))
166 3207 fjp
            {
167
                result = i;
168
                break;
169
            }
170
        }
171
        return result;
172
    }
173
174
    /**
175 3248 fjp
     * 0 based index of the ID field
176 3207 fjp
     * @return Returns the idFieldID.
177
     */
178
    public int getIdFieldID() {
179
        if (idFieldID == -1)
180
            idFieldID = getIdField(fieldID);
181
        return idFieldID;
182
    }
183
    /**
184
     * @return Returns the sRID_EPSG.
185
     */
186
    public String getSRID_EPSG() {
187
        return SRID_EPSG;
188
    }
189
    /**
190
     * @param srid_epsg The sRID_EPSG to set.
191
     */
192
    public void setSRID_EPSG(String srid_epsg) {
193
        SRID_EPSG = srid_epsg;
194
    }
195 3236 fjp
    /**
196
     * @return Returns the classToInstantiate.
197
     */
198
    public String getClassToInstantiate() {
199
        return classToInstantiate;
200
    }
201
    /**
202
     * @param classToInstantiate The classToInstantiate to set.
203
     */
204
    public void setClassToInstantiate(String classToInstantiate) {
205
        this.classToInstantiate = classToInstantiate;
206
    }
207 3347 fjp
208
    public int getFieldIdByName(String name)
209
    {
210
        int resul = -1;
211 3977 fjp
        for (int i=0; i<fieldsDesc.length; i++)
212 3347 fjp
        {
213 6033 fjp
            if (fieldsDesc[i].getFieldName().equalsIgnoreCase(name))
214 3347 fjp
            {
215
                resul = i;
216
                break;
217
            }
218
        }
219
        return resul;
220
    }
221 4740 fjp
        public Connection getConnection() {
222 4748 fjp
                return conn;
223 4740 fjp
        }
224
225
        public void setConnection(Connection connection) {
226
                conn = connection;
227
        }
228
        public int getDimension() {
229
                return dimension;
230
        }
231
232
        public void setDimension(int dim) {
233
                dimension = dim;
234
        }
235
236 3207 fjp
}