KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > demos > scalability > jdbc > JDBCScalabilitySubject


1 //Contributions by Stefan Ortmanns.
2

3 package org.prevayler.demos.scalability.jdbc;
4
5 import org.prevayler.demos.scalability.*;
6 import java.sql.*;
7
8
9 abstract class JDBCScalabilitySubject implements ScalabilityTestSubject {
10
11     protected final String JavaDoc connectionURL;
12     protected final String JavaDoc user;
13     protected final String JavaDoc password;
14
15     {System.gc();}
16
17
18     protected JDBCScalabilitySubject(String JavaDoc jdbcDriverClassName, String JavaDoc connectionURL, String JavaDoc user, String JavaDoc password) {
19         try {
20             Class.forName(jdbcDriverClassName);
21         } catch (Exception JavaDoc ex) {
22             ex.printStackTrace();
23             throw new RuntimeException JavaDoc("Exception loading JDBC driver class: " + jdbcDriverClassName);
24         }
25
26         this.connectionURL = connectionURL;
27         this.user = user;
28         this.password = password;
29     }
30
31     public String JavaDoc name() {
32         return "JDBC";
33     }
34
35     public void replaceAllRecords(int records) {
36         ((JDBCScalabilityConnection)createTestConnection()).replaceAllRecords(records);
37     }
38
39     protected Connection createConnection() {
40         try {
41
42             return DriverManager.getConnection(connectionURL, user, password);
43
44         } catch (SQLException sqlx) {
45             sqlx.printStackTrace();
46             throw new RuntimeException JavaDoc("Exception while trying to connect: " + sqlx);
47         }
48     }
49 }
50
Popular Tags