-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigCloneBenchDB.java
80 lines (67 loc) · 2.15 KB
/
BigCloneBenchDB.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package database;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;
public class BigCloneBenchDB {
private static BigCloneBenchDB instance = null;
private BoneCP connectionPool = null;
public static void reinit(String name) throws SQLException {
if(instance != null) {
instance.connectionPool.close();
instance = null;
}
instance = new BigCloneBenchDB();
}
private static BigCloneBenchDB getConnectionPool() throws SQLException {
if(instance == null)
instance = new BigCloneBenchDB();
return instance;
}
private BigCloneBenchDB() throws SQLException {
BoneCPConfig config = new BoneCPConfig();
Path db = Paths.get("bigclonebenchdb/bcb").toAbsolutePath();
config.setJdbcUrl("jdbc:h2:" + db.toString() + ";IFEXISTS=TRUE");
config.setUsername("sa");
config.setPassword("");
config.setMinConnectionsPerPartition(1);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
connectionPool = new BoneCP(config);
}
public static Connection getConnection() throws SQLException {
return BigCloneBenchDB.getConnectionPool().connectionPool.getConnection();
}
/**
* Opens a new private connection to the database (not in pool). Your responsibility to close the connection.
* @return
* @throws SQLException
* @throws ClassNotFoundException
*/
public static Connection getPrivateConnection() throws SQLException, ClassNotFoundException {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:bcb","sa","");
return conn;
}
public static String getVersion() throws SQLException {
String retval;
Connection conn = BigCloneBenchDB.getConnection();
String sql = "SELECT version FROM version LIMIT 1";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()) {
retval = rs.getString("version");
} else {
retval = "unknown";
}
rs.close();
stmt.close();
conn.close();
return retval;
}
}