svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / FieldDescription.java @ 11051
History | View | Annotate | Download (4.7 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 String toString() { |
54 |
return getFieldAlias();
|
55 |
} |
56 |
|
57 |
public static int stringToType(String strType) { |
58 |
int type = -1; |
59 |
if (strType.equals("String")) |
60 |
type = Types.VARCHAR;
|
61 |
if (strType.equals("Double")) |
62 |
type = Types.DOUBLE;
|
63 |
if (strType.equals("Integer")) |
64 |
type = Types.INTEGER;
|
65 |
if (strType.equals("Boolean")) |
66 |
type = Types.BOOLEAN;
|
67 |
if (strType.equals("Date")) |
68 |
type = Types.DATE;
|
69 |
|
70 |
if (type == -1) { |
71 |
throw new RuntimeException("Type not recognized: " + strType); |
72 |
} |
73 |
return type;
|
74 |
|
75 |
} |
76 |
|
77 |
public static String typeToString(int sqlType) { |
78 |
switch (sqlType) {
|
79 |
case Types.NUMERIC: |
80 |
case Types.BIGINT: |
81 |
case Types.INTEGER: |
82 |
case Types.SMALLINT: |
83 |
case Types.TINYINT: |
84 |
return "Integer"; |
85 |
|
86 |
case Types.BIT: |
87 |
return "Boolean"; |
88 |
|
89 |
case Types.CHAR: |
90 |
case Types.VARCHAR: |
91 |
case Types.LONGVARCHAR: |
92 |
return "String"; |
93 |
|
94 |
case Types.DATE: |
95 |
return "Date"; |
96 |
|
97 |
case Types.FLOAT: |
98 |
case Types.DOUBLE: |
99 |
case Types.DECIMAL: |
100 |
case Types.REAL: |
101 |
return "Double"; |
102 |
|
103 |
case Types.BINARY: |
104 |
case Types.VARBINARY: |
105 |
case Types.LONGVARBINARY: |
106 |
return "Binary"; |
107 |
|
108 |
case Types.TIMESTAMP: |
109 |
return "Timestamp"; |
110 |
|
111 |
case Types.TIME: |
112 |
return "Time"; |
113 |
|
114 |
case Types.OTHER: |
115 |
default:
|
116 |
throw new RuntimeException("Type not recognized: " + sqlType); |
117 |
} |
118 |
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* Internal field name.
|
123 |
*/
|
124 |
private String fieldName; |
125 |
|
126 |
private String fieldAlias; |
127 |
|
128 |
private int fieldType; |
129 |
|
130 |
private Value defaultValue = new NullValue(); |
131 |
|
132 |
/**
|
133 |
* En campos num?ricos, numero de d?gitos a la izquierda del punto En campos
|
134 |
* de texto, numero de caracteres.
|
135 |
*/
|
136 |
private int fieldLength = 8; |
137 |
|
138 |
/**
|
139 |
* En campos num?ricos, numero de d?gitos a la derecha del punto.
|
140 |
*/
|
141 |
private int fieldDecimalCount = 0; |
142 |
|
143 |
/**
|
144 |
* @return Returns the fieldDecimalCount.
|
145 |
*/
|
146 |
public int getFieldDecimalCount() { |
147 |
return fieldDecimalCount;
|
148 |
} |
149 |
|
150 |
/**
|
151 |
* @param fieldDecimalCount
|
152 |
* The fieldDecimalCount to set.
|
153 |
*/
|
154 |
public void setFieldDecimalCount(int fieldDecimalCount) { |
155 |
this.fieldDecimalCount = fieldDecimalCount;
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* @return Returns the fieldLength.
|
160 |
*/
|
161 |
public int getFieldLength() { |
162 |
return fieldLength;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* @param fieldLength
|
167 |
* The fieldLength to set.
|
168 |
*/
|
169 |
public void setFieldLength(int fieldLength) { |
170 |
this.fieldLength = fieldLength;
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* @return Returns the fieldName.
|
175 |
*/
|
176 |
public String getFieldName() { |
177 |
return fieldName;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* @param fieldName
|
182 |
* The fieldName to set.
|
183 |
*/
|
184 |
public void setFieldName(String fieldName) { |
185 |
this.fieldName = fieldName;
|
186 |
this.fieldAlias = fieldName;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* @return Returns the fieldType.
|
191 |
*/
|
192 |
public int getFieldType() { |
193 |
return fieldType;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @param fieldType
|
198 |
* The fieldType to set.
|
199 |
*/
|
200 |
public void setFieldType(int fieldType) { |
201 |
this.fieldType = fieldType;
|
202 |
} |
203 |
|
204 |
public String getFieldAlias() { |
205 |
return fieldAlias;
|
206 |
} |
207 |
|
208 |
public void setFieldAlias(String fieldAlias) { |
209 |
this.fieldAlias = fieldAlias;
|
210 |
} |
211 |
|
212 |
public FieldDescription cloneField() {
|
213 |
FieldDescription resul = new FieldDescription();
|
214 |
resul.fieldAlias = fieldAlias; |
215 |
resul.fieldName = fieldName; |
216 |
resul.fieldDecimalCount = fieldDecimalCount; |
217 |
resul.fieldType = fieldType; |
218 |
return resul;
|
219 |
} |
220 |
|
221 |
public Value getDefaultValue() {
|
222 |
return defaultValue;
|
223 |
} |
224 |
|
225 |
public void setDefaultValue(Value defaultValue) { |
226 |
this.defaultValue = defaultValue;
|
227 |
} |
228 |
|
229 |
} |