Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_905 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / FieldDescription.java @ 10767

History | View | Annotate | Download (4.64 KB)

1 3207 fjp
/*
2
 * Created on 27-oct-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5 6595 jaume
 *
6 3207 fjp
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7 6595 jaume
 *
8 3207 fjp
 * 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 6595 jaume
 *
13 3207 fjp
 * 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 6595 jaume
 *
18 3207 fjp
 * 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 6595 jaume
 *
22 3207 fjp
 * 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 6595 jaume
 *
34 3207 fjp
 *    or
35 6595 jaume
 *
36 3207 fjp
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40 6595 jaume
 *
41 3207 fjp
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.cit.gvsig.fmap.drivers;
45
46 6458 fjp
import java.sql.Types;
47
48 6212 fjp
import com.hardcode.gdbms.engine.values.NullValue;
49
import com.hardcode.gdbms.engine.values.Value;
50
51 3207 fjp
public class FieldDescription {
52
53 6458 fjp
        public static int stringToType(String strType) {
54
                int type = -1;
55
                if (strType.equals("String"))
56
                        type = Types.VARCHAR;
57
                if (strType.equals("Double"))
58
                        type = Types.DOUBLE;
59
                if (strType.equals("Integer"))
60
                        type = Types.INTEGER;
61
                if (strType.equals("Boolean"))
62
                        type = Types.BOOLEAN;
63
                if (strType.equals("Date"))
64
                        type = Types.DATE;
65 3207 fjp
66 6458 fjp
                if (type == -1) {
67
                        throw new RuntimeException("Type not recognized: " + strType);
68
                }
69
                return type;
70 3207 fjp
71 6458 fjp
        }
72 3207 fjp
73 6458 fjp
        public static String typeToString(int sqlType) {
74
                switch (sqlType) {
75
                case Types.NUMERIC:
76
                case Types.BIGINT:
77 6595 jaume
                case Types.INTEGER:
78
                case Types.SMALLINT:
79
                case Types.TINYINT:
80 6458 fjp
                        return "Integer";
81 3207 fjp
82 6458 fjp
                case Types.BIT:
83
                        return "Boolean";
84 3207 fjp
85 6458 fjp
                case Types.CHAR:
86
                case Types.VARCHAR:
87
                case Types.LONGVARCHAR:
88
                        return "String";
89 3207 fjp
90 6458 fjp
                case Types.DATE:
91
                        return "Date";
92
93
                case Types.FLOAT:
94
                case Types.DOUBLE:
95
                case Types.DECIMAL:
96
                case Types.REAL:
97
                        return "Double";
98
99
                case Types.BINARY:
100
                case Types.VARBINARY:
101
                case Types.LONGVARBINARY:
102
                        return "Binary";
103
104
                case Types.TIMESTAMP:
105
                        return "Timestamp";
106
107
                case Types.TIME:
108
                        return "Time";
109
110
                case Types.OTHER:
111
                default:
112
                        throw new RuntimeException("Type not recognized: " + sqlType);
113 6595 jaume
                }
114 6458 fjp
115
        }
116
117
        /**
118
         * Internal field name.
119
         */
120
        private String fieldName;
121
122
        private String fieldAlias;
123
124
        private int fieldType;
125
126
        private Value defaultValue = new NullValue();
127
128
        /**
129
         * En campos num?ricos, numero de d?gitos a la izquierda del punto En campos
130
         * de texto, numero de caracteres.
131
         */
132 8765 jjdelcerro
        private int fieldLength = 8;
133 6458 fjp
134
        /**
135
         * En campos num?ricos, numero de d?gitos a la derecha del punto.
136
         */
137 8765 jjdelcerro
        private int fieldDecimalCount = 0;
138 6458 fjp
139
        /**
140
         * @return Returns the fieldDecimalCount.
141
         */
142
        public int getFieldDecimalCount() {
143
                return fieldDecimalCount;
144
        }
145
146
        /**
147
         * @param fieldDecimalCount
148
         *            The fieldDecimalCount to set.
149
         */
150
        public void setFieldDecimalCount(int fieldDecimalCount) {
151
                this.fieldDecimalCount = fieldDecimalCount;
152
        }
153
154
        /**
155
         * @return Returns the fieldLength.
156
         */
157
        public int getFieldLength() {
158
                return fieldLength;
159
        }
160
161
        /**
162
         * @param fieldLength
163
         *            The fieldLength to set.
164
         */
165
        public void setFieldLength(int fieldLength) {
166
                this.fieldLength = fieldLength;
167
        }
168
169
        /**
170
         * @return Returns the fieldName.
171
         */
172
        public String getFieldName() {
173
                return fieldName;
174
        }
175
176
        /**
177
         * @param fieldName
178
         *            The fieldName to set.
179
         */
180
        public void setFieldName(String fieldName) {
181
                this.fieldName = fieldName;
182
                this.fieldAlias = fieldName;
183
        }
184
185
        /**
186
         * @return Returns the fieldType.
187
         */
188
        public int getFieldType() {
189
                return fieldType;
190
        }
191
192
        /**
193
         * @param fieldType
194
         *            The fieldType to set.
195
         */
196
        public void setFieldType(int fieldType) {
197
                this.fieldType = fieldType;
198
        }
199
200 6093 fjp
        public String getFieldAlias() {
201
                return fieldAlias;
202
        }
203
204
        public void setFieldAlias(String fieldAlias) {
205
                this.fieldAlias = fieldAlias;
206
        }
207 6458 fjp
208 6093 fjp
        public FieldDescription cloneField() {
209
                FieldDescription resul = new FieldDescription();
210
                resul.fieldAlias = fieldAlias;
211
                resul.fieldName = fieldName;
212
                resul.fieldDecimalCount = fieldDecimalCount;
213
                resul.fieldType = fieldType;
214
                return resul;
215
        }
216
217 6212 fjp
        public Value getDefaultValue() {
218
                return defaultValue;
219
        }
220
221
        public void setDefaultValue(Value defaultValue) {
222
                this.defaultValue = defaultValue;
223
        }
224
225 3207 fjp
}