Exemplo n.º 1
0
        public void RemoveAttribute([NotNull] ObjectAttribute attribute)
        {
            ClearAttributeMaps();

            _attributes.Remove(attribute);
            attribute.Dataset = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AttributedAssociation"/> class.
        /// </summary>
        /// <param name="name">The association name.</param>
        /// <param name="cardinality">The cardinality of the association. Note this may also be 1:1 or 1:n,
        /// as these might also be defined as 'attributed'.</param>
        /// <param name="destinationForeignKeyName">Name of the destination foreign key.</param>
        /// <param name="destinationForeignKeyType">Type of the destination foreign key.</param>
        /// <param name="destinationPrimaryKey">The destination primary key.</param>
        /// <param name="originForeignKeyName">Name of the origin foreign key.</param>
        /// <param name="originForeignKeyType">Type of the origin foreign key.</param>
        /// <param name="originPrimaryKey">The origin primary key.</param>
        public AttributedAssociation([NotNull] string name,
                                     AssociationCardinality cardinality,
                                     [NotNull] string destinationForeignKeyName,
                                     FieldType destinationForeignKeyType,
                                     [NotNull] ObjectAttribute destinationPrimaryKey,
                                     [NotNull] string originForeignKeyName,
                                     FieldType originForeignKeyType,
                                     [NotNull] ObjectAttribute originPrimaryKey)
            : base(name, cardinality)
        {
            Assert.ArgumentNotNullOrEmpty(destinationForeignKeyName,
                                          nameof(destinationForeignKeyName));
            Assert.ArgumentNotNullOrEmpty(originForeignKeyName, nameof(originForeignKeyName));
            Assert.NotNullOrEmpty(destinationPrimaryKey.Name);
            Assert.NotNullOrEmpty(originPrimaryKey.Name);

            AssociationAttribute destinationForeignKey = AddAttribute(
                destinationForeignKeyName, destinationForeignKeyType);
            AssociationAttribute originForeignKey = AddAttribute(
                originForeignKeyName, originForeignKeyType);

            // TODO should be renamed to AttributedAssociationEnd! cardinality may also be 1:1 or 1:n
            DestinationEnd = new ManyToManyAssociationEnd(this, destinationForeignKey,
                                                          destinationPrimaryKey);
            OriginEnd = new ManyToManyAssociationEnd(this, originForeignKey,
                                                     originPrimaryKey);
        }
Exemplo n.º 3
0
        public void Redirect([NotNull] ObjectAttribute primaryKey)
        {
            Assert.ArgumentNotNull(primaryKey, nameof(primaryKey));

            _primaryKey = primaryKey;

            Redirect(primaryKey.Dataset);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManyToManyAssociationEnd"/> class.
        /// </summary>
        /// <param name="association">The association.</param>
        /// <param name="foreignKey">The foreign key.</param>
        /// <param name="primaryKey">The primary key.</param>
        public ManyToManyAssociationEnd([NotNull] AttributedAssociation association,
                                        [NotNull] AssociationAttribute foreignKey,
                                        [NotNull] ObjectAttribute primaryKey)
            : base(association, primaryKey.Dataset, false)
        {
            Assert.ArgumentNotNull(foreignKey, nameof(foreignKey));
            Assert.ArgumentNotNull(primaryKey, nameof(primaryKey));

            _foreignKey = foreignKey;
            _primaryKey = primaryKey;
        }
Exemplo n.º 5
0
        public ObjectSubtype AddObjectSubType([NotNull] string name,
                                              [NotNull] ObjectAttribute attribute,
                                              [CanBeNull] object attributeValue,
                                              VariantValueType valueType =
                                              VariantValueType.Null)
        {
            Assert.ArgumentNotNullOrEmpty(name, nameof(name));
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            ObjectSubtype objectSubtype = AddObjectSubType(name);

            objectSubtype.AddCriterion(attribute, attributeValue, valueType);

            return(objectSubtype);
        }
Exemplo n.º 6
0
        public bool RemoveCriterion([NotNull] ObjectAttribute attribute)
        {
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            foreach (ObjectSubtypeCriterion criteria in _criteria)
            {
                if (Equals(criteria.Attribute, attribute))
                {
                    _criteria.Remove(criteria);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ForeignKeyAssociation"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="cardinality">The association cardinality.</param>
        /// <param name="foreignKey">The foreign key (on destination table).</param>
        /// <param name="primaryKey">The primary key (on origin table).</param>
        public ForeignKeyAssociation([NotNull] string name,
                                     AssociationCardinality cardinality,
                                     [NotNull] ObjectAttribute foreignKey,
                                     [NotNull] ObjectAttribute primaryKey)
            : base(name, cardinality)
        {
            Assert.ArgumentNotNull(foreignKey, nameof(foreignKey));
            Assert.ArgumentNotNull(primaryKey, nameof(primaryKey));

            Assert.NotNullOrEmpty(foreignKey.Name, "fk name is null");
            Assert.NotNullOrEmpty(primaryKey.Name, "pk name is null");

            DestinationEnd = new ForeignKeyAssociationEnd(this, foreignKey);
            OriginEnd      = new PrimaryKeyAssociationEnd(this, primaryKey);
        }
Exemplo n.º 8
0
        public ObjectSubtype AddObjectSubType([NotNull] string name,
                                              [NotNull] string attributeName,
                                              [CanBeNull] object attributeValue,
                                              VariantValueType valueType =
                                              VariantValueType.Null)
        {
            Assert.ArgumentNotNullOrEmpty(name, nameof(name));
            Assert.ArgumentNotNullOrEmpty(attributeName, nameof(attributeName));

            ObjectAttribute attribute = ObjectDataset.GetAttribute(attributeName);

            Assert.NotNull(attribute, "attribute '{0}' not found in '{1}' ",
                           attributeName, ObjectDataset.Name);

            return(AddObjectSubType(name, attribute, attributeValue, valueType));
        }
Exemplo n.º 9
0
        public ObjectSubtypeCriterion AddCriterion([NotNull] string attributeName,
                                                   object attributeValue,
                                                   VariantValueType valueType =
                                                   VariantValueType.Null)
        {
            Assert.ArgumentNotNullOrEmpty(attributeName, nameof(attributeName));

            ObjectAttribute attribute =
                _objectType.ObjectDataset.GetAttribute(attributeName);

            Assert.NotNull(attribute, "Attribute {0} not found for {1}",
                           attributeName,
                           _objectType.ObjectDataset.Name);

            return(AddCriterion(attribute, attributeValue, valueType));
        }
Exemplo n.º 10
0
        public ObjectAttribute AddAttribute([NotNull] ObjectAttribute attribute)
        {
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            // validate attribute
            if (string.IsNullOrEmpty(attribute.Name))
            {
                throw new ArgumentException("Attribute has no name");
            }

            if (attribute.Dataset != null)
            {
                throw new ArgumentException("Attribute already assigned to dataset");
            }

            foreach (ObjectAttribute existingAttribute in _attributes)
            {
                if (string.Compare(existingAttribute.Name, attribute.Name,
                                   StringComparison.OrdinalIgnoreCase) == 0)
                {
                    throw new ArgumentException(
                              string.Format("Attribute with same name already exists: {0}",
                                            attribute.Name), nameof(attribute));
                }

                if (attribute.Role != null && existingAttribute.Role == attribute.Role)
                {
                    throw new ArgumentException(
                              string.Format(
                                  "Attribute with same role already exists: {0} role: {1}",
                                  existingAttribute.Name,
                                  Enum.GetName(typeof(AttributeRole), attribute.Role)),
                              nameof(attribute));
                }
            }

            ClearAttributeMaps();

            attribute.Dataset = this;

            _attributes.Add(attribute);

            _msg.DebugFormat("Added attribute {0}", attribute.Name);

            return(attribute);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectSubtypeCriterion"/> class.
        /// </summary>
        /// <param name="attribute">The attribute that the criterion is based on.</param>
        /// <param name="attributeValue">The attribute value.</param>
        /// <param name="valueType">Type of the value.</param>
        public ObjectSubtypeCriterion([NotNull] ObjectAttribute attribute,
                                      [CanBeNull] object attributeValue,
                                      VariantValueType valueType = VariantValueType.Null)
        {
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            _attribute = attribute;

            if (valueType == VariantValueType.Null)
            {
                // attributeValue = null; // "" can not be cast to numeric
                _attributeValue = VariantValueFactory.Create(attribute, attributeValue);
            }
            else
            {
                _attributeValue = new VariantValue(attributeValue, valueType);
            }
        }
Exemplo n.º 12
0
        public ObjectSubtypeCriterion AddCriterion([NotNull] ObjectAttribute attribute,
                                                   object attributeValue,
                                                   VariantValueType variantValueType =
                                                   VariantValueType.Null)
        {
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            var criterion = new ObjectSubtypeCriterion(attribute, attributeValue,
                                                       variantValueType);

            if (_criteria.Contains(criterion))
            {
                throw new ArgumentException(
                          string.Format(
                              "Criterion already exists in collection. Attribue={0}, Value={1}",
                              attribute.Name, attributeValue ?? "<null>"));
            }

            _criteria.Add(criterion);

            return(criterion);
        }
Exemplo n.º 13
0
 internal void AttributeChanged([NotNull] ObjectAttribute attribute)
 {
     ClearAttributeMaps();
 }
Exemplo n.º 14
0
        public void Redirect([NotNull] ObjectAttribute foreignKey)
        {
            _foreignKey = foreignKey;

            Redirect(foreignKey.Dataset);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ForeignKeyAssociationEnd"/> class.
 /// </summary>
 /// <param name="association">The association.</param>
 /// <param name="foreignKey">The foreign key.</param>
 public ForeignKeyAssociationEnd([NotNull] Association association,
                                 [NotNull] ObjectAttribute foreignKey)
     : base(association, foreignKey.Dataset, true)
 {
     _foreignKey = foreignKey;
 }
Exemplo n.º 16
0
        public bool ContainsCriterion([NotNull] ObjectAttribute attribute)
        {
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            return(_criteria.Any(criterion => Equals(criterion.Attribute, attribute)));
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrimaryKeyAssociationEnd"/> class.
 /// </summary>
 /// <param name="association">The association.</param>
 /// <param name="primaryKey">The primary key.</param>
 public PrimaryKeyAssociationEnd([NotNull] Association association,
                                 [NotNull] ObjectAttribute primaryKey)
     : base(association, primaryKey.Dataset, false)
 {
     _primaryKey = primaryKey;
 }