root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / driver / FieldDescription.java @ 21606
History | View | Annotate | Download (5.21 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 |
/************************************************
|
45 |
* *
|
46 |
* Modfied By: *
|
47 |
* Prodevelop Integraci?n de Tecnolog?as SL *
|
48 |
* Conde Salvatierra de ?lava , 34-10 *
|
49 |
* 46004 Valencia *
|
50 |
* Spain *
|
51 |
* *
|
52 |
* +34 963 510 612 *
|
53 |
* +34 963 510 968 *
|
54 |
* gis@prodevelop.es *
|
55 |
* http://www.prodevelop.es *
|
56 |
* *
|
57 |
* gvSIG Mobile Team 2006 *
|
58 |
* *
|
59 |
************************************************/
|
60 |
|
61 |
package es.prodevelop.gvsig.mobile.fmap.driver; |
62 |
|
63 |
import java.sql.Types; |
64 |
|
65 |
import com.hardcode.gdbms.engine.values.NullValue; |
66 |
import com.hardcode.gdbms.engine.values.Value; |
67 |
|
68 |
/**
|
69 |
* This class stores the metadata of a particular field
|
70 |
* @author iver
|
71 |
*
|
72 |
*/
|
73 |
public class FieldDescription { |
74 |
|
75 |
public static int stringToType(String strType) { |
76 |
int type = -1; |
77 |
if (strType.equals("String")) |
78 |
type = Types.VARCHAR;
|
79 |
if (strType.equals("Double")) |
80 |
type = Types.DOUBLE;
|
81 |
if (strType.equals("Integer")) |
82 |
type = Types.INTEGER;
|
83 |
if (strType.equals("Boolean")) |
84 |
type = Types.BOOLEAN;
|
85 |
if (strType.equals("Date")) |
86 |
type = Types.DATE;
|
87 |
|
88 |
if (type == -1) { |
89 |
throw new RuntimeException("Type not recognized: " + strType); |
90 |
} |
91 |
return type;
|
92 |
|
93 |
} |
94 |
|
95 |
public static String typeToString(int sqlType) { |
96 |
switch (sqlType) {
|
97 |
case Types.NUMERIC: |
98 |
case Types.BIGINT: |
99 |
case Types.INTEGER: |
100 |
case Types.SMALLINT: |
101 |
case Types.TINYINT: |
102 |
return "Integer"; |
103 |
|
104 |
case Types.BIT: |
105 |
return "Boolean"; |
106 |
|
107 |
case Types.CHAR: |
108 |
case Types.VARCHAR: |
109 |
case Types.LONGVARCHAR: |
110 |
return "String"; |
111 |
|
112 |
case Types.DATE: |
113 |
return "Date"; |
114 |
|
115 |
case Types.FLOAT: |
116 |
case Types.DOUBLE: |
117 |
case Types.DECIMAL: |
118 |
case Types.REAL: |
119 |
return "Double"; |
120 |
|
121 |
case Types.BINARY: |
122 |
case Types.VARBINARY: |
123 |
case Types.LONGVARBINARY: |
124 |
return "Binary"; |
125 |
|
126 |
case Types.TIMESTAMP: |
127 |
return "Timestamp"; |
128 |
|
129 |
case Types.TIME: |
130 |
return "Time"; |
131 |
|
132 |
case Types.OTHER: |
133 |
default:
|
134 |
throw new RuntimeException("Type not recognized: " + sqlType); |
135 |
} |
136 |
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Internal field name.
|
141 |
*/
|
142 |
private String fieldName; |
143 |
|
144 |
private String fieldAlias; |
145 |
|
146 |
private int fieldType; |
147 |
|
148 |
private Value defaultValue = new NullValue(); |
149 |
|
150 |
/**
|
151 |
* En campos num?ricos, numero de d?gitos a la izquierda del punto En campos
|
152 |
* de texto, numero de caracteres.
|
153 |
*/
|
154 |
private int fieldLength = 8; |
155 |
|
156 |
/**
|
157 |
* En campos num?ricos, numero de d?gitos a la derecha del punto.
|
158 |
*/
|
159 |
private int fieldDecimalCount = 0; |
160 |
|
161 |
/**
|
162 |
* @return Returns the fieldDecimalCount.
|
163 |
*/
|
164 |
public int getFieldDecimalCount() { |
165 |
return fieldDecimalCount;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* @param fieldDecimalCount
|
170 |
* The fieldDecimalCount to set.
|
171 |
*/
|
172 |
public void setFieldDecimalCount(int fieldDecimalCount) { |
173 |
this.fieldDecimalCount = fieldDecimalCount;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* @return Returns the fieldLength.
|
178 |
*/
|
179 |
public int getFieldLength() { |
180 |
return fieldLength;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* @param fieldLength
|
185 |
* The fieldLength to set.
|
186 |
*/
|
187 |
public void setFieldLength(int fieldLength) { |
188 |
this.fieldLength = fieldLength;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* @return Returns the fieldName.
|
193 |
*/
|
194 |
public String getFieldName() { |
195 |
return fieldName;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* @param fieldName
|
200 |
* The fieldName to set.
|
201 |
*/
|
202 |
public void setFieldName(String fieldName) { |
203 |
this.fieldName = fieldName;
|
204 |
this.fieldAlias = fieldName;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* @return Returns the fieldType.
|
209 |
*/
|
210 |
public int getFieldType() { |
211 |
return fieldType;
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* @param fieldType
|
216 |
* The fieldType to set.
|
217 |
*/
|
218 |
public void setFieldType(int fieldType) { |
219 |
this.fieldType = fieldType;
|
220 |
} |
221 |
|
222 |
public String getFieldAlias() { |
223 |
return fieldAlias;
|
224 |
} |
225 |
|
226 |
public void setFieldAlias(String fieldAlias) { |
227 |
this.fieldAlias = fieldAlias;
|
228 |
} |
229 |
|
230 |
public FieldDescription cloneField() {
|
231 |
FieldDescription resul = new FieldDescription();
|
232 |
resul.fieldAlias = fieldAlias; |
233 |
resul.fieldName = fieldName; |
234 |
resul.fieldDecimalCount = fieldDecimalCount; |
235 |
resul.fieldType = fieldType; |
236 |
return resul;
|
237 |
} |
238 |
|
239 |
public Value getDefaultValue() {
|
240 |
return defaultValue;
|
241 |
} |
242 |
|
243 |
public void setDefaultValue(Value defaultValue) { |
244 |
this.defaultValue = defaultValue;
|
245 |
} |
246 |
|
247 |
} |