主頁 > 軟體設計 > 面試:面試官有沒有在Mybatis執行程序上為過難你呢?看完就不再慫(圖文決議)

面試:面試官有沒有在Mybatis執行程序上為過難你呢?看完就不再慫(圖文決議)

2020-09-29 10:02:08 軟體設計

前言

在了解了MyBatis初始化加載程序后,我們也應該研究看看SQL執行程序是怎樣執行?這樣我們對于Mybatis的整個執行流程都熟悉了,在開發遇到問題也可以很快定位到問題,

更重要的,在面試中遇到面試官咨詢Mybatis的知識點的時候,可以很順暢的把這一套流程講出來,面試官也會覺得你已掌握Mybatis知識點了,可能就不問了,趕緊瞄瞄,

簡介SQL執行程序

經過MyBatis初始化加載Sql執行程序所需的資訊后,我們就可以通過 SqlSessionFactory 物件得到 SqlSession ,然后執行 SQL 陳述句了,接下來看看Sql執行具體程序,SQL大致執行流程圖如下所示:

接下來我們來看看每個執行鏈路中的具體執行程序,

SqlSession

SqlSession 是 MyBatis 暴露給外部使用的統一介面層,通過 SqlSessionFactory 創建,且其是包含和資料庫打交道所有操作介面,

下面通過時序圖描述 SqlSession 物件的創建流程:

在生成SqlSession的同時,基于executorType初始化好Executor 實作類,

public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
    executorType = executorType == null ? defaultExecutorType : executorType;
    executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
    Executor executor;
    if (ExecutorType.BATCH == executorType) {
      executor = new BatchExecutor(this, transaction);
    } else if (ExecutorType.REUSE == executorType) {
      executor = new ReuseExecutor(this, transaction);
    } else {
      executor = new SimpleExecutor(this, transaction);
    }
    if (cacheEnabled) {
      executor = new CachingExecutor(executor);
    }
    executor = (Executor) interceptorChain.pluginAll(executor);
    return executor;
  }

最頂層的SqlSession介面已生成,那我們可以來看看sql的執行程序下一步是怎樣的呢?怎樣使用代理類MapperProxy

MapperProxy

MapperProxyMapper介面與SQL 陳述句映射的關鍵,通過 MapperProxy 可以讓對應的 SQL 陳述句跟介面進行系結的,具體流程如下:

  • MapperProxy代理類生成流程
  • MapperProxy代理類執行操作

MapperProxy代理類生成流程

其中,MapperRegistryConfiguration 的一個屬性,在決議配置時候會在MapperRegistry 中快取了 MapperProxyFactoryknownMappers 變數Map 集合,

``MapperRegistry會根據mapper介面型別獲取已快取的MapperProxyFactoryMapperProxyFactory會基于SqlSession來生成MapperProxy`代理物件,

 public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
        MapperProxyFactory<T> mapperProxyFactory = (MapperProxyFactory)this.knownMappers.get(type);
        if (mapperProxyFactory == null) {
            throw new BindingException("Type " + type + " is not known to the MapperRegistry.");
        } else {
            try {
                return mapperProxyFactory.newInstance(sqlSession);
            } catch (Exception var5) {
                throw new BindingException("Error getting mapper instance. Cause: " + var5, var5);
            }
        }
    }

當呼叫SqlSession介面時,MapperProxy怎么是實作的呢?MyBatisMapper介面 是通過動態代理實作的,呼叫 Mapper 介面的任何方法都會執行 MapperProxy::invoke() 方法,

 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        try {
            //Object型別執行
            if (Object.class.equals(method.getDeclaringClass())) {
                return method.invoke(this, args);
            }
			//介面默認方法執行
            if (method.isDefault()) {
                if (privateLookupInMethod == null) {
                    return this.invokeDefaultMethodJava8(proxy, method, args);
                }

                return this.invokeDefaultMethodJava9(proxy, method, args);
            }
        } catch (Throwable var5) {
            throw ExceptionUtil.unwrapThrowable(var5);
        }
        MapperMethod mapperMethod = this.cachedMapperMethod(method);
        return mapperMethod.execute(this.sqlSession, args);
    }

但最侄訓呼叫到mapperMethod::execute() 方法執行,主要是判斷是 INSERTUPDATEDELETESELECT 陳述句去操作,其中如果是查詢的話,還會判斷回傳值的型別,

 public Object execute(SqlSession sqlSession, Object[] args) {
        Object result;
        Object param;
        switch(this.command.getType()) {
        case INSERT:
            param = this.method.convertArgsToSqlCommandParam(args);
            result = this.rowCountResult(sqlSession.insert(this.command.getName(), param));
            break;
        case UPDATE:
            param = this.method.convertArgsToSqlCommandParam(args);
            result = this.rowCountResult(sqlSession.update(this.command.getName(), param));
            break;
        case DELETE:
            param = this.method.convertArgsToSqlCommandParam(args);
            result = this.rowCountResult(sqlSession.delete(this.command.getName(), param));
            break;
        case SELECT:
            if (this.method.returnsVoid() && this.method.hasResultHandler()) {
                this.executeWithResultHandler(sqlSession, args);
                result = null;
            } else if (this.method.returnsMany()) {
                result = this.executeForMany(sqlSession, args);
            } else if (this.method.returnsMap()) {
                result = this.executeForMap(sqlSession, args);
            } else if (this.method.returnsCursor()) {
                result = this.executeForCursor(sqlSession, args);
            } else {
                param = this.method.convertArgsToSqlCommandParam(args);
                result = sqlSession.selectOne(this.command.getName(), param);
                if (this.method.returnsOptional() && (result == null || !this.method.getReturnType().equals(result.getClass()))) {
                    result = Optional.ofNullable(result);
                }
            }
            break;
        case FLUSH:
            result = sqlSession.flushStatements();
            break;
        default:
            throw new BindingException("Unknown execution method for: " + this.command.getName());
        }

        if (result == null && this.method.getReturnType().isPrimitive() && !this.method.returnsVoid()) {
            throw new BindingException("Mapper method '" + this.command.getName() + " attempted to return null from a method with a primitive return type (" + this.method.getReturnType() + ").");
        } else {
            return result;
        }
    }

通過以上的分析,總結出

  • Mapper介面實際物件為代理物件MapperProxy
  • MapperProxy繼承InvocationHandler,實作invoke方法;
  • MapperProxyFactory::newInstance() 方法,基于 JDK 動態代理的方式創建了一個 MapperProxy 的代理類;
  • 最侄訓呼叫到mapperMethod::execute() 方法執行,完成操作,
  • 而且更重要一點是,MyBatis 使用的動態代理和普遍動態代理有點區別,沒有實作類,只有介面,MyBatis 動態代理類圖結構如下所示:

已以SELECT 為例, 呼叫會SqlSession ::selectOne() 方法,繼續往下執行,會執行 Executor::query() 方法,

public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) {
        List var5;
        try {
            MappedStatement ms = this.configuration.getMappedStatement(statement);
            var5 = this.executor.query(ms, this.wrapCollection(parameter), rowBounds, Executor.NO_RESULT_HANDLER);
        } catch (Exception var9) {
            throw ExceptionFactory.wrapException("Error querying database.  Cause: " + var9, var9);
        } finally {
            ErrorContext.instance().reset();
        }

        return var5;
    }

執行到Executor類,那么我們來看看其究竟有什么?

Executor

Executor物件為SQL 的執行引擎,負責增刪改查的具體操作,頂層介面SqlSession中都會有一個 Executor 物件,可以理解為 JDBC 中 Statement 的封裝版,

Executor 是最頂層的是執行器,它有兩個實作類,分別是BaseExecutorCachingExecutor

  • BaseExecutor 是一個抽象類,實作了大部分 Executor 介面定義的功能,降低了介面實作的難度,BaseExecutor基于配接器設計模式之介面適配會有三個子類,分別是 SimpleExecutorReuseExecutorBatchExecutor

    • SimpleExecutor : 是 MyBatis 中默認簡單執行器,每執行一次updateselect,就開啟一個Statement物件,用完立刻關閉Statement物件

    • ReuseExecutor : 可重用執行器, 執行updateselect,以sql作為key查找Statement物件,存在就使用,不存在就創建,用完后,不關閉Statement物件,而是放置于Map<String, Statement>內,供下一次使用,簡言之,就是重復使用Statement物件

    • BatchExecutor : 批處理執行器,用于執行update(沒有select,JDBC批處理不支持select將多個 SQL 一次性輸出到資料庫,

  • CachingExecutor: 快取執行器,為Executor物件增加了二級快取的相關功:先從快取中查詢結果,如果存在就回傳之前的結果;如果不存在,再委托給Executor delegate 去資料庫中取,delegate 可以是上面任何一個執行器,

Mybatis組態檔中,可以指定默認的ExecutorType執行器型別,也可以手動給DefaultSqlSessionFactory的創建SqlSession的方法傳遞ExecutorType型別引數,

看完Exector簡介之后,繼續跟蹤執行流程鏈路分析,SqlSession 中的 JDBC 操作部分最終都會委派給 Exector 實作,Executor::query()方法,看看在Exector的執行是怎樣的?

每次查詢都會先經過CachingExecutor快取執行器, 會先判斷二級快取中是否存在查詢 SQL ,如果存在直接從二級快取中獲取,不存在即為第一次執行,會直接執行SQL 陳述句,并創建快取,都是由CachingExecutor::query()操作完成的,

public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {
        BoundSql boundSql = ms.getBoundSql(parameterObject);
        CacheKey key = this.createCacheKey(ms, parameterObject, rowBounds, boundSql);
        return this.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
    }

public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
        //獲取查詢陳述句對應的二級快取
    	Cache cache = ms.getCache();
        //sql查詢是否存在在二級快取中
   	    if (cache != null) {
            //根據 <select> 節點的配置,判斷否需要清空二級快取
            this.flushCacheIfRequired(ms);
            if (ms.isUseCache() && resultHandler == null) {
                this.ensureNoOutParams(ms, boundSql);
                //查詢二級快取
                List<E> list = (List)this.tcm.getObject(cache, key);
                if (list == null) {
                    //二級快取沒用相應的結果物件,呼叫封裝的Executor物件的 query() 方法
                    list = this.delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
                    //將查詢結果保存到二級快取中
                    this.tcm.putObject(cache, key, list);
                }

                return list;
            }
        }
		//沒有啟動二級快取,直接呼叫底層 Executor 執行資料資料庫查詢操作
        return this.delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
    }

如果在經過CachingExecutor快取執行器(二級快取)沒有回傳值的話,就會執行BaseExecutor 以及其的實作類,默認為SimpleExecutor ,首先會在一級快取中獲取查詢結果,獲得不到,最侄訓通過SimpleExecutor:: ()去資料庫中查詢,

 public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
        ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
        if (this.closed) {
            throw new ExecutorException("Executor was closed.");
        } else {
            //是否清除本地快取
            if (this.queryStack == 0 && ms.isFlushCacheRequired()) {
                this.clearLocalCache();
            }

            List list;
            try {
                ++this.queryStack;
                //從一級快取中,獲取查詢結果
                list = resultHandler == null ? (List)this.localCache.getObject(key) : null;
                //獲取到結果,則進行處理
                if (list != null) {
                    this.handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
                } else {
                    //獲得不到,則從資料庫中查詢
                    list = this.queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
                }
            } finally {
                --this.queryStack;
            }

            if (this.queryStack == 0) {
                //執行延遲加載
                Iterator var8 = this.deferredLoads.iterator();

                while(var8.hasNext()) {
                    BaseExecutor.DeferredLoad deferredLoad = (BaseExecutor.DeferredLoad)var8.next();
                    deferredLoad.load();
                }

                this.deferredLoads.clear();
                if (this.configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
                    this.clearLocalCache();
                }
            }

            return list;
        }
    }

那么SimpleExecutor::doQuery()如何去資料庫中查詢獲取到結果呢?其實執行到這邊mybatis的執行程序就從 Executor轉交給 StatementHandler處理,

public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
        Statement stmt = null;

        List var9;
        try {
            Configuration configuration = ms.getConfiguration();
            StatementHandler handler = configuration.newStatementHandler(this.wrapper, ms, parameter, rowBounds, resultHandler, boundSql);
            stmt = this.prepareStatement(handler, ms.getStatementLog());
            var9 = handler.query(stmt, resultHandler);
        } finally {
            this.closeStatement(stmt);
        }

        return var9;
    }

這樣我們的執行鏈路分析已到StatementHandler了,現在讓我們去一探究竟其原理

StatementHandler

StatementHandler負責處理Mybatis與JDBC之間Statement的互動,即Statement物件與資料庫進行互動,其為頂級介面,有4個實作類,其中三個是Statement物件與資料庫進行互動類, 另外一個是路由功能的,

  • RoutingStatementHandler: 對 Statement 物件沒有實際操作,主要負責另外三個StatementHandler的創建及呼叫, 而且在MyBatis執行時,使用的StatementHandler介面物件實際上就是 RoutingStatementHandler 物件,
  • SimpleStatementHandler: 管理 Statement 物件, 用于簡單SQL的處理 ,
  • PreparedStatementHandler: 管理 Statement 物件,預處理SQL的介面 ,
  • CallableStatementHandler:管理 Statement 物件,用于執行存盤程序相關的介面 ,

在經歷過Executor后,基于初始化加載到MapperState中的StatementType的型別通過Configuration.newStatementHandler()方法中的RoutingStatementHandler 生成StatementHandler實際處理類,

 public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
        switch(ms.getStatementType()) {
        case STATEMENT:
            this.delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
            break;
        case PREPARED:
            this.delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
            break;
        case CALLABLE:
            this.delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
            break;
        default:
            throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
        }

    }

現在先以PreparedStatementHandler預處理為例,接著Sql的執行鏈路來分析,StatementHandler::query()StatementHandler::execute()真正執行Sql查詢操作,

public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
    String sql = boundSql.getSql();
    statement.execute(sql);
    return resultSetHandler.handleResultSets(statement);
  }

但執行真正查詢操作之前,還進行哪些處理呢?還會進行ParameterHandler對 SQL 引數的預處理:對引數進行動態Sql映射,那么ParameterHandler又如何實作對引數進行動態映射的呢?

ParameterHandler

ParameterHandler 引數處理器, 用來設定引數規則的,負責為sql 陳述句引數動態賦值,其有兩個介面

  • getParameterObject: 用于讀取引數
  • setParameters: 用于對 PreparedStatement 的引數賦值

SimpleExecutor執行構造PreparedStatementHandler完,會呼叫parameterize()方法將PreparedStatement物件里SQL轉交ParameterHandler實作類 DefaultParameterHandler::setParameters()方法 設定 PreparedStatement 的占位符引數 ,

private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {
    Statement stmt;
    Connection connection = getConnection(statementLog);
    stmt = handler.prepare(connection, transaction.getTimeout());
   	//引數動態賦值
    handler.parameterize(stmt);
    return stmt;
  }

DefaultParameterHandler::setParameters()如何對SQL進行動態賦值呢?在執行前將已裝載好的BoundSql物件資訊進行使用

 public void setParameters(PreparedStatement ps) {
    ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
     //獲取待動態賦值引數串列的封裝parameterMappings
    List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
    if (parameterMappings != null) {
      for (int i = 0; i < parameterMappings.size(); i++) {
        ParameterMapping parameterMapping = parameterMappings.get(i);
          //是否為輸入引數
        if (parameterMapping.getMode() != ParameterMode.OUT) {
          Object value;
          //獲取待動態引數屬性名
          String propertyName = parameterMapping.getProperty();
          if (boundSql.hasAdditionalParameter(propertyName)) { // issue #448 ask first for additional params
            value = boundSql.getAdditionalParameter(propertyName);
          } else if (parameterObject == null) {
            value = null;
          } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
            value = parameterObject;
          } else {
            MetaObject metaObject = configuration.newMetaObject(parameterObject);
            value = metaObject.getValue(propertyName);
          }
           在通過 SqlSource 的parse 方法得到parameterMappings 的具體實作中,我們會得到parameterMappings 的 typeHandler
          TypeHandler typeHandler = parameterMapping.getTypeHandler();
          //獲取jdbc資料型別
          JdbcType jdbcType = parameterMapping.getJdbcType();
          if (value == null && jdbcType == null) {
            jdbcType = configuration.getJdbcTypeForNull();
          }
          try {
            //
            typeHandler.setParameter(ps, i + 1, value, jdbcType);
          } catch (TypeException | SQLException e) {
            throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
          }
        }
      }
    }
  }

執行完SQL 引數的預處理,當StatementHandler::execute()真正執行查詢操作執行完后,有回傳結果,需要對回傳結果進行ResultSetHandler處理,現在看看最后的結果的處理流程,

ResultSetHandler

ResultSetHandler結果決議器,將查詢結果的ResultSet 轉換成映射的對應結果(java DTO等),其有三介面

  • handleResultSets():處理結果集
  • handleCursorResultSets():批量處理結果集
  • handleOutputParameters():處理存盤程序回傳的結果集

其默認的實作為DefaultResultSetHandler,主要功能為:

  • 處理Statement 執行后產生的結果集生成相對的輸出結果、
  • 處理存盤程序執行后的輸出引數

那看看DefaultResultSetHandler::handleResultSets()如何處理?

  • 當有多個ResultSet的結果集合,每個ResultSet對應一個Object 物件,如果不考慮存盤程序,普通的查詢只有一個ResultSet
  • ResultSetWrapper封裝了ResultSet結果集,其屬性包含ResultSet ,ResultMap
@Override
public List<Object> handleResultSets(Statement stmt) throws SQLException {
    ErrorContext.instance().activity("handling results").object(mappedStatement.getId());

    //當有多個ResultSet的結果集合,每個ResultSet對應一個Object 物件
    final List<Object> multipleResults = new ArrayList<>();

    int resultSetCount = 0;
    //獲得首個 ResultSet 物件,并封裝成 ResultSetWrapper 物件
    ResultSetWrapper rsw = getFirstResultSet(stmt);

    //獲得 ResultMap 陣列
    List<ResultMap> resultMaps = mappedStatement.getResultMaps();
    int resultMapCount = resultMaps.size();
    validateResultMapsCount(rsw, resultMapCount); // <3.1> 校驗
    while (rsw != null && resultMapCount > resultSetCount) {
        //獲得 ResultMap 物件
        ResultMap resultMap = resultMaps.get(resultSetCount);
        //處理 ResultSet ,將結果添加到 multipleResults 中
        handleResultSet(rsw, resultMap, multipleResults, null);
        //獲得下一個 ResultSet 物件,并封裝成 ResultSetWrapper 物件
        rsw = getNextResultSet(stmt);
        //清理
        cleanUpAfterHandlingResultSet();
        // resultSetCount ++
        resultSetCount++;
    }

    String[] resultSets = mappedStatement.getResultSets();
    if (resultSets != null) {
        while (rsw != null && resultSetCount < resultSets.length) {
            ResultMapping parentMapping = nextResultMaps.get(resultSets[resultSetCount]);
            if (parentMapping != null) {
                String nestedResultMapId = parentMapping.getNestedResultMapId();
                ResultMap resultMap = configuration.getResultMap(nestedResultMapId);
                handleResultSet(rsw, resultMap, null, parentMapping);
            }
            rsw = getNextResultSet(stmt);
            cleanUpAfterHandlingResultSet();
            resultSetCount++;
        }
    }

    //如果是 multipleResults 單元素,則取首元素回傳
    return ollapseSingleResultList(multipleResults);
}

其實在ResultSetHandler結果集處理是比較復雜的,這里只是簡單的介紹一下,有興趣的可以再深入研究一下,后期有空也會寫,

執行到這邊,Mybatis SQL執行基本完了,會把轉換后的結果集回傳到操作者,

結論

在SQL執行程序主要涉及了SqlSessionMapperProxy,Executor,StatementHandler,ParameterHandler以及ResultSetHandler,包括引數動態系結,Sql執行查詢資料庫資料,結果回傳集映射等,而且每個環節涉及的內容都很多,每個介面都可以抽出單獨分析,后續有時間再一一詳細的看看,后面還是再分析一下插件的應用,

各位看官還可以嗎?喜歡的話,動動手指點個💗,點個關注唄!!謝謝支持!
歡迎關注,原創技術文章第一時間推出
在這里插入圖片描述

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/137895.html

標籤:其他

上一篇:Java崗7年經驗,面臨小廠58W年薪和位元組跳動的45W年薪,怎么選擇才最適合

下一篇:螞蟻金服Java崗社招面試5面歷程

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more