1 | /** |
2 | * Copyright 2009 ATG DUST Project |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * |
7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
8 | * |
9 | * Unless required by applicable law or agreed to in writing, software |
10 | * distributed under the License is distributed on an "AS IS" BASIS, |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | * See the License for the specific language governing permissions and limitations under the License. |
13 | */ |
14 | |
15 | package atg.adapter.gsa; |
16 | |
17 | /** |
18 | * The purpose of this class is to map from a the database specific type name |
19 | * for a column to the <code>java.sql.Types</code> for that column. Given a |
20 | * DatabaseTableInfo for a given database it will return the jdbc type for the |
21 | * supported GSA types. |
22 | * |
23 | * @version $Id: //test/UnitTests/base/main/src/Java/atg/adapter/gsa/DatabaseTypeNameToJDBC.java#2 $ |
24 | * @author adamb |
25 | * @see java.sql.Types |
26 | */ |
27 | public class DatabaseTypeNameToJDBC { |
28 | |
29 | public DatabaseTableInfo mTableInfo = null; |
30 | public static final int UNKNOWN = -9999; |
31 | |
32 | // ------------------------------- |
33 | /** |
34 | * Creates a new instance of this class initialized with the given |
35 | * DatabaseTableInfo object. |
36 | * |
37 | * @param pTableInfo |
38 | */ |
39 | public DatabaseTypeNameToJDBC(DatabaseTableInfo pTableInfo) { |
40 | mTableInfo = pTableInfo; |
41 | } |
42 | |
43 | // ------------------------------- |
44 | /** |
45 | * Given a database specific type name, returns the matching |
46 | * <code>java.sql.Types</code> constant. If there is no suitable match this |
47 | * method returns the constant <code>UNKNOWN</code>. |
48 | * |
49 | * @param pTypeName |
50 | * @return |
51 | */ |
52 | public int databaseTypeNametoJDBCType(String pTypeName) { |
53 | // Walk the DatabaseTableInfo and do a comparison. |
54 | if (mTableInfo.mVarcharType.equals(pTypeName)) { |
55 | return java.sql.Types.VARCHAR; |
56 | } else if (mTableInfo.mIntType.equals(pTypeName)) { |
57 | // Fix for MS SQLServer |
58 | if("NUMERIC".equals(pTypeName)){ |
59 | return java.sql.Types.NUMERIC; |
60 | }else{ |
61 | return java.sql.Types.INTEGER; |
62 | } |
63 | } else if (mTableInfo.mBinaryType.equals(pTypeName)) { |
64 | return java.sql.Types.BLOB; |
65 | } else if (mTableInfo.mLongVarcharType.equals(pTypeName)) { |
66 | return java.sql.Types.LONGVARCHAR; |
67 | } else if (mTableInfo.mTimestampType.equals(pTypeName)) { |
68 | return java.sql.Types.TIMESTAMP; |
69 | } else if (mTableInfo.mCharType.equals(pTypeName)) { |
70 | return java.sql.Types.CHAR; |
71 | } else if (mTableInfo.mDateType.equals(pTypeName)) { |
72 | return java.sql.Types.DATE; |
73 | } else if (mTableInfo.mDecimalType.equals(pTypeName)) { |
74 | return java.sql.Types.DECIMAL; |
75 | } else |
76 | return UNKNOWN; |
77 | } |
78 | } |