KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > sybase > TypeMapper


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.sybase;
24
25 import java.sql.Types JavaDoc;
26
27 import org.xquark.extractor.common.MessageLibrary;
28 import org.xquark.extractor.common.SqlWrapperException;
29 import org.xquark.jdbc.typing.DbType;
30
31 public class TypeMapper {
32     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     public static String JavaDoc mapType(DbType type) {
36         StringBuffer JavaDoc retVal = new StringBuffer JavaDoc();
37
38         int typeCode = type.getJDBCType();
39         switch (typeCode) {
40 // case Types.ARRAY:
41
// retVal.append("ARRAY");
42
// break;
43
// case Types.BIGINT:
44
// retVal.append("BIGINT");
45
// break;
46
// case Types.BINARY:
47
// retVal.append("BINARY");
48
// break;
49
case Types.BIT://
50
retVal.append("BIT");
51                 break;
52 // case Types.BLOB:
53
// retVal.append("BLOB");
54
// break;
55
case Types.CHAR:
56                 retVal.append("NCHAR");
57                 break;
58 // case Types.CLOB:
59
// retVal.append("CLOB");
60
// break;
61
case Types.DATE:
62                 retVal.append("DATETIME");
63                 break;
64             case Types.DECIMAL:
65                 retVal.append("DECIMAL");
66                 break;
67 // case Types.DISTINCT:
68
// retVal.append("DISTINCT");
69
// break;
70
case Types.DOUBLE: //
71
retVal.append("DOUBLE");
72                 break;
73             case Types.FLOAT://
74
retVal.append("REAL");
75                 break;
76             case Types.INTEGER://
77
retVal.append("INTEGER");
78                 break;
79 // case Types.JAVA_OBJECT:
80
// retVal.append("JAVA_OBJECT");
81
// break;
82
// case Types.LONGVARBINARY:
83
// retVal.append("LONGVARBINARY");
84
// break;
85
// case Types.LONGVARCHAR:
86
// retVal.append("LONGVARCHAR");
87
// break;
88
// case Types.NULL:
89
// retVal.append("NULL");
90
// break;
91
// case Types.NUMERIC:
92
// retVal.append("NUMERIC");
93
// break;
94
case Types.REAL: //
95
retVal.append("REAL");
96                 break;
97             case Types.SMALLINT: //
98
retVal.append("SMALLINT");
99                 break;
100 // case Types.STRUCT:
101
// retVal.append("STRUCT");
102
// break;
103
case Types.TIME:
104                 retVal.append("DATETIME");
105                 break;
106             case Types.TIMESTAMP://
107
retVal.append("TIMESTAMP");
108                 break;
109             case Types.TINYINT: //
110
retVal.append("TINYINT");
111                 break;
112 // case Types.VARBINARY:
113
// retVal.append("VARBINARY");
114
// break;
115
case Types.VARCHAR:
116                 retVal.append("NVARCHAR");
117                 break;
118             default:
119                 throw new SqlWrapperException(MessageLibrary.getMessage("T_N_SUP_TYPE", type.name()));
120 // break;
121
}
122
123         if (Types.CHAR == typeCode || Types.VARCHAR== typeCode || Types.DECIMAL == typeCode) {
124             retVal.append('(');
125             retVal.append(Long.toString(type.getLength()));
126         }
127         if (Types.CHAR == typeCode || Types.VARCHAR == typeCode) {
128             retVal.append(')');
129         }
130         else if (Types.DECIMAL == typeCode) {
131             retVal.append(", ");
132             retVal.append(Integer.toString(type.getScale()));
133             retVal.append(')');
134         }
135         return retVal.toString();
136     }
137
138 }
139
Popular Tags