示例#1
0
 /// <summary>
 /// Copies the properties from another collection into this one
 /// </summary>
 /// <param name="propCol">A collection of properties</param>
 public void Add(IBOPropCol propCol)
 {
     foreach (IBOProp prop in propCol.Values)
     {
         this.Add(prop);
     }
 }
示例#2
0
        /// <summary>
        /// Generates an "insert" sql statement for the properties in the
        /// business object
        /// </summary>
        /// <param name="propsToInclude">A collection of properties to insert,
        /// if the previous include-all boolean was not set to true</param>
        /// <param name="tableName">The table name</param>
        private void GenerateSingleInsertStatement(IBOPropCol propsToInclude, string tableName)
        {
            ISupportsAutoIncrementingField supportsAutoIncrementingField = null;

            if (_bo.Props.HasAutoIncrementingField)
            {
                supportsAutoIncrementingField = new SupportsAutoIncrementingFieldBO(_bo);
            }
            this.InitialiseStatement(tableName, supportsAutoIncrementingField);

            ModifyForInheritance(propsToInclude);

            foreach (BOProp prop in _bo.Props.SortedValues)
            {
                if (propsToInclude.Contains(prop.PropertyName))
                {
                    if (!prop.PropDef.AutoIncrementing)
                    {
                        AddPropToInsertStatement(prop);
                    }
                }
            }

            _insertSql.Statement.Append(String.Format(
                                            "INSERT INTO {0} ({1}) VALUES ({2})",
                                            _connection.SqlFormatter.DelimitTable(tableName),
                                            _dbFieldList, _dbValueList));
            _statements.Insert(0, _insertSql);
        }
示例#3
0
        public void TestCreateRelProp()
        {
            IBOPropCol propCol = _propDefCol.CreateBOPropertyCol(true);
            IRelProp   relProp = _relPropDef.CreateRelProp(propCol);

            Assert.AreEqual("Prop", relProp.OwnerPropertyName);
            Assert.AreEqual("PropName", relProp.RelatedClassPropName);
        }
示例#4
0
 /// <summary>
 /// Constructor to initialise a new relationship
 /// </summary>
 /// <param name="owningBo">The business object that owns the relationship</param>
 /// <param name="lRelDef">The relationship definition</param>
 /// <param name="lBOPropCol">The set of properties used to initialise the RelKey object</param>
 /// <param name="timeOut">The timeout between when the collection was last loaded.</param>
 public MultipleRelationship
     (IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol, int timeOut)
     : base(owningBo, lRelDef, lBOPropCol)
 {
     _boCol = new Lazy <RelatedBusinessObjectCollection <TBusinessObject> >(() =>
                                                                            (RelatedBusinessObjectCollection <TBusinessObject>)
                                                                            RelationshipUtils.CreateRelatedBusinessObjectCollection(_relDef.RelatedObjectAssemblyName, _relDef.RelatedObjectClassName, this));
     TimeOut = timeOut;
 }
示例#5
0
 /// <summary>
 /// Constructor to initialise a new instance. This initialises the RelKey and sets all its
 /// relationship properties (IRelProp).
 /// </summary>
 /// <param name="lRelKeyDef">The relationship key definition</param>
 /// <param name="lBoPropCol">The properties of the business object that this relationship key
 /// is being created form</param>
 public RelKey(IEnumerable <IRelPropDef> lRelKeyDef, IBOPropCol lBoPropCol)
 {
     _relProps = new Dictionary <string, IRelProp>();
     foreach (RelPropDef relPropDef in lRelKeyDef)
     {
         var relProp = relPropDef.CreateRelProp(lBoPropCol);
         relProp.PropValueUpdated += (sender, e) => FireRelatedPropValueChangedEvent();
         this.Add(relProp);
     }
 }
示例#6
0
        /// <summary>
        /// Create a new collection of relationships
        /// </summary>
        /// <param name="lBoPropCol">The collection of properties</param>
        /// <param name="bo">The business object that will manage these
        /// relationships</param>
        /// <returns>Returns the new collection created</returns>
        public RelationshipCol CreateRelationshipCol(IBOPropCol lBoPropCol, IBusinessObject bo)
        {
            RelationshipCol lRelationshipCol = new RelationshipCol(bo);

            foreach (RelationshipDef lRelationshipDef in this)
            {
                lRelationshipCol.Add(lRelationshipDef.CreateRelationship(bo, lBoPropCol));
            }
            return(lRelationshipCol);
        }
示例#7
0
        /// <summary>
        /// Creates a new collection of business object keys (BOKey)
        /// using the key definitions in this collection.
        /// </summary>
        /// <param name="lBOPropCol">The collection of properties</param>
        /// <returns>Returns a new BOKey collection object containing a mirror
        /// of this key definition collection</returns>
        public BOKeyCol CreateBOKeyCol(IBOPropCol lBOPropCol)
        {
            BOKeyCol lBOKeyCol = new BOKeyCol();

            foreach (IKeyDef lKeyDef in this)
            {
                lBOKeyCol.Add(lKeyDef.CreateBOKey(lBOPropCol));
            }
            return(lBOKeyCol);
        }
示例#8
0
        /// <summary>
        /// Creates a new business object key (BOKey) using this key
        /// definition and its property definitions
        /// </summary>
        /// <param name="lBOPropCol">The master property collection</param>
        /// <returns>Returns a new BOKey object that mirrors this
        /// key definition</returns>
        public virtual IBOKey CreateBOKey(IBOPropCol lBOPropCol)
        {
            BOKey lBOKey = new BOKey(this);

            foreach (IPropDef lPropDef in _propDefs.Values)
            {
                lBOKey.Add(lBOPropCol[lPropDef.PropertyName]);
            }
            return(lBOKey);
        }
示例#9
0
 /// <summary>
 /// Constructor to initialise a new instance. This initialises the RelKey and sets all its
 /// relationship properties (IRelProp).
 /// </summary>
 /// <param name="lRelKeyDef">The relationship key definition</param>
 /// <param name="lBoPropCol">The properties of the business object that this relationship key
 /// is being created form</param>
 public RelKey(IEnumerable<IRelPropDef> lRelKeyDef, IBOPropCol lBoPropCol)
 {
     _relProps = new Dictionary<string, IRelProp>();
     foreach (RelPropDef relPropDef in lRelKeyDef)
     {
         var relProp = relPropDef.CreateRelProp(lBoPropCol);
         relProp.PropValueUpdated += (sender, e) => FireRelatedPropValueChangedEvent();
         this.Add(relProp);
     }
 }
示例#10
0
        /// <summary>
        /// Creates a new business object key (BOKey) using this key
        /// definition and its property definitions. Creates either a new
        /// BOObjectID object (if the primary key is the object's ID)
        /// or a BOPrimaryKey object.
        /// </summary>
        /// <param name="lBOPropCol">The master property collection</param>
        /// <returns>Returns a new BOKey object that mirrors this
        /// key definition</returns>
        public override IBOKey CreateBOKey(IBOPropCol lBOPropCol)
        {
            BOPrimaryKey lBOKey = _isGuidObjectID ? new BOObjectID(this) : new BOPrimaryKey(this);

            foreach (PropDef lPropDef in this)
            {
                lBOKey.Add(lBOPropCol[lPropDef.PropertyName]);
            }
            return(lBOKey);
        }
 private static void AddPersistableProps(IBOPropCol propsToInclude, IBOPropCol propsToIncludeTemp)
 {
     foreach (BOProp prop in propsToIncludeTemp)
     {
         if (prop.PropDef.Persistable && prop.PropDef.ReadWriteRule != PropReadWriteRule.ReadOnly)
         {
             propsToInclude.Add(prop);
         }
     }
 }
 private static void AddPersistableProps(IBOPropCol propsToInclude, IBOPropCol propsToIncludeTemp)
 {
     foreach (BOProp prop in propsToIncludeTemp)
     {
         if (prop.PropDef.Persistable && prop.PropDef.ReadWriteRule != PropReadWriteRule.ReadOnly)
         {
             propsToInclude.Add(prop);
         }
     }
 }
        ///<summary>
        /// This constructor initialises this update log with the BusinessObject to be updated.
        /// This businessobject is then searched for the default UserLastUpdated and DateLastUpdated properties
        /// that are to be updated when the BusinessObject is updated.
        ///</summary>
        ///<param name="businessObject">The BusinessObject to be updated</param>
        public BusinessObjectLastUpdatePropertiesLog(IBusinessObject businessObject)
        {
            IBOPropCol boPropCol = businessObject.Props;
            string     propName  = "UserLastUpdated";

            if (boPropCol.Contains(propName))
            {
                _userLastUpdatedBoProp = boPropCol[propName];
            }
            propName = "DateLastUpdated";
            if (boPropCol.Contains(propName))
            {
                _dateLastUpdatedBoProp = boPropCol[propName];
            }
        }
示例#14
0
        public void TestCreateRelPropNotNull()
        {
            PropDef    propDef    = new PropDef("Prop1", typeof(string), PropReadWriteRule.ReadWrite, "1");
            RelPropDef relPropDef = new RelPropDef(propDef, "PropName1");
            PropDefCol propDefCol = new PropDefCol();

            propDefCol.Add(propDef);
            IBOPropCol propCol = propDefCol.CreateBOPropertyCol(true);
            IRelProp   relProp = relPropDef.CreateRelProp(propCol);

            Assert.AreEqual(relPropDef.OwnerPropertyName, relProp.OwnerPropertyName);
            Assert.AreEqual(relPropDef.RelatedClassPropName, relProp.RelatedClassPropName);

            Assert.IsFalse(relProp.IsNull);
        }
示例#15
0
        private void ModifyForInheritance(IBOPropCol propsToInclude)
        {
            //Recursively
            //Look at the superclass and if it is single table inheritance then
            // add the discriminator property to the BOPropCol if it doesnt exist
            // and set the value to the this super class' name

            ClassDef classDef = _currentClassDef; //rather than _bo.ClassDef\

            IBOPropCol discriminatorProps = new BOPropCol();

            AddDiscriminatorProperties(classDef, propsToInclude, discriminatorProps);
            foreach (BOProp boProp in discriminatorProps)
            {
                AddPropToInsertStatement(boProp);
            }
        }
        /// <summary>
        /// Builds a collection of properties to include in the insertion,
        /// depending on the inheritance type.
        /// </summary>
        protected virtual IBOPropCol GetPropsToInclude(IClassDef currentClassDef)
        {
            IBOPropCol propsToIncludeTemp = currentClassDef.PropDefcol.CreateBOPropertyCol(true);

            IBOPropCol propsToInclude = new BOPropCol();

            AddPersistableProps(propsToInclude, propsToIncludeTemp);

            while (((ClassDef)currentClassDef).IsUsingSingleTableInheritance() ||
                   ((ClassDef)currentClassDef).IsUsingConcreteTableInheritance())
            {
                var boPropertyCol = currentClassDef.SuperClassClassDef.PropDefcol.CreateBOPropertyCol(true);
                AddPersistableProps(propsToInclude, boPropertyCol);
                currentClassDef = currentClassDef.SuperClassClassDef;
            }

            return(propsToInclude);
        }
示例#17
0
 /// <summary>
 /// Constructor to initialise a new relationship
 /// </summary>
 /// <param name="owningBo">The business object from where the
 /// relationship originates</param>
 /// <param name="lRelDef">The relationship definition</param>
 /// <param name="lBOPropCol">The set of properties used to
 /// initialise the RelKey object</param>
 protected Relationship(IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol)
 {
     if (owningBo == null)
     {
         throw new ArgumentNullException("owningBo");
     }
     if (lRelDef == null)
     {
         throw new ArgumentNullException("lRelDef");
     }
     if (lBOPropCol == null)
     {
         throw new ArgumentNullException("lBOPropCol");
     }
     _relDef   = lRelDef;
     _owningBo = owningBo;
     _relKey   = new Lazy <IRelKey>(() => _relDef.RelKeyDef.CreateRelKey(lBOPropCol));
 }
示例#18
0
        /// <summary>
        /// Returns the ID as a Value.
        /// <li>"In cases where the <see cref="IBusinessObject"/> has an ID with a single
        ///    property this will return the value of the property.
        /// </li>
        /// <li>"In cases where the <see cref="IBusinessObject"/>  has an ccomposite ID
        ///    (i.e. with more than one property) this will return a list with the values of the properties.
        /// </li>
        /// </summary>
        /// <returns>Returns an object</returns>
        public object GetAsValue()
        {
            //If this is a non composite PrimaryKey then return the primaryKeyPropsValue
            //else return the concatenated PrimaryKey PropName:PropValue pairs for the
            //CompositePrimaryKey
            IBOPropCol boPropCol = this.GetBOPropCol();

            foreach (BOProp boProp in boPropCol)
            {
                //HACK: This is really wierd code the boPropCol does not have an int accessor.
                // there is therefore no way to get the first item in the col other than this.
                //This will return the value for a NonCompositePrimaryKey
                if (boPropCol.Count == 1)
                {
                    return(boProp.Value);
                }
            }
            return(this.AsString_CurrentValue());
        }
示例#19
0
        /// <summary>
        /// Determines which parent ID field to add to the insertion list, depending on which
        /// ID attribute was specified in the class definition.  There are four possibilities:
        ///    1) The child contains a foreign key to the parent, with the parent ID's name
        ///    2) No attribute was given, assumes the above.
        ///    3) The child's ID has a copy of the parent's ID value
        ///    4) The child has no ID and just inherits the parent's ID (still has the parent's
        ///        ID as a field in its own table)
        /// </summary>
        private void AddParentID(IBOPropCol propsToInclude)
        {
            IClassDef currentClassDef = _currentClassDef;

            while (currentClassDef.SuperClassClassDef != null &&
                   currentClassDef.SuperClassClassDef.PrimaryKeyDef == null)
            {
                currentClassDef = currentClassDef.SuperClassClassDef;
            }
            if (currentClassDef.SuperClassClassDef == null || currentClassDef.SuperClassClassDef.PrimaryKeyDef == null)
            {
                return;
            }

            var superClassDef           = (SuperClassDef)currentClassDef.SuperClassDef;
            var parentIDCopyFieldName   = superClassDef.ID;
            var superClassPrimaryKeyDef = (PrimaryKeyDef)currentClassDef.SuperClassClassDef.PrimaryKeyDef;

            if (string.IsNullOrEmpty(parentIDCopyFieldName) ||
                superClassPrimaryKeyDef.KeyName == parentIDCopyFieldName)
            {
                propsToInclude.Add(
                    superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol());
            }
            else if (parentIDCopyFieldName != currentClassDef.PrimaryKeyDef.KeyName)
            {
                if (superClassPrimaryKeyDef.Count > 1)
                {
                    throw new InvalidXmlDefinitionException("For a super class definition " +
                                                            "using class table inheritance, the ID attribute can only refer to a " +
                                                            "parent with a single primary key.  Leaving out the attribute will " +
                                                            "allow composite primary keys where the child's copies have the same " +
                                                            "field name as the parent.");
                }
                var parentProp = superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol()[superClassPrimaryKeyDef.KeyName];
                var profDef    = new PropDef(parentIDCopyFieldName, parentProp.PropertyType, PropReadWriteRule.ReadWrite, null);
                var newProp    = new BOProp(profDef)
                {
                    Value = parentProp.Value
                };
                propsToInclude.Add(newProp);
            }
        }
示例#20
0
        public void TestCreateRelKey()
        {
            IBOPropCol propCol = mPropDefCol.CreateBOPropertyCol(true);
            IRelKey    relKey  = mRelKeyDef.CreateRelKey(propCol);

            Assert.IsTrue(relKey.Contains("Prop"));
            Assert.IsTrue(relKey.Contains("Prop2"));
            IRelProp relProp = relKey["Prop"];

            Assert.AreEqual("Prop", relProp.OwnerPropertyName);
            Assert.AreEqual("PropName", relProp.RelatedClassPropName);
            relProp = relKey["Prop2"];
            Assert.AreEqual("Prop2", relProp.OwnerPropertyName);
            Assert.AreEqual("PropName2", relProp.RelatedClassPropName);

            Assert.IsTrue(relKey.HasRelatedObject(),
                          "This is true since the values for the properties should have defaulted to 1 each");

            Assert.AreEqual("(PropName = '1') AND (PropName2 = '2')", relKey.Criteria.ToString());
        }
示例#21
0
        /// <summary>
        /// Generates an "update" sql statement for the properties in the
        /// business object
        /// </summary>
        /// <param name="tableName">The table name</param>
        /// <param name="propsToInclude">A collection of properties to update,
        /// if the previous include-all boolean was not set to true</param>
        /// <param name="isSuperClassStatement">Whether a super-class is involved</param>
        /// <param name="currentClassDef">The current class definition</param>
        private void GenerateSingleUpdateStatement(string tableName, IBOPropCol propsToInclude,
                                                   bool isSuperClassStatement, ClassDef currentClassDef)
        {
            _updateSql = new SqlStatement(_connection);
            _updateSql.Statement.Append(
                @"UPDATE " + _connection.SqlFormatter.DelimitTable(tableName) + " SET ");
            int includedProps = 0;

            foreach (BOProp prop in _bo.Props.SortedValues)
            {
                if (propsToInclude.Contains(prop.PropertyName))
                {
                    PrimaryKeyDef primaryKeyDef = (PrimaryKeyDef)_bo.ClassDef.PrimaryKeyDef ?? (PrimaryKeyDef)_bo.ID.KeyDef;
                    if (prop.IsDirty &&
                        ((primaryKeyDef.IsGuidObjectID && !primaryKeyDef.Contains(prop.PropertyName)) ||
                         !primaryKeyDef.IsGuidObjectID))
                    {
                        includedProps++;
                        _updateSql.Statement.Append(_connection.SqlFormatter.DelimitField(prop.DatabaseFieldName));
                        _updateSql.Statement.Append(" = ");
                        //prop.PropDef.GetDataMapper().GetDatabaseValue(prop.Value);
                        _updateSql.AddParameterToStatement(prop.Value);
                        _updateSql.Statement.Append(", ");
                    }
                }
            }
            _updateSql.Statement.Remove(_updateSql.Statement.Length - 2, 2); //remove the last ", "
            if (isSuperClassStatement)
            {
                _updateSql.Statement.Append(" WHERE " + StatementGeneratorUtils.PersistedDatabaseWhereClause(BOPrimaryKey.GetSuperClassKey(currentClassDef, _bo), _updateSql));
            }
            else
            {
                _updateSql.Statement.Append(" WHERE " + StatementGeneratorUtils.PersistedDatabaseWhereClause((BOKey)_bo.ID, _updateSql));
            }
            if (includedProps > 0)
            {
                _statements.Add(_updateSql);
            }
        }
示例#22
0
        private void AddDiscriminatorProperties(ClassDef classDef, IBOPropCol propsToInclude, IBOPropCol discriminatorProps)
        {
            ClassDef classDefWithSTI = null;

            if (classDef.IsUsingSingleTableInheritance() || classDefWithSTI != null)
            {
                string discriminator = null;
                if (classDef.SuperClassDef != null)
                {
                    discriminator = classDef.SuperClassDef.Discriminator;
                }
                else if (classDefWithSTI != null)
                {
                    discriminator = classDefWithSTI.SuperClassDef.Discriminator;
                }
                if (discriminator == null)
                {
                    throw new InvalidXmlDefinitionException("A super class has been defined " +
                                                            "using Single Table Inheritance, but no discriminator column has been set.");
                }
                if (propsToInclude.Contains(discriminator) && _bo.Props.Contains(discriminator))
                {
                    var boProp = _bo.Props[discriminator];
                    boProp.Value = _bo.ClassDef.ClassName;
                }
                else if (!discriminatorProps.Contains(discriminator))
                {
                    var propDef           = new PropDef(discriminator, typeof(string), PropReadWriteRule.ReadWrite, null);
                    var discriminatorProp = new BOProp(propDef, _bo.ClassDef.ClassName);
                    discriminatorProps.Add(discriminatorProp);
                }
            }

            if (classDef.IsUsingSingleTableInheritance())
            {
                IClassDef superClassClassDef = classDef.SuperClassClassDef;
                AddDiscriminatorProperties((ClassDef)superClassClassDef, propsToInclude, discriminatorProps);
            }
        }
示例#23
0
 /// <summary>
 /// Constructor to initialise a new relationship
 /// </summary>
 /// <param name="owningBo">The business object that owns the
 /// relationship</param>
 /// <param name="lRelDef">The relationship definition</param>
 /// <param name="lBOPropCol">The set of properties used to
 /// initialise the RelKey object</param>
 public MultipleRelationship(IBusinessObject owningBo, RelationshipDef lRelDef, IBOPropCol lBOPropCol)
     : this(owningBo, lRelDef, lBOPropCol, 0)
 {
 }
示例#24
0
        /// <summary>
        /// Create a relationship key based on this key definition and
        /// its associated property definitions
        /// </summary>
        /// <param name="lBoPropCol">The collection of properties</param>
        /// <returns>Returns the new RelKey object</returns>
        public IRelKey CreateRelKey(IBOPropCol lBoPropCol)
        {
            RelKey lRelKey = new RelKey(this, lBoPropCol);

            return(lRelKey);
        }
示例#25
0
        /// <summary>
        /// Overrides abstract method of parent to facilitate creation of
        /// a new Multiple Relationship
        /// </summary>
        /// <param name="owningBo">The business object that will manage
        /// this relationship</param>
        /// <param name="lBOPropCol">The collection of properties</param>
        /// <returns>Returns the new relationship that has been created</returns>
        public override IRelationship CreateRelationship(IBusinessObject owningBo, IBOPropCol lBOPropCol)
        {
            var relationshipBOType = typeof(MultipleRelationship <>).MakeGenericType(this.RelatedObjectClassType);

            return((IMultipleRelationship)Activator.CreateInstance(relationshipBOType, owningBo, this, lBOPropCol, this.TimeOut));
        }
示例#26
0
		/// <summary>
		/// Constructor to initialise a new relationship
		/// </summary>
		/// <param name="owningBo">The business object from where the 
		/// relationship originates</param>
		/// <param name="lRelDef">The relationship definition</param>
		/// <param name="lBOPropCol">The set of properties used to
		/// initialise the RelKey object</param>
		protected Relationship(IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol)
		{
			if (owningBo == null) throw new ArgumentNullException("owningBo");
			if (lRelDef == null) throw new ArgumentNullException("lRelDef");
			if (lBOPropCol == null) throw new ArgumentNullException("lBOPropCol");
			_relDef = lRelDef;
			_owningBo = owningBo;
			_relKey = new Lazy<IRelKey>(() => _relDef.RelKeyDef.CreateRelKey(lBOPropCol));
		}
示例#27
0
 public override IRelationship CreateRelationship(IBusinessObject owningBo, IBOPropCol lBOPropCol)
 {
     return(null);
 }
示例#28
0
 /// <summary>
 /// Constrcutor for <see cref="MultipleRelationshipBase"/>
 /// </summary>
 /// <param name="owningBo">The <see cref="IBusinessObject"/> that owns this BO.</param>
 /// <param name="lRelDef">The <see cref="IRelationshipDef"/> that identifies  </param>
 /// <param name="lBOPropCol"></param>
 protected MultipleRelationshipBase(IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol)
     : base(owningBo, lRelDef, lBOPropCol)
 {
 }
示例#29
0
 /// <summary>
 /// Constructor to initialise a new relationship
 /// </summary>
 /// <param name="owningBo">The business object that owns the
 /// relationship</param>
 /// <param name="lRelDef">The relationship definition</param>
 /// <param name="lBOPropCol">The set of properties used to
 /// initialise the RelKey object</param>
 public SingleRelationship(IBusinessObject owningBo, IRelationshipDef lRelDef, IBOPropCol lBOPropCol)
     : base(owningBo, lRelDef, lBOPropCol)
 {
     this.RelKey.RelatedPropValueChanged += (sender, e) => FireRelatedBusinessObjectChangedEvent();
 }
示例#30
0
 /// <summary>
 /// Create and return a new Relationship based on the relationship definition.
 /// </summary>
 /// <param name="owningBo">The business object that owns
 /// this relationship e.g. The department</param>
 /// <param name="lBOPropCol">The collection of properties of the Business object</param>
 /// <returns>The new relationship object created</returns>
 public abstract IRelationship CreateRelationship(IBusinessObject owningBo, IBOPropCol lBOPropCol);
        /// <summary>
        /// Determines which parent ID field to add to the insertion list, depending on which
        /// ID attribute was specified in the class definition.  There are four possibilities:
        ///    1) The child contains a foreign key to the parent, with the parent ID's name
        ///    2) No attribute was given, assumes the above.
        ///    3) The child's ID has a copy of the parent's ID value
        ///    4) The child has no ID and just inherits the parent's ID (still has the parent's
        ///        ID as a field in its own table)
        /// </summary>
        private void AddParentID(IBOPropCol propsToInclude)
        {
            IClassDef currentClassDef = _currentClassDef;
            while (currentClassDef.SuperClassClassDef != null &&
                   currentClassDef.SuperClassClassDef.PrimaryKeyDef == null)
            {
                currentClassDef = currentClassDef.SuperClassClassDef;
            }
            if (currentClassDef.SuperClassClassDef ==  null ||currentClassDef.SuperClassClassDef.PrimaryKeyDef == null) return;

            var superClassDef = (SuperClassDef) currentClassDef.SuperClassDef;
            var parentIDCopyFieldName = superClassDef.ID;
            var superClassPrimaryKeyDef = (PrimaryKeyDef) currentClassDef.SuperClassClassDef.PrimaryKeyDef;
            if (string.IsNullOrEmpty(parentIDCopyFieldName) ||
                superClassPrimaryKeyDef.KeyName == parentIDCopyFieldName)
            {
                propsToInclude.Add(
                    superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol());
            }
            else if (parentIDCopyFieldName != currentClassDef.PrimaryKeyDef.KeyName)
            {
                if (superClassPrimaryKeyDef.Count > 1)
                {
                    throw new InvalidXmlDefinitionException("For a super class definition " +
                                                            "using class table inheritance, the ID attribute can only refer to a " +
                                                            "parent with a single primary key.  Leaving out the attribute will " +
                                                            "allow composite primary keys where the child's copies have the same " +
                                                            "field name as the parent.");
                }
                var parentProp = superClassPrimaryKeyDef.CreateBOKey(_bo.Props).GetBOPropCol()[superClassPrimaryKeyDef.KeyName];
                var profDef = new PropDef(parentIDCopyFieldName, parentProp.PropertyType, PropReadWriteRule.ReadWrite, null);
                var newProp = new BOProp(profDef) {Value = parentProp.Value};
                propsToInclude.Add(newProp);
            }
        }
示例#32
0
		/// <summary>
        /// Creates a new business object key (BOKey) using this key
        /// definition and its property definitions. Creates either a new
        /// BOObjectID object (if the primary key is the object's ID) 
        /// or a BOPrimaryKey object.
        /// </summary>
        /// <param name="lBOPropCol">The master property collection</param>
        /// <returns>Returns a new BOKey object that mirrors this
        /// key definition</returns>
        public override IBOKey CreateBOKey(IBOPropCol lBOPropCol)
        {
            BOPrimaryKey lBOKey = _isGuidObjectID ? new BOObjectID(this) : new BOPrimaryKey(this);
            foreach (PropDef lPropDef in this)
            {
                lBOKey.Add(lBOPropCol[lPropDef.PropertyName]);
            }
            return lBOKey;
        }
示例#33
0
 public override IRelationship CreateRelationship(IBusinessObject owningBo, IBOPropCol lBOPropCol)
 {
     return null;
 }
示例#34
0
        /// <summary>
        /// Creates a new RelProp object based on this property definition
        /// </summary>
        /// <param name="boPropCol">The collection of properties</param>
        /// <returns>The newly created RelProp object</returns>
        protected internal IRelProp CreateRelProp(IBOPropCol boPropCol)
		{
		    IBOProp boProp = boPropCol[OwnerPropertyName];
		    return new RelProp(this, boProp);
		}
        private void ModifyForInheritance(IBOPropCol propsToInclude)
        {
            //Recursively
            //Look at the superclass and if it is single table inheritance then 
            // add the discriminator property to the BOPropCol if it doesnt exist 
            // and set the value to the this super class' name

            ClassDef classDef = _currentClassDef; //rather than _bo.ClassDef\

            IBOPropCol discriminatorProps = new BOPropCol();
            AddDiscriminatorProperties(classDef, propsToInclude, discriminatorProps);
            foreach (BOProp boProp in discriminatorProps)
            {
                AddPropToInsertStatement(boProp);
            }
        }
示例#36
0
        /// <summary>
        /// Creates a new RelProp object based on this property definition
        /// </summary>
        /// <param name="boPropCol">The collection of properties</param>
        /// <returns>The newly created RelProp object</returns>
        protected internal IRelProp CreateRelProp(IBOPropCol boPropCol)
        {
            IBOProp boProp = boPropCol[OwnerPropertyName];

            return(new RelProp(this, boProp));
        }
示例#37
0
 /// <summary>
 /// Overrides abstract method of RelationshipDef to create a new
 /// relationship
 /// </summary>
 /// <param name="owningBo">The business object that will manage
 /// this relationship</param>
 /// <param name="lBOPropCol">The collection of properties</param>
 /// <returns></returns>
 public override IRelationship CreateRelationship(IBusinessObject owningBo, IBOPropCol lBOPropCol)
 {
     Type relationshipBOType = typeof (SingleRelationship<>).MakeGenericType(this.RelatedObjectClassType);
     return (ISingleRelationship) Activator.CreateInstance(relationshipBOType, owningBo, this, lBOPropCol);
 }
示例#38
0
 /// <summary>
 /// Create a new collection of relationships
 /// </summary>
 /// <param name="lBoPropCol">The collection of properties</param>
 /// <param name="bo">The business object that will manage these
 /// relationships</param>
 /// <returns>Returns the new collection created</returns>
 public RelationshipCol CreateRelationshipCol(IBOPropCol lBoPropCol, IBusinessObject bo)
 {
     RelationshipCol lRelationshipCol = new RelationshipCol(bo);
     foreach (RelationshipDef lRelationshipDef in this)
     {
         lRelationshipCol.Add(lRelationshipDef.CreateRelationship(bo, lBoPropCol));
     }
     return lRelationshipCol;
 }
示例#39
0
 /// <summary>
 /// Create a relationship key based on this key definition and
 /// its associated property definitions
 /// </summary>
 /// <param name="lBoPropCol">The collection of properties</param>
 /// <returns>Returns the new RelKey object</returns>
 public IRelKey CreateRelKey(IBOPropCol lBoPropCol)
 {
     RelKey lRelKey = new RelKey(this, lBoPropCol);
     return lRelKey;
 }
 /// <summary>
 /// Generates an "update" sql statement for the properties in the
 /// business object
 /// </summary>
 /// <param name="tableName">The table name</param>
 /// <param name="propsToInclude">A collection of properties to update,
 /// if the previous include-all boolean was not set to true</param>
 /// <param name="isSuperClassStatement">Whether a super-class is involved</param>
 /// <param name="currentClassDef">The current class definition</param>
 private void GenerateSingleUpdateStatement(string tableName, IBOPropCol propsToInclude,
                                            bool isSuperClassStatement, ClassDef currentClassDef)
 {
     _updateSql = new SqlStatement(_connection);
     _updateSql.Statement.Append(
         @"UPDATE " + _connection.SqlFormatter.DelimitTable(tableName) + " SET ");
     int includedProps = 0;
     foreach (BOProp prop in _bo.Props.SortedValues)
     {
         if (propsToInclude.Contains(prop.PropertyName))
         {
             PrimaryKeyDef primaryKeyDef = (PrimaryKeyDef)_bo.ClassDef.PrimaryKeyDef ?? (PrimaryKeyDef)_bo.ID.KeyDef;
             if (prop.IsDirty &&
                 ((primaryKeyDef.IsGuidObjectID && !primaryKeyDef.Contains(prop.PropertyName)) ||
                  !primaryKeyDef.IsGuidObjectID))
             {
                 includedProps++;
                 _updateSql.Statement.Append(_connection.SqlFormatter.DelimitField(prop.DatabaseFieldName));
                 _updateSql.Statement.Append(" = ");
                 //prop.PropDef.GetDataMapper().GetDatabaseValue(prop.Value);
                 _updateSql.AddParameterToStatement(prop.Value);
                 _updateSql.Statement.Append(", ");
             }
         }
     }
     _updateSql.Statement.Remove(_updateSql.Statement.Length - 2, 2); //remove the last ", "
     if (isSuperClassStatement)
     {
         _updateSql.Statement.Append(" WHERE " + StatementGeneratorUtils.PersistedDatabaseWhereClause(BOPrimaryKey.GetSuperClassKey(currentClassDef, _bo), _updateSql));
     }
     else
     {
         _updateSql.Statement.Append(" WHERE " + StatementGeneratorUtils.PersistedDatabaseWhereClause((BOKey) _bo.ID, _updateSql));
     }
     if (includedProps > 0)
     {
         _statements.Add(_updateSql);
     }
 }
        private void AddDiscriminatorProperties(ClassDef classDef, IBOPropCol propsToInclude, IBOPropCol discriminatorProps)
        {
            ClassDef classDefWithSTI = null;
            if (classDef.IsUsingSingleTableInheritance() || classDefWithSTI != null)
            {
                string discriminator = null;
                if (classDef.SuperClassDef != null)
                {
                    discriminator = classDef.SuperClassDef.Discriminator;
                }
                else if (classDefWithSTI != null)
                {
                    discriminator = classDefWithSTI.SuperClassDef.Discriminator;
                }
                if (discriminator == null)
                {
                    throw new InvalidXmlDefinitionException("A super class has been defined " +
                                                            "using Single Table Inheritance, but no discriminator column has been set.");
                }
                if (propsToInclude.Contains(discriminator) && _bo.Props.Contains(discriminator))
                {
                    var boProp = _bo.Props[discriminator];
                    boProp.Value = _bo.ClassDef.ClassName;
                }
                else if (!discriminatorProps.Contains(discriminator))
                {
                    var propDef = new PropDef(discriminator, typeof (string), PropReadWriteRule.ReadWrite, null);
                    var discriminatorProp = new BOProp(propDef, _bo.ClassDef.ClassName);
                    discriminatorProps.Add(discriminatorProp);
                }
            }

            if (classDef.IsUsingSingleTableInheritance())
            {
                IClassDef superClassClassDef = classDef.SuperClassClassDef;
                AddDiscriminatorProperties((ClassDef) superClassClassDef, propsToInclude, discriminatorProps);
            }
        }
示例#42
0
 /// <summary>
 /// Creates a new business object key (BOKey) using this key
 /// definition and its property definitions
 /// </summary>
 /// <param name="lBOPropCol">The master property collection</param>
 /// <returns>Returns a new BOKey object that mirrors this
 /// key definition</returns>
 public virtual IBOKey CreateBOKey(IBOPropCol lBOPropCol)
 {
     BOKey lBOKey = new BOKey(this);
     foreach (IPropDef lPropDef in _propDefs.Values)
     {
         lBOKey.Add(lBOPropCol[lPropDef.PropertyName]);
     }
     return lBOKey;
 }
        /// <summary>
        /// Generates an "insert" sql statement for the properties in the
        /// business object
        /// </summary>
        /// <param name="propsToInclude">A collection of properties to insert,
        /// if the previous include-all boolean was not set to true</param>
        /// <param name="tableName">The table name</param>
        private void GenerateSingleInsertStatement(IBOPropCol propsToInclude, string tableName)
        {
            ISupportsAutoIncrementingField supportsAutoIncrementingField = null;
            if (_bo.Props.HasAutoIncrementingField)
            {
                supportsAutoIncrementingField = new SupportsAutoIncrementingFieldBO(_bo);
            }
            this.InitialiseStatement(tableName, supportsAutoIncrementingField);

            ModifyForInheritance(propsToInclude);

            foreach (BOProp prop in _bo.Props.SortedValues)
            {
                if (propsToInclude.Contains(prop.PropertyName))
                {
                    if (!prop.PropDef.AutoIncrementing) 
                        AddPropToInsertStatement(prop);
                }
            }

            _insertSql.Statement.Append(String.Format(
                                            "INSERT INTO {0} ({1}) VALUES ({2})",
                                            _connection.SqlFormatter.DelimitTable(tableName),
                                            _dbFieldList, _dbValueList));
            _statements.Insert(0, _insertSql);
        }
示例#44
0
 /// <summary>
 /// Create and return a new Relationship based on the relationship definition.
 /// </summary>
 /// <param name="owningBo">The business object that owns
 /// this relationship e.g. The department</param>
 /// <param name="lBOPropCol">The collection of properties of the Business object</param>
 /// <returns>The new relationship object created</returns>
 public abstract IRelationship CreateRelationship(IBusinessObject owningBo, IBOPropCol lBOPropCol);