Statistics
| Revision:

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

History | View | Annotate | Download (4.64 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
public class FieldDescription {
52

    
53
        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

    
66
                if (type == -1) {
67
                        throw new RuntimeException("Type not recognized: " + strType);
68
                }
69
                return type;
70

    
71
        }
72

    
73
        public static String typeToString(int sqlType) {
74
                switch (sqlType) {
75
                case Types.NUMERIC:
76
                case Types.BIGINT:
77
                case Types.INTEGER:
78
                case Types.SMALLINT:
79
                case Types.TINYINT:
80
                        return "Integer";
81

    
82
                case Types.BIT:
83
                        return "Boolean";
84

    
85
                case Types.CHAR:
86
                case Types.VARCHAR:
87
                case Types.LONGVARCHAR:
88
                        return "String";
89

    
90
                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
                }
114

    
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
        private int fieldLength = 8;
133

    
134
        /**
135
         * En campos num?ricos, numero de d?gitos a la derecha del punto.
136
         */
137
        private int fieldDecimalCount = 0;
138

    
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
        public String getFieldAlias() {
201
                return fieldAlias;
202
        }
203

    
204
        public void setFieldAlias(String fieldAlias) {
205
                this.fieldAlias = fieldAlias;
206
        }
207

    
208
        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
        public Value getDefaultValue() {
218
                return defaultValue;
219
        }
220

    
221
        public void setDefaultValue(Value defaultValue) {
222
                this.defaultValue = defaultValue;
223
        }
224

    
225
}