java - how to change datasource connection url dynamically in Jboss 6 -
i using jboss as6 container manager tracsaction. using single mysql data source defined in mysql-ds.xml. have user requirement multiple users can have different database contents.so planning create new database each user.in future can change database design. quick solution, need find way crossover between different databases.
this default configuration. need change dbname
<local-tx-datasource> <jndi-name>defaultds</jndi-name> <connection-url>jdbc:mysql://144.0.0.1:3306/**dbname**</connection-url> <driver-class>com.mysql.jdbc.driver</driver-class> <user-name>root</user-name> <password>password</password> <max-pool-size>100</max-pool-size> <min-pool-size>0</min-pool-size> <connection-property name="readonly">false</connection-property> <autoreconnect>true</autoreconnect> <failoverreadonly>false</failoverreadonly> <maxreconnects>0</maxreconnects> <initialtimeout>15</initialtimeout> <idle-timeout-minutes>0</idle-timeout-minutes> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.mysqlexceptionsorter</exception-sorter-class-name> <!-- should used on drivers after 3.22.1 "ping" support <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.mysqlvalidconnectionchecker</valid-connection-checker-class-name> --> <!-- sql call when connection created <new-connection-sql>some arbitrary sql</new-connection-sql> --> <!-- sql call on existing pooled connection when obtained pool - mysqlvalidconnectionchecker preferred newer drivers <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql> --> </local-tx-datasource>
i using container manager transcaction.i need find way change connection-url of data source configuration.then clear entity manager connect new database.is possible
for task can hold multiple (5 in case) persistence contexts. link appropriate context choosing according user name example. simpliest solution. work 5 contexts open , hold connection. maybe it's need: 1 hand context ready use , don't need warmed.
another option construct persistence conext manually in java se envirionment. can helpful if not able hold many resources , switching not regular (once day. example).
you can find lot of articles describing how use jpa in java se environment. able use them in same manner (so not use container injection mechanism, find persistnece context through raw jndi)
https://dzone.com/articles/jpa-tutorial-setting-jpa-java http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/settingupjpa/settingupjpa.htm
Comments
Post a Comment