database - How to change Play 2 Framework DB configuration at runtime? -
we using play 2.1.1 , built-in jpa integration (jpa.em() etc).
- how can dynamically change db.pass property? play.application().configuration() seems immutable of play 2.1. (or we're @ least not aware of mutators)
- if able change db.pass, how can reload db configuration jpa.em() returns entitymanager using new password?
what trying avoid having recreate entitymanager using entitymanagerfactory. want continue let play manage in jpa helper class.
background
the system has default db configuration running locally. when deployed server, db password dynamically set on running application using following script:
#!/bin/bash stty -echo read -p "password: " pass stty echo curl -k https://127.0.0.1:8443/someurl/pwd --data "password=$pass"
the application receives data , recreates hibernate sessionfactory. our new play app required similar.
the key use configfactory create new config entry. new config contains entry password value coming http call password service.
a new configuration created using new config, in turn falls original config original configuration.
basically new password entry supersedes original.
it sound long winded when it, code pretty readable.
public class global extends globalsettings { // inject http client make call password @override public configuration onloadconfig(configuration configuration, file file, classloader classloader) { final config config = configfactory.parsestring(string.format("db.default.user=%s", callpasswordservice())); return new configuration(config.withfallback(configuration.getwrappedconfiguration().underlying())); } }
Comments
Post a Comment