コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Statement"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="parameterClass">The parameter class.</param>
        /// <param name="parameterMap">The parameter map.</param>
        /// <param name="resultClass">The result class.</param>
        /// <param name="resultMaps">The result maps.</param>
        /// <param name="listClass">The list class.</param>
        /// <param name="listClassFactory">The list class factory.</param>
        /// <param name="cacheModel">The cache model.</param>
        /// <param name="remapResults">if set to <c>true</c> [remap results].</param>
        /// <param name="extends">The extends.</param>
        /// <param name="sqlSource">The SQL source.</param>
        /// <param name="preserveWhitespace">Preserve whitespace.</param>
        public Statement(
            string id,
            Type parameterClass,
            ParameterMap parameterMap,
            Type resultClass,
            ResultMapCollection resultMaps,
            Type listClass,
            IFactory listClassFactory,
            CacheModel cacheModel,
            bool remapResults,
            string extends,
            ISqlSource sqlSource,
            bool preserveWhitespace)
        {
            Contract.Require.That(id, Is.Not.Null & Is.Not.Empty).When("retrieving argument id");

            this.id                 = id;
            this.parameterClass     = parameterClass;
            this.parameterMap       = parameterMap;
            this.resultClass        = resultClass;
            this.resultMaps         = resultMaps;
            this.listClass          = listClass;
            this.listClassFactory   = listClassFactory;
            this.cacheModel         = cacheModel;
            allowRemapping          = remapResults;
            this.extends            = extends;
            this.sqlSource          = sqlSource;
            this.preserveWhitespace = preserveWhitespace;
        }
コード例 #2
0
ファイル: DaoFactory.cs プロジェクト: yunqian44/FoxOne
 static DaoFactory()
 {
     _actionExecutors = TypeHelper.GetAllImplInstance <ISqlActionExecutor>();
     _parameters      = ObjectHelper.GetAllObjects <ISqlParameters>();
     _providers       = TypeHelper.GetAllImplInstance <IDaoProvider>();
     _daos            = new ConcurrentDictionary <string, Dao>();
     _sqlSource       = new SqlSource().LoadSqls();
 }
コード例 #3
0
ファイル: Update.cs プロジェクト: techvenky/mybatisnet
        /// <summary>
        /// Initializes a new instance of the <see cref="Update"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="parameterClass">The parameter class.</param>
        /// <param name="parameterMap">The parameter map.</param>
        /// <param name="remapResults">if set to <c>true</c> [remap results].</param>
        /// <param name="extends">The extends.</param>
        /// <param name="sqlSource">The SQL source.</param>
        /// <param name="preserveWhitespace">Preserve whitespace.</param>
        public Update(
            string id, 
            Type parameterClass,
            ParameterMap parameterMap,
            bool remapResults,
            string extends,
            ISqlSource sqlSource,
            bool preserveWhitespace)
            : base(id, parameterClass, parameterMap, null, new ResultMapCollection(), null, null, null, remapResults, extends, sqlSource, preserveWhitespace)
		{}
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Update"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="parameterClass">The parameter class.</param>
 /// <param name="parameterMap">The parameter map.</param>
 /// <param name="remapResults">if set to <c>true</c> [remap results].</param>
 /// <param name="extends">The extends.</param>
 /// <param name="sqlSource">The SQL source.</param>
 /// <param name="preserveWhitespace">Preserve whitespace.</param>
 public Update(
     string id,
     Type parameterClass,
     ParameterMap parameterMap,
     bool remapResults,
     string extends,
     ISqlSource sqlSource,
     bool preserveWhitespace)
     : base(id, parameterClass, parameterMap, null, new ResultMapCollection(), null, null, null, remapResults, extends, sqlSource, preserveWhitespace)
 {
 }
コード例 #5
0
ファイル: DaoFactory.cs プロジェクト: liuyanchen1994/FoxOne
        private static void Initialize()
        {
            //必须先初始化ActionExecutor,因为在加载Sql时需要引用
            _actionExecutors = TypeHelper.GetAllImplInstance <ISqlActionExecutor>();
            _parameters      = ObjectHelper.GetAllObjects <ISqlParameters>();


            InitializeProviders();
            InitializeMappingProviders();

            _daos      = new ConcurrentDictionary <string, Dao>();
            _sqlSource = new SqlSource().LoadSqls();
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectKey"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="type">The type.</param>
 /// <param name="resultMaps">The result maps.</param>
 /// <param name="selectKeyType">Type of the select key.</param>
 /// <param name="sqlSource">The SQL source.</param>
 /// <param name="preserveWhitespace">Preserve whitespace.</param>
 public SelectKey(
     string id,
     string propertyName,
     Type type,
     ResultMapCollection resultMaps,
     SelectKeyType selectKeyType,
     ISqlSource sqlSource,
     bool preserveWhitespace
     )
     : base(id, null, null, type, resultMaps, null, null, null, false, string.Empty, sqlSource, preserveWhitespace)
 {
     this.propertyName  = propertyName;
     this.selectKeyType = selectKeyType;
 }
コード例 #7
0
ファイル: Delete.cs プロジェクト: techvenky/mybatisnet
        /// <summary>
        /// Initializes a new instance of the <see cref="Delete"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="parameterClass">The parameter class.</param>
        /// <param name="parameterMap">The parameter map.</param>
        /// <param name="resultClass">The result class.</param>
        /// <param name="resultMaps">The result maps.</param>
        /// <param name="listClass">The list class.</param>
        /// <param name="listClassFactory">The list class factory.</param>
        /// <param name="cacheModel">The cache model.</param>
        /// <param name="remapResults">if set to <c>true</c> [remap results].</param>
        /// <param name="extends">The extends.</param>
        /// <param name="sqlSource">The SQL source.</param>
        /// <param name="preserveWhitespace">Preserve whitespace.</param>
        public Delete(
            string id, 
            Type parameterClass,
            ParameterMap parameterMap,
            Type resultClass,
            ResultMapCollection resultMaps,
            Type listClass,
            IFactory listClassFactory,
            CacheModel cacheModel,
            bool remapResults,
            string extends,
            ISqlSource sqlSource,
            bool preserveWhitespace
            )
            : base(id, parameterClass, parameterMap, resultClass, resultMaps, listClass, listClassFactory, cacheModel, remapResults, extends, sqlSource, preserveWhitespace)
		{}
コード例 #8
0
ファイル: Delete.cs プロジェクト: vdimensions/mybatisnet
 /// <summary>
 /// Initializes a new instance of the <see cref="Delete"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="parameterClass">The parameter class.</param>
 /// <param name="parameterMap">The parameter map.</param>
 /// <param name="resultClass">The result class.</param>
 /// <param name="resultMaps">The result maps.</param>
 /// <param name="listClass">The list class.</param>
 /// <param name="listClassFactory">The list class factory.</param>
 /// <param name="cacheModel">The cache model.</param>
 /// <param name="remapResults">if set to <c>true</c> [remap results].</param>
 /// <param name="extends">The extends.</param>
 /// <param name="sqlSource">The SQL source.</param>
 /// <param name="preserveWhitespace">Preserve whitespace.</param>
 public Delete(
     string id,
     Type parameterClass,
     ParameterMap parameterMap,
     Type resultClass,
     ResultMapCollection resultMaps,
     Type listClass,
     IFactory listClassFactory,
     CacheModel cacheModel,
     bool remapResults,
     string extends,
     ISqlSource sqlSource,
     bool preserveWhitespace
     )
     : base(id, parameterClass, parameterMap, resultClass, resultMaps, listClass, listClassFactory, cacheModel, remapResults, extends, sqlSource, preserveWhitespace)
 {
 }
コード例 #9
0
        /// <summary>
        /// Deserializes the specified configuration in a Statement object.
        /// </summary>
        /// <param name="modelStore"></param>
        /// <param name="config">The config.</param>
        /// <param name="configurationSetting">Default settings.</param>
        /// <returns></returns>
        protected void BaseDeserialize(IModelStore modelStore, IConfiguration config, ConfigurationSetting configurationSetting)
        {
            nameSpace          = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_NAMESPACE);
            id                 = configurationSetting.UseStatementNamespaces ? ApplyNamespace(nameSpace, config.Id) : config.Id;
            cacheModelName     = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_CACHEMODEL);
            extendsName        = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_EXTENDS);
            listClassName      = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_LISTCLASS);
            parameterClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERCLASS);
            parameterMapName   = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERMAP);
            resultClassName    = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTCLASS);
            resultMapName      = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTMAP);
            remapResults       = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_REMAPRESULTS, false);
            sqlSourceClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_SQLSOURCE);
            preserveWhitespace = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PRESERVEWHITSPACE, configurationSetting.PreserveWhitespace);

            // Gets the results Map
            if (resultMapName.Length > 0)
            {
                string[] ids = resultMapName.Split(',');
                for (int i = 0; i < ids.Length; i++)
                {
                    string name = ApplyNamespace(nameSpace, ids[i].Trim());
                    resultsMap.Add(modelStore.GetResultMap(name));
                }
            }
            // Gets the results class
            if (resultClassName.Length > 0)
            {
                string[] classNames = resultClassName.Split(',');
                for (int i = 0; i < classNames.Length; i++)
                {
                    resultClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(classNames[i].Trim());
                    IFactory resultClassFactory = null;
                    if (Type.GetTypeCode(resultClass) == TypeCode.Object &&
                        (resultClass.IsValueType == false) && resultClass != typeof(DataRow))
                    {
                        resultClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(resultClass, Type.EmptyTypes);
                    }
                    IDataExchange dataExchange = modelStore.DataExchangeFactory.GetDataExchangeForClass(resultClass);
                    bool          isSimpleType = modelStore.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(resultClass);
                    IResultMap    autoMap      = new AutoResultMap(resultClass, resultClassFactory, dataExchange, isSimpleType);
                    resultsMap.Add(autoMap);
                }
            }

            // Gets the ParameterMap
            if (parameterMapName.Length > 0)
            {
                parameterMap = modelStore.GetParameterMap(parameterMapName);
            }
            // Gets the ParameterClass
            if (parameterClassName.Length > 0)
            {
                parameterClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(parameterClassName);
            }

            // Gets the listClass
            if (listClassName.Length > 0)
            {
                listClass        = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(listClassName);
                listClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(listClass, Type.EmptyTypes);
            }

            // Gets the CacheModel
            if (cacheModelName.Length > 0)
            {
                cacheModel = modelStore.GetCacheModel(cacheModelName);
            }
            // Gets the SqlSource
            if (sqlSourceClassName.Length > 0)
            {
                Type     sqlSourceType = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(sqlSourceClassName);
                IFactory factory       = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(sqlSourceType, Type.EmptyTypes);
                sqlSource = (ISqlSource)factory.CreateInstance(null);
            }
        }
コード例 #10
0
ファイル: SelectKey.cs プロジェクト: techvenky/mybatisnet
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectKey"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="type">The type.</param>
        /// <param name="resultMaps">The result maps.</param>
        /// <param name="selectKeyType">Type of the select key.</param>
        /// <param name="sqlSource">The SQL source.</param>
        /// <param name="preserveWhitespace">Preserve whitespace.</param>
        public SelectKey(
            string id, 
            string propertyName,
            Type type,
            ResultMapCollection resultMaps,
            SelectKeyType selectKeyType,
            ISqlSource sqlSource,
            bool preserveWhitespace
            )
            : base(id, null, null, type, resultMaps, null, null, null, false, string.Empty, sqlSource, preserveWhitespace)
		{
            this.propertyName = propertyName;
            this.selectKeyType = selectKeyType;
        }
コード例 #11
0
        /// <summary>
        /// Deserializes the specified configuration in a Statement object.
        /// </summary>
        /// <param name="modelStore"></param>
        /// <param name="config">The config.</param>
        /// <param name="configurationSetting">Default settings.</param>
        /// <returns></returns>
        /// <remarks>
        /// Updated By: Richard Beacroft
        /// Updated Date: 11\10\2013
        /// Description: configurationSetting can be null and therefore references to it have to assume that it could be null.
        /// </remarks>
        protected void BaseDeserialize(IModelStore modelStore, IConfiguration config, ConfigurationSetting configurationSetting)
        {
            // DefaultModelBuilderTest.Test_DefaultModelBuilder assumes that configurationSetting can be null - added code accordingly.
            // Typically, no public method should allow null to be passed-in, best handled by overloading method to exclude parameter, or in .NET 4, use optional parameter.
            var preserveWhitespace = (configurationSetting == null) ? false : configurationSetting.PreserveWhitespace;
            bool useStatementNamespaces = (configurationSetting == null) ? false : configurationSetting.UseStatementNamespaces;

            nameSpace = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_NAMESPACE);
            id = useStatementNamespaces ? ApplyNamespace(nameSpace, config.Id) : config.Id;
            cacheModelName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_CACHEMODEL);
            extendsName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_EXTENDS);
            listClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_LISTCLASS);
            parameterClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERCLASS);
            parameterMapName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERMAP);
            resultClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTCLASS);
            resultMapName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTMAP);
            remapResults = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_REMAPRESULTS, false);
            sqlSourceClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_SQLSOURCE);
            preserveWhitespace = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PRESERVEWHITSPACE, preserveWhitespace);

            // Gets the results Map
            if (resultMapName.Length > 0)
            {
                string[] ids = resultMapName.Split(',');
                for (int i = 0; i < ids.Length; i++)
                {
                    string name = ApplyNamespace(nameSpace, ids[i].Trim());
                    resultsMap.Add(modelStore.GetResultMap(name));
                }
            }

            // Gets the results class
            if (resultClassName.Length > 0)
            {
                string[] classNames = resultClassName.Split(',');
                for (int i = 0; i < classNames.Length; i++)
                {
                    resultClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(classNames[i].Trim());
                    IFactory resultClassFactory = null;
                    if (Type.GetTypeCode(resultClass) == TypeCode.Object &&
                        (resultClass.IsValueType == false) && resultClass != typeof(DataRow))
                    {
                        resultClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(resultClass, Type.EmptyTypes);
                    }
                    IDataExchange dataExchange = modelStore.DataExchangeFactory.GetDataExchangeForClass(resultClass);
                    bool isSimpleType = modelStore.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(resultClass);
                    IResultMap autoMap = new AutoResultMap(resultClass, resultClassFactory, dataExchange, isSimpleType);
                    resultsMap.Add(autoMap);
                }
            }

            // Gets the ParameterMap
            if (parameterMapName.Length > 0)
            {
                parameterMap = modelStore.GetParameterMap(parameterMapName);
            }

            // Gets the ParameterClass
            if (parameterClassName.Length > 0)
            {
                parameterClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(parameterClassName);
            }

            // Gets the listClass
            if (listClassName.Length > 0)
            {
                listClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(listClassName);
                listClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(listClass, Type.EmptyTypes);
            }

            // Gets the CacheModel
            if (cacheModelName.Length > 0)
            {
                cacheModel = modelStore.GetCacheModel(cacheModelName);
            }

            // Gets the SqlSource
            if (sqlSourceClassName.Length > 0)
            {
                Type sqlSourceType = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(sqlSourceClassName);
                IFactory factory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(sqlSourceType, Type.EmptyTypes);
                sqlSource = (ISqlSource)factory.CreateInstance(null);
            }
        }
コード例 #12
0
        /// <summary>
        /// Deserializes the specified configuration in a Statement object.
        /// </summary>
        /// <param name="modelStore"></param>
        /// <param name="config">The config.</param>
        /// <param name="configurationSetting">Default settings.</param>
        /// <returns></returns>
        /// <remarks>
        /// Updated By: Richard Beacroft
        /// Updated Date: 11\10\2013
        /// Description: configurationSetting can be null and therefore references to it have to assume that it could be null.
        /// </remarks>
        protected void BaseDeserialize(IModelStore modelStore, IConfiguration config, ConfigurationSetting configurationSetting)
        {
            // DefaultModelBuilderTest.Test_DefaultModelBuilder assumes that configurationSetting can be null - added code accordingly.
            // Typically, no public method should allow null to be passed-in, best handled by overloading method to exclude parameter, or in .NET 4, use optional parameter.
            var  preserveWhitespace     = (configurationSetting == null) ? false : configurationSetting.PreserveWhitespace;
            bool useStatementNamespaces = (configurationSetting == null) ? false : configurationSetting.UseStatementNamespaces;

            nameSpace          = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_NAMESPACE);
            id                 = useStatementNamespaces ? ApplyNamespace(nameSpace, config.Id) : config.Id;
            cacheModelName     = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_CACHEMODEL);
            extendsName        = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_EXTENDS);
            listClassName      = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_LISTCLASS);
            parameterClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERCLASS);
            parameterMapName   = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERMAP);
            resultClassName    = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTCLASS);
            resultMapName      = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTMAP);
            remapResults       = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_REMAPRESULTS, false);
            sqlSourceClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_SQLSOURCE);
            preserveWhitespace = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PRESERVEWHITSPACE, preserveWhitespace);

            // Gets the results Map
            if (resultMapName.Length > 0)
            {
                string[] ids = resultMapName.Split(',');
                for (int i = 0; i < ids.Length; i++)
                {
                    string name = ApplyNamespace(nameSpace, ids[i].Trim());
                    resultsMap.Add(modelStore.GetResultMap(name));
                }
            }

            // Gets the results class
            if (resultClassName.Length > 0)
            {
                string[] classNames = resultClassName.Split(',');
                for (int i = 0; i < classNames.Length; i++)
                {
                    resultClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(classNames[i].Trim());
                    IFactory resultClassFactory = null;
                    if (Type.GetTypeCode(resultClass) == TypeCode.Object &&
                        (resultClass.IsValueType == false) && resultClass != typeof(DataRow))
                    {
                        resultClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(resultClass, Type.EmptyTypes);
                    }
                    IDataExchange dataExchange = modelStore.DataExchangeFactory.GetDataExchangeForClass(resultClass);
                    bool          isSimpleType = modelStore.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(resultClass);
                    IResultMap    autoMap      = new AutoResultMap(resultClass, resultClassFactory, dataExchange, isSimpleType);
                    resultsMap.Add(autoMap);
                }
            }

            // Gets the ParameterMap
            if (parameterMapName.Length > 0)
            {
                parameterMap = modelStore.GetParameterMap(parameterMapName);
            }

            // Gets the ParameterClass
            if (parameterClassName.Length > 0)
            {
                parameterClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(parameterClassName);
            }

            // Gets the listClass
            if (listClassName.Length > 0)
            {
                listClass        = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(listClassName);
                listClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(listClass, Type.EmptyTypes);
            }

            // Gets the CacheModel
            if (cacheModelName.Length > 0)
            {
                cacheModel = modelStore.GetCacheModel(cacheModelName);
            }

            // Gets the SqlSource
            if (sqlSourceClassName.Length > 0)
            {
                Type     sqlSourceType = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(sqlSourceClassName);
                IFactory factory       = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(sqlSourceType, Type.EmptyTypes);
                sqlSource = (ISqlSource)factory.CreateInstance(null);
            }
        }
コード例 #13
0
        /// <summary>
        /// Builds the the iBATIS core model (statement, alias, resultMap, parameterMap, dataSource)
        /// from an <see cref="IConfigurationStore"/> and store all the refrences in an <see cref="IModelStore"/> .
        /// </summary>
        /// <param name="configurationSetting">The configuration setting.</param>
        /// <param name="store">The configuration store.</param>
        /// <returns>The model store</returns>
        public virtual void BuildModel(ConfigurationSetting configurationSetting, IConfigurationStore store)
        {
            IObjectFactory      objectFactory      = null;
            IGetAccessorFactory getAccessorFactory = null;
            ISetAccessorFactory setAccessorFactory = null;
            ISessionFactory     sessionFactory     = null;
            ISessionStore       sessionStore       = null;

            if (configurationSetting != null)
            {
                objectFactory          = configurationSetting.ObjectFactory;
                setAccessorFactory     = configurationSetting.SetAccessorFactory;
                getAccessorFactory     = configurationSetting.GetAccessorFactory;
                dataSource             = configurationSetting.DataSource;
                sessionFactory         = configurationSetting.SessionFactory;
                sessionStore           = configurationSetting.SessionStore;
                dynamicSqlEngine       = configurationSetting.DynamicSqlEngine;
                isCacheModelsEnabled   = configurationSetting.IsCacheModelsEnabled;
                useStatementNamespaces = configurationSetting.UseStatementNamespaces;
                useReflectionOptimizer = configurationSetting.UseReflectionOptimizer;
                preserveWhitespace     = configurationSetting.PreserveWhitespace;
            }

            // Xml setting override code setting
            //取store中的数据初始化类成员 为下面做准备
            LoadSetting(store);

            if (objectFactory == null)
            {
                objectFactory = new ObjectFactory(useReflectionOptimizer);
            }
            if (setAccessorFactory == null)
            {
                setAccessorFactory = new SetAccessorFactory(useReflectionOptimizer);
            }
            if (getAccessorFactory == null)
            {
                getAccessorFactory = new GetAccessorFactory(useReflectionOptimizer);
            }
            AccessorFactory accessorFactory = new AccessorFactory(setAccessorFactory, getAccessorFactory);

            TypeHandlerFactory typeHandlerFactory = new TypeHandlerFactory();
            TypeAlias          alias = new TypeAlias("MEMORY", typeof(PerpetualCache));

            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Perpetual", typeof(PerpetualCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("LRU", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Lru", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("FIFO", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Fifo", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("Weak", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("WEAK", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("MemCached", typeof(MemCached));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("MEMCACHED", typeof(MemCached));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("AnsiStringTypeHandler", typeof(AnsiStringTypeHandler));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            //将以上类信息存入到modelStore中 实质性工作
            modelStore.DataExchangeFactory = new DataExchangeFactory(typeHandlerFactory, objectFactory, accessorFactory);

            if (sessionStore == null)
            {
                sessionStore = SessionStoreFactory.GetSessionStore(modelStore.Id);
            }
            //将ISessionStore类对象存入modelStore中 准备数据库的连接 与 事物操作功能  实质性工作
            modelStore.SessionStore = sessionStore;

            //初始化DefaultModelBuilder的成员变量
            deSerializerFactory = new DeSerializerFactory(modelStore);

            //设置一个空类型的参数映射类
            ParameterMap emptyParameterMap = new ParameterMap(
                ConfigConstants.EMPTY_PARAMETER_MAP,
                string.Empty,
                string.Empty,
                typeof(string),
                modelStore.DataExchangeFactory.GetDataExchangeForClass(null), //获得ComplexDataExchange对象
                false);

            //向参数字典中添加一个空参数类
            modelStore.AddParameterMap(emptyParameterMap);

            //完成了对DefaultModelBuilder成员变量dbProviderFactory的初始化,其中完成了对provider使用中节点的类初始化
            BuildProviders(store);

            //完成了对DefaultModelBuilder成员变量IDataSource的初始化,包括数据库的名字 连接字符串 以及DbPrivder类
            BuildDataSource(store);

            if (sessionFactory == null)
            {
                sessionFactory = new DefaultSessionFactory(
                    dataSource,
                    modelStore.SessionStore,
                    new DefaultTransactionManager(new AdoTransactionFactory()));
            }
            //初始化modelStore中的ISessionFactory变量
            modelStore.SessionFactory = sessionFactory;

            //将具体SQLXML配置文件中的Alias节点对应的别名信息写入到modelStore中的TypeHandlerFactory的字典中
            BuildTypeAlias(store);

            //将TypeHanders下的子节点信息放入 modelStore.DataExchangeFactory.TypeHandlerFactory中的字典当中
            BuildTypeHandlers(store);

            //将cacheModels下子节点cacheModel加入到modelStore的CacheModel字典中
            BuildCacheModels(store);
            //将resultMap节点信息添加到modelStore的resultMaps中
            BuildResultMaps(store);

            //为resultMapping属性所在的节点信息类设置对应的ResultProperty
            for (int i = 0; i < nestedProperties.Count; i++)
            {
                ResultProperty property = nestedProperties[i];
                property.NestedResultMap = modelStore.GetResultMap(property.NestedResultMapName);
            }

            for (int i = 0; i < discriminators.Count; i++)
            {
                //完成对discriminator类中对字典的初始化
                discriminators[i].Initialize(modelStore);
            }
            //将parameter节点信息添加到modelStore类中的parameterMaps字典中
            BuildParameterMaps(store);

            //将statements下的节点添加到modelStore的statements的字典中
            BuildMappedStatements(store, configurationSetting);

            for (int i = 0; i < store.CacheModels.Length; i++)
            {
                CacheModel cacheModel = modelStore.GetCacheModel(store.CacheModels[i].Id);

                for (int j = 0; j < cacheModel.StatementFlushNames.Count; j++)
                {
                    string           statement       = cacheModel.StatementFlushNames[j];
                    IMappedStatement mappedStatement = modelStore.GetMappedStatement(statement);
                    if (mappedStatement != null)
                    {
                        //为IMappedStatement类的Executed制定委托事件  目的是清空缓存
                        cacheModel.RegisterTriggerStatement(mappedStatement);
                        if (logger.IsDebugEnabled)
                        {
                            logger.Debug("Registering trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]");
                        }
                    }
                    else
                    {
                        if (logger.IsWarnEnabled)
                        {
                            logger.Warn("Unable to register trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]. Statement does not exist.");
                        }
                    }
                }
            }

            if (logger.IsInfoEnabled)
            {
                logger.Info("Model Store");
                logger.Info(modelStore.ToString());
            }
        }
コード例 #14
0
        /// <summary>
        /// Deserializes the specified configuration in a Statement object.
        /// </summary>
        /// <param name="modelStore"></param>
        /// <param name="config">The config.</param>
        /// <param name="configurationSetting">Default settings.</param>
        /// <returns></returns>
        protected void BaseDeserialize(IModelStore modelStore, IConfiguration config, ConfigurationSetting configurationSetting)
        {
            nameSpace = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_NAMESPACE);
            id = configurationSetting.UseStatementNamespaces ? ApplyNamespace(nameSpace, config.Id) : config.Id;
            cacheModelName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_CACHEMODEL);
            extendsName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_EXTENDS);
            listClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_LISTCLASS);
            parameterClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERCLASS);
            parameterMapName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PARAMETERMAP);
            resultClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTCLASS);
            resultMapName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_RESULTMAP);
            remapResults = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_REMAPRESULTS, false);
            sqlSourceClassName = ConfigurationUtils.GetStringAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_SQLSOURCE);
            preserveWhitespace = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_PRESERVEWHITSPACE, configurationSetting.PreserveWhitespace);

            // Gets the results Map
            if (resultMapName.Length > 0)
            {
                string[] ids = resultMapName.Split(',');
                for (int i = 0; i < ids.Length; i++)
                {
                    string name = ApplyNamespace(nameSpace, ids[i].Trim());
                    resultsMap.Add(modelStore.GetResultMap(name));
                }
            }
            // Gets the results class
            if (resultClassName.Length > 0)
            {
                string[] classNames = resultClassName.Split(',');
                for (int i = 0; i < classNames.Length; i++)
                {
                    resultClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(classNames[i].Trim());
                    IFactory resultClassFactory = null;
                    if (Type.GetTypeCode(resultClass) == TypeCode.Object &&
                        (resultClass.IsValueType == false) && resultClass != typeof(DataRow))
                    {
                        resultClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(resultClass, Type.EmptyTypes);
                    }
                    IDataExchange dataExchange = modelStore.DataExchangeFactory.GetDataExchangeForClass(resultClass);
                    bool isSimpleType = modelStore.DataExchangeFactory.TypeHandlerFactory.IsSimpleType(resultClass);
                    IResultMap autoMap = new AutoResultMap(resultClass, resultClassFactory, dataExchange, isSimpleType);
                    resultsMap.Add(autoMap);
                }
            }

            // Gets the ParameterMap
            if (parameterMapName.Length > 0)
            {
                parameterMap = modelStore.GetParameterMap(parameterMapName);
            }
            // Gets the ParameterClass
            if (parameterClassName.Length > 0)
            {
                parameterClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(parameterClassName);
            }

            // Gets the listClass
            if (listClassName.Length > 0)
            {
                listClass = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(listClassName);
                listClassFactory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(listClass, Type.EmptyTypes);
            }

            // Gets the CacheModel
            if (cacheModelName.Length > 0)
            {
                cacheModel = modelStore.GetCacheModel(cacheModelName);
            }
            // Gets the SqlSource
            if (sqlSourceClassName.Length > 0)
            {
                Type sqlSourceType = modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(sqlSourceClassName);
                IFactory factory = modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(sqlSourceType, Type.EmptyTypes);
                sqlSource = (ISqlSource)factory.CreateInstance(null);
            }
        }
コード例 #15
0
        /// <summary>
        /// Builds the the iBATIS core model (statement, alias, resultMap, parameterMap, dataSource)
        /// from an <see cref="IConfigurationStore"/> and store all the refrences in an <see cref="IModelStore"/> .
        /// </summary>
        /// <param name="configurationSetting">The configuration setting.</param>
        /// <param name="store">The configuration store.</param>
        /// <returns>The model store</returns>
        public virtual void BuildModel(ConfigurationSetting configurationSetting, IConfigurationStore store)
        {
            IObjectFactory objectFactory = null;
            IGetAccessorFactory getAccessorFactory = null;
            ISetAccessorFactory setAccessorFactory = null;
            ISessionFactory sessionFactory = null;
            ISessionStore sessionStore = null;
            
            if (configurationSetting != null)
            {
                objectFactory = configurationSetting.ObjectFactory;
                setAccessorFactory = configurationSetting.SetAccessorFactory;
                getAccessorFactory = configurationSetting.GetAccessorFactory;
                dataSource = configurationSetting.DataSource;
                sessionFactory = configurationSetting.SessionFactory;
                sessionStore = configurationSetting.SessionStore;
                dynamicSqlEngine = configurationSetting.DynamicSqlEngine;
                isCacheModelsEnabled = configurationSetting.IsCacheModelsEnabled;
                useStatementNamespaces = configurationSetting.UseStatementNamespaces;
                useReflectionOptimizer = configurationSetting.UseReflectionOptimizer;
                preserveWhitespace = configurationSetting.PreserveWhitespace;
            }
            
            // Xml setting override code setting
            LoadSetting(store);

            if (objectFactory == null)
            {
                objectFactory = new ObjectFactory(useReflectionOptimizer);
            }
            if (setAccessorFactory == null)
            {
                setAccessorFactory = new SetAccessorFactory(useReflectionOptimizer);
            }
            if (getAccessorFactory == null)
            {
                getAccessorFactory = new GetAccessorFactory(useReflectionOptimizer);
            }
            AccessorFactory accessorFactory = new AccessorFactory(setAccessorFactory, getAccessorFactory);

            TypeHandlerFactory typeHandlerFactory = new TypeHandlerFactory();
            TypeAlias alias = new TypeAlias("MEMORY", typeof(PerpetualCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Perpetual", typeof(PerpetualCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("LRU", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Lru", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("FIFO", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Fifo", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("Weak", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("WEAK", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("AnsiStringTypeHandler", typeof(AnsiStringTypeHandler));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            
            modelStore.DataExchangeFactory = new DataExchangeFactory(typeHandlerFactory, objectFactory, accessorFactory);

            if (sessionStore == null)
            {
                sessionStore = SessionStoreFactory.GetSessionStore(modelStore.Id);
            }
            modelStore.SessionStore = sessionStore;
            
            deSerializerFactory = new DeSerializerFactory(modelStore); 

            ParameterMap emptyParameterMap = new ParameterMap(
                ConfigConstants.EMPTY_PARAMETER_MAP,
                string.Empty,
                string.Empty,
                typeof(string),
                modelStore.DataExchangeFactory.GetDataExchangeForClass(null), 
                false);
            modelStore.AddParameterMap(emptyParameterMap);

            BuildProviders(store);
            BuildDataSource(store);

            if (sessionFactory == null)
            {
                sessionFactory = new DefaultSessionFactory(
                    dataSource, 
                    modelStore.SessionStore,
                    new DefaultTransactionManager(new AdoTransactionFactory()));
            }
            modelStore.SessionFactory = sessionFactory;

            BuildTypeAlias(store);
            BuildTypeHandlers(store);
            BuildCacheModels(store);
            BuildResultMaps(store);

            for (int i = 0; i < nestedProperties.Count; i++)
            {
                ResultProperty property = nestedProperties[i];
                property.NestedResultMap = modelStore.GetResultMap(property.NestedResultMapName);
            }

            for (int i = 0; i < discriminators.Count; i++)
            {
                discriminators[i].Initialize(modelStore);
            }
            BuildParameterMaps(store);
            BuildMappedStatements(store, configurationSetting);

            for (int i = 0; i < store.CacheModels.Length; i++)
            {
                CacheModel cacheModel = modelStore.GetCacheModel(store.CacheModels[i].Id);

                for (int j = 0; j < cacheModel.StatementFlushNames.Count; j++)
                {
                    string statement = cacheModel.StatementFlushNames[j];
                    IMappedStatement mappedStatement = modelStore.GetMappedStatement(statement);
                    if (mappedStatement != null)
                    {
                        cacheModel.RegisterTriggerStatement(mappedStatement);
                        if (logger.IsDebugEnabled)
                        {
                            logger.Debug("Registering trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]");
                        }
                    }
                    else
                    {
                        if (logger.IsWarnEnabled)
                        {
                            logger.Warn("Unable to register trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]. Statement does not exist.");
                        }
                    }

                }
            }

            if (logger.IsInfoEnabled)
            {
                logger.Info("Model Store");
                logger.Info(modelStore.ToString());
            }
        }
コード例 #16
0
        /// <summary>
        /// Builds the the MyBatis core model (statement, alias, resultMap, parameterMap, dataSource)
        /// from an <see cref="IConfigurationStore"/> and store all the refrences in an <see cref="IModelStore"/> .
        /// </summary>
        /// <param name="configurationSetting">The configuration setting.</param>
        /// <param name="store">The configuration store.</param>
        /// <returns>The model store</returns>
        public virtual void BuildModel(ConfigurationSetting configurationSetting, IConfigurationStore store)
        {
            IObjectFactory      objectFactory      = null;
            IGetAccessorFactory getAccessorFactory = null;
            ISetAccessorFactory setAccessorFactory = null;
            ISessionFactory     sessionFactory     = null;
            ISessionStore       sessionStore       = null;

            if (configurationSetting != null)
            {
                objectFactory          = configurationSetting.ObjectFactory;
                setAccessorFactory     = configurationSetting.SetAccessorFactory;
                getAccessorFactory     = configurationSetting.GetAccessorFactory;
                dataSource             = configurationSetting.DataSource;
                sessionFactory         = configurationSetting.SessionFactory;
                sessionStore           = configurationSetting.SessionStore;
                dynamicSqlEngine       = configurationSetting.DynamicSqlEngine;
                isCacheModelsEnabled   = configurationSetting.IsCacheModelsEnabled;
                useStatementNamespaces = configurationSetting.UseStatementNamespaces;
                useReflectionOptimizer = configurationSetting.UseReflectionOptimizer;
                preserveWhitespace     = configurationSetting.PreserveWhitespace;
            }

            // Xml setting override code setting
            LoadSetting(store);

            if (objectFactory == null)
            {
                objectFactory = new ObjectFactory(useReflectionOptimizer);
            }
            if (setAccessorFactory == null)
            {
                setAccessorFactory = new SetAccessorFactory(useReflectionOptimizer);
            }
            if (getAccessorFactory == null)
            {
                getAccessorFactory = new GetAccessorFactory(useReflectionOptimizer);
            }
            AccessorFactory accessorFactory = new AccessorFactory(setAccessorFactory, getAccessorFactory);

            TypeHandlerFactory typeHandlerFactory = new TypeHandlerFactory();
            TypeAlias          alias = new TypeAlias("MEMORY", typeof(PerpetualCache));

            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Perpetual", typeof(PerpetualCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("LRU", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Lru", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("FIFO", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Fifo", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("Weak", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("WEAK", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("AnsiStringTypeHandler", typeof(AnsiStringTypeHandler));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            modelStore.DataExchangeFactory = new DataExchangeFactory(typeHandlerFactory, objectFactory, accessorFactory);

            if (sessionStore == null)
            {
                sessionStore = SessionStoreFactory.GetSessionStore(modelStore.Id);
            }
            modelStore.SessionStore = sessionStore;

            deSerializerFactory = new DeSerializerFactory(modelStore);

            ParameterMap emptyParameterMap = new ParameterMap(
                ConfigConstants.EMPTY_PARAMETER_MAP,
                string.Empty,
                string.Empty,
                typeof(string),
                modelStore.DataExchangeFactory.GetDataExchangeForClass(null),
                false);

            modelStore.AddParameterMap(emptyParameterMap);

            BuildProviders(store);
            BuildDataSource(store);

            if (sessionFactory == null)
            {
                sessionFactory = new DefaultSessionFactory(
                    dataSource,
                    modelStore.SessionStore,
                    new DefaultTransactionManager(new AdoTransactionFactory()));
            }
            modelStore.SessionFactory = sessionFactory;

            BuildTypeAlias(store);
            BuildTypeHandlers(store);
            BuildCacheModels(store);
            BuildResultMaps(store);

            for (int i = 0; i < nestedProperties.Count; i++)
            {
                ResultProperty property = nestedProperties[i];
                property.NestedResultMap = modelStore.GetResultMap(property.NestedResultMapName);
            }

            for (int i = 0; i < discriminators.Count; i++)
            {
                discriminators[i].Initialize(modelStore);
            }
            BuildParameterMaps(store);
            BuildMappedStatements(store, configurationSetting);

            for (int i = 0; i < store.CacheModels.Length; i++)
            {
                CacheModel cacheModel = modelStore.GetCacheModel(store.CacheModels[i].Id);

                for (int j = 0; j < cacheModel.StatementFlushNames.Count; j++)
                {
                    string           statement       = cacheModel.StatementFlushNames[j];
                    IMappedStatement mappedStatement = modelStore.GetMappedStatement(statement);
                    if (mappedStatement != null)
                    {
                        cacheModel.RegisterTriggerStatement(mappedStatement);
                        if (logger.IsDebugEnabled)
                        {
                            logger.Debug("Registering trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]");
                        }
                    }
                    else
                    {
                        if (logger.IsWarnEnabled)
                        {
                            logger.Warn("Unable to register trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]. Statement does not exist.");
                        }
                    }
                }
            }

            if (logger.IsInfoEnabled)
            {
                logger.Info("Model Store");
                logger.Info(modelStore.ToString());
            }
        }
コード例 #17
0
ファイル: DefaultModelBuilder.cs プロジェクト: reckcn/CSharp
        /// <summary>
        /// Builds the the iBATIS core model (statement, alias, resultMap, parameterMap, dataSource)
        /// from an <see cref="IConfigurationStore"/> and store all the refrences in an <see cref="IModelStore"/> .
        /// </summary>
        /// <param name="configurationSetting">The configuration setting.</param>
        /// <param name="store">The configuration store.</param>
        /// <returns>The model store</returns>
        public virtual void BuildModel(ConfigurationSetting configurationSetting, IConfigurationStore store)
        {
            IObjectFactory objectFactory = null;
            IGetAccessorFactory getAccessorFactory = null;
            ISetAccessorFactory setAccessorFactory = null;
            ISessionFactory sessionFactory = null;
            ISessionStore sessionStore = null;
            
            if (configurationSetting != null)
            {
                objectFactory = configurationSetting.ObjectFactory;
                setAccessorFactory = configurationSetting.SetAccessorFactory;
                getAccessorFactory = configurationSetting.GetAccessorFactory;
                dataSource = configurationSetting.DataSource;
                sessionFactory = configurationSetting.SessionFactory;
                sessionStore = configurationSetting.SessionStore;
                dynamicSqlEngine = configurationSetting.DynamicSqlEngine;
                isCacheModelsEnabled = configurationSetting.IsCacheModelsEnabled;
                useStatementNamespaces = configurationSetting.UseStatementNamespaces;
                useReflectionOptimizer = configurationSetting.UseReflectionOptimizer;
                preserveWhitespace = configurationSetting.PreserveWhitespace;
            }
            
            // Xml setting override code setting 
            //取store中的数据初始化类成员 为下面做准备
            LoadSetting(store);

            if (objectFactory == null)
            {
                objectFactory = new ObjectFactory(useReflectionOptimizer);
            }
            if (setAccessorFactory == null)
            {
                setAccessorFactory = new SetAccessorFactory(useReflectionOptimizer);
            }
            if (getAccessorFactory == null)
            {
                getAccessorFactory = new GetAccessorFactory(useReflectionOptimizer);
            }
            AccessorFactory accessorFactory = new AccessorFactory(setAccessorFactory, getAccessorFactory);

            TypeHandlerFactory typeHandlerFactory = new TypeHandlerFactory();
            TypeAlias alias = new TypeAlias("MEMORY", typeof(PerpetualCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Perpetual", typeof(PerpetualCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("LRU", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Lru", typeof(LruCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("FIFO", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("Fifo", typeof(FifoCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("Weak", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("WEAK", typeof(WeakCache));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("MemCached", typeof(MemCached));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);
            alias = new TypeAlias("MEMCACHED", typeof(MemCached));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            alias = new TypeAlias("AnsiStringTypeHandler", typeof(AnsiStringTypeHandler));
            typeHandlerFactory.AddTypeAlias(alias.Id, alias);

            //将以上类信息存入到modelStore中 实质性工作
            modelStore.DataExchangeFactory = new DataExchangeFactory(typeHandlerFactory, objectFactory, accessorFactory);

            if (sessionStore == null)
            {
                sessionStore = SessionStoreFactory.GetSessionStore(modelStore.Id);
            }
            //将ISessionStore类对象存入modelStore中 准备数据库的连接 与 事物操作功能  实质性工作
            modelStore.SessionStore = sessionStore;

            //初始化DefaultModelBuilder的成员变量 
            deSerializerFactory = new DeSerializerFactory(modelStore); 

            //设置一个空类型的参数映射类
            ParameterMap emptyParameterMap = new ParameterMap(
                ConfigConstants.EMPTY_PARAMETER_MAP,
                string.Empty,
                string.Empty,
                typeof(string),
                modelStore.DataExchangeFactory.GetDataExchangeForClass(null), //获得ComplexDataExchange对象
                false);

            //向参数字典中添加一个空参数类
            modelStore.AddParameterMap(emptyParameterMap);

            //完成了对DefaultModelBuilder成员变量dbProviderFactory的初始化,其中完成了对provider使用中节点的类初始化
            BuildProviders(store);

            //完成了对DefaultModelBuilder成员变量IDataSource的初始化,包括数据库的名字 连接字符串 以及DbPrivder类
            BuildDataSource(store);

            if (sessionFactory == null)
            {
                sessionFactory = new DefaultSessionFactory(
                    dataSource, 
                    modelStore.SessionStore,
                    new DefaultTransactionManager(new AdoTransactionFactory()));
            }
            //初始化modelStore中的ISessionFactory变量
            modelStore.SessionFactory = sessionFactory;

            //将具体SQLXML配置文件中的Alias节点对应的别名信息写入到modelStore中的TypeHandlerFactory的字典中
            BuildTypeAlias(store);

            //将TypeHanders下的子节点信息放入 modelStore.DataExchangeFactory.TypeHandlerFactory中的字典当中
            BuildTypeHandlers(store);

            //将cacheModels下子节点cacheModel加入到modelStore的CacheModel字典中
            BuildCacheModels(store);
            //将resultMap节点信息添加到modelStore的resultMaps中
            BuildResultMaps(store);

            //为resultMapping属性所在的节点信息类设置对应的ResultProperty
            for (int i = 0; i < nestedProperties.Count; i++)
            {
                ResultProperty property = nestedProperties[i];
                property.NestedResultMap = modelStore.GetResultMap(property.NestedResultMapName);
            }

            for (int i = 0; i < discriminators.Count; i++)
            {
                //完成对discriminator类中对字典的初始化
                discriminators[i].Initialize(modelStore);
            }
            //将parameter节点信息添加到modelStore类中的parameterMaps字典中
            BuildParameterMaps(store);

            //将statements下的节点添加到modelStore的statements的字典中
            BuildMappedStatements(store, configurationSetting);

            for (int i = 0; i < store.CacheModels.Length; i++)
            {
                CacheModel cacheModel = modelStore.GetCacheModel(store.CacheModels[i].Id);

                for (int j = 0; j < cacheModel.StatementFlushNames.Count; j++)
                {
                    string statement = cacheModel.StatementFlushNames[j];
                    IMappedStatement mappedStatement = modelStore.GetMappedStatement(statement);
                    if (mappedStatement != null)
                    {
                        //为IMappedStatement类的Executed制定委托事件  目的是清空缓存
                        cacheModel.RegisterTriggerStatement(mappedStatement);
                        if (logger.IsDebugEnabled)
                        {
                            logger.Debug("Registering trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]");
                        }
                    }
                    else
                    {
                        if (logger.IsWarnEnabled)
                        {
                            logger.Warn("Unable to register trigger statement [" + statement + "] to cache model [" + cacheModel.Id + "]. Statement does not exist.");
                        }
                    }

                }
            }

            if (logger.IsInfoEnabled)
            {
                logger.Info("Model Store");
                logger.Info(modelStore.ToString());
            }
        }