设计模式课程 设计模式精讲 10-2 外观模式源码解析

1    源码解析

1.1  源码解析1(jdk中的JDBCUtils工具类)

1.2  源码解析2

1.3  源码解析3

1.4  源码解析4

1    源码解析

1.1  源码解析1(jdk中的JDBCUtils工具类)

jdbc在springJDBC中的封装

/**
     * Close the given JDBC Connection and ignore any thrown exception.
     * This is useful for typical finally blocks in manual JDBC code.
     * @param con the JDBC Connection to close (may be {@code null})
     */
    public static void closeConnection(Connection con) {
        if (con != null) {
            try {
                con.close();
            }
            catch (SQLException ex) {
                logger.debug("Could not close JDBC Connection", ex);
            }
            catch (Throwable ex) {
                // We don‘t trust the JDBC driver: It might throw RuntimeException or Error.
                logger.debug("Unexpected exception on closing JDBC Connection", ex);
            }
        }
    }

    /**
     * Close the given JDBC Statement and ignore any thrown exception.
     * This is useful for typical finally blocks in manual JDBC code.
     * @param stmt the JDBC Statement to close (may be {@code null})
     */
    public static void closeStatement(Statement stmt) {
        if (stmt != null) {
            try {
                stmt.close();
            }
            catch (SQLException ex) {
                logger.trace("Could not close JDBC Statement", ex);
            }
            catch (Throwable ex) {
                // We don‘t trust the JDBC driver: It might throw RuntimeException or Error.
                logger.trace("Unexpected exception on closing JDBC Statement", ex);
            }
        }
    }

    /**
     * Close the given JDBC ResultSet and ignore any thrown exception.
     * This is useful for typical finally blocks in manual JDBC code.
     * @param rs the JDBC ResultSet to close (may be {@code null})
     */
    public static void closeResultSet(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            }
            catch (SQLException ex) {
                logger.trace("Could not close JDBC ResultSet", ex);
            }
            catch (Throwable ex) {
                // We don‘t trust the JDBC driver: It might throw RuntimeException or Error.
                logger.trace("Unexpected exception on closing JDBC ResultSet", ex);
            }
        }
    }

1.2  源码解析2(mybaties应用的Configuration)

通过封装之后,我们的客户端都有这些功能,这一组接口交给客户端来访问

public MetaObject newMetaObject(Object object) {
    return MetaObject.forObject(object, objectFactory, objectWrapperFactory, reflectorFactory);
  }

  public ParameterHandler newParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
    ParameterHandler parameterHandler = mappedStatement.getLang().createParameterHandler(mappedStatement, parameterObject, boundSql);
    parameterHandler = (ParameterHandler) interceptorChain.pluginAll(parameterHandler);
    return parameterHandler;
  }

  public ResultSetHandler newResultSetHandler(Executor executor, MappedStatement mappedStatement, RowBounds rowBounds, ParameterHandler parameterHandler,
      ResultHandler resultHandler, BoundSql boundSql) {
    ResultSetHandler resultSetHandler = new DefaultResultSetHandler(executor, mappedStatement, parameterHandler, resultHandler, boundSql, rowBounds);
    resultSetHandler = (ResultSetHandler) interceptorChain.pluginAll(resultSetHandler);
    return resultSetHandler;
  }

1.3  源码解析3(在tomcat中的应用)

1.4  源码解析4

原文地址:https://www.cnblogs.com/1446358788-qq/p/11484213.html

时间: 2024-08-29 12:08:03

设计模式课程 设计模式精讲 10-2 外观模式源码解析的相关文章

Java 集合系列 10 Hashtable详细介绍(源码解析)和使用示例

java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java 集合系列 04 LinkedList详细介绍(源码解析)和使用示例 Java 集合系列 05 Vector详细介绍(源码解析)和使用示例 Java 集合系列 06 Stack详细介绍(源码解析)和使用示例 Java 集合系列 07 List总结(LinkedList, ArrayList等使用场景和

设计模式课程 设计模式精讲 15-3 桥接模式源码解析

1 桥接模式源码解析 1.1 源码解析1 jdk中的应用(驱动类) 1 桥接模式源码解析 1.1 源码解析1 jdk中的应用(驱动类) 步骤: class.forName 调取驱动接口的静态块,触发驱动管理类DriverManager 的注册驱动方法,从而将该驱动放到CopyOnWriteArrayList中. getConnect方法是通过传入url用户名密码. 针对不同的数据库,通过driverManager中的不同方法,获取的都是相同的接口,jdbc在最初的时候设计了一套接口,再由各个数据

设计模式课程 设计模式精讲 17-3 模板方法模式源码解析

1 源码解析 1.1 源码解析1(在jdk中的使用) 1.2 源码解析2(在servlet中的应用) 1.3 源码解析3(在mybaties中的应用) 1 源码解析 1.1 源码解析1(在jdk中的使用) AbstractList(父类) public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E> { //get方法为抽象方法,完全交给子类去实现 abstr

设计模式课程 设计模式精讲 16-5 代理模式源码解析

1 源码解析 1.1 源码解析1(jdk中的应用) 1.2 源码解析2(spring中的应用) 1.3 源码解析3(mybaties中的应用) 1 源码解析 1.1 源码解析1(jdk中的应用) java.lang.reflect.Proxy public class Proxy implements java.io.Serializable { protected Proxy(InvocationHandler h) { doNewInstanceCheck(); this.h = h; }

设计模式课程 设计模式精讲 18-3 迭代器模式源码解析

1 源码解析 1.1 源码解析1(jdk中的应用) 1.2 源码解析2(mybaties中的应用)   1 源码解析 1.1 源码解析1(jdk中的应用) java.util.Iterator(接口) public interface Iterator<E> { /** * Returns {@code true} if the iteration has more elements. * (In other words, returns {@code true} if {@link #nex

设计模式课程 设计模式精讲 19-3 策略模式源码解析

1 源码解析 1.1 源码解析1(jdk中的应用1) 1.2 源码解析2(jdk中的应用2) 1.3 源码解析3(Spring中的应用1) 1.4 源码解析4(Spring中的应用2) 1 源码解析 1.1 源码解析1(jdk中的应用1) java.util.Comparator(策略类)作为比较器的应用 package java.util; public interface Comparator<T> { int compare(T o1, T o2); boolean equals(Obj

设计模式课程 设计模式精讲 12-3 适配器模式源码解析

1 源码解析 1.1 源码解析1(在jdk中的应用) 1.2 源码解析2(Spring中的通知管理) 1.3 源码解析3(SpringMVC中的应用) 1 源码解析 1.1 源码解析1(在jdk中的应用) xmlAdapter(此类是用于适配xml的一个类,是处理xml序列化和反序列化的一个类) public abstract class XmlAdapter<ValueType,BoundType> { /** * Do-nothing constructor for the derived

设计模式课程 设计模式精讲 21-3 观察者模式源码解析

1 源码解析 1.1 源码解析1(jdk中的应用) 1.2 源码解析2(Spring中的应用) 1.3 源码解析为何算出666?   1 源码解析 1.1 源码解析1(jdk中的应用) java.util.regex.Pattern (java正则表达式通过java.util.regex包下的Pattern类与Matcher类实现) 1.2 源码解析2(Spring中的应用) 测试类:(通过el表达式计算出结果)(以下代码中红色粗体为跳转顺序) package com.geely.design.

第10章 外观模式(Fa?ade Pattern)

原文   第10章 外观模式(Fa?ade Pattern) 概述:   在软件开发系统中,客户程序经常会与复杂系统的内部子系统之间产生耦合,而导致客户程序随着子系统的变化而变化.那么如何简化客户程序与子系统之间的交互接口?如何将复杂系统的内部子系统与客户程序之间的依赖解耦?这就是要说的Fa?ade 模式. 为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用.[GOF <设计模式>] 结构图: 这里在附上一个有助于理解的图 未使用外观