/// <summary> /// Insert or replace artefacts. /// </summary> /// <param name="maintainables"> /// The maintainables. /// </param> /// <typeparam name="T"> /// The <see cref="IMaintainableObject"/> based interface /// </typeparam> /// <returns> /// The <see cref="IEnumerable{ArtefactImportStatus}"/>. /// </returns> protected IEnumerable <ArtefactImportStatus> ReplaceOrInsert <T>(IEnumerable <T> maintainables) where T : IMaintainableObject { foreach (var artefact in maintainables) { using (DbTransactionState state = DbTransactionState.Create(this._database)) { ArtefactImportStatus artefactImportStatus; try { artefactImportStatus = this.ReplaceOrInsert(state, artefact); state.Commit(); } catch (MappingStoreException e) { _log.Error(artefact.Urn.ToString(), e); state.RollBack(); artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e)); } catch (DbException e) { _log.Error(artefact.Urn.ToString(), e); state.RollBack(); artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e)); } yield return(artefactImportStatus); } } }
/// <summary> /// Insert the specified <paramref name="maintainables"/> to the mapping store. /// </summary> /// <param name="maintainables"> /// The maintainable. /// </param> /// <returns> /// The <see cref="IEnumerable{ArtefactImportStatus}"/>. /// </returns> public new IEnumerable <ArtefactImportStatus> Insert(IEnumerable <ICategorisationObject> maintainables) { var cache = new StructureCache(); foreach (var artefact in maintainables) { using (DbTransactionState state = DbTransactionState.Create(this.Database)) { ArtefactImportStatus artefactImportStatus; try { artefactImportStatus = this.InsertInternal(state, artefact, cache); state.Commit(); } catch (MappingStoreException e) { _log.Error(artefact.Urn.ToString(), e); state.RollBack(); artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e)); } catch (DbException e) { _log.Error(artefact.Urn.ToString(), e); state.RollBack(); artefactImportStatus = new ArtefactImportStatus(-1, artefact.AsReference.GetErrorMessage(e)); } yield return(artefactImportStatus); } } }
/// <summary> /// Delete the specified <paramref name="objects"/> from Mapping Store if they exist. /// </summary> /// <param name="objects"> /// The objects. /// </param> /// <typeparam name="T"> The type of maintainable object</typeparam> protected void DeleteObjects <T>(IEnumerable <T> objects) where T : IMaintainableObject { foreach (var maintainableObject in objects) { using (DbTransactionState state = DbTransactionState.Create(this._database)) { try { IStructureReference structureReference = maintainableObject.AsReference; var status = GetFinalStatus(state, structureReference); if (status != null && status.PrimaryKey > 0) { _log.DebugFormat(CultureInfo.InvariantCulture, "Deleting artefact record {0}.", structureReference.GetAsHumanReadableString()); this.Delete(state, status.PrimaryKey); } else { _log.WarnFormat(CultureInfo.InvariantCulture, "Failed to delete artefact record {0}.", structureReference.GetAsHumanReadableString()); } state.Commit(); } catch (Exception e) { state.RollBack(); _log.Error(maintainableObject.Urn, e); throw; } } } }