现在我在控制器中定义了以下两个连接到两个不同数据库的bean。当前场景中的两个bean
控制器从Web服务调用收到doc_id
和empID_
后,同时执行。我不希望这种情况发生。
当前情景:
@RequestMapping(value="/showEmpDetails", method=RequestMethod.GET)
public String showEmpDetails
(
@RequestParam(value="doc_id", defaultValue="0") String doc_id,
@RequestParam(value="emp_id", defaultValue="1234") String empID_
)
{ String jsonString = "";
try {
// Bean 1 defined for an Oracle database
EmployeeDao empDao = (EmployeeDao) context.getBean("empDao");
// Bean 2 defined for different Oracle database
EmployeeDao empForValueDao = (EmployeeDao) context.getBean("empValueDao");
List<ShowDescription> beanONE = empForValueDao.getemployeeDetails(empID_);
List<ShowDescription> beanTWO = empDao.getCompanyShowDocument(doc_id);
}
return JsonString;
}
预期情景:
我希望首先执行beanONE
,在调用getemployeeDetails
方法后在控制器中返回一个值,然后传递该值
doc_id
旁边第二次调用bean的时间,如下所示。以这种方式,我在getCompanyShowDocument
方法中使用的SQL查询可以生成
使用这个值,并得到我期待的结果。
@RequestMapping(value="/showEmpDetails", method=RequestMethod.GET)
public String showEmpDetails
(
@RequestParam(value="doc_id", defaultValue="0") String doc_id,
@RequestParam(value="emp_id", defaultValue="1234") String empID_
)
{ String jsonString = "";
try {
// Bean 1 defined for different Oracle database
EmployeeDao empForValueDao = (EmployeeDao) context.getBean("empValueDao");
// Bean 2 defined for an Oracle database
EmployeeDao empDao = (EmployeeDao) context.getBean("empDao");
List<ShowDescription> beanONE = empForValueDao.getemployeeDetails(empID_);
List<ShowDescription> beanTWO = empDao.getCompanyShowDocument(doc_id,returnedValue);
}
return JsonString;
}
在XML中,我将bean定义如下:
<bean id="empDao" class="abc.edg.myproj.dao.impl.EmployeeDaoImpl">
<property name="dataSource"><ref bean="DB_ONE"/></property>
</bean>
<bean id="empValueDao" class="abc.edg.myproj.dao.impl.EmployeeDaoImpl">
<property name="dataSource"><ref bean="DB_TWO"/></property>
</bean>
有可能实现我上面描述的内容吗?请指教。感谢
根据评论中的要求添加getemployeeeDetails
方法:
public List<ShowDescription> getemployeeDetails(String empID) throws DaoException
{
DataSource ds = null;
Connection conn = null;
PreparedStatement pstmt2 = null;
ResultSet rs2 = null;
List<ShowDescription> employeeValue = new ArrayList<ShowDescription>();
try {
ds = jdbcTemplate.getDataSource();
conn = ds.getConnection();
pstmt2 = conn.prepareStatement(selectValueSQL);
pstmt2.setString(1, empID);
rs2 = pstmt2.executeQuery();
while(rs2.next()) {
ShowDescription employeeRecord = new ShowDescription();
employeeRecord.setEmployeeValue(rs2.getString("value"));
employeeValue.add(employeeRecord);
System.out.println("I am inside getemployeeDetails method to get the cvtermPropValue");
System.out.println(employeeRecord.getEmployeeValue()); // Prints the value
}
} catch(Throwable th) {
//some code
} finally {
// Closing all resources here
}
return employeeValue;
}