public Map<String, Object>[] query(String dataSourceName, String sql, Object... params) { SimpleJdbcDaoSupport daoSupport = getDaoSupport(dataSourceName); Preconditions.checkNotNull(daoSupport," daosupport is null- please check the datasource name"); List<Map<String, Object>> result = daoSupport.getSimpleJdbcTemplate().queryForList(sql, params); Map<String, Object>[] arr = new Map[result.size()]; for (int i=0; i < result.size(); i++) { arr[i] = result.get(i); } return arr; }
private SimpleJdbcDaoSupport getDaoSupport(String dataSourceName) { Object dsBean = applicationContext.getBean(dataSourceName); if (dsBean instanceof DataSource) { SimpleJdbcDaoSupport daoSupport = new SimpleJdbcDaoSupport(); daoSupport.setDataSource((DataSource) dsBean); return daoSupport; } else { throw new AlfrescoRuntimeException("dataSource '" + dataSourceName + "' not found."); } }
@ScriptMethod() public int update(String dataSourceName, String sql, Object... params) { SimpleJdbcDaoSupport daoSupport = getDaoSupport(dataSourceName); Preconditions.checkNotNull(daoSupport," daosupport is null- please check the datasource name"); return daoSupport.getSimpleJdbcTemplate().update(sql, params); }