Beispiel #1
0
        public static void SetFor(IRuntimeDatabaseConfiguration conf,
                                  DatabaseSettingsSerialization.Source source,
                                  DatabaseSettingsSerialization.User user,
                                  DatabaseSettingsSerialization.DataSpace dataSpace,
                                  Action <ISetting <string>, string> setter)
        {
            setter(new Setting <string>(BuildSettingName(source, user, dataSpace, DatabaseConfigurations.ProviderKeyName), null), conf.DatabaseProvider.Key.Serialize());

            var wrapper = new MetaDatabaseConfiguration(conf);

            foreach (var param in wrapper.PersistableParameters)
            {
                setter(new Setting <string>(BuildSettingName(source, user, dataSpace, param.Name), null, param.Encrypt), param.Get());
            }
        }
Beispiel #2
0
        protected static DatabaseAccessProvider <IPlatformDatabaseServices> CreatePlatformDatabaseAccessProvider(
            DatabaseSettingsSerialization.Source source,
            DatabaseSettingsSerialization.User user,
            DatabaseSettingsSerialization.DataSpace dataSpace,
            ISettingsProvider settingsProvider)
        {
            var pluginProvider = PlatformDatabasePluginProvider;

            IRuntimeDatabaseConfiguration conf = RuntimeDatabaseConfigurations.For(pluginProvider, source, user, dataSpace, settingsProvider);

            if (conf == null || conf.ConnectionString.IsEmpty())
            {
                throw new InvalidOperationException("Unable to obtain the connection string. Please run Configuration Tool.");
            }

            var services = pluginProvider.GetImplementation(conf.DatabaseProvider.Key).GetPlatformDatabaseServices(conf);

            return(new DatabaseAccessProvider <IPlatformDatabaseServices>(
                       services,
                       services.TransactionService.CreateTransactionManager()));
        }
Beispiel #3
0
        public static IRuntimeDatabaseConfiguration For(
            DatabasePluginProvider <IPlatformDatabaseProvider> provider,
            DatabaseSettingsSerialization.Source source,
            DatabaseSettingsSerialization.User user,
            DatabaseSettingsSerialization.DataSpace dataSpace,
            ISettingsProvider settingsProvider)
        {
            var providerKeySetting = new Setting <string>(BuildSettingName(source, user, dataSpace, DatabaseConfigurations.ProviderKeyName), string.Empty);
            var providerKeyString  = settingsProvider.Get(providerKeySetting);

            if (string.IsNullOrEmpty(providerKeyString))
            {
                return(null);
            }

            var providerKey = DatabaseProviderKey.Deserialize(providerKeyString);
            var conf        = provider.GetImplementation(providerKey).CreateEmptyRuntimeDatabaseConfiguration();

            RuntimeDatabaseConfigurations.Fill(conf, BuildSettingName(source, user, dataSpace, ""), settingsProvider);

            return(conf);
        }
        protected static DatabaseAccessProvider <IPlatformDatabaseServices> CreatePlatformDatabaseAccessProvider(
            DatabaseSettingsSerialization.Source source,
            DatabaseSettingsSerialization.User user)
        {
            var pluginProvider = PlatformDatabasePluginProvider;

            var key = Pair.Create(source, user);
            IRuntimeDatabaseConfiguration conf;

            if (source == DatabaseSettingsSerialization.Source.Application)
            {
                // We don't use GetOrAdd because in Java computeIfAbsent holds a lock
                // while evaluating the factory function which can lead to deadlocks when one thread
                // is initializing the database access for the first time and another is retrieving
                // a setting from the database
                if (!cachedPlatformAccessConfigurations.TryGetValue(key, out conf))
                {
                    var newConf = RuntimeDatabaseConfigurations.For(pluginProvider, source, user);
                    conf = cachedPlatformAccessConfigurations.GetOrAdd(key, newConf);
                }
            }
            else
            {
                // Service Configurations can't be cached becase the underlining settings storage keeps changing as they serve diferent sandboxes
                conf = RuntimeDatabaseConfigurations.For(pluginProvider, source, user);
            }

            if (conf == null || conf.ConnectionString.IsEmpty())
            {
                throw new InvalidOperationException("Unable to obtain the connection string. Please run Configuration Tool.");
            }

            var services = pluginProvider.GetImplementation(conf.ProviderKey()).GetPlatformDatabaseServices(conf);

            services.IntrospectionService.QueryTimeout = IntrospectionQueryTimeout;
            return(new DatabaseAccessProvider <IPlatformDatabaseServices>(
                       services,
                       services.TransactionService.CreateTransactionManager()));
        }
Beispiel #5
0
        private static string BuildSettingName(DatabaseSettingsSerialization.Source source, DatabaseSettingsSerialization.User user, DatabaseSettingsSerialization.DataSpace dataSpace, string settingName)
        {
            string dataSpaceStr = null;

            switch (dataSpace)
            {
            case DatabaseSettingsSerialization.DataSpace.Business:
                dataSpaceStr = "Business";
                break;

            case DatabaseSettingsSerialization.DataSpace.Logging:
                dataSpaceStr = "Logging";
                break;

            default:
                dataSpaceStr = "Platform";
                break;
            }

            return(DatabaseConfigurations.SettingPrefix + "." + dataSpaceStr + "." + source + "." + user + "." + settingName);
        }
        protected static DatabaseAccessProvider <IPlatformDatabaseServices> GetProviderForDatabase(IRuntimeDatabaseConfiguration configurationForDatabase,
                                                                                                   DatabaseSettingsSerialization.User user, DatabaseAccessProvider <IPlatformDatabaseServices> systemDatabaseProvider,
                                                                                                   IDictionary <string, DatabaseAccessProvider <IPlatformDatabaseServices> > providersByIdentifier,
                                                                                                   IDictionary <string, ITransactionManager> transactionManagersByIdentifier)
        {
            if (configurationForDatabase == null)
            {
                return(systemDatabaseProvider);
            }

            bool supportsUnifiedTransactionManager = (user == DatabaseSettingsSerialization.User.Admin) ||
                                                     Settings.GetBool(Settings.Configs.SupportUnifiedMDC);

            var systemConfig = systemDatabaseProvider.DatabaseServices.DatabaseConfiguration;

            string managerIdentifier = supportsUnifiedTransactionManager ?
                                       configurationForDatabase.Username
                : configurationForDatabase.DatabaseIdentifier;

            string systemManagerIdentifier = supportsUnifiedTransactionManager ?
                                             systemConfig.Username
                : systemConfig.DatabaseIdentifier;

            bool sameIdentifier = managerIdentifier.EqualsIgnoreCase(systemManagerIdentifier);
            // If using the system manager to access the system database, we can use the SystemProvider
            bool sameDatabase = configurationForDatabase.DatabaseIdentifier.EqualsIgnoreCase(systemConfig.DatabaseIdentifier);

            if (sameIdentifier && sameDatabase)
            {
                return(systemDatabaseProvider);
            }

            // In unified MDC scenarios, we want to use a provider with a shared transaction manager
            // while keeping the original configuration that uses the correct database identifier
            string providerIdentifier = managerIdentifier + (supportsUnifiedTransactionManager ? "-" + configurationForDatabase.DatabaseIdentifier : "");
            DatabaseAccessProvider <IPlatformDatabaseServices> provider;

            if (!providersByIdentifier.TryGetValue(providerIdentifier, out provider))
            {
                lock (providersByIdentifier) {
                    if (!providersByIdentifier.TryGetValue(providerIdentifier, out provider))
                    {
                        ITransactionManager manager = sameIdentifier ? systemDatabaseProvider.TransactionManager : null;
                        if (manager == null && !transactionManagersByIdentifier.TryGetValue(managerIdentifier, out manager))
                        {
                            var services = PlatformDatabasePluginProvider
                                           .GetImplementation(configurationForDatabase.ProviderKey())
                                           .GetPlatformDatabaseServices(configurationForDatabase);
                            manager = services.TransactionService.CreateTransactionManager();
                            transactionManagersByIdentifier.Add(managerIdentifier, manager);
                        }

                        // TODO: Check with the Stack Team if we can optimized this
                        var dapServices = PlatformDatabasePluginProvider
                                          .GetImplementation(configurationForDatabase.ProviderKey())
                                          .GetPlatformDatabaseServices(configurationForDatabase);

                        dapServices.IntrospectionService.QueryTimeout = IntrospectionQueryTimeout;
                        provider = new DatabaseAccessProvider <IPlatformDatabaseServices>(
                            dapServices,
                            manager);

                        providersByIdentifier.Add(providerIdentifier, provider);
                    }
                }
            }
            return(provider);
        }
        protected internal static IRuntimeDatabaseConfiguration ConfigurationForDatabase(string databaseName, DatabaseSettingsSerialization.Source source, DatabaseSettingsSerialization.User user)
        {
            if (string.IsNullOrEmpty(databaseName) ||
                (databaseName == Constants.SystemDatabaseLogicalName) ||
                (databaseName == ForSystemDatabase.DatabaseServices.DatabaseConfiguration.DatabaseIdentifier))
            {
                return(null);
            }

            using (var trans = ForSystemDatabase.GetCommitableTransaction()) {
                var eSpaceParams = DBRuntimePlatform.Instance.GetCatalogDetailsByName(trans, databaseName, user);
                if (eSpaceParams == null)
                {
                    return(null);
                }

                var baseConf = RuntimeDatabaseConfigurations.For(
                    CurrentPlatformDatabasesPluginProvider,
                    source,
                    user);

                baseConf.SetParameters(eSpaceParams);
                return(baseConf);
            }
        }
 protected internal static IRuntimeDatabaseConfiguration ConfigurationForDatabase(string databaseName, DatabaseSettingsSerialization.User user)
 {
     return(ConfigurationForDatabase(databaseName, AccessRequester, user));
 }
Beispiel #9
0
        protected static DatabaseAccessProvider <IPlatformDatabaseServices> GetProviderForDatabase(IRuntimeDatabaseConfiguration configurationForDatabase,
                                                                                                   DatabaseSettingsSerialization.User user, DatabaseAccessProvider <IPlatformDatabaseServices> baseProvider,
                                                                                                   IDictionary <string, DatabaseAccessProvider <IPlatformDatabaseServices> > providersByIdentifier,
                                                                                                   IDictionary <string, ITransactionManager> transactionManagersByIdentifier)
        {
            if (configurationForDatabase == null)
            {
                return(baseProvider);
            }

            // ***************** MDC STUFF ***************************
            var databaseConfig = baseProvider.DatabaseServices.DatabaseConfiguration;

            string managerIdentifier         = configurationForDatabase.Username;
            string databaseManagerIdentifier = databaseConfig.Username;

            bool sameIdentifier = managerIdentifier.EqualsIgnoreCase(databaseManagerIdentifier);
            // If using the system manager to access the system database, we can use the SystemProvider
            bool sameDatabase = configurationForDatabase.DatabaseIdentifier.EqualsIgnoreCase(databaseConfig.DatabaseIdentifier);

            if (sameIdentifier && sameDatabase)
            {
                return(baseProvider);
            }

            // In unified MDC scenarios, we want to use a provider with a shared transaction manager
            // while keeping the original configuration that uses the correct database identifier
            string providerIdentifier = managerIdentifier + "-" + configurationForDatabase.DatabaseIdentifier;
            DatabaseAccessProvider <IPlatformDatabaseServices> provider;

            if (!providersByIdentifier.TryGetValue(providerIdentifier, out provider))
            {
                lock (providersByIdentifier) {
                    if (!providersByIdentifier.TryGetValue(providerIdentifier, out provider))
                    {
                        ITransactionManager manager = sameIdentifier ? baseProvider.TransactionManager : null;
                        if (manager == null && !transactionManagersByIdentifier.TryGetValue(managerIdentifier, out manager))
                        {
                            var services = PlatformDatabasePluginProvider
                                           .GetImplementation(configurationForDatabase.DatabaseProvider.Key)
                                           .GetPlatformDatabaseServices(configurationForDatabase);
                            manager = services.TransactionService.CreateTransactionManager();
                            transactionManagersByIdentifier.Add(managerIdentifier, manager);
                        }

                        // TODO: Check with the Stack Team if we can optimized this
                        var dapServices = PlatformDatabasePluginProvider
                                          .GetImplementation(configurationForDatabase.DatabaseProvider.Key)
                                          .GetPlatformDatabaseServices(configurationForDatabase);

                        provider = new DatabaseAccessProvider <IPlatformDatabaseServices>(
                            dapServices,
                            manager);

                        providersByIdentifier.Add(providerIdentifier, provider);
                    }
                }
            }
            // ***************** MDC STUFF ***************************
            return(provider);
        }
Beispiel #10
0
        public static void SetFor(IRuntimeDatabaseConfiguration conf, DatabaseSettingsSerialization.Source source, DatabaseSettingsSerialization.User user, Action <string, string> setter)
        {
            var prefix = DatabaseConfigurations.SettingPrefix + "." + source + "." + user + ".";

            setter(prefix + DatabaseConfigurations.ProviderKeyName, conf.ProviderKey().Serialize());

            var wrapper = new MetaDatabaseConfiguration(conf);

            foreach (var param in wrapper.PersistableParameters)
            {
                setter(prefix + param.Name,
                       param.Encrypt? SecureConfidentialInformationEncryption.EncryptMaintainingCompatibility(param.Get()): param.Get());
            }
        }
Beispiel #11
0
 public static void SetOnCacheFor(IRuntimeDatabaseConfiguration conf, DatabaseSettingsSerialization.Source source, DatabaseSettingsSerialization.User user)
 {
     SetFor(conf, source, user, Settings.Set);
 }
Beispiel #12
0
        public static IRuntimeDatabaseConfiguration For(DatabasePluginProvider <IPlatformDatabaseProvider> provider, DatabaseSettingsSerialization.Source source, DatabaseSettingsSerialization.User user)
        {
            var @params = Read(source, user);

            if (@params.Count == 0)
            {
                return(null);
            }

            var providerKey = DatabaseProviderKey.Deserialize(@params[DatabaseConfigurations.ProviderKeyName].ToString());
            var conf        = provider.GetImplementation(providerKey).CreateEmptyRuntimeDatabaseConfiguration();

            RuntimeDatabaseConfigurations.Fill(conf, @params);

            return(conf);
        }
Beispiel #13
0
        private static Dictionary <string, object> Read(DatabaseSettingsSerialization.Source source, DatabaseSettingsSerialization.User user)
        {
            var prefix  = DatabaseConfigurations.SettingPrefix + "." + source + "." + user + ".";
            var @params = new Dictionary <string, object>();

            foreach (var settings in Settings.GetByPrefix(prefix))
            {
                @params.Add(settings.First.Substring(prefix.Length), settings.Second);
            }
            return(@params);
        }