KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > cache > OutOfMemoryCacheScenario


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.cache;
26
27 import java.sql.Connection JavaDoc;
28
29 import org.objectweb.cjdbc.controller.cache.result.AbstractResultCache;
30 import org.objectweb.cjdbc.scenario.templates.Raidb1Template;
31 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
32 import org.objectweb.cjdbc.scenario.tools.util.MemoryProfiler;
33
34 /**
35  * This class defines a OutOfMemoryCacheScenario
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
38  * @version 1.0
39  */

40 public class OutOfMemoryCacheScenario extends Raidb1Template
41 {
42
43   int NUMBER_ROUND = 5000;
44
45   boolean cleanTables = true;
46
47   public void testMultipleAdd() throws Exception JavaDoc
48   {
49     Connection JavaDoc con = getCJDBCConnection();
50
51     MemoryProfiler memProp = new MemoryProfiler();
52     memProp.start();
53
54     for (int i = 0; i < NUMBER_ROUND; i++)
55       round(con);
56     
57     memProp.quit();
58     memProp.join();
59   }
60
61   private void round(Connection JavaDoc con) throws Exception JavaDoc
62   {
63
64     batchAdd(con, "DOCUMENT");
65     batchAdd(con, "ADDRESS");
66     batchAdd(con, "PRODUCT");
67
68     AbstractResultCache cache = mainVdb.getRequestManager().getResultCache();
69
70     if (cleanTables)
71     {
72       cleanTableCache(con, "DOCUMENT", "TOTAL");
73       cleanTableCache(con, "ADDRESS", "FIRSTNAME");
74       cleanTableCache(con, "PRODUCT", "NAME");
75     }
76
77   }
78
79   private void cleanTableCache(Connection JavaDoc con, String JavaDoc table, String JavaDoc column)
80       throws Exception JavaDoc
81   {
82     con.createStatement().executeUpdate(
83         "update " + table + " set " + column + "=0");
84   }
85
86   private void batchAdd(Connection JavaDoc con, String JavaDoc table) throws Exception JavaDoc
87   {
88     for (int i = 0; i < 50; i++)
89       ScenarioUtility.getSingleQueryResult("select * from " + table
90           + " where ID=" + i, con, true);
91   }
92 }
Popular Tags