|
11 | 11 | import javax.annotation.PostConstruct; |
12 | 12 | import javax.validation.constraints.NotNull; |
13 | 13 | import java.math.BigInteger; |
| 14 | +import java.net.URI; |
14 | 15 | import java.security.SecureRandom; |
15 | 16 | import java.sql.*; |
16 | 17 | import java.util.Collections; |
@@ -216,19 +217,22 @@ public String bindRoleToDatabase(String serviceInstanceId, String bindingId) thr |
216 | 217 | //executeUpdate("ALTER DEFAULT PRIVILEGES FOR ROLE \""+serviceInstanceId+"\" IN SCHEMA public GRANT ALL ON TABLES TO \"" + bindingId + "\""); |
217 | 218 | //executeUpdate("ALTER DEFAULT PRIVILEGES FOR ROLE \""+serviceInstanceId+"\" IN SCHEMA public GRANT ALL ON SEQUENCES TO \"" + bindingId + "\""); |
218 | 219 | //executeUpdate("ALTER DEFAULT PRIVILEGES FOR ROLE \""+serviceInstanceId+"\" IN SCHEMA public GRANT ALL ON FUNCTIONS TO \"" + bindingId + "\""); |
219 | | - |
| 220 | + String s_uri = jdbcTemplate.getDataSource().getConnection().getMetaData().getURL().replace("jdbc:postgresql://", "").split("/")[0]; |
220 | 221 | // Support multi-proxy |
221 | | - String uri = jdbcTemplate.getDataSource().getConnection().getMetaData().getURL().replace("jdbc:postgresql://", "").split("/")[0]; |
222 | | - String dbURL = String.format("postgres://%s:%s@%s/%s",serviceInstanceId, findServiceInstance(serviceInstanceId).getCredentials(), uri , serviceInstanceId); |
223 | | - /* |
224 | | - String dbURL = String.format("postgres://%s:%s@%s:%d/%s", |
225 | | - // hack for multibinding |
226 | | - serviceInstanceId, |
227 | | - findServiceInstance(serviceInstanceId).getCredentials(), |
228 | | - //bindingId, passwd, |
229 | | - uri.getHost(), uri.getPort() == -1 ? 5432 : uri.getPort(), serviceInstanceId); |
230 | | - |
231 | | - */ |
| 222 | + String dbURL=""; |
| 223 | + if (s_uri.contains(",")){ |
| 224 | + dbURL = String.format("postgres://%s:%s@%s/%s",serviceInstanceId, findServiceInstance(serviceInstanceId).getCredentials(), s_uri , serviceInstanceId); |
| 225 | + }else{ |
| 226 | + |
| 227 | + URI uri = new URI(jdbcTemplate.getDataSource().getConnection().getMetaData().getURL().replace("jdbc:", "")); |
| 228 | + dbURL = String.format("postgres://%s:%s@%s:%d/%s", |
| 229 | + // hack for multibinding |
| 230 | + serviceInstanceId, |
| 231 | + findServiceInstance(serviceInstanceId).getCredentials(), |
| 232 | + //bindingId, passwd, |
| 233 | + uri.getHost(), uri.getPort() == -1 ? 5432 : uri.getPort(), serviceInstanceId); |
| 234 | + } |
| 235 | + |
232 | 236 | return dbURL; |
233 | 237 | } |
234 | 238 |
|
|
0 commit comments