diff --git a/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/CloudFoundryModule.java b/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/CloudFoundryModule.java index 721217f287f..9f8ef9f2ee3 100644 --- a/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/CloudFoundryModule.java +++ b/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/CloudFoundryModule.java @@ -12,6 +12,7 @@ import org.eclipse.dirigible.cf.utils.CloudFoundryUtils; import org.eclipse.dirigible.cf.utils.CloudFoundryUtils.HanaDbEnv; +import org.eclipse.dirigible.cf.utils.CloudFoundryUtils.HanaSchemaEnv; import org.eclipse.dirigible.cf.utils.CloudFoundryUtils.PostgreDbEnv; import org.eclipse.dirigible.cms.api.ICmsProvider; import org.eclipse.dirigible.commons.api.module.AbstractDirigibleModule; @@ -40,7 +41,8 @@ public int getPriority() { protected void configure() { boolean customPostgreDb = bindPostgreDb(CloudFoundryUtils.getPostgreDbEnv()); boolean customHanaDb = bindHanaDb(CloudFoundryUtils.getHanaDbEnv()); - if (!customPostgreDb && !customHanaDb) { + boolean customHanaSchema = bindHanaSchema(CloudFoundryUtils.getHanaSchemaEnv()); + if (!customPostgreDb && !customHanaDb && !customHanaSchema) { Configuration.set(IDatabase.DIRIGIBLE_DATABASE_PROVIDER, "local"); } } @@ -80,6 +82,25 @@ private boolean bindHanaDb(HanaDbEnv env) { return true; } + private boolean bindHanaSchema(HanaSchemaEnv env) { + if (env == null) { + return false; + } + + String name = DATABASE_HANA; + String url = env.getCredentials().getUrl(); + String username = env.getCredentials().getUsername(); + String password = env.getCredentials().getPassword(); + String driver = DATABASE_HANA_DRIVER; + + setDatabaseProperties(name, url, driver, username, password); + + String maxConnectionsCount = Configuration.get(IDatabase.DIRIGIBLE_DATABASE_DEFAULT_MAX_CONNECTIONS_COUNT, "32"); + Configuration.set(IDatabase.DIRIGIBLE_DATABASE_DEFAULT_MAX_CONNECTIONS_COUNT, maxConnectionsCount); + Configuration.set(DIRIGIBLE_MESSAGING_USE_DEFAULT_DATABASE, "false"); + return true; + } + private void setDatabaseProperties(String name, String url, String driver) { setDatabaseProperties(name, url, driver, null, null); } diff --git a/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/utils/CloudFoundryUtils.java b/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/utils/CloudFoundryUtils.java index f59a4aef878..919a8cce533 100644 --- a/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/utils/CloudFoundryUtils.java +++ b/releng/sap-cf-base/src/main/java/org/eclipse/dirigible/cf/utils/CloudFoundryUtils.java @@ -72,6 +72,12 @@ public static HanaDbEnv getHanaDbEnv() { return vcapServicesEnv.getHanaDbEnv() != null ? vcapServicesEnv.getHanaDbEnv().get(0) : null; } + public static HanaSchemaEnv getHanaSchemaEnv() { + String envJson = EnvFacade.get(VCAP_SERVICES); + VcapServicesEnv vcapServicesEnv = GsonHelper.GSON.fromJson(envJson, VcapServicesEnv.class); + return vcapServicesEnv.getHanaSchemaEnv() != null ? vcapServicesEnv.getHanaSchemaEnv().get(0) : null; + } + public static class VcapServicesEnv { private List xsuaa; @@ -82,6 +88,9 @@ public static class VcapServicesEnv { @SerializedName("hana-db") private List hanaDbEnv; + @SerializedName("hana") + private List hanaSchemaEnv; + public List getXsuaa() { return xsuaa; } @@ -105,6 +114,14 @@ public List getHanaDbEnv() { public void setHanaDbEnv(List hanaDbEnv) { this.hanaDbEnv = hanaDbEnv; } + + public List getHanaSchemaEnv() { + return hanaSchemaEnv; + } + + public void setHanaSchemaEnv(List hanaSchemaEnv) { + this.hanaSchemaEnv = hanaSchemaEnv; + } } public static class XsuaaEnv { @@ -315,4 +332,51 @@ public void setUrl(String url) { } } } + + public static class HanaSchemaEnv { + + private HanaSchemaCredentialsEnv credentials; + + public HanaSchemaCredentialsEnv getCredentials() { + return credentials; + } + + public void setCredentials(HanaSchemaCredentialsEnv credentials) { + this.credentials = credentials; + } + + public static class HanaSchemaCredentialsEnv { + + private String url; + + @SerializedName("user") + private String username; + + private String password; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + } + } } \ No newline at end of file