Statistics
| Revision:

root / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / FieldDescription.java @ 10450

History | View | Annotate | Download (5.52 KB)

1
/*
2
 * Created on 27-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.sql.Types;
47

    
48
import com.hardcode.gdbms.engine.values.NullValue;
49
import com.hardcode.gdbms.engine.values.Value;
50

    
51
/**
52
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
53
 */
54
public class FieldDescription {
55

    
56
        public String toString() {
57
                return getFieldAlias();
58
        }
59

    
60
        public static int stringToType(String strType) {
61
                int type = -1;
62
                if (strType.equals("String"))
63
                        type = Types.VARCHAR;
64
                if (strType.equals("Double"))
65
                        type = Types.DOUBLE;
66
                if (strType.equals("Integer"))
67
                        type = Types.INTEGER;
68
                if (strType.equals("Boolean"))
69
                        type = Types.BOOLEAN;
70
                if (strType.equals("Date"))
71
                        type = Types.DATE;
72

    
73
                if (type == -1) {
74
                        throw new RuntimeException("Type not recognized: " + strType);
75
                }
76
                return type;
77

    
78
        }
79

    
80
        public static String typeToString(int sqlType) {
81
                switch (sqlType) {
82
                case Types.NUMERIC:
83
                case Types.BIGINT:
84
                case Types.INTEGER:
85
                case Types.SMALLINT:
86
                case Types.TINYINT:
87
                        return "Integer";
88

    
89
                case Types.BIT:
90
                        return "Boolean";
91

    
92
                case Types.CHAR:
93
                case Types.VARCHAR:
94
                case Types.LONGVARCHAR:
95
                        return "String";
96

    
97
                case Types.DATE:
98
                        return "Date";
99

    
100
                case Types.FLOAT:
101
                case Types.DOUBLE:
102
                case Types.DECIMAL:
103
                case Types.REAL:
104
                        return "Double";
105

    
106
                case Types.BINARY:
107
                case Types.VARBINARY:
108
                case Types.LONGVARBINARY:
109
                        return "Binary";
110

    
111
                case Types.TIMESTAMP:
112
                        return "Timestamp";
113

    
114
                case Types.TIME:
115
                        return "Time";
116

    
117
                case Types.OTHER:
118
                default:
119
                        throw new RuntimeException("Type not recognized: " + sqlType);
120
                }
121

    
122
        }
123

    
124
        /**
125
         * Internal field name.
126
         * @uml.property  name="fieldName"
127
         */
128
        private String fieldName;
129

    
130
        /**
131
         * @uml.property  name="fieldAlias"
132
         */
133
        private String fieldAlias;
134

    
135
        /**
136
         * @uml.property  name="fieldType"
137
         */
138
        private int fieldType;
139

    
140
        /**
141
         * @uml.property  name="defaultValue"
142
         */
143
        private Value defaultValue = new NullValue();
144

    
145
        /**
146
         * En campos num?ricos, numero de d?gitos a la izquierda del punto En campos de texto, numero de caracteres.
147
         * @uml.property  name="fieldLength"
148
         */
149
        private int fieldLength = 8;
150

    
151
        /**
152
         * En campos num?ricos, numero de d?gitos a la derecha del punto.
153
         * @uml.property  name="fieldDecimalCount"
154
         */
155
        private int fieldDecimalCount = 0;
156

    
157
        /**
158
         * @return  Returns the fieldDecimalCount.
159
         * @uml.property  name="fieldDecimalCount"
160
         */
161
        public int getFieldDecimalCount() {
162
                return fieldDecimalCount;
163
        }
164

    
165
        /**
166
         * @param fieldDecimalCount  The fieldDecimalCount to set.
167
         * @uml.property  name="fieldDecimalCount"
168
         */
169
        public void setFieldDecimalCount(int fieldDecimalCount) {
170
                this.fieldDecimalCount = fieldDecimalCount;
171
        }
172

    
173
        /**
174
         * @return  Returns the fieldLength.
175
         * @uml.property  name="fieldLength"
176
         */
177
        public int getFieldLength() {
178
                return fieldLength;
179
        }
180

    
181
        /**
182
         * @param fieldLength  The fieldLength to set.
183
         * @uml.property  name="fieldLength"
184
         */
185
        public void setFieldLength(int fieldLength) {
186
                this.fieldLength = fieldLength;
187
        }
188

    
189
        /**
190
         * @return  Returns the fieldName.
191
         * @uml.property  name="fieldName"
192
         */
193
        public String getFieldName() {
194
                return fieldName;
195
        }
196

    
197
        /**
198
         * @param fieldName  The fieldName to set.
199
         * @uml.property  name="fieldName"
200
         */
201
        public void setFieldName(String fieldName) {
202
                this.fieldName = fieldName;
203
                this.fieldAlias = fieldName;
204
        }
205

    
206
        /**
207
         * @return  Returns the fieldType.
208
         * @uml.property  name="fieldType"
209
         */
210
        public int getFieldType() {
211
                return fieldType;
212
        }
213

    
214
        /**
215
         * @param fieldType  The fieldType to set.
216
         * @uml.property  name="fieldType"
217
         */
218
        public void setFieldType(int fieldType) {
219
                this.fieldType = fieldType;
220
        }
221

    
222
        /**
223
         * @return
224
         * @uml.property  name="fieldAlias"
225
         */
226
        public String getFieldAlias() {
227
                return fieldAlias;
228
        }
229

    
230
        /**
231
         * @param fieldAlias
232
         * @uml.property  name="fieldAlias"
233
         */
234
        public void setFieldAlias(String fieldAlias) {
235
                this.fieldAlias = fieldAlias;
236
        }
237

    
238
        public FieldDescription cloneField() {
239
                FieldDescription resul = new FieldDescription();
240
                resul.fieldAlias = fieldAlias;
241
                resul.fieldName = fieldName;
242
                resul.fieldDecimalCount = fieldDecimalCount;
243
                resul.fieldType = fieldType;
244
                return resul;
245
        }
246

    
247
        /**
248
         * @return
249
         * @uml.property  name="defaultValue"
250
         */
251
        public Value getDefaultValue() {
252
                return defaultValue;
253
        }
254

    
255
        /**
256
         * @param defaultValue
257
         * @uml.property  name="defaultValue"
258
         */
259
        public void setDefaultValue(Value defaultValue) {
260
                this.defaultValue = defaultValue;
261
        }
262

    
263
}