예제 #1
0
        /// <summary>
        /// Creates the dependency enlisters for any dependecies that require notification enlistment
        /// </summary>
        /// <param name="dependencyConfig">Settings for the dependencies</param>
        /// <param name="defaultConnectionName">connection name to use when setting up data dependencies if no connection string provider is specified</param>
        /// <param name="defaultConnectionString">default connection string to use for data dependencies if no connection string provider is specified </param>
        private void CreateDependencyEnlisters(CacheDependenciesElement dependencyConfig, string defaultConnectionName,
                                               string defaultConnectionString)
        {
            //dont do anything if there is no config
            if (dependencyConfig == null)
            {
                log.Debug("no data dependencies specified");
                return;
            }

            //build the table dependency enlisters
            if (dependencyConfig.TableDependencies.Count > 0)
            {
                foreach (TableCacheDependencyElement tableConfig in dependencyConfig.TableDependencies)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("configuring sql table dependency, '{0}' using table, '{1}', and database entry. '{2}'",
                                         tableConfig.Name, tableConfig.TableName, tableConfig.DatabaseEntryName);
                    }

                    var tableEnlister = new SqlTableCacheDependencyEnlister(tableConfig.TableName, tableConfig.DatabaseEntryName);

                    _dependencyEnlisters.Add(tableEnlister);
                }
            }

            //build the command dependency enlisters
            if (dependencyConfig.CommandDependencies.Count > 0)
            {
                foreach (CommandCacheDependencyElement commandConfig in dependencyConfig.CommandDependencies)
                {
                    //construct the correct connection string provider, we will do are best fallback to a connection string provider
                    //that will help us find a connection string even if one isnt specified

                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("configuring sql command dependency, '{0}', using command, '{1}'", commandConfig.Name,
                                         commandConfig.Command);
                        log.DebugFormat("command configured as stored procedure: {0}", commandConfig.IsStoredProcedure);
                    }

                    IConnectionStringProvider connectionStringProvider;
                    string connectionName = null;

                    if (commandConfig.ConnectionStringProviderType != null)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("Activating configured connection string provider, '{0}'",
                                             commandConfig.ConnectionStringProviderType.ToString());
                        }

                        connectionStringProvider =
                            Activator.CreateInstance(commandConfig.ConnectionStringProviderType) as IConnectionStringProvider;
                        connectionName = commandConfig.ConnectionName;
                    }
                    else
                    {
                        //no connection string provider specified so use the appropriate default
                        //if a connection string was specified and we dont have a specifi name in the cache regions settings
                        //then just use the default connection string
                        if (String.IsNullOrEmpty(defaultConnectionName) && String.IsNullOrEmpty(commandConfig.ConnectionName))
                        {
                            log.DebugFormat("no connection string provider specified using nhibernate configured connection string");

                            connectionStringProvider = new StaticConnectionStringProvider(defaultConnectionString);
                        }
                        else
                        {
                            //we dont have any connection strings specified so we must get it from config
                            connectionStringProvider = new ConfigConnectionStringProvider();

                            //tweak the connection name based on whether the region has one specified or not
                            if (String.IsNullOrEmpty(commandConfig.ConnectionName) == false)
                            {
                                connectionName = commandConfig.ConnectionName;
                            }
                            else
                            {
                                connectionName = defaultConnectionName;
                            }

                            if (log.IsDebugEnabled)
                            {
                                log.DebugFormat("no connection string provider specified, using connection with name : {0}", connectionName);
                            }
                        }
                    }

                    var commandEnlister = new SqlCommandCacheDependencyEnlister(commandConfig.Command, commandConfig.IsStoredProcedure,
                                                                                commandConfig.CommandTimeout, connectionName, 
                                                                                connectionStringProvider);

                    _dependencyEnlisters.Add(commandEnlister);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Creates the dependency enlisters for any dependecies that require notification enlistment
        /// </summary>
        /// <param name="dependencyConfig">Settings for the dependencies</param>
        /// <param name="defaultConnectionName">connection name to use when setting up data dependencies if no connection string provider is specified</param>
        /// <param name="defaultConnectionString">default connection string to use for data dependencies if no connection string provider is specified </param>
        private void CreateDependencyEnlisters(CacheDependenciesElement dependencyConfig, string defaultConnectionName,
                                               string defaultConnectionString)
        {
            //dont do anything if there is no config
            if (dependencyConfig == null)
            {
                log.Debug("no data dependencies specified");
                return;
            }

            //build the table dependency enlisters
            if (dependencyConfig.TableDependencies.Count > 0)
            {
                foreach (TableCacheDependencyElement tableConfig in dependencyConfig.TableDependencies)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("configuring sql table dependency, '{0}' using table, '{1}', and database entry. '{2}'",
                                        tableConfig.Name, tableConfig.TableName, tableConfig.DatabaseEntryName);
                    }

                    var tableEnlister = new SqlTableCacheDependencyEnlister(tableConfig.TableName, tableConfig.DatabaseEntryName);

                    _dependencyEnlisters.Add(tableEnlister);
                }
            }

            //build the command dependency enlisters
            if (dependencyConfig.CommandDependencies.Count > 0)
            {
                foreach (CommandCacheDependencyElement commandConfig in dependencyConfig.CommandDependencies)
                {
                    //construct the correct connection string provider, we will do are best fallback to a connection string provider
                    //that will help us find a connection string even if one isnt specified

                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("configuring sql command dependency, '{0}', using command, '{1}'", commandConfig.Name,
                                        commandConfig.Command);
                        log.DebugFormat("command configured as stored procedure: {0}", commandConfig.IsStoredProcedure);
                    }

                    IConnectionStringProvider connectionStringProvider;
                    string connectionName = null;

                    if (commandConfig.ConnectionStringProviderType != null)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("Activating configured connection string provider, '{0}'",
                                            commandConfig.ConnectionStringProviderType.ToString());
                        }

                        connectionStringProvider =
                            Activator.CreateInstance(commandConfig.ConnectionStringProviderType) as IConnectionStringProvider;
                        connectionName = commandConfig.ConnectionName;
                    }
                    else
                    {
                        //no connection string provider specified so use the appropriate default
                        //if a connection string was specified and we dont have a specifi name in the cache regions settings
                        //then just use the default connection string
                        if (String.IsNullOrEmpty(defaultConnectionName) && String.IsNullOrEmpty(commandConfig.ConnectionName))
                        {
                            log.DebugFormat("no connection string provider specified using nhibernate configured connection string");

                            connectionStringProvider = new StaticConnectionStringProvider(defaultConnectionString);
                        }
                        else
                        {
                            //we dont have any connection strings specified so we must get it from config
                            connectionStringProvider = new ConfigConnectionStringProvider();

                            //tweak the connection name based on whether the region has one specified or not
                            if (String.IsNullOrEmpty(commandConfig.ConnectionName) == false)
                            {
                                connectionName = commandConfig.ConnectionName;
                            }
                            else
                            {
                                connectionName = defaultConnectionName;
                            }

                            if (log.IsDebugEnabled)
                            {
                                log.DebugFormat("no connection string provider specified, using connection with name : {0}", connectionName);
                            }
                        }
                    }

                    var commandEnlister = new SqlCommandCacheDependencyEnlister(commandConfig.Command, commandConfig.IsStoredProcedure,
                                                                                commandConfig.CommandTimeout, connectionName,
                                                                                connectionStringProvider);

                    _dependencyEnlisters.Add(commandEnlister);
                }
            }
        }