0

I have an user-defined service in Bluemix (on-premise database that is not on the Bluemix cloud), and the credentials looks like this:

System-Provided:
{
 "VCAP_SERVICES": {
  "user-provided": [
   {
    "credentials": {
     "dbname": "",
     "host": "",
     "password": "",
     "port": "",
     "username": ""
    },
    "label": "user-provided",
    "name": "some-service",
    "syslog_drain_url": "",
    "tags": []
   }
  ]
 }
}

Is there a way to parse the JSON somehow and read it into these persistence unit properties?

<properties>
  <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
  <property name="javax.persistence.jdbc.url" value=''/>
  <property name="javax.persistence.jdbc.user" value=""/>
  <property name="javax.persistence.jdbc.password" value=""/>
</properties>
Frank Song
  • 11
  • 4

1 Answers1

0

When you create your EntityManagerFactory you can pass custom values to override persistence files like this:

HashMap<String,String> props=new HashMap<>();
props.put("javax.persistence.jdbc.url", "yourUserName");
EntityManagerFactory emf=Persistence.createEntityManagerFactory("YourPersistenceUnitPU",props);

To parse JSON you can use google gson lib.

Mateus Viccari
  • 7,389
  • 14
  • 65
  • 101