Guest User

Untitled

a guest
Mar 9th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. String sharedDatabaseUrl = System.getenv("SHARED_DATABASE_URL");
  2. Matcher m = Pattern.compile("postgres://(.+):(.+)@(.+)/(.+)").matcher(sharedDatabaseUrl);
  3. if (m.matches()) {
  4. String postgresUser = m.group(1);
  5. String postgresPassword = m.group(2);
  6. String postgresHost = m.group(3);
  7. String postgresName = m.group(4);
  8. String jdbcUrl = String.format("jdbc:postgresql://%s/%s", postgresHost, postgresName);
  9.  
  10. properties.setProperty(EntityManagerProperties.JDBC_USER, postgresUser);
  11. properties.setProperty(EntityManagerProperties.JDBC_PASSWORD, postgresPassword);
  12. properties.setProperty(EntityManagerProperties.JDBC_URL, jdbcUrl);
  13. EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName, properties);
Add Comment
Please, Sign In to add comment