summaryrefslogtreecommitdiffstats
path: root/das-java/trunk/tools/src/main/java/org/apache/tuscany/das/rdb/util/SQLTypeChecker.java
blob: 73fe97771999611b226c17ae9d0c85b4670de68a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package org.apache.tuscany.das.rdb.util;

import java.sql.Types;

public class SQLTypeChecker {
	
	public static int getSQLTypeFromString(String sqlTypeString) {
		if(sqlTypeString.equals("CHAR")) return Types.CHAR;
		if(sqlTypeString.equals("VARCHAR")) return Types.VARCHAR;
		if(sqlTypeString.equals("LONGVARCHAR")) return Types.LONGVARCHAR;
		if(sqlTypeString.equals("NUMERIC")) return Types.NUMERIC;
		if(sqlTypeString.equals("DECIMAL")) return Types.DECIMAL;
		if(sqlTypeString.equals("BIT")) return Types.BIT;
		if(sqlTypeString.equals("BOOLEAN")) return Types.BOOLEAN;
		if(sqlTypeString.equals("TINYINT")) return Types.TINYINT;
		if(sqlTypeString.equals("SMALLINT")) return Types.SMALLINT;
		if(sqlTypeString.equals("INTEGER")) return Types.INTEGER;
		if(sqlTypeString.equals("BIGINT")) return Types.BIGINT;
		if(sqlTypeString.equals("REAL")) return Types.REAL;
		if(sqlTypeString.equals("FLOAT")) return Types.FLOAT;
		if(sqlTypeString.equals("DOUBLE")) return Types.DOUBLE;
		if(sqlTypeString.equals("BINARY")) return Types.BINARY;
		if(sqlTypeString.equals("VARBINARY")) return Types.VARBINARY;
		if(sqlTypeString.equals("LONGVARBINARY")) return Types.LONGVARBINARY;
		if(sqlTypeString.equals("DATE")) return Types.DATE;
		if(sqlTypeString.equals("TIME")) return Types.TIME;
		if(sqlTypeString.equals("TIMESTAMP")) return Types.TIMESTAMP;
		if(sqlTypeString.equals("CLOB")) return Types.CLOB;
		if(sqlTypeString.equals("BLOB")) return Types.BLOB;
		if(sqlTypeString.equals("ARRAY")) return Types.ARRAY;
		if(sqlTypeString.equals("DISTINCT")) return Types.DISTINCT;
		if(sqlTypeString.equals("STRUCT")) return Types.STRUCT;
		if(sqlTypeString.equals("REF")) return Types.REF;
		if(sqlTypeString.equals("DATALINK")) return Types.DATALINK;
		if(sqlTypeString.equals("JAVA_OBJECT")) return Types.JAVA_OBJECT;
		return Types.OTHER;
	}

	/*xsd : SDO 
	anySimpleType Object
	anyType DataObject
	anyURI URI
	base64Binary Bytes
	boolean Boolean
	byte Byte
	date YearMonthDay
	dateTime DateTime
	decimal Decimal
	double Double
	duration Duration
	ENTITIES Strings
	ENTITY String
	float Float
	gDay Day
	gMonth Month
	gMonthDay MonthDay
	gYear Year
	gYearMonth YearMonth
	hexBinary Bytes
	ID String
	IDREF String
	IDREFS Strings
	int Int
	integer Integer
	language String
	long Long
	Name String
	NCName String
	negativeInteger Integer
	NMTOKEN String
	NMTOKENS Strings
	nonNegativeInteger Integer
	nonPositiveInteger Integer
	normalizedString String
	NOTATION String
	positiveInteger Integer
	QName URI
	short Short
	string String
	time Time
	token String
	unsignedByte Short
	unsignedInt long
	unsignedLong Integer
	unsignedShort Int*/
	static final String anySimpleTypeXSD = "anySimpleType";
	static final String anyTypeXSD = "anyType";
	static final String anyURIXSD = "anyURI";
	static final String base64BinaryXSD = "base64Binary";
	static final String booleanXSD = "boolean";
	static final String byteXSD = "byte";
	static final String dateXSD = "date";
	static final String dateTimeXSD = "dateTime";
	static final String decimalXSD = "decimal";
	static final String doubleXSD = "double";
	static final String durationXSD = "duration";
	static final String ENTITIESXSD = "ENTITIES";
	static final String ENTITYXSD = "ENTITY";
	static final String floatXSD = "float"; 
	static final String gDayXSD = "gDay"; 
	static final String gMonthXSD = "gMonth"; 
	static final String gMonthDayXSD = "gMonthDay"; 
	static final String gYearXSD = "gYear"; 
	static final String gYearMonthXSD = "gYearMonth"; 
	static final String hexBinaryXSD = "hexBinary"; 
	static final String IDXSD = "ID"; 
	static final String IDREFXSD = "IDREF"; 
	static final String IDREFSXSD = "IDREF"; 
	static final String intXSD = "int"; 
	static final String integerXSD = "integer"; 
	static final String languageXSD = "language"; 
	static final String longXSD = "long"; 
	static final String NameXSD = "Name"; 
	static final String NCNameXSD = "NCName"; 
	static final String negativeIntegerXSD = "negativeInteger"; 
	static final String NMTOKENXSD = "NMTOKEN"; 
	static final String NMTOKENSXSD = "NMTOKENS";
	static final String nonNegativeIntegerXSD = "nonNegativeInteger"; 
	static final String nonPositiveIntegerXSD = "nonPositiveInteger"; 
	static final String normalizedStringXSD = "normalizedString"; 
	static final String NOTATIONXSD = "NOTATION"; 
	static final String positiveIntegerXSD = "positiveInteger"; 
	static final String QNameXSD = "QName"; 
	static final String shortXSD = "short"; 
	static final String stringXSD = "string"; 
	static final String timeXSD = "time"; 
	static final String tokenXSD = "token"; 
	static final String unsignedByteXSD = "unsignedByte"; 
	static final String unsignedIntXSD = "unsignedInt"; 
	static final String unsignedLongXSD = "unsignedLong"; 
	static final String unsignedShortXSD = "unsignedShort"; 
	
	public static String xsdTypeForSDOType(String sdoTypeName) {
		if(sdoTypeName.equals("Object")) return anySimpleTypeXSD;
		if(sdoTypeName.equals("DataObject")) return anyTypeXSD;
		if(sdoTypeName.equals("URI")) return anyURIXSD;
		if(sdoTypeName.equals("Bytes")) return base64BinaryXSD;
		if(sdoTypeName.equals("Boolean")) return booleanXSD;
		if(sdoTypeName.equals("boolean")) return booleanXSD;
		if(sdoTypeName.equals("Byte")) return byteXSD;
		if(sdoTypeName.equals("YearMonthDay")) return dateXSD;
		if(sdoTypeName.equals("DateTime")) return dateTimeXSD;
		if(sdoTypeName.equals("Date")) return dateTimeXSD;
		if(sdoTypeName.equals("Decimal")) return decimalXSD;
		if(sdoTypeName.equals("Double")) return doubleXSD;
		if(sdoTypeName.equals("double")) return doubleXSD;
		if(sdoTypeName.equals("Duration")) return durationXSD;
		if(sdoTypeName.equals("Strings")) return ENTITIESXSD;
		if(sdoTypeName.equals("String")) return stringXSD;
		if(sdoTypeName.equals("Float")) return floatXSD;
		if(sdoTypeName.equals("float")) return floatXSD;
		if(sdoTypeName.equals("Day")) return gDayXSD;
		if(sdoTypeName.equals("Month")) return gMonthXSD;
		if(sdoTypeName.equals("MonthDay")) return gMonthDayXSD;
		if(sdoTypeName.equals("Year")) return gYearXSD;
		if(sdoTypeName.equals("YearMonth")) return gYearMonthXSD;
		if(sdoTypeName.equals("Bytes")) return hexBinaryXSD;
		if(sdoTypeName.equals("Int")) return intXSD;
		if(sdoTypeName.equals("IntObject")) return intXSD;
		if(sdoTypeName.equals("Integer")) return integerXSD;
		if(sdoTypeName.equals("Long")) return longXSD;		
		if(sdoTypeName.equals("long")) return longXSD;
		if(sdoTypeName.equals("Short")) return shortXSD;
		if(sdoTypeName.equals("Time")) return timeXSD;
		if(sdoTypeName.equals("long")) return unsignedIntXSD;
		return "";
	}
}