forked from utPLSQL/utPLSQL-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSourceProvider.java
More file actions
49 lines (38 loc) · 1.72 KB
/
DataSourceProvider.java
File metadata and controls
49 lines (38 loc) · 1.72 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
45
46
47
48
49
package org.utplsql.cli;
import org.utplsql.cli.datasource.TestedDataSourceProvider;
import javax.sql.DataSource;
import java.io.File;
import java.sql.SQLException;
/**
* Helper class to give you a ready-to-use datasource
*
* @author pesse
*/
public class DataSourceProvider {
static {
String oracleHome = System.getenv("ORACLE_HOME");
if (oracleHome != null && System.getProperty("oracle.net.tns_admin") == null) {
System.setProperty("oracle.net.tns_admin",
String.join(File.separator, oracleHome, "NETWORK", "ADMIN"));
}
}
public static DataSource getDataSource(String connectString, int maxConnections) throws SQLException {
requireOjdbc();
ConnectionConfig config = new ConnectionConfig(connectString);
warnIfSysDba(config);
return new TestedDataSourceProvider(config, maxConnections).getDataSource();
}
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");
}
}
private static void warnIfSysDba(ConnectionConfig config) {
if (config.isSysDba()) {
System.out.println("WARNING: You are connecting to the database as SYSDBA or SYSOPER, which is NOT RECOMMENDED and can put your database at risk!");
}
}
}