예제 #1
0
        /// <summary>
        /// Retrieves all database routines.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token.</param>
        /// <returns>A collection of database routines.</returns>
        public async IAsyncEnumerable <IDatabaseRoutine> GetAllRoutines([EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            var queryResult = await Connection.QueryAsync <RoutineData>(
                AllSourcesQuery,
                cancellationToken
                ).ConfigureAwait(false);

            var routines = queryResult
                           .GroupBy(r => new { r.SchemaName, r.RoutineName })
                           .Select(r =>
            {
                var name = Identifier.CreateQualifiedIdentifier(IdentifierDefaults.Server, IdentifierDefaults.Database, r.Key.SchemaName, r.Key.RoutineName);

                var lines = r
                            .OrderBy(r => r.LineNumber)
                            .Where(r => r.Text != null)
                            .Select(r => r.Text !);
                var definition          = lines.Join(string.Empty);
                var unwrappedDefinition = OracleUnwrapper.Unwrap(definition);

                return(new DatabaseRoutine(name, unwrappedDefinition));
            });

            foreach (var routine in routines)
            {
                yield return(routine);
            }
        }
예제 #2
0
        private async Task <string> LoadDefinitionAsyncCore(Identifier routineName, CancellationToken cancellationToken)
        {
            // fast path
            if (routineName.Schema == IdentifierDefaults.Schema)
            {
                var userLines = await Connection.QueryAsync <string>(
                    UserDefinitionQuery,
                    new { RoutineName = routineName.LocalName },
                    cancellationToken
                    ).ConfigureAwait(false);

                if (userLines.Empty())
                {
                    return(string.Empty);
                }

                var userDefinition = userLines.Join(string.Empty);
                return(OracleUnwrapper.Unwrap(userDefinition));
            }

            var lines = await Connection.QueryAsync <string>(
                DefinitionQuery,
                new { SchemaName = routineName.Schema, RoutineName = routineName.LocalName },
                cancellationToken
                ).ConfigureAwait(false);

            if (lines.Empty())
            {
                return(string.Empty);
            }

            var definition = lines.Join(string.Empty);

            return(OracleUnwrapper.Unwrap(definition));
        }
        /// <summary>
        /// Retrieves all database packages.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token.</param>
        /// <returns>A collection of database packages.</returns>
        public async IAsyncEnumerable <IOracleDatabasePackage> GetAllPackages([EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            var queryResult = await Connection.QueryAsync <RoutineData>(
                AllSourcesQuery,
                cancellationToken
                ).ConfigureAwait(false);

            var packages = queryResult
                           .GroupBy(r => new { r.SchemaName, r.RoutineName })
                           .Select(r =>
            {
                var name = Identifier.CreateQualifiedIdentifier(IdentifierDefaults.Server, IdentifierDefaults.Database, r.Key.SchemaName, r.Key.RoutineName);

                var specLines = r
                                .Where(p => p.RoutineType == PackageObjectType)
                                .OrderBy(p => p.LineNumber)
                                .Where(p => p.Text != null)
                                .Select(p => p.Text !);
                var bodyLines = r
                                .Where(p => p.RoutineType == PackageBodyObjectType)
                                .OrderBy(p => p.LineNumber)
                                .Where(p => p.Text != null)
                                .Select(p => p.Text !);

                var spec = specLines.Join(string.Empty);
                var body = bodyLines.Any()
                        ? Option <string> .Some(bodyLines.Join(string.Empty))
                        : Option <string> .None;

                var specification = OracleUnwrapper.Unwrap(spec);
                var packageBody   = body.Map(OracleUnwrapper.Unwrap);

                return(new OracleDatabasePackage(name, specification, packageBody));
            });

            foreach (var package in packages)
            {
                yield return(package);
            }
        }
        private async Task <IOracleDatabasePackage> LoadPackageAsyncCore(Identifier packageName, CancellationToken cancellationToken)
        {
            // fast path
            if (packageName.Schema == IdentifierDefaults.Schema)
            {
                var lines = await Connection.QueryAsync <PackageData>(
                    UserPackageDefinitionQuery,
                    new { PackageName = packageName.LocalName },
                    cancellationToken
                    ).ConfigureAwait(false);

                var spec = lines
                           .Where(p => p.SourceType == PackageObjectType)
                           .OrderBy(p => p.LineNumber)
                           .Where(p => p.Text != null)
                           .Select(p => p.Text !)
                           .Join(string.Empty);
                var bodyLines = lines
                                .Where(p => p.SourceType == PackageBodyObjectType)
                                .OrderBy(p => p.LineNumber)
                                .Where(p => p.Text != null)
                                .Select(p => p.Text !);

                var body = bodyLines.Any()
                    ? Option <string> .Some(bodyLines.Join(string.Empty))
                    : Option <string> .None;

                var specification = OracleUnwrapper.Unwrap(spec);
                var packageBody   = body.Map(OracleUnwrapper.Unwrap);

                return(new OracleDatabasePackage(packageName, specification, packageBody));
            }
            else
            {
                var lines = await Connection.QueryAsync <PackageData>(
                    PackageDefinitionQuery,
                    new { SchemaName = packageName.Schema, PackageName = packageName.LocalName },
                    cancellationToken
                    ).ConfigureAwait(false);

                var spec = lines
                           .Where(p => p.SourceType == PackageObjectType)
                           .OrderBy(p => p.LineNumber)
                           .Where(p => p.Text != null)
                           .Select(p => p.Text !)
                           .Join(string.Empty);
                var bodyLines = lines
                                .Where(p => p.SourceType == PackageBodyObjectType)
                                .OrderBy(p => p.LineNumber)
                                .Where(p => p.Text != null)
                                .Select(p => p.Text !);

                var body = bodyLines.Any()
                    ? Option <string> .Some(bodyLines.Join(string.Empty))
                    : Option <string> .None;

                var specification = OracleUnwrapper.Unwrap(spec);
                var packageBody   = body.Map(OracleUnwrapper.Unwrap);

                return(new OracleDatabasePackage(packageName, specification, packageBody));
            }
        }