KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > tools > testlet > ClobTestLet


1
2 /**
3  * C-JDBC: Clustered JDBC.
4  * Copyright (C) 2002-2004 French National Institute For Research In Computer
5  * Science And Control (INRIA).
6  * Contact: c-jdbc@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or any later
11  * version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16  * for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21  *
22  * Initial developer(s): Nicolas Modrzyk.
23  * Contributor(s): ______________________.
24  */

25
26 package org.objectweb.cjdbc.scenario.tools.testlet;
27
28 import java.sql.Clob JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.PreparedStatement JavaDoc;
31 import java.sql.ResultSet JavaDoc;
32
33 /**
34  * This class defines a ClobTestLet
35  *
36  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
37  * @version 1.0
38  */

39 public class ClobTestLet extends AbstractConnectionTestLet
40 {
41
42   /**
43    * Creates a new <code>ClobTestLet</code> object
44    *
45    * @param con connection to use for testing
46    */

47   public ClobTestLet(Connection JavaDoc con)
48   {
49     super(con);
50     config.put(TABLE_NAME, "BLOB");
51     config.put(UPDATED_COLUMN_VALUE, "I am a CLOB");
52     config.put(COLUMN_NAME, "blob");
53   }
54
55   /**
56    * @see org.objectweb.cjdbc.scenario.tools.testlet.AbstractTestLet#execute()
57    */

58   public void execute() throws Exception JavaDoc
59   {
60     String JavaDoc ss = (String JavaDoc) config.get(UPDATED_COLUMN_VALUE);
61     String JavaDoc tableName = (String JavaDoc) config.get(TABLE_NAME);
62     String JavaDoc columnName = (String JavaDoc) config.get(COLUMN_NAME);
63
64     String JavaDoc insertQuery = "Insert into " + tableName + " values(3,?)";
65     PreparedStatement JavaDoc ps;
66     if (useCJDBCClass())
67     {
68       Clob JavaDoc clob = new org.objectweb.cjdbc.driver.Clob(ss);
69       ps = jdbcConnection.prepareStatement(insertQuery);
70       ps.setClob(1, clob);
71       ps.executeUpdate();
72     }
73     else
74     {
75       ps = jdbcConnection.prepareStatement(insertQuery);
76       ps.setString(1, ss);
77       ps.executeUpdate();
78     }
79     // Test retrieval implementation independant
80
ps = jdbcConnection.prepareStatement("Select * from " + tableName + " where id=3");
81     ResultSet JavaDoc rs = ps.executeQuery();
82     rs.first();
83     Clob JavaDoc rsclob = rs.getClob(columnName);
84     String JavaDoc ret = rsclob.getSubString(0, (int) rsclob.length());
85     if (ret.equalsIgnoreCase(ss) == false)
86     {
87       fail("Retrieved:" + ret + " is different from:" + ss);
88     }
89     // Test without own implementation
90
String JavaDoc clob2 = "I am a clob as well";
91     PreparedStatement JavaDoc ps1 = jdbcConnection.prepareStatement("Insert into " + tableName
92         + " values(4,?)");
93     ps1.setString(1, clob2);
94     ps1.executeUpdate();
95
96     PreparedStatement JavaDoc ps2 = jdbcConnection.prepareStatement("Select * from " + tableName
97         + " where id=4");
98     ResultSet JavaDoc rs2 = ps2.executeQuery();
99     rs2.first();
100     Clob JavaDoc rs2clob = rs2.getClob(columnName);
101     String JavaDoc ret2 = rs2clob.getSubString(0, (int) rs2clob.length());
102     if (ret2.equalsIgnoreCase(clob2) == false)
103     {
104       fail("Retrieved:" + ret2 + " is different from:" + clob2);
105     }
106
107   }
108
109 }
Popular Tags