Work
任务一、查看单个数据源
更新及查询的操作流程:
1)更新操作:页面(.vm)----->路径(uris.xml)----->顶级Action(AbstractAction.java)----->具体的action----->顶级服务接口(GenericService.java)----->具体的Service----->顶级DAO接口(GenericDAO)----->具体的DAO----->对应的sql处理.xml文件
2)查询操作:页面(.vm)----->路径(uris.xml)----->对应的java类.java----->顶级服务接口(GenericService.java)----->具体的Service----->顶级DAO接口(GenericDAO)----->具体的DAO
----->对应的sql处理.xml文件
- 时间:2018.1.19-2018.1.20 任务名:单个数据源的查看 结果:画出具体流程图
程序详细流程:
1)dataSourceList.vm页面点击“查看”按钮
#set ($dataSourceInfoURL = $homeModule.setTarget("dataSourceInfo.vm").addQueryData("dataMediaSourceId", $source.id))
<a href="$dataSourceInfoURL"><img src="images/ico_edit.png" width="13" height="13" /><span class="ico_font">查看</span></a>
2)sourceid为数据源id
从本页面的源码得知
#foreach ($source in $sources)
<tr> <td width="5%">$!source.id</td> <td width="12%">$!source.name</td> <td>$!source.type</td> <td>$!source.encode</td> <td>$!source.url</td>3)最终显示数据源页面是dataSourceInfo.vm
查看源码可知,信息是从source中获取
- uris.xml文件—负责前台页面的跳转路径配置
学习地址:http://blog.csdn.net/cpf2016/article/details/45559769
从$homeModule.setTarget(“”)可知
对应的配置信息如下
<uris:turbine-uri id="homeModule" exposed="true" extends="server">
<componentPath>/</componentPath></uris:turbine-uri>
- DataSourceInfo.java类—(对应的是module控制器的screen)
1)根据:.vm的文件的名字
执行execute()方法
public void execute(@Param("dataMediaSourceId") Long dataMediaSourceId, Context context) throws Exception {
//查询单个数据源
DataMediaSource dataMediaSource = dataMediaSourceService.findById(dataMediaSourceId); // 查询所有数据表List<DataMedia> dataMedias = dataMediaService.listByDataMediaSourceId(dataMediaSource.getId());
//把上述查询结果放在context域中,便于页面取值
context.put("source", dataMediaSource); context.put("dataMedias", dataMedias);}由图可知把查询的结果放在context中,前台页面就可以用$source和$dataMedias取值
- DataMediaSourceSerrviceImpl.java类
1)根据:顶级Service接口(GenericService.java)找到dataMediaSourceService再找到本类
执行findById()方法如下:
public DataMediaSource findById(Long dataMediaSourceId) {
Assert.assertNotNull(dataMediaSourceId); List<DataMediaSource> dataMediaSources = listByIds(dataMediaSourceId); if (dataMediaSources.size() != 1) {//用一个数据源id查询出多条结果证明有异常
String exceptionCause = "query dataMediaSourceId:" + dataMediaSourceId + " but return " + dataMediaSources.size() + " dataMediaSource."; logger.error("ERROR ## " + exceptionCause); throw new ManagerException(exceptionCause); }//返回查询结果—索引值为0,是list集合的第一个元素
return dataMediaSources.get(0);}
3)找方法listByIds()如下:
public List<DataMediaSource> listByIds(Long... identities) {
List<DataMediaSourceDO> dataMediaSourceDos = null;//没有参数
if (identities.length < 1) {//查询所有数据源
dataMediaSourceDos = dataMediaSourceDao.listAll(); if (dataMediaSourceDos.isEmpty()) {//数据库的数据源查询为空
logger.debug("DEBUG ## couldn't query any dataMediaSource, maybe hasn't create any dataMediaSource.");//返回null
return new ArrayList<DataMediaSource>(); } } else {//查询出单个数据源
dataMediaSourceDos = dataMediaSourceDao.listByMultiId(identities); if (dataMediaSourceDos.isEmpty()) { String exceptionCause = "couldn't query any dataMediaSource by dataMediaSourceIds:" + Arrays.toString(identities); logger.error("ERROR ## " + exceptionCause); throw new ManagerException(exceptionCause); } } //转换成do模式,返回 return doToModel(dataMediaSourceDos);}4)找类dataMediaSourceDao
GenericDAO>DataSourceDAO
根据:顶级DAO接口(GenericDAO.java)找到实现类IbatisDataMediaSourceDAO.java类
如下查询方法:
public DataMediaSourceDO findById(Long dataMediaSourceId) {
Assert.assertNotNull(dataMediaSourceId); return (DataMediaSourceDO) getSqlMapClientTemplate().queryForObject("findDataMediaSourceById", dataMediaSourceId);}从3)中可以看出必须转为DO模式
- 通过findDataMediaSourceById找到最终查询单个数据源的SQL语句的.xml配置文件
sqlmap-mapping-datamediasource.xml
具体的SQL配置信息如下图:
<select id="findDataMediaSourceById" resultMap="dataMediaSourceResult" parameterClass="long"> select <include refid="allDataMediaSourceColumns" /> from DATA_MEDIA_SOURCE where ID = #value#</select>
任务二、搜索所有数据表
- 主界面navigation.vm点击数据表配置
源码:
<li><a href="$dataMediaListLink">数据表配置</a></li>
- 找到跳转路径从uris.xml
源码:
<uris:turbine-uri id="dataMediaListLink" exposed="true"
extends="homeModule"> <target>dataMediaList.vm</target></uris:turbine-uri>- 找到dataMediaList.vm
如下查找所有的数据表
<form id="pageform" name="pageform" action="$homeModule.setTarget('dataMediaList.vm')" method="post">
<input type="hidden" id="pageIndex" name="pageIndex" value=""/><input type="hidden" id="searchKey" name="searchKey" value="$!searchKey"/> </form>
4.找到dataMediaList.java类
源码如下:
public void execute(@Param("pageIndex") int pageIndex, @Param("searchKey") String searchKey, Context context)
throws Exception { @SuppressWarnings("unchecked")//查询条件是一个Map集合
Map<String, Object> condition = new HashMap<String, Object>(); if ("请输入关键字(目前支持DataMedia的ID、名字搜索)".equals(searchKey)) { searchKey = ""; } condition.put("searchKey", searchKey); int count = dataMediaService.getCount(condition);//这里的Paginator是分页对象
Paginator paginator = new Paginator();//设置分页的记录数
paginator.setItems(count);//设置分页的当前页数
paginator.setPage(pageIndex);// condition.put("offset", paginator.getOffset()); condition.put("length", paginator.getLength());//根据条件查询出所有的数据表 List<DataMedia> dataMedias = dataMediaService.listByCondition(condition); List<SeniorDataMedia> seniorDataMedias = new ArrayList<SeniorDataMedia>(); for (DataMedia dataMedia : dataMedias) { SeniorDataMedia seniorDataMedia = new SeniorDataMedia(); seniorDataMedia.setId(dataMedia.getId()); seniorDataMedia.setEncode(dataMedia.getEncode()); seniorDataMedia.setGmtCreate(dataMedia.getGmtCreate()); seniorDataMedia.setGmtModified(dataMedia.getGmtModified()); seniorDataMedia.setName(dataMedia.getName()); seniorDataMedia.setNamespace(dataMedia.getNamespace()); seniorDataMedia.setSource(dataMedia.getSource()); List<DataMediaPair> pairs = dataMediaPairService.listByDataMediaId(dataMedia.getId()); seniorDataMedia.setPairs(pairs); if (pairs.size() < 1) { seniorDataMedia.setUsed(false); } else { seniorDataMedia.setUsed(true); } seniorDataMedias.add(seniorDataMedia); } context.put("dataMedias", seniorDataMedias); context.put("paginator", paginator); context.put("searchKey", searchKey);}1)结果页面用dataMedias来取出所有的数据表集合
5.通过listByCondition找到DataMediaServiceImpl.java类
public List<DataMedia> listByCondition(Map condition) {
List<DataMedia> dataMedias = new ArrayList<DataMedia>(); try { List<DataMediaDO> dataMediaDos = dataMediaDao.listByCondition(condition); if (dataMediaDos.isEmpty()) { logger.debug("DEBUG ## couldn't query any dataMedias by the condition:" + JsonUtils.marshalToString(condition)); return dataMedias; } dataMedias = doToModel(dataMediaDos); } catch (Exception e) { logger.error("ERROR ## query dataMedias by condition has an exception!"); throw new ManagerException(e); } return dataMedias;}- 通过listByCondition()方法找到IbatisDataMediaDAO.java类
public List<DataMediaDO> listByCondition(Map condition) {
List<DataMediaDO> dataMediaDos = getSqlMapClientTemplate().queryForList("listDataMedias", condition); return dataMediaDos;}- 找到sqlmap-mapping-datamedia.xml文件—最终的SQL配置文件
<select id="listDataMedias" resultMap="dataMediaResult">
select <include refid="allDataMediaColumns" /> from DATA_MEDIA <dynamic prepend="where"> <isNotEmpty property="searchKey"> NAME like concat('%',replace(#searchKey#,'_','\_'),'%') or NAMESPACE like concat('%',replace(#searchKey#,'_','\_'),'%') or ID like concat('%',replace(#searchKey#,'_','\_'),'%') </isNotEmpty> </dynamic> ORDER BY ID DESC <dynamic> <isNotEmpty property="offset" > <isNotEmpty property="length"> limit #offset#, #length# </isNotEmpty> </isNotEmpty> </dynamic></select>