博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
我的工作内容
阅读量:5022 次
发布时间:2019-06-12

本文共 7543 字,大约阅读时间需要 25 分钟。

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文件

                                                                                                                                                                                                                                                                                                                                                                           

 

  1. 时间: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中获取

 

  1. 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>

 

 

  1. 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取值

 

 

  1. 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模式

  1. 通过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>

 

任务二、搜索所有数据表

  1. 主界面navigation.vm点击数据表配置

源码:

<li><a href="$dataMediaListLink">数据表配置</a></li>

  1. 找到跳转路径从uris.xml

源码:

<uris:turbine-uri id="dataMediaListLink" exposed="true"

   extends="homeModule">
   <target>dataMediaList.vm</target>
</uris:turbine-uri>

  1. 找到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 ("请输入关键字(目前支持DataMediaID、名字搜索)".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;
}

  1. 通过listByCondition()方法找到IbatisDataMediaDAO.java

public List<DataMediaDO> listByCondition(Map condition) {

    List<DataMediaDO> dataMediaDos = getSqlMapClientTemplate().queryForList("listDataMedias", condition);
    return dataMediaDos;
}

  1. 找到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>

 

转载于:https://www.cnblogs.com/StephenChowcai/p/9158399.html

你可能感兴趣的文章
C# 课堂总结3-语句
查看>>
精读《Scheduling in React》
查看>>
[Leetcode] 4Sum
查看>>
java.lang.StackOverflowError 解决方法
查看>>
hibernate事务控制
查看>>
[WCF编程]10.操作:请求/应答操作
查看>>
xfire实现webservice客户端之测试关注点
查看>>
在MySQL数据库中出现中文显示乱码
查看>>
对高内聚,低耦合的理解
查看>>
Codeforces Round #545 (Div. 2) C. Skyscrapers (离散化)
查看>>
fee photo
查看>>
PLSQL如何输出字典的脚本文件.sql
查看>>
idea热部署+自动编译
查看>>
SharePoint表单和工作流 - Nintex篇(三)
查看>>
mysql调优
查看>>
AlexNet详解
查看>>
清除目录下的SVN信息
查看>>
JS 定时提交 以及 保持在网页存在的时候session不失效的小技巧
查看>>
PYTHON常用数据类型(列表,元组,字典)
查看>>
nginx负载均衡tomcat和配置ssl
查看>>