Skip to content

Instantly share code, notes, and snippets.

@sofusalbertsen
Last active September 27, 2015 12:00
Show Gist options
  • Save sofusalbertsen/56dcb15652a56ef3c178 to your computer and use it in GitHub Desktop.
Save sofusalbertsen/56dcb15652a56ef3c178 to your computer and use it in GitHub Desktop.
Env builder to change from local to OpenStack db. when in production.
/*
* Author: Sofus Albertsen
*
*/
import static org.eclipse.persistence.config.PersistenceUnitProperties.*;
import java.util.HashMap;
import java.util.Map;
public class EnvBuilder {
public static Map<String, String> getOpenShiftEnvVars() {
Map<String, String> out = new HashMap<String, String>();
Map<String, String> env = System.getenv();
//If openshift is not present at the runtime, then return an empty map
if (!env.keySet().contains("OPENSHIFT_MYSQL_DB_USERNAME")) {
return out;
}
//Else, build up the URL's for the database
String url = "JDBC:MYSQL://";
url=url+System.getenv("OPENSHIFT_MYSQL_DB_HOST")+":";
url=url+System.getenv("OPENSHIFT_MYSQL_DB_PORT")+"/";
url=url+System.getenv("OPENSHIFT_GEAR_NAME");
out.put(JDBC_URL, url);
out.put(JDBC_USER, System.getenv("OPENSHIFT_MYSQL_DB_USERNAME"));
out.put(JDBC_PASSWORD, System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD"));
return out;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment