Esempio n. 1
0
        private OracleDatabaseModel(ConnectionStringSettings connectionString, string identifier)
        {
            ObjectScriptExtractor = new OracleObjectScriptExtractor(this);

            _connectionString = connectionString;
            var connectionStringBuilder = new OracleConnectionStringBuilder(_connectionString.ConnectionString)
            {
                SelfTuning = false, MinPoolSize = 1, IncrPoolSize = 1
            };

            if (String.IsNullOrWhiteSpace(connectionStringBuilder.UserID))
            {
                throw new ArgumentException("Connection string must contain USER ID");
            }

            ConnectionIdentifier  = identifier;
            _moduleName           = $"{ModuleNameSqlPadDatabaseModelBase}/{identifier}";
            _initialSchema        = _currentSchema = connectionStringBuilder.UserID.ToQuotedIdentifier().Trim('"');
            _connectionStringName = $"{connectionStringBuilder.DataSource}_{_currentSchema}";

            HasDbaPrivilege = String.Equals(connectionStringBuilder.DBAPrivilege.ToUpperInvariant(), "SYSDBA");

            lock (ActiveDataModelRefresh)
            {
                if (!WaitingDataModelRefresh.ContainsKey(_connectionStringName))
                {
                    WaitingDataModelRefresh[_connectionStringName] = new List <RefreshModel>();
                }
            }

            _dataDictionaryMapper = new OracleDataDictionaryMapper(this, RaiseRefreshStatusChanged);

            InternalRefreshStarted   += InternalRefreshStartedHandler;
            InternalRefreshCompleted += InternalRefreshCompletedHandler;

            //_customTypeGenerator = OracleCustomTypeGenerator.GetCustomTypeGenerator(connectionString.Name);
        }
Esempio n. 2
0
        private bool RefreshSchemaObjectMetadata()
        {
            var lastRefresh = DateTime.Now;

            try
            {
                RefreshSchemas();

                var allObjects = _dataDictionaryMapper.BuildDataDictionary();

                var userPrograms    = _dataDictionaryMapper.GetUserFunctionMetadata().SelectMany(g => g).ToArray();
                var builtInPrograms = _dataDictionaryMapper.GetBuiltInFunctionMetadata().SelectMany(g => g).ToArray();
                _allProgramMetadata = builtInPrograms
                                      .Concat(userPrograms)
                                      .ToLookup(m => m.Identifier);

                var stopwatch = Stopwatch.StartNew();

                var nonSchemaBuiltInFunctionMetadata = new List <OracleProgramMetadata>();

                foreach (var programMetadata in builtInPrograms.Concat(userPrograms))
                {
                    if (String.IsNullOrEmpty(programMetadata.Identifier.Owner))
                    {
                        nonSchemaBuiltInFunctionMetadata.Add(programMetadata);
                        continue;
                    }

                    var packageIdentifier = OracleObjectIdentifier.Create(programMetadata.Identifier.Owner, programMetadata.Identifier.Package);
                    if (allObjects.TryGetFirstValue(out OracleSchemaObject schemaObject, packageIdentifier))
                    {
                        ((OraclePackage)schemaObject).Programs.Add(programMetadata);
                        programMetadata.Owner = schemaObject;
                    }
                    else
                    {
                        var programIdentifier = OracleObjectIdentifier.Create(programMetadata.Identifier.Owner, programMetadata.Identifier.Name);
                        if (allObjects.TryGetFirstValue(out schemaObject, programIdentifier))
                        {
                            ((OracleSchemaProgram)schemaObject).Metadata = programMetadata;
                            programMetadata.Owner = schemaObject;
                        }
                    }
                }

                OracleDataDictionaryMapper.WriteTrace(ConnectionString.Name, $"Function and procedure metadata schema object mapping finished in {stopwatch.Elapsed}. ");

                stopwatch.Reset();

                _uniqueConstraintReferringReferenceConstraints = BuildUniqueConstraintReferringReferenceConstraintLookup(allObjects.Values);

                var databaseLinks    = _dataDictionaryMapper.GetDatabaseLinks();
                var characterSets    = _dataDictionaryMapper.GetCharacterSets();
                var statisticsKeys   = SafeFetchDictionary(_dataDictionaryMapper.GetStatisticsKeys, "OracleDataDictionaryMapper.GetStatisticsKeys failed: ");
                var systemParameters = SafeFetchDictionary(_dataDictionaryMapper.GetSystemParameters, "OracleDataDictionaryMapper.GetSystemParameters failed: ");

                OracleDataDictionaryMapper.WriteTrace(ConnectionString.Name, $"Unique constraint, database link, character sets, statistics keys and system parameter mapping finished in {stopwatch.Elapsed}. ");

                _dataDictionary = new OracleDataDictionary(allObjects, databaseLinks, nonSchemaBuiltInFunctionMetadata, characterSets, statisticsKeys, systemParameters, lastRefresh);

                OracleDataDictionaryMapper.WriteTrace(ConnectionString.Name, "Data dictionary metadata cache has been initialized successfully. ");

                //_customTypeGenerator.GenerateCustomTypeAssembly(_dataDictionary);

                CachedDataDictionaries[_connectionStringName] = _dataDictionary;

                return(true);
            }
            catch (Exception e)
            {
                OracleDataDictionaryMapper.WriteTrace(ConnectionString.Name, $"Oracle data dictionary refresh failed: {e}");
                return(false);
            }
        }