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 java.sql.Types;
24
25 import org.dbunit.dataset.datatype.BinaryStreamDataType;
26 import org.dbunit.dataset.datatype.DataType;
27 import org.dbunit.dataset.datatype.DataTypeException;
28 import org.dbunit.dataset.datatype.StringDataType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33 * Specialized factory that recognizes Oracle data types for Oracle 10 and higher.
34 * <br>
35 * Handles the CLOBs and BLOBs as string and binary stream respectively which is supported
36 * since oracle 10.
37 * <br>
38 * This is recommended by oracle:
39 * <a href="http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/clob10g/handlingclobsinoraclejdbc10g.html">
40 * Oracle technology sample code</a>
41 *
42 * @author gommma
43 * @since 2.3.0
44 * @version $Revision: 730 $
45 */
46 public class Oracle10DataTypeFactory extends OracleDataTypeFactory
47 {
48 /**
49 * Logger for this class
50 */
51 private static final Logger logger = LoggerFactory.getLogger(Oracle10DataTypeFactory.class);
52
53
54 protected static final DataType CLOB_AS_STRING = new StringDataType("CLOB", Types.CLOB);
55 protected static final DataType BLOB_AS_STREAM = new BinaryStreamDataType("BLOB", Types.BLOB);
56
57 public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException
58 {
59 if(logger.isDebugEnabled())
60 logger.debug("createDataType(sqlType={}, sqlTypeName={}) - start", String.valueOf(sqlType), sqlTypeName);
61
62 // BLOB
63 if ("BLOB".equals(sqlTypeName))
64 {
65 return BLOB_AS_STREAM;
66 }
67
68 // CLOB
69 if ("CLOB".equals(sqlTypeName))
70 {
71 return CLOB_AS_STRING;
72 }
73 return super.createDataType(sqlType, sqlTypeName);
74 }
75 }