View Javadoc

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.PreparedStatement;
24  import java.sql.ResultSet;
25  import java.sql.SQLException;
26  
27  import oracle.jdbc.OraclePreparedStatement;
28  import oracle.jdbc.OracleResultSet;
29  import oracle.sql.OPAQUE;
30  import oracle.sql.OpaqueDescriptor;
31  
32  import org.dbunit.dataset.datatype.BlobDataType;
33  import org.dbunit.dataset.datatype.TypeCastException;
34  
35  /**
36   * 
37   * TODO UnitTests are completely missing
38   * @author Phil Barr
39   * @author Last changed by: $Author: jbhurst $
40   * @version $Revision: 1072 $ $Date: 2009-10-12 19:46:45 +0200 (lun, 12 ott 2009) $
41   * @since 2.4.0
42   */
43  public class OracleXMLTypeDataType extends BlobDataType
44  {
45  
46      public Object getSqlValue(int column, ResultSet resultSet) throws SQLException, TypeCastException
47      {
48          byte[] data = new byte[0];
49          OracleResultSet oracleResultSet = (OracleResultSet) resultSet;
50          OPAQUE opaque = oracleResultSet.getOPAQUE(column);
51          if (opaque != null) 
52          {
53              data = opaque.getBytes();
54          }
55  
56          // return the byte data (using typeCast to cast it to Base64 notation)
57          return typeCast(data);
58      }
59  
60      public void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException
61      {
62          OraclePreparedStatement oraclePreparedStatement = (OraclePreparedStatement) statement;
63          OpaqueDescriptor opaqueDescriptor = OpaqueDescriptor.createDescriptor("SYS.XMLTYPE", statement.getConnection());
64          OPAQUE opaque = new OPAQUE(opaqueDescriptor, (byte[]) typeCast(value), statement.getConnection());
65          oraclePreparedStatement.setOPAQUE(column, opaque);
66      }
67  }