KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > ext > oracle > OracleDataTypeFactory


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

21 package org.dbunit.ext.oracle;
22
23 import org.dbunit.dataset.datatype.DataType;
24 import org.dbunit.dataset.datatype.DataTypeException;
25 import org.dbunit.dataset.datatype.DefaultDataTypeFactory;
26 import org.dbunit.dataset.datatype.BinaryStreamDataType;
27
28 import java.sql.Types JavaDoc;
29
30 /**
31  * Specialized factory that recognizes Oracle data types.
32
33  * @author manuel.laflamme
34  * @since Jul 17, 2003
35  * @version $Revision: 1.12 $
36  */

37 public class OracleDataTypeFactory extends DefaultDataTypeFactory
38 {
39     public static final DataType ORACLE_BLOB = new OracleBlobDataType();
40     public static final DataType ORACLE_CLOB = new OracleClobDataType();
41     public static final DataType LONG_RAW = new BinaryStreamDataType(
42             "LONG RAW", Types.LONGVARBINARY);
43
44     public DataType createDataType(int sqlType, String JavaDoc sqlTypeName) throws DataTypeException
45     {
46         // Map Oracle DATE to TIMESTAMP
47
if (sqlType == Types.DATE)
48         {
49             return DataType.TIMESTAMP;
50         }
51
52         // TIMESTAMP
53
if (sqlTypeName.startsWith("TIMESTAMP"))
54         {
55             return DataType.TIMESTAMP;
56         }
57
58         // BLOB
59
if ("BLOB".equals(sqlTypeName))
60         {
61             return ORACLE_BLOB;
62         }
63
64         // CLOB
65
if ("CLOB".equals(sqlTypeName) || "NCLOB".equals(sqlTypeName))
66         {
67             return ORACLE_CLOB;
68         }
69
70         // NVARCHAR2
71
if ("NVARCHAR2".equals(sqlTypeName))
72         {
73             return DataType.VARCHAR;
74         }
75
76         // NCHAR
77
if (sqlTypeName.startsWith("NCHAR"))
78         {
79             return DataType.CHAR;
80         }
81
82         // FLOAT
83
if ("FLOAT".equals(sqlTypeName))
84         {
85             return DataType.FLOAT;
86         }
87
88         // LONG RAW
89
if (LONG_RAW.toString().equals(sqlTypeName))
90         {
91             return LONG_RAW;
92         }
93
94         return super.createDataType(sqlType, sqlTypeName);
95     }
96 }
97
Popular Tags