KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > test > cases > TestRebuildIndex


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.test.cases;
6
7 import java.sql.*;
8 import java.util.Random JavaDoc;
9
10 import org.h2.tools.DeleteDbFiles;
11 import org.h2.util.MemoryUtils;
12
13 public class TestRebuildIndex {
14     public static void main (String JavaDoc[] args) throws Exception JavaDoc {
15         boolean init = false;
16         if(init) {
17             DeleteDbFiles.execute(".", "test", false);
18         }
19         Class.forName("org.h2.Driver");
20         Connection conn = DriverManager.getConnection("jdbc:h2:test;cache_type=lzf", "sa", "sa");
21         Statement stat = conn.createStatement();
22         if(init) {
23             stat.executeUpdate("DROP TABLE IF EXISTS TEST");
24             stat.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA INT)");
25             PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?)");
26             int max = 1000000;
27             Random JavaDoc random = new Random JavaDoc(10);
28             for(int i=0; i<max; i++) {
29                 prep.setInt(1, i);
30 // prep.setInt(2, max - i);
31
prep.setInt(2, random.nextInt());
32                 prep.execute();
33             }
34         } else {
35             long time = System.currentTimeMillis();
36             stat.execute("CREATE INDEX IDXDATA ON TEST(DATA)");
37             time = System.currentTimeMillis() - time;
38             System.out.println("time: " + time);
39             // lzf: 5688 / 11944 kb
40
// tq: 4875 ms / 12131 kb
41
System.out.println("mem: " + MemoryUtils.getMemoryUsed());
42         }
43         conn.close();
44     }
45 }
46
Popular Tags