-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDataSourceProvider.java
More file actions
44 lines (35 loc) · 1.45 KB
/
DataSourceProvider.java
File metadata and controls
44 lines (35 loc) · 1.45 KB
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
package org.utplsql.cli;
import com.zaxxer.hikari.HikariDataSource;
import org.utplsql.api.EnvironmentVariableUtil;
import javax.sql.DataSource;
import java.io.File;
/** Helper class to give you a ready-to-use datasource
*
* @author pesse
*/
public class DataSourceProvider {
static {
String oracleHome = EnvironmentVariableUtil.getEnvValue("ORACLE_HOME");
if (oracleHome != null) {
System.setProperty("oracle.net.tns_admin",
String.join(File.separator, oracleHome, "NETWORK", "ADMIN"));
}
}
public static DataSource getDataSource(ConnectionInfo info, int maxConnections ) {
requireOjdbc();
HikariDataSource pds = new HikariDataSource();
pds.setJdbcUrl("jdbc:oracle:thin:" + info.getConnectionString());
pds.setAutoCommit(false);
pds.setMaximumPoolSize(maxConnections);
return pds;
}
private static void requireOjdbc() {
if ( !OracleLibraryChecker.checkOjdbcExists() )
{
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");
throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
}
}
}