public bool HasSubscriptionStructures(DataSource source)
 {
     using (DatabaseConnectionFactory.Create(source))
     {
         return DatabaseGateway.GetScalarUsing<int>(source, SubscriptionQueries.HasSubscriptionStructures()) == 1;
     }
 }
        public IDbConnectionConfiguration Get(DataSource dataSource)
        {
            Guard.AgainstNull(dataSource, "dataSource");

            if (!dbConnectionConfigurations.ContainsKey(dataSource.Key))
            {
                lock(padlock)
                {
                    if (!dbConnectionConfigurations.ContainsKey(dataSource.Key))
                    {
                        var settings = ConfigurationManager.ConnectionStrings[dataSource.Name];

                        if (settings == null)
                        {
                            throw new InvalidOperationException(
                                string.Format(DataResources.ConnectionStringMissing, dataSource.Name));
                        }

                        dbConnectionConfigurations.Add(dataSource.Key, new DbConnectionConfiguration(dataSource, settings.ProviderName, settings.ConnectionString));
                    }
                }
            }

            return dbConnectionConfigurations[dataSource.Key];
        }
        public IDbConnection CreateConnection(DataSource source)
        {
            var dbConnectionConfiguration = _dbConnectionConfigurationProvider.Get(source);

            if (!_dbProviderFactories.ContainsKey(source.Key))
            {
                lock(padlock)
                {
                    if (!_dbProviderFactories.ContainsKey(source.Key))
                    {
                        var factory = DbProviderFactories.GetFactory(dbConnectionConfiguration.ProviderName);

                        _dbProviderFactories.Add(source.Key, factory);

                        _log.Verbose(string.Format(DataResources.DbProviderFactoryCached, dbConnectionConfiguration.ProviderName));
                    }
                }
            }

            var dbProviderFactory = _dbProviderFactories[source.Key];

            var connection = dbProviderFactory.CreateConnection();

            connection.ConnectionString = dbConnectionConfiguration.ConnectionString;

            _log.Verbose(string.Format(DataResources.DbConnectionCreated, source.Name));

            return connection;
        }
        public IDbConnectionConfiguration Get(DataSource source)
        {
            Guard.AgainstNull(source, "source");

            var settings = ConfigurationManager.ConnectionStrings[source.Name];

            if (settings != null)
            {
                return new DbConnectionConfiguration(source, settings.ProviderName, settings.ConnectionString);
            }

            foreach (var provider in dbConnectionConfigurationProviders)
            {
                var configuration = provider.Get(source);

                if (configuration == null)
                {
                    continue;
                }

                return configuration;
            }

            throw new InvalidOperationException(
                string.Format(
                    "The required connection string with name '{0}' is not specified in the application configuration file and has not been registered with any of the providers.",
                    source.Name));
        }
        public IDbCommand CreateCommandUsing(DataSource source, IDbConnection connection, IQuery query)
        {
            var command = connection.CreateCommand();

            command.CommandTimeout = commandTimeout;
            query.Prepare(source, command);

            return command;
        }
        public DbConnectionConfiguration(DataSource dataSource, string providerName, string connectionString)
        {
            Guard.AgainstNull(dataSource, "dataSource");
            Guard.AgainstNullOrEmptyString(providerName, "providerName");
            Guard.AgainstNullOrEmptyString(connectionString, "connectionString");

            Name = dataSource.Name;
            ProviderName = providerName;
            ConnectionString = connectionString;
        }
        public IDatabaseConnection Add(DataSource source, IDatabaseConnection connection)
        {
            Infrastructure.Guard.AgainstNull(connection, "connection");

            Guard();

            connections.Add(source.Key, connection);

            return connection;
        }
        public IDatabaseConnection Get(DataSource source)
        {
            Guard();

            if (!connections.ContainsKey(source.Key))
            {
                throw new ApplicationException(string.Format(DataResources.ThreadStaticDatabaseConnectionCacheMissingEntry, source.Name));
            }

            return connections[source.Key];
        }
        public void Prepare(DataSource source, IDbCommand command)
        {
            Guard.AgainstNull(source, "source");
            Guard.AgainstNull(command, "command");

            command.CommandText = procedure;
            command.CommandType = CommandType.StoredProcedure;

            foreach (var pair in parameterValues)
            {
                command.Parameters.Add(pair.Key.CreateDataParameter(source.DbDataParameterFactory, pair.Value));
            }
        }
        public IDatabaseConnection Create(DataSource source)
        {
            if (_databaseConnectionCache.Contains(source))
            {
                var existingDatabaseConnection = new ExistingDatabaseConnection(_databaseConnectionCache.Get(source));

                _log.Verbose(string.Format(DataResources.ExistingDatabaseConnectionReturned, source.Name));

                return existingDatabaseConnection;
            }

            var databaseConnection = new DatabaseConnection(source, _dbConnectionFactory.CreateConnection(source), _dbCommandFactory, _databaseConnectionCache);

            _log.Verbose(string.Format(DataResources.DatabaseConnectionCreated, source.Name));

            return databaseConnection;
        }
        public IDbConnectionConfiguration Get(DataSource source)
        {
            try
            {
                var store = managementConfiguration.DataStoreRepository().Get(source.Name);

                return store == null
                       	? null
                       	: new DbConnectionConfiguration(source,
                       	                                store.ProviderName,
                       	                                store.ConnectionString);
            }
            catch
            {
                return null;
            }
        }
        public DatabaseConnection(DataSource dataSource, IDbConnection connection, IDbCommandFactory dbCommandFactory, 
            IDatabaseConnectionCache databaseConnectionCache, bool ownedConnection = true, IDbTransaction currentTransaction = null)
        {
            Guard.AgainstNull(dataSource, "dataSource");
            Guard.AgainstNull(connection, "connection");
            Guard.AgainstNull(dbCommandFactory, "dbCommandFactory");
            Guard.AgainstNull(databaseConnectionCache, "databaseConnectionCache");

            _dataSource = dataSource;
            _dbCommandFactory = dbCommandFactory;
            _databaseConnectionCache = databaseConnectionCache;

            Connection = connection;
            _ownedConnection = ownedConnection;
            Transaction = currentTransaction;
            _ownedTransaction = currentTransaction == null;

            _log = Log.For(this);

            _log.Verbose(string.Format(DataResources.DbConnectionCreated, dataSource.Name));

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    Connection.Open();
                    _log.Verbose(string.Format(DataResources.DbConnectionOpened, dataSource.Name));
                }
                else
                {
                    _log.Verbose(string.Format(DataResources.DbConnectionAlreadyOpen, dataSource.Name));
                }
            }
            catch (Exception ex)
            {
                _log.Error(string.Format(DataResources.DbConnectionOpenException, dataSource.Name, ex.Message));

                throw;
            }

            databaseConnectionCache.Add(dataSource, this);
        }
Beispiel #13
0
 public DataTable All(DataSource source)
 {
     return DatabaseGateway.GetDataTableFor(source, ScheduleQueries.All());
 }
        public bool Contains(DataSource source)
        {
            Guard();

            return connections.ContainsKey(source.Key);
        }
 public DataTable MessageTypes(DataSource source, string uri)
 {
     return DatabaseGateway.GetDataTableFor(source, SubscriptionQueries.MessageTypes(uri));
 }
 public DataTable All(DataSource source)
 {
     return DatabaseGateway.GetDataTableFor(source, SubscriptionRequestQueries.All());
 }
        public void Remove(DataSource source)
        {
            Guard();

            connections.Remove(source.Key);
        }
 public DataTable AllUris(DataSource source)
 {
     return DatabaseGateway.GetDataTableFor(source, SubscriptionQueries.AllUris());
 }
 public bool HasScheduleStructures(DataSource source)
 {
     return _databaseGateway.GetScalarUsing<int>(source, _queryFactory.HasScheduleStructures()) == 1;
 }