/// <summary> /// Builds a Mapped Statement for a statement. /// </summary> /// <param name="statement">The statement.</param> /// <param name="mappedStatement">The mapped statement.</param> /// <returns></returns> private IMappedStatement BuildCachingStatement(IStatement statement, MappedStatement mappedStatement) { IMappedStatement mapStatement = mappedStatement; if (statement.CacheModel != null && isCacheModelsEnabled) { mapStatement = new CachingStatement(mappedStatement); } return mapStatement; }
/// <summary> /// Constructor /// </summary> /// <param name="statement"></param> public CachingStatement(MappedStatement statement) { mappedStatement = statement; }
/// <summary> /// Builds an <see cref="Procedure"/> for a procedure configuration. /// </summary> /// <param name="statementConfig">The statement config.</param> /// <param name="configurationSetting"></param> private IMappedStatement BuildProcedure(IConfiguration statementConfig, ConfigurationSetting configurationSetting) { BaseStatementDeSerializer procedureDeSerializer = new ProcedureDeSerializer(); IStatement statement = procedureDeSerializer.Deserialize(modelStore, statementConfig, configurationSetting); ProcessSqlStatement(statementConfig, statement); MappedStatement mappedStatement = new MappedStatement(modelStore, statement); return BuildCachingStatement(statement, mappedStatement); }
/// <summary> /// Builds an <see cref="Insert"/> for a insert configuration. /// </summary> /// <param name="statementConfig">The statement config.</param> /// <param name="configurationSetting"></param> private IMappedStatement BuildInsert(IConfiguration statementConfig, ConfigurationSetting configurationSetting) { BaseStatementDeSerializer insertDeSerializer = new InsertDeSerializer(); IStatement statement = insertDeSerializer.Deserialize(modelStore, statementConfig, configurationSetting); ProcessSqlStatement(statementConfig, statement); MappedStatement mappedStatement = new InsertMappedStatement(modelStore, statement); Insert insert = (Insert)statement; if (insert.SelectKey != null) { ConfigurationCollection selectKeys = statementConfig.Children.Find(ConfigConstants.ELEMENT_SELECTKEY); IConfiguration selectKeyConfig = selectKeys[0]; ProcessSqlStatement(selectKeyConfig, insert.SelectKey); MappedStatement mapStatement = new MappedStatement(modelStore, insert.SelectKey); modelStore.AddMappedStatement(mapStatement); } return BuildCachingStatement(statement, mappedStatement); }
/// <summary> /// Builds a <see cref="Statement"/> for a statement configuration. /// </summary> /// <param name="statementConfig">The statement config.</param> /// <param name="configurationSetting"></param> private IMappedStatement BuildStatement(IConfiguration statementConfig, ConfigurationSetting configurationSetting) { BaseStatementDeSerializer statementDeSerializer = new StatementDeSerializer(); //解析statement节点属性到类中 IStatement statement = statementDeSerializer.Deserialize(modelStore, statementConfig, configurationSetting); //估计是处理statement节点对应的文本内容 ----->确实如此 此处是个核心 一个statement节点的配置信息 和 对应的内存类 //处理的结果放在了statement中 包括了要执行的sql语句和参数 ProcessSqlStatement(statementConfig, statement); //具体封装了IDbcommand IDataReader的一些类 MappedStatement mappedStatement = new MappedStatement(modelStore, statement); //放入缓存类中 并返回mappedStatement return BuildCachingStatement(statement, mappedStatement); }