-
Notifications
You must be signed in to change notification settings - Fork 16
/
UIConnectionFactory.java
60 lines (54 loc) · 1.64 KB
/
UIConnectionFactory.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
import java.sql.*;
import org.postgresql.ds.*;
import java.io.IOException;
public class UIConnectionFactory
{
// example to use:
// Connection conn = UIConnectionFactory.getConnection();
private static PGPoolingDataSource ds;
private UIConnectionFactory()
{
}
public static synchronized PGPoolingDataSource getDataSource() throws SQLException
{
if (ds == null)
{
try
{
System.out.println("Creating new connection pool");
OSProperties.getPropValues(UI.configFile);
ds = new PGPoolingDataSource();
ds.setDataSourceName("OutsourcerUIPool");
ds.setServerName(OSProperties.gpServer);
ds.setDatabaseName(OSProperties.gpDatabase);
ds.setPortNumber(OSProperties.gpPort);
ds.setUser(OSProperties.gpUserName);
ds.setPassword(OSProperties.gpPassword);
ds.setMaxConnections(10);
}
catch (IOException iox)
{
System.out.println("Unable to load config file. Check environment variables and try again.");
throw new SQLException(iox.getMessage());
}
}
return ds;
}
public static Connection getConnection() throws SQLException
{
try
{
return getDataSource().getConnection();
}
catch (SQLException ex)
{
System.out.println(ex.getMessage());
System.out.println("gpServer from properties: " + OSProperties.gpServer);
System.out.println("gpDatabase from properties: " + OSProperties.gpDatabase);
System.out.println("gpPort from properties: " + OSProperties.gpPort);
System.out.println("gpUsername from properties: " + OSProperties.gpUserName);
System.out.println("gpPassword from properties: " + OSProperties.gpPassword);
throw new SQLException(ex.getMessage());
}
}
}