KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > driver > SetFetchSizeScenario


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

24
25 package org.objectweb.cjdbc.scenario.raidb1.driver;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.HashMap JavaDoc;
32
33 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet;
34 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread;
35 import org.objectweb.cjdbc.scenario.templates.Raidb1Template;
36 import org.objectweb.cjdbc.scenario.tools.util.PrivilegedAccessor;
37
38 /**
39  * This class defines a SetFetchSizeScenario
40  *
41  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
42  * @version 1.0
43  */

44 public class SetFetchSizeScenario extends Raidb1Template
45 {
46
47   /**
48    * It seems the setFetchsize is ignored and the controller loads all the
49    * resultset in memory, thus resulting in an <code>OutOfMemory</code>
50    * exception
51    *
52    * @throws Exception if fails
53    */

54   public void testFetchSize() throws Exception JavaDoc
55   {
56     final int fetchsize = 5;
57     Connection JavaDoc con = getCJDBCConnection();
58     con.setAutoCommit(false);
59     String JavaDoc sql = "Select * from ADDRESS,DOCUMENT,PRODUCT";
60     PreparedStatement JavaDoc ps = con.prepareStatement(sql);
61     ps.setFetchSize(fetchsize);
62     ResultSet JavaDoc rs = ps.executeQuery();
63     ArrayList JavaDoc activeThreads = mainVdb.getActiveThreads();
64     VirtualDatabaseWorkerThread vt = (VirtualDatabaseWorkerThread) activeThreads
65         .get(0);
66     HashMap JavaDoc streamedResultSet = (HashMap JavaDoc) PrivilegedAccessor.getValue(vt,
67         "streamedResultSet");
68     String JavaDoc key = (String JavaDoc) streamedResultSet.keySet().iterator().next();
69     ControllerResultSet resultSet = (ControllerResultSet) streamedResultSet
70         .get(key);
71
72     int count = 0;
73     ArrayList JavaDoc data = new ArrayList JavaDoc();
74     while (rs.next())
75     {
76       // System.out.println("count[" + count + "]:" + resultSet.getData());
77
if ((count++) % fetchsize == 0)
78         assertNotSame(data, resultSet.getData());
79       data = resultSet.getData();
80       if (count > 10000)
81         break;
82     }
83     assertEquals("Invalid fetch size from resultset", fetchsize, rs
84         .getFetchSize());
85   }
86 }
Popular Tags