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)); } } }
public void Build(object parentObject, Stack<SqlCommand> deleteFirstCommands, Stack<SqlCommand> deleteCommands) { Type objectType = parentObject.GetType(); this.ProcessObjectForDelete(parentObject, objectType, deleteFirstCommands, deleteCommands); this.HandlePersistentChildCollections(parentObject, objectType, deleteFirstCommands, deleteCommands); this.HandlePersistentChildren(parentObject, objectType, deleteFirstCommands, deleteCommands); }
private void HandlePersistentChildren(object objectToInsert, Type objectType, Stack<SqlCommand> deleteFirstCommands, Stack<SqlCommand> deleteCommands) { List<PropertyInfo> childProperties = objectType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentChild))).ToList(); foreach (PropertyInfo propertyInfo in childProperties) { object childObject = propertyInfo.GetValue(objectToInsert, null); if (childObject != null) { this.ProcessObjectForDelete(childObject, childObject.GetType(), deleteFirstCommands, deleteCommands); this.HandlePersistentChildCollections(childObject, childObject.GetType(), deleteFirstCommands, deleteCommands); this.HandlePersistentChildren(childObject, childObject.GetType(), deleteFirstCommands, deleteCommands); } } }
public SqlCommandSubmitter(string databaseName) { switch (databaseName) { case "YPIDATA": this.m_ConnectionString = @"Data Source=TestSQL;Initial Catalog=YPIData;Integrated Security=True"; break; case "YPILocalData": this.m_ConnectionString = @"Data Source=.\LIS;Initial Catalog=YPILocalData;Integrated Security=True"; break; default: throw new Exception("Database name does not match existing."); } this.m_SqlInsertCommands = new Queue<SqlCommand>(); this.m_SqlInsertLastCommands = new Queue<SqlCommand>(); this.m_SqlDeleteFirstCommands = new Stack<SqlCommand>(); this.m_SqlDeleteCommands = new Stack<SqlCommand>(); this.m_SqlUpdateCommands = new Queue<SqlCommand>(); }
private void HandlePersistentChildCollections(object parentObject, Type objectType, Stack<SqlCommand> deleteFirstCommands, Stack<SqlCommand> deleteCommands) { List<PropertyInfo> childCollectionProperties = objectType.GetProperties() .Where( prop => prop.GetCustomAttributes(typeof(PersistentCollection), true) .Where(pc => ((PersistentCollection)pc).IsBuildOnly == false) .Any() ) .ToList(); foreach (PropertyInfo propertyInfo in childCollectionProperties) { IEnumerable<object> childCollectionObject = (IEnumerable<object>)propertyInfo.GetValue(parentObject, null); foreach (object listObject in childCollectionObject) { this.ProcessObjectForDelete(listObject, listObject.GetType(), deleteFirstCommands, deleteCommands); this.HandlePersistentChildCollections(listObject, listObject.GetType(), deleteFirstCommands, deleteCommands); this.HandlePersistentChildren(listObject, listObject.GetType(), deleteFirstCommands, deleteCommands); } } }
private DocumentGateway() { this.m_Stack = new Stack(); }
private void RunSqlCommands(Stack<SqlCommand> sqlCommandStack) { while (sqlCommandStack.Count != 0) { SqlCommand cmd = sqlCommandStack.Pop(); using (SqlConnection cn = new SqlConnection(this.m_ConnectionString)) { cn.Open(); cmd.Connection = cn; cmd.ExecuteNonQuery(); Console.WriteLine(cmd.CommandText); } } }
private void RunSqlCommands(Stack<SqlCommand> sqlCommandStack, SqlConnection cn, SqlTransaction trans) { while (sqlCommandStack.Count != 0) { SqlCommand cmd = sqlCommandStack.Pop(); cmd.Connection = cn; cmd.Transaction = trans; cmd.ExecuteNonQuery(); } }