예제 #1
0
        private static int CompareConstraints(IConstraint lft, IConstraint rgt)
        {
            var nl = lft.Name;
            var nr = rgt.Name;

            if (lft.GetType() != rgt.GetType())
            {
                return(String.Compare(lft.GetType().FullName, rgt.GetType().FullName));
            }
            if (nl != null && nr != null)
            {
                return(String.Compare(nl, nr));
            }
            return(0);
        }
예제 #2
0
        private void Visit(IConstraint constraint)
        {
            var constrainType = constraint.GetType().Name;

            switch (constrainType)
            {
            case "QConClass":
                Visit(constraint as QConClass);
                break;

            case "QConObject":
                Visit(constraint as QConObject);
                break;

            case "QConJoin":
                Visit(constraint as QConJoin);
                break;

            case "QConPath":
                Visit(constraint as QConPath);
                break;

            default:
                throw new ArgumentException(constrainType);
            }
        }
예제 #3
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Adds a constraint to 'constraint'.
        /// </summary>
        /// <param name="property">
        ///  The property.
        /// </param>
        /// <param name="constraint">
        ///  The constraint.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        public void AddConstraint(ISchemaProperty property, IConstraint constraint)
        {
            var owner = property.Owner as ISchemaElement;

            if (owner == null)
            {
                return;
            }

            var interfaces = ReflectionHelper.GetInterfaces(constraint.GetType());

            var constraintElementType = interfaces.Where(i => ReflectionHelper.IsGenericType(i, typeof(IValidationValueObjectConstraint <>)))
                                        .Select(i => ReflectionHelper.GetGenericArguments(i).First())
                                        .FirstOrDefault();

            if (constraintElementType != null)
            {
                var category = ((IValidationValueObjectConstraint)constraint).Category;
                AddConstraint(owner, new CheckPropertyConstraintProxy(property, constraintElementType, constraint, ConstraintKind.Validate, category));
            }
            else
            {
                constraintElementType = interfaces.Where(i => ReflectionHelper.IsGenericType(i, typeof(ICheckValueObjectConstraint <>)))
                                        .Select(i => ReflectionHelper.GetGenericArguments(i).First())
                                        .FirstOrDefault();
                if (constraintElementType != null)
                {
                    AddConstraint(owner, new CheckPropertyConstraintProxy(property, constraintElementType, constraint, ConstraintKind.Check, null));
                }
                else
                {
                    throw new HyperstoreException("Invalid constraint type for property " + property.Name);
                }
            }
        }
예제 #4
0
        public InstanceRegistration(IConstraint constraint, ActionDescriptor actionDescriptor, ControllerDescriptor controllerDescriptor, FilterScope scope1)
            : base(actionDescriptor, controllerDescriptor, scope1)
        {
            if (constraint == null)
            {
                throw new ArgumentNullException("constraint", "Constraint instance can not be null.");
            }

            Constraint     = constraint;
            ConstraintType = Constraint.GetType();
        }
예제 #5
0
        public InstanceRegistration(IConstraint constraint, ActionDescriptor actionDescriptor, ControllerDescriptor controllerDescriptor, FilterScope scope1)
            : base(actionDescriptor, controllerDescriptor, scope1)
        {
            if (constraint == null)
            {
                throw new ArgumentNullException("constraint", "Constraint instance can not be null.");
            }

            Constraint = constraint;
            ConstraintType = Constraint.GetType();
        }
예제 #6
0
        private QConClass ClassConstraint()
        {
            if (i_constraints.Size() != 1)
            {
                return(null);
            }
            IConstraint constr = SingleConstraint();

            if (constr.GetType() != typeof(QConClass))
            {
                return(null);
            }
            return((QConClass)constr);
        }
예제 #7
0
 public static Constraint CreateCopy(IConstraint cnt)
 {
     if (cnt is IIndex)
     {
         return(new IndexConstraint((IIndex)cnt));
     }
     if (cnt is IPrimaryKey)
     {
         return(new PrimaryKey((IPrimaryKey)cnt));
     }
     if (cnt is IForeignKey)
     {
         return(new ForeignKey((IForeignKey)cnt));
     }
     if (cnt is IUnique)
     {
         return(new UniqueConstraint((IUnique)cnt));
     }
     if (cnt is ICheck)
     {
         return(new CheckConstraint((ICheck)cnt));
     }
     throw new InternalError("DAE-00036 Unknown constraint type:" + cnt.GetType().ToString());
 }
        private static ExtendedConstraint ExtendConstraint(IConstraint constraint, ReadOnlyCollection <DimensionWithValues> dimensionValues)
        {
            List <int> dimensionIndexes = GetDimensionIndexes(constraint, dimensionValues).ToList();

            if (dimensionIndexes.Count == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                  "Constraint {0} doesn't have any required dimensions.", constraint.GetType().Name));
            }
            ReadOnlyCollection <DimensionWithValues> dimensionValuesSubset = dimensionIndexes.Select(di => dimensionValues[di]).ToList().AsReadOnly();
            ExtendedConstraint ret = new ExtendedConstraint(dimensionIndexes, dimensionValues);

            foreach (ReadOnlyCollection <int> indexes in CombinatorialUtilities.GetAllIndexCombinations(dimensionValuesSubset.Select(dv => dv.Values.Count)))
            {
                Vector v = CombinatorialUtilities.ConstructVector(dimensionValuesSubset, indexes);
                if (constraint.IsValid(v))
                {
                    ret.AddNewValueCombinations(indexes);
                }
            }
            return(ret);
        }
        private static int GetIndexOfConstraintDimension(IConstraint constraint, ReadOnlyCollection <DimensionWithValues> dimensionValues,
                                                         QualifiedDimension dimension)
        {
            int ret = 0;

            foreach (DimensionWithValues dv in dimensionValues)
            {
                if (IsSubset(dimension, dv.Dimension))
                {
                    return(ret);
                }
                ret++;
            }
            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                              "Dimension {0} from constraint {1} was not found in the matrix (all dimensions: {2}).",
                                                              dimension.FullyQualifiedName, constraint.GetType().Name, string.Join(",", dimensionValues.Select(dv => dv.Dimension.FullyQualifiedName))));
        }
		private static ExtendedConstraint ExtendConstraint(IConstraint constraint, ReadOnlyCollection<DimensionWithValues> dimensionValues)
		{
			List<int> dimensionIndexes = GetDimensionIndexes(constraint, dimensionValues).ToList();
			if (dimensionIndexes.Count == 0)
			{
				throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
					"Constraint {0} doesn't have any required dimensions.", constraint.GetType().Name));
			}
			ReadOnlyCollection<DimensionWithValues> dimensionValuesSubset = dimensionIndexes.Select(di => dimensionValues[di]).ToList().AsReadOnly();
			ExtendedConstraint ret = new ExtendedConstraint(dimensionIndexes, dimensionValues);
			foreach (ReadOnlyCollection<int> indexes in CombinatorialUtilities.GetAllIndexCombinations(dimensionValuesSubset.Select(dv => dv.Values.Count)))
			{
				Vector v = CombinatorialUtilities.ConstructVector(dimensionValuesSubset, indexes);
				if (constraint.IsValid(v))
				{
					ret.AddNewValueCombinations(indexes);
				}
			}
			return ret;
		}
		private static int GetIndexOfConstraintDimension(IConstraint constraint, ReadOnlyCollection<DimensionWithValues> dimensionValues,
			QualifiedDimension dimension)
		{
			int ret = 0;
			foreach (DimensionWithValues dv in dimensionValues)
			{
				if (IsSubset(dimension, dv.Dimension))
				{
					return ret;
				}
				ret++;
			}
			throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
				"Dimension {0} from constraint {1} was not found in the matrix (all dimensions: {2}).",
				dimension.FullyQualifiedName, constraint.GetType().Name, string.Join(",", dimensionValues.Select(dv => dv.Dimension.FullyQualifiedName))));
		}
예제 #12
0
 public static bool EqualsConstraints(IConstraint csrc, IConstraint cdst, DbDiffOptions options, bool checkNames, DbObjectPairing pairing)
 {
     if (checkNames && !options.IgnoreConstraintNames)
     {
         if (!EqualNames(csrc.Name, cdst.Name, options))
         {
             if (csrc is IPrimaryKey && cdst is IPrimaryKey && (pairing.Source.Dialect.DialectCaps.AnonymousPrimaryKey || pairing.Target.Dialect.DialectCaps.AnonymousPrimaryKey))
             {
                 // do nothing
             }
             else
             {
                 return(false);
             }
         }
     }
     if (csrc.GetType() != cdst.GetType())
     {
         return(false);
     }
     if (csrc is ColumnsConstraint)
     {
         ITableStructure tsrc = pairing.Source.FindTable(csrc.Table.FullName);
         ITableStructure tdst = pairing.Target.FindTable(cdst.Table.FullName);
         if (!EqualsColumnRefs(tsrc, tdst, ((ColumnsConstraint)csrc).Columns, ((ColumnsConstraint)cdst).Columns))
         {
             return(false);
         }
         //if (!((ColumnsConstraint)csrc).Columns.EqualSequence(((ColumnsConstraint)cdst).Columns)) return false;
         if (csrc is ForeignKey)
         {
             var fsrc = (ForeignKey)csrc;
             var fdst = (ForeignKey)cdst;
             if (!EqualFullNames(fsrc.PrimaryKeyTable, fdst.PrimaryKeyTable, options))
             {
                 return(false);
             }
             ITableStructure psrc = pairing.Source.FindTable(fsrc.PrimaryKeyTable);
             ITableStructure pdst = pairing.Target.FindTable(fdst.PrimaryKeyTable);
             if (!EqualsColumnRefs(psrc, pdst, fsrc.PrimaryKeyColumns, fdst.PrimaryKeyColumns))
             {
                 return(false);
             }
             if (fsrc.OnDeleteAction != fdst.OnDeleteAction)
             {
                 return(false);
             }
             if (fsrc.OnUpdateAction != fdst.OnUpdateAction)
             {
                 return(false);
             }
         }
         if (csrc is IIndex)
         {
             var isrc = (IndexConstraint)csrc;
             var idst = (IndexConstraint)cdst;
             if (isrc.IsUnique != idst.IsUnique)
             {
                 return(false);
             }
         }
     }
     if (csrc is CheckConstraint)
     {
         if (((CheckConstraint)csrc).Expression != ((CheckConstraint)cdst).Expression)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #13
0
 public void ChangeConstraint(IConstraint csrc, IConstraint cdst)
 {
     PutCmd("/* RECREATE %i TO %i (%s) */", csrc.Name, cdst.Name, cdst.GetType().Name);
 }