Java/Spring/JDBC: changing database schema property at run-time -


i'm trying come solution following problem:

i have number of spring beans various daos in application configured like:

<bean id="productdao" class="com.myproject.productjdbcdao">     <property name="datasource" ref="datasource" />     <property name="getallproductssql" value="select * ${myschema}product_table" /> </bean>  <bean id="customerdao" class="com.myproject.customerjdbcdao">     <property name="datasource" ref="datasource" /> </bean> 

where myschema set in our properties file like:

myschema=testdbschema. 

i have spring bean post processor configured like:

<bean class="com.project.schemaawarebeanpostprocessor">     <property name="myschema" value="${myschema}" />     <property name="differentschema" value="${differentschema}" /> </bean> 

where postprocessbeforeinitialization() method implementation looks like:

@override public object postprocessbeforeinitialization(object bean, string beanname) throws beansexception {     if(bean instanceof schemaawareinterface) {         schemaawareinterface dao = (schemaawareinterface) bean;         dao.setschemas(this.myschema, this.differentschema);     }     return bean;     } 

so dao implements schemaawareinterface can , store schema values when it's bean created spring. example, customerdao implementation might this:

public class customerjdbcdao extends jdbcdaosupport implements schemaawareinterface {     private string myschema;      @override     public void setschemas(string myschema, string differentschema) {          this.myschema = myschema;     }      public list<customer> getcustomers() {         //code uses this.myschema build dynamic sql     } } 

now, want able arbitrarily change value of myschema while application running dao or class created original myschema value updated use new value. how accomplish this?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -