root / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / schemabuilder / XTypes.java @ 4152
History | View | Annotate | Download (6.62 KB)
1 |
/*
|
---|---|
2 |
* Created on 07-feb-2006
|
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 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: XTypes.java 4152 2006-02-17 16:39:24Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.3 2006-02-17 16:34:00 azabala
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.2 2006/02/13 18:37:41 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.1 2006/02/09 15:59:48 azabala
|
55 |
* First version in CVS
|
56 |
*
|
57 |
*
|
58 |
*/
|
59 |
package com.iver.gvsig.geoprocessing.schemabuilder; |
60 |
|
61 |
import java.sql.Types; |
62 |
import java.util.Date; |
63 |
|
64 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
65 |
import com.hardcode.gdbms.engine.values.DateValue; |
66 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
67 |
import com.hardcode.gdbms.engine.values.FloatValue; |
68 |
import com.hardcode.gdbms.engine.values.IntValue; |
69 |
import com.hardcode.gdbms.engine.values.LongValue; |
70 |
import com.hardcode.gdbms.engine.values.StringValue; |
71 |
import com.hardcode.gdbms.engine.values.Value; |
72 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
73 |
|
74 |
/**
|
75 |
* This is a similar try to com.iver.cit.gvsig.jdbc_spatial.XTypes to do a Types
|
76 |
* management in GvSig
|
77 |
*
|
78 |
* @author azabala
|
79 |
*
|
80 |
*/
|
81 |
public abstract class XTypes { |
82 |
// Geometry types
|
83 |
public final static int SHAPE_NULL = 0; |
84 |
public final static int POINT = 1; |
85 |
public final static int LINE = 2; |
86 |
public final static int POLYGON = 4; |
87 |
public final static int TEXT = 8; |
88 |
public final static int MULTI = 16; |
89 |
public final static int MULTIPOINT = 32; |
90 |
public final static int CIRCLE = 64; |
91 |
public final static int ARC = 128; |
92 |
public final static int ELLIPSE = 256; |
93 |
public final static int Z = 512; |
94 |
|
95 |
public static final int BIT = Types.BIT; |
96 |
public static final int TINYINT = Types.TINYINT; |
97 |
public static final int SMALLINT = Types.SMALLINT; |
98 |
public static final int INTEGER = Types.INTEGER; |
99 |
public static final int BIGINT = Types.BIGINT; |
100 |
public static final int FLOAT = Types.FLOAT; |
101 |
public static final int REAL = Types.REAL; |
102 |
public static final int DOUBLE = Types.DOUBLE; |
103 |
public static final int NUMERIC = Types.NUMERIC; |
104 |
public static final int DECIMAL = Types.DECIMAL; |
105 |
public static final int CHAR = Types.CHAR; |
106 |
public static final int VARCHAR = Types.VARCHAR; |
107 |
public static final int LONGVARCHAR = Types.LONGVARCHAR; |
108 |
public static final int DATE = Types.DATE; |
109 |
public static final int TIME = Types.TIME; |
110 |
public static final int TIMESTAMP = Types.TIMESTAMP; |
111 |
public static final int BINARY = Types.BINARY; |
112 |
public static final int VARBINARY = Types.VARBINARY; |
113 |
public static final int LONGVARBINARY = Types.LONGVARBINARY; |
114 |
public static final int NULL = Types.NULL; |
115 |
public static final int OTHER = Types.OTHER; |
116 |
public static final int JAVA_OBJECT = Types.JAVA_OBJECT; |
117 |
public static final int DISTINCT = Types.DISTINCT; |
118 |
public static final int STRUCT = Types.STRUCT; |
119 |
public static final int ARRAY = Types.ARRAY; |
120 |
public static final int BLOB = Types.BLOB; |
121 |
public static final int CLOB = Types.CLOB; |
122 |
public static final int REF = Types.REF; |
123 |
public static final int DATALINK = Types.DATALINK; |
124 |
public static final int BOOLEAN = Types.BOOLEAN; |
125 |
|
126 |
public static boolean isNumeric(int fieldType) { |
127 |
switch (fieldType) {
|
128 |
case DOUBLE:
|
129 |
case FLOAT:
|
130 |
case INTEGER:
|
131 |
case SMALLINT:
|
132 |
case BIGINT:
|
133 |
case NUMERIC:
|
134 |
case REAL:
|
135 |
case TINYINT:
|
136 |
case DECIMAL:
|
137 |
return true; |
138 |
} |
139 |
return false; |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Convert an int data type in a text sql type. Is abstract because it will
|
144 |
* be strongly dependant of sql rdbms.
|
145 |
*
|
146 |
* @param fieldType
|
147 |
* @return
|
148 |
*/
|
149 |
public abstract String fieldTypeToString(int fieldType); |
150 |
|
151 |
|
152 |
|
153 |
public static Object getObject(Value value, int fieldType){ |
154 |
Object solution = null; |
155 |
switch (fieldType) {
|
156 |
case Types.VARCHAR: |
157 |
StringValue str = (StringValue) value; |
158 |
solution = str.getValue(); |
159 |
break;
|
160 |
case Types.FLOAT: |
161 |
FloatValue fval = (FloatValue) value; |
162 |
solution = new Float(fval.floatValue()); |
163 |
break;
|
164 |
case Types.DOUBLE: |
165 |
DoubleValue dval = (DoubleValue)value; |
166 |
solution = new Double(dval.doubleValue()); |
167 |
break;
|
168 |
case Types.INTEGER: |
169 |
IntValue intval = (IntValue)value; |
170 |
solution = new Integer(intval.intValue()); |
171 |
break;
|
172 |
case Types.BIGINT: |
173 |
LongValue lval = (LongValue) value; |
174 |
solution = new Long(lval.longValue()); |
175 |
break;
|
176 |
case Types.BIT: |
177 |
BooleanValue bval = (BooleanValue) value; |
178 |
solution = new Boolean(bval.getValue()); |
179 |
break;
|
180 |
case Types.DATE: |
181 |
DateValue dtval = (DateValue) value; |
182 |
solution = dtval.getValue(); |
183 |
break;
|
184 |
} |
185 |
return solution;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Returns a Value from its data type (fieldType) and an Object with its
|
190 |
* value
|
191 |
*
|
192 |
* TODO Move to ValueFactory
|
193 |
*
|
194 |
* @param plainObject
|
195 |
* @param fieldType
|
196 |
* @return
|
197 |
*/
|
198 |
public static Value getValue(Object object, int fieldType) { |
199 |
Value solution = null;
|
200 |
switch (fieldType) {
|
201 |
case Types.VARCHAR: |
202 |
String str = (String) object; |
203 |
solution = ValueFactory.createValue(str); |
204 |
break;
|
205 |
case Types.FLOAT: |
206 |
float fval = ((Float) object).floatValue(); |
207 |
solution = ValueFactory.createValue(fval); |
208 |
break;
|
209 |
case Types.DOUBLE: |
210 |
double dval = ((Double) object).doubleValue(); |
211 |
solution = ValueFactory.createValue(dval); |
212 |
break;
|
213 |
case Types.INTEGER: |
214 |
int ival = ((Integer) object).intValue(); |
215 |
solution = ValueFactory.createValue(ival); |
216 |
break;
|
217 |
case Types.BIGINT: |
218 |
long lval = ((Long) object).longValue(); |
219 |
solution = ValueFactory.createValue(lval); |
220 |
break;
|
221 |
case Types.BIT: |
222 |
boolean bval = ((Boolean) object).booleanValue(); |
223 |
solution = ValueFactory.createValue(bval); |
224 |
break;
|
225 |
case Types.DATE: |
226 |
Date dtval = (Date) object; |
227 |
solution = ValueFactory.createValue(dtval); |
228 |
break;
|
229 |
default:
|
230 |
solution = ValueFactory.createNullValue(); |
231 |
} |
232 |
return solution;
|
233 |
} |
234 |
|
235 |
} |