Mercurial Hosting > nabble
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/global/Server.java Thu Mar 21 19:15:52 2019 -0600 @@ -0,0 +1,51 @@ +package global; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Properties; + + +public final class Server { + + private static final Map<String,Server> map = new LinkedHashMap<String,Server>(); + + // call from beanshell + public static void add(String name,String dbUrl,String dbUser,String dbPassword,String host) throws ClassNotFoundException { + map.put( name, new Server(name,dbUrl,dbUser,dbPassword,host) ); + } + + static Collection<Server> getServers() { + return map.values(); + } + + public static Server getServer(String name) { + return map.get(name); + } + + public final String name; + private final String dbUrl; + private final Properties dbProperties = new Properties(); + public final String host; + + private Server(String name,String dbUrl,String dbUser,String dbPassword,String host) + throws ClassNotFoundException + { + this.name = name; + Class.forName("org.postgresql.Driver"); + this.dbUrl = dbUrl; + dbProperties.setProperty("user",dbUser); + dbProperties.setProperty("password",dbPassword); + this.host = host; + } + + Connection getConnection() + throws SQLException + { + return DriverManager.getConnection(dbUrl,dbProperties); + } + +}