Statistics
| Revision:

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

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

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

    
235
        public void setDimension(int dim) {
236
                dimension = dim;
237
        }
238
        public void setSchema(String schema) {
239
                this.schema = schema;         
240
        }
241
        public String getSchema() {
242
                return schema;
243
        }
244
        /**
245
         * @return schema.tableName or only tableName if schema is not defined
246
         */
247
        public String getComposedTableName() {
248
                String compoundTable = getSchema()!=null?(getSchema() + "." + getTableName()):getTableName();
249
                return compoundTable;
250
        }
251
        
252
}