DatabaseBuilder.java [src/java/m/gis] Revision: 13f86dea363c34ca36688b71617cfb69d196e484 Date: Tue May 12 17:30:39 MDT 2015
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package m.gis;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;
/**
*
* @author ktraff
*/
public class DatabaseBuilder {
/**
* Represents all possible target database connections.
*/
public static enum DB { POSTGRES };
private DB type;
private Logger log;
private String port;
private String dbName;
private String hostname;
private String username;
private String password;
public DatabaseBuilder() {
}
public DatabaseBuilder setAll(Logger log) {
setType(DB.POSTGRES)
.setLogger(log)
.setHostname("localhost")
.setPort("5432")
.setDbName("erams")
.setUsername("erams")
.setPassword("ids12_foTT");
return this;
}
public DatabaseBuilder setType(DB type) {
this.type = type;
return this;
}
public DatabaseBuilder setLogger(Logger log) {
this.log = log;
return this;
}
public DatabaseBuilder setHostname(String hostname) {
this.hostname = hostname;
return this;
}
public DatabaseBuilder setPort(String port) {
this.port = port;
return this;
}
public DatabaseBuilder setDbName(String dbName) {
this.dbName = dbName;
return this;
}
public DatabaseBuilder setUsername(String username) {
this.username = username;
return this;
}
public DatabaseBuilder setPassword(String password) {
this.password = password;
return this;
}
public Database create() {
switch (type) {
case POSTGRES:
return new PostgresqlDatabase(hostname, port, dbName, username, password, log);
default:
return new PostgresqlDatabase(hostname, port, dbName, username, password, log);
}
}
}