zoukankan      html  css  js  c++  java
  • jfinal对象封装Record原理

     
    
     
    
    /*DbPro.class*/
    
    public transient Record findFirst(String sql, Object paras[]{
    List result = find(sql, paras);
    return result.size() <= 0 ? null : (Record)result.get(0);
    }
    
    
    public transient List find(String sql, Object paras[])
    {
    Connection conn = null;
    List list;
    try
    {
    conn = config.getConnection();
    list = find(config, conn, sql, paras);
    }
    catch(Exception e)
    {
    throw new ActiveRecordException(e);
    }
    config.close(conn);
    return list;
    Exception exception;
    exception;
    config.close(conn);
    throw exception;
    }
    
    
    transient List find(Config config, Connection conn, String sql, Object paras[])
    throws SQLException
    {
    PreparedStatement pst = conn.prepareStatement(sql);
    config.dialect.fillStatement(pst, paras);
    ResultSet rs = pst.executeQuery();
    List result = RecordBuilder.build(config, rs);   //返回List<Record>
    DbKit.closeQuietly(rs, pst);
    return result;
    }
    
    
    /*RecordBuilder.class
    *把一条记录对象封装Record对象
    */
    public static final List build(Config config, ResultSet rs)
    throws SQLException
    {
    List result = new ArrayList();
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    String labelNames[] = new String[columnCount + 1];
    int types[] = new int[columnCount + 1];
    buildLabelNamesAndTypes(rsmd, labelNames, types);
    Record record;
    for(; rs.next(); result.add(record))
    {
    record = new Record();
    record.setColumnsMap(config.containerFactory.getColumnsMap());
    Map columns = record.getColumns();
    for(int i = 1; i <= columnCount; i++)
    {
    Object value;
    if(types[i] < 2004)
    value = rs.getObject(i);
    else
    if(types[i] == 2005)
    value = ModelBuilder.handleClob(rs.getClob(i));
    else
    if(types[i] == 2011)
    value = ModelBuilder.handleClob(rs.getNClob(i));
    else
    if(types[i] == 2004)
    value = ModelBuilder.handleBlob(rs.getBlob(i));
    else
    value = rs.getObject(i);
    columns.put(labelNames[i], value);
    }
    
    }
    
    return result;
    }
    
      
      
    

      

  • 相关阅读:
    css选择器解析规则
    swiper轮播图包含视频或图片
    css实现文字选中变色
    swiper鼠标滚轮事件
    C语言中,关于相除的问题
    输入测试字符型数据的组数,再输入字符型数据,排坑
    C语言中,字符型数字与常数型数字的加减实现
    C语言的指针用法:输入一堆字符,把非字母的删去。
    C语言中倒序输出你输入的数。
    C语言中,嵌套的if语句的一些经验...
  • 原文地址:https://www.cnblogs.com/chenweichu/p/5946078.html
Copyright © 2011-2022 走看看