我正在处理一些现有的应用程序,它在服务器启动时加载单个数据库查询。
现在我想在同一个代码中传递更多(可能3-4个查询)而不是一个查询。 即如何在春天传递多个查询
这是代码 -
myspring.xml
<property name="mypropertyfiles">
<list>
<value>test1.properties</value>
<value>test2.properties</value>
</list>
</property>
<bean id="mybean" class="com.test.MyBean">
<constructor-arg><ref-bean="mypropertyfiles"/><const-arg>
<constructor-arg><ref-bean="dataSource"/><const-arg>
<constructor-arg><value>select pcode, pname from PRODUCT1</value>
// Here only one query. **but I want to pass more queries like**
//select pcode, pname from PRODUCT2,
//select ocode, oname from ORDER1,
//select ocode, oname from ORDER2
<const-arg> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
MyBean.java
public class MyBean extends PropertyPlaceholderConfigurer
{
private DataSource dSource;
private String dbQuery;
// this is existing map to store PRODUCT1 table details
Map product1Map = new ConcurrentHashMap();
//lly, I will create more product2Map,order1Map , order2Map to store my
//queries data from PRODUCT2,ORDER1,ORDER2 tables
// here it is taking only one query.But I want more queries ie list
MyBean (Resource[] resources , DataSource dSource,String dbQuery){
super();
setLocations(resources);
this.dSource=dSource;
this.dbQuery=dbQuery;
}
@override
public String resolvePlaceholder(String p,Peroperties p){
//some code.....
loadQuery();
}
loadQuery(){
JdbcTemplate j;
j.execute(dbQuery,.......) // exsiting code has one query only{
public Map doInPreparestament(Preaprestatement ps){
rs =ps.executeQuery..
while(rs.next){
product1Map.put(rs.getString("pcode"),rs.getString("pname")); // only one map
}
}
}
}
问题 -
如何从“myspring.xml
”文件
我想使用现有的loadQuery方法加载我的所有查询并放入其他地图,例如product2Map
,order1Map
,order2Map