예제 #1
0
        /// <summary>
        /// Gets the delete work units.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="et"></param>
        /// <param name="modifiedFields"></param>
        /// <returns></returns>
        public override IWorkUnit[] GetDeleteWorkUnits(object entity, EntityType et, EntityField[] modifiedFields)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (modifiedFields == null)
            {
                throw new ArgumentNullException("modifiedFields");
            }

            // create...
            WorkUnitCollection units = new WorkUnitCollection();

            if (FlatTableWorkUnit.DoesExtendedTableExist(et))
            {
                // Create a delete work unit for extended properties, we may not have any field changes
                // get all of the fields...
                EntityField[] keyFields = et.GetKeyFields();
                object[]      values    = et.Storage.GetValues(entity, keyFields);

                // add...
                units.Add(new FlatTableDeleteAllWorkUnit(et, entity, keyFields, values));
            }

            // return...
            return(units.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Gets the insert work units.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="et"></param>
        /// <param name="modifiedFields"></param>
        /// <returns></returns>
        public override IWorkUnit[] GetInsertWorkUnits(object entity, EntityType et, EntityField[] modifiedFields)
        {
            // results...
            WorkUnitCollection units = new WorkUnitCollection();

            // check...
            if (FlatTableWorkUnit.DoesExtendedTableExist(et))
            {
                // keys...
                EntityField[] keyFields = et.GetKeyFields();
                if (keyFields == null)
                {
                    throw new InvalidOperationException("keyFields is null.");
                }

                // create...
                foreach (EntityField field in modifiedFields)
                {
                    ArrayList unitFields = new ArrayList(keyFields);
                    unitFields.Add(field);

                    EntityField[] workUnitFields = (EntityField[])unitFields.ToArray(typeof(EntityField));
                    object[]      values         = et.Storage.GetValues(entity, workUnitFields);

                    // create...
                    units.Add(new FlatTableInsertWorkUnit(et, entity, workUnitFields, values));
                }
            }

            // return...
            return(units.ToArray());
        }
예제 #3
0
        /// <summary>
        /// Gets the work units to use with an update.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="et"></param>
        /// <param name="modifiedFields"></param>
        /// <returns></returns>
        public override IWorkUnit[] GetUpdateWorkUnits(object entity, EntityType et, EntityField[] modifiedFields)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (et == null)
            {
                throw new ArgumentNullException("et");
            }
            if (modifiedFields == null)
            {
                throw new ArgumentNullException("modifiedFields");
            }

            // key fields...
            EntityField[] keyFields = et.GetKeyFields();
            if (keyFields == null)
            {
                throw new InvalidOperationException("'keyFields' is null.");
            }
            if (keyFields.Length == 0)
            {
                throw new InvalidOperationException("'keyFields' is zero-length.");
            }

            // get...
            WorkUnitCollection units = new WorkUnitCollection();

            if (FlatTableWorkUnit.DoesExtendedTableExist(et))
            {
                // create...
                foreach (EntityField field in modifiedFields)
                {
                    // mbr - 17-03-2006 - check that we don't actually have null...  if we do, we actually need to delete the row...
                    if (et.Storage.IsDBNull(entity, field))
                    {
                        // add...
                        object[] keyValues = et.Storage.GetValues(entity, keyFields);
                        units.Add(new FlatTableDeleteOneWorkUnit(et, entity, keyFields, keyValues, field.NativeName.Name));;
                    }
                    else
                    {
                        ArrayList unitFields = new ArrayList(keyFields);
                        unitFields.Add(field);

                        EntityField[] workUnitFields = (EntityField[])unitFields.ToArray(typeof(EntityField));
                        object[]      values         = et.Storage.GetValues(entity, workUnitFields);

                        // create...
                        units.Add(new FlatTableUpdateWorkUnit(et, entity, workUnitFields, values));
                    }
                }
            }

            // return...
            return(units.ToArray());
        }