java - How to apply DRY for Liquibase data source config and persistence.xml? -


i using liquibase , java ee jboss. configure persistence.xml file in project specify data source want use.

in jboss configs:

<datasources>     <datasource jta="true" jndi-name="java:jboss/datasources/webstoriesds" pool-name="java:jboss/datasources/webstoriesds" enabled="true" use-java-context="true" use-ccm="true">         <connection-url>jdbc:postgresql://127.0.0.1:5432/mydatabase</connection-url>         <driver>org.postgresql</driver>         <security>             <user-name>postgres</user-name>             <password>postgres</password>         </security>     </datasource>     <drivers>         <driver name="org.postgresql" module="org.postgresql">             <xa-datasource-class>org.postgresql.xa.pgxadatasource</xa-datasource-class>         </driver>      </drivers> </datasources> 

in project's persistence.xml:

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">   <persistence-unit name="persistenceunit">     <jta-data-source>java:jboss/datasources/webstoriesds</jta-data-source>   </persistence-unit> </persistence> 

and project's web.xml:

<context-param>   <param-name>liquibase.datasource</param-name>   <param-value>java:jboss/datasources/webstoriesds</param-value> </context-param> 

well, can see have 1 data source reference in jboss , 2 references in project. how apply dry principle here , use 1 reference in jboss configs , 1 reference in project? use properties file hold data source name?

i need configure in way that, when need change name, change in 2 places: in project , in jboss configs.

both standard liquibase , jpa require datasource explicitly listed. logical reference, can change datasource points without affecting either configuration unless want change datasource name (as listed).

if wanting remove explicit reference either liquibase or jpa, easiest subclass liquibase.integration.servlet.liquibaseservletlistener , override getdatasource() method reference persitanceunit , return it. allow specify datasource in persistance.xml , no longer need liquibase.datasource configuration in web.xml.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -