///<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];
            }
        }
예제 #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
        /// <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);
            }
        }
예제 #4
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);
            }
        }
        /// <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);
        }
        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);
            }
        }
 /// <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);
     }
 }