Mercurial Hosting > nabble
comparison src/global/Server.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 package global; | |
2 | |
3 import java.sql.Connection; | |
4 import java.sql.DriverManager; | |
5 import java.sql.SQLException; | |
6 import java.util.Collection; | |
7 import java.util.LinkedHashMap; | |
8 import java.util.Map; | |
9 import java.util.Properties; | |
10 | |
11 | |
12 public final class Server { | |
13 | |
14 private static final Map<String,Server> map = new LinkedHashMap<String,Server>(); | |
15 | |
16 // call from beanshell | |
17 public static void add(String name,String dbUrl,String dbUser,String dbPassword,String host) throws ClassNotFoundException { | |
18 map.put( name, new Server(name,dbUrl,dbUser,dbPassword,host) ); | |
19 } | |
20 | |
21 static Collection<Server> getServers() { | |
22 return map.values(); | |
23 } | |
24 | |
25 public static Server getServer(String name) { | |
26 return map.get(name); | |
27 } | |
28 | |
29 public final String name; | |
30 private final String dbUrl; | |
31 private final Properties dbProperties = new Properties(); | |
32 public final String host; | |
33 | |
34 private Server(String name,String dbUrl,String dbUser,String dbPassword,String host) | |
35 throws ClassNotFoundException | |
36 { | |
37 this.name = name; | |
38 Class.forName("org.postgresql.Driver"); | |
39 this.dbUrl = dbUrl; | |
40 dbProperties.setProperty("user",dbUser); | |
41 dbProperties.setProperty("password",dbPassword); | |
42 this.host = host; | |
43 } | |
44 | |
45 Connection getConnection() | |
46 throws SQLException | |
47 { | |
48 return DriverManager.getConnection(dbUrl,dbProperties); | |
49 } | |
50 | |
51 } |