public virtual Dictionary <string, int> SaveToDatabase(object objectToSave, SpringBaseDao baseDao, Type mappingAttributesType, bool inheritMappingAttributes) { Type objectToSaveType = objectToSave.GetType(); MappingContext mappingContext = MappingContext.GetMappingContext(objectToSaveType, mappingAttributesType, inheritMappingAttributes); BuildObjectSql(mappingContext, baseDao); IBeforeSaveToDatabase beforeSaveToDatabase = objectToSave as IBeforeSaveToDatabase; if (beforeSaveToDatabase != null) { beforeSaveToDatabase.BeforeSaveToDatabase(); } Dictionary <string, int> insertRowCounts = new Dictionary <string, int>(); baseDao.TransactionTemplate.Execute(delegate { baseDao.AdoTemplate.ClassicAdoTemplate.Execute(delegate(IDbCommand command) { ColumnCachedValues cachedValues = new ColumnCachedValues(); SaveToDatabase(null, objectToSave, null, cachedValues, mappingContext, insertRowCounts, command); return(null); }); return(null); }); return(insertRowCounts); }
public virtual void BeforeSaveToDatabase() { CollectionUtils.ForEach(Items, delegate(object item) { IBeforeSaveToDatabase beforeSaveToDatabase = item as IBeforeSaveToDatabase; if (beforeSaveToDatabase != null) { beforeSaveToDatabase.BeforeSaveToDatabase(); } }); }
public virtual void BeforeSaveToDatabase() { CollectionUtils.ForEach(Items, delegate(object item) { IBeforeSaveToDatabase beforeSaveToDatabase = item as IBeforeSaveToDatabase; if (beforeSaveToDatabase != null) { beforeSaveToDatabase.BeforeSaveToDatabase(); } }); // Fricken .NET deserializer is simply not working with xml attributes! this.Operation = GetOperation(Items); }
public virtual Dictionary <string, int> SaveToDatabase <T>(IEnumerable <T> objectsToSave, SpringBaseDao baseDao, bool deleteAllBeforeSave, Type mappingAttributesType, bool inheritMappingAttributes) { Type objectToSaveType = typeof(T); MappingContext mappingContext = MappingContext.GetMappingContext(objectToSaveType, mappingAttributesType, inheritMappingAttributes); BuildObjectSql(mappingContext, baseDao); Dictionary <string, int> insertRowCounts = new Dictionary <string, int>(); baseDao.TransactionTemplate.Execute(delegate { baseDao.AdoTemplate.ClassicAdoTemplate.Execute(delegate(IDbCommand command) { if (deleteAllBeforeSave) { DeleteAllFromDatabase(objectToSaveType, baseDao, mappingAttributesType); } int count = 0; CollectionUtils.ForEach(objectsToSave, delegate(T objectToSave) { ++count; bool doSave = true; ICanSaveToDatabase checkToSaveToDatabase = objectToSave as ICanSaveToDatabase; if (checkToSaveToDatabase != null) { if (!checkToSaveToDatabase.CanSaveToDatabase(this, baseDao)) { doSave = false; } } if (doSave) { IBeforeSaveToDatabase beforeSaveToDatabase = objectToSave as IBeforeSaveToDatabase; if (beforeSaveToDatabase != null) { beforeSaveToDatabase.BeforeSaveToDatabase(); } ColumnCachedValues cachedValues = new ColumnCachedValues(); SaveToDatabase(null, objectToSave, null, cachedValues, mappingContext, insertRowCounts, command); } }); return(null); }); return(null); }); return(insertRowCounts); }