Ejemplo n.º 1
0
        private void ProcessObjectForUpdate(object objectToUpdate, Type objectType, object originalValues, Queue <SqlCommand> commandQueue)
        {
            if (PersistenceHelper.ArePersistentPropertiesEqual(objectToUpdate, originalValues) == false)
            {
                PersistentClass persistentClassAttribute = (PersistentClass)objectType.GetCustomAttributes(typeof(PersistentClass), false).Single();

                PropertyInfo   keyProperty       = objectType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
                PropertyBridge keyPropertyBridge = PropertyBridgeFactory.GetPropertyBridge(keyProperty, objectToUpdate);

                if (persistentClassAttribute.HasPersistentBaseClass == true)
                {
                    Type rootType = PersistenceHelper.GetRootType(objectToUpdate);
                    List <PropertyBridge> basePropertyBridgeList = this.GetPropertyBridgeList(rootType, objectToUpdate, originalValues);
                    if (basePropertyBridgeList.Count != 0)
                    {
                        commandQueue.Enqueue(this.CreateSqlCommand(keyPropertyBridge, basePropertyBridgeList, persistentClassAttribute.BaseStorageName));
                    }
                }

                if (persistentClassAttribute.IsPersisted == true)
                {
                    List <PropertyBridge> propertyBridgeList = this.GetPropertyBridgeList(objectType, objectToUpdate, originalValues);
                    if (propertyBridgeList.Count != 0)
                    {
                        commandQueue.Enqueue(this.CreateSqlCommand(keyPropertyBridge, propertyBridgeList, persistentClassAttribute.StorageName));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ProcessObjectForDelete(object objectToDelete, Type objectType, Stack <SqlCommand> deleteFirstCommands, Stack <SqlCommand> deleteCommands)
        {
            PersistentClass persistentClassAttribute = (PersistentClass)objectType.GetCustomAttributes(typeof(PersistentClass), false).Single();
            PropertyInfo    keyProperty       = objectType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
            PropertyBridge  keyPropertyBridge = PropertyBridgeFactory.GetPropertyBridge(keyProperty, objectToDelete);

            if (persistentClassAttribute.IsPersisted == true)
            {
                if (persistentClassAttribute.IsManyToManyRelationship == true)
                {
                    deleteFirstCommands.Push(this.CreateSqlCommand(keyPropertyBridge, persistentClassAttribute.StorageName));
                }
                else
                {
                    deleteCommands.Push(this.CreateSqlCommand(keyPropertyBridge, persistentClassAttribute.StorageName));
                }
            }

            if (persistentClassAttribute.HasPersistentBaseClass == true)
            {
                if (persistentClassAttribute.IsManyToManyRelationship == true)
                {
                    deleteFirstCommands.Push(this.CreateSqlCommand(keyPropertyBridge, persistentClassAttribute.BaseStorageName));
                }
                else
                {
                    deleteCommands.Push(this.CreateSqlCommand(keyPropertyBridge, persistentClassAttribute.BaseStorageName));
                }
            }
        }
Ejemplo n.º 3
0
        private List <PropertyBridge> GetPropertyBridgeList(Type type, object objectToUpdate, object originalValues)
        {
            List <PropertyBridge> propertyBridgeList = new List <PropertyBridge>();
            List <PropertyInfo>   properties         = PersistenceHelper.GetPropertiesToHandle(type);

            foreach (PropertyInfo property in properties)
            {
                var originalValue = property.GetValue(originalValues, null);
                var currentValue  = property.GetValue(objectToUpdate, null);

                if (currentValue == null && originalValue != null)
                {
                    PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, objectToUpdate);
                    propertyBridgeList.Add(propertyBridge);
                }
                if (currentValue != null && originalValue == null)
                {
                    PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, objectToUpdate);
                    propertyBridgeList.Add(propertyBridge);
                }
                else if (currentValue != null && originalValue != null)
                {
                    if (currentValue.Equals(originalValue) == false)
                    {
                        PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, objectToUpdate);
                        propertyBridgeList.Add(propertyBridge);
                    }
                }
            }

            return(propertyBridgeList);
        }
Ejemplo n.º 4
0
        private List <PropertyBridge> GetPropertyBridgeList(Type type, object o)
        {
            List <PropertyBridge> propertyBridgeList = new List <PropertyBridge>();
            List <PropertyInfo>   properties         = PersistenceHelper.GetPropertiesToHandle(type);

            foreach (PropertyInfo property in properties)
            {
                var currentValue = property.GetValue(o, null);
                if (currentValue != null)
                {
                    PropertyBridge propertyBridge = PropertyBridgeFactory.GetPropertyBridge(property, o);
                    propertyBridgeList.Add(propertyBridge);
                }
            }

            return(propertyBridgeList);
        }
Ejemplo n.º 5
0
        private void ProcessObjectForInsert(object objectToInsert, Type objectType, Queue <SqlCommand> insertCommands, Queue <SqlCommand> insertLastCommands)
        {
            PersistentClass persistentClassAttribute = (PersistentClass)objectType.GetCustomAttributes(typeof(PersistentClass), false).Single();
            PropertyInfo    keyProperty = objectType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
            PersistentPrimaryKeyProperty keyAttribute = (PersistentPrimaryKeyProperty)keyProperty.GetCustomAttributes(typeof(PersistentPrimaryKeyProperty), false).Single();
            PropertyBridge keyPropertyBridge          = PropertyBridgeFactory.GetPropertyBridge(keyProperty, objectToInsert);
            string         keyPropertyValue           = (string)keyPropertyBridge.GetPropertyValue();

            if (this.m_InsertSubclassOnly == false)
            {
                if (persistentClassAttribute.HasPersistentBaseClass == true)
                {
                    Type rootType = PersistenceHelper.GetRootType(objectToInsert);
                    List <PropertyBridge> basePropertyBridgeList = this.GetPropertyBridgeList(rootType, objectToInsert);
                    if (persistentClassAttribute.IsManyToManyRelationship == true)
                    {
                        SqlCommand sqlCommand = this.CreateSqlCommand(keyPropertyBridge, basePropertyBridgeList, persistentClassAttribute.BaseStorageName, keyAttribute.IsAutoGenerated);
                        insertLastCommands.Enqueue(sqlCommand);
                    }
                    else
                    {
                        SqlCommand sqlCommand = this.CreateSqlCommand(keyPropertyBridge, basePropertyBridgeList, persistentClassAttribute.BaseStorageName, keyAttribute.IsAutoGenerated);
                        insertCommands.Enqueue(sqlCommand);
                    }
                }
            }

            if (persistentClassAttribute.IsPersisted == true)
            {
                List <PropertyBridge> propertyBridgeList = this.GetPropertyBridgeList(objectType, objectToInsert);
                if (persistentClassAttribute.IsManyToManyRelationship == true)
                {
                    SqlCommand sqlCommandToAdd = this.CreateSqlCommand(keyPropertyBridge, propertyBridgeList, persistentClassAttribute.StorageName, keyAttribute.IsAutoGenerated);
                    insertLastCommands.Enqueue(sqlCommandToAdd);
                }
                else
                {
                    SqlCommand sqlCommand = this.CreateSqlCommand(keyPropertyBridge, propertyBridgeList, persistentClassAttribute.StorageName, keyAttribute.IsAutoGenerated);
                    insertCommands.Enqueue(sqlCommand);
                }
            }
        }