public ReflectionSynonym(IRelationalDatabase database, IDatabaseDialect dialect, Type synonymType)
        {
            if (database == null)
            {
                throw new ArgumentException(nameof(database));
            }
            if (dialect == null)
            {
                throw new ArgumentNullException(nameof(dialect));
            }
            if (synonymType == null)
            {
                throw new ArgumentNullException(nameof(synonymType));
            }

            Name = dialect.GetQualifiedNameOrDefault(database, synonymType);
            var targetType = GetBaseGenericTypeArg(synonymType);

            Target = dialect.GetQualifiedNameOrDefault(database, targetType);
        }
        public ReflectionSequence(IRelationalDatabase database, IDatabaseDialect dialect, Type sequenceType)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            if (dialect == null)
            {
                throw new ArgumentNullException(nameof(dialect));
            }
            if (sequenceType == null)
            {
                throw new ArgumentNullException(nameof(sequenceType));
            }

            var typeInfo = sequenceType.GetTypeInfo();

            if (!typeInfo.ImplementedInterfaces.Contains(ISequenceType))
            {
                throw new ArgumentException($"The sequence type { typeInfo.FullName } must implement the { ISequenceType.FullName } interface.", nameof(sequenceType));
            }
            var ctor = sequenceType.GetDefaultConstructor();

            if (ctor == null)
            {
                throw new ArgumentException($"The sequence type { typeInfo.FullName } does not contain a default constructor.", nameof(sequenceType));
            }

            var instance     = ctor.Invoke(Array.Empty <object>()) as ISequence;
            var sequenceName = dialect.GetQualifiedNameOrDefault(database, sequenceType);

            var minValue = instance !.MinValue.ToOption();
            var maxValue = instance !.MaxValue.ToOption();

            // create an inner sequence, which will perform validation
            var sequence = new DatabaseSequence(
                sequenceName,
                instance !.Start,
                instance !.Increment,
                minValue,
                maxValue,
                instance !.Cycle,
                instance !.Cache
                );

            Cache     = sequence.Cache;
            Cycle     = sequence.Cycle;
            Increment = sequence.Increment;
            MaxValue  = maxValue;
            MinValue  = minValue;
            Name      = sequenceName;
            Start     = sequence.Start;
        }
Beispiel #3
0
        public ReflectionView(IRelationalDatabase database, IDatabaseDialect dialect, Type viewType)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            if (dialect == null)
            {
                throw new ArgumentNullException(nameof(dialect));
            }

            ViewType = viewType ?? throw new ArgumentNullException(nameof(viewType));
            Name     = dialect.GetQualifiedNameOrDefault(database, ViewType);
        }
        public ReflectionRoutine(IRelationalDatabase database, IDatabaseDialect dialect, Type routineType)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            if (dialect == null)
            {
                throw new ArgumentNullException(nameof(dialect));
            }

            RoutineType = routineType ?? throw new ArgumentNullException(nameof(routineType));
            Name        = dialect.GetQualifiedNameOrDefault(database, RoutineType);
        }