/// <summary> /// Persist the components of the specified container /// </summary> public static void PersistComponents(IDbConnection conn, IDbTransaction tx, bool isUpdate, IComponentPersister persister, IContainer cont) { // Now time for sub-components foreach (IComponent cmp in cont.Components) { IComponentPersister cmpp = DatabasePersistenceService.GetPersister(cmp.GetType()); if (cmpp != null) { var vid = cmpp.Persist(conn, tx, cmp, isUpdate); // Add this component to the registered components? if (vid != null) { RegisterComponent(conn, tx, Decimal.Parse(vid.Identifier), cmp, (cmp.Site.Container as HealthServiceRecordContainer).Id, cmp.Site.Container); } } else { throw new InvalidOperationException(String.Format("Cannot find persister for '{0}'", cmp.GetType().FullName)); } } }
/// <summary> /// De-Persist components /// </summary> public static void DePersistComponents(IDbConnection conn, IContainer cont, IComponentPersister parent, bool loadFast) { List <ComponentData> tComponents = GetComponents(conn, cont, false); // Include Inverse roles? if (cont is RegistrationEvent) { tComponents.AddRange(GetComponents(conn, new HealthServiceRecordComponentRef() { Id = (cont as RegistrationEvent).Id }, true)); } // Reconstruct components foreach (var cmp in tComponents) { #if PERFMON Trace.TraceInformation("{0} : {1}", DateTime.Now.ToString("HH:mm:ss.ffff"), cmp.m_roleType.ToString()); #endif IComponentPersister cmpp = DatabasePersistenceService.GetPersister(cmp.m_componentType); if (cmpp != null) { // Determine if we've already de-persisted the object HealthServiceRecordComponent dcComp = m_alreadyDepersisted.Find(o => o != null && o.GetType().Equals(cmp.m_componentType) && o is IIdentifiable && (o as IIdentifiable).Identifier == cmp.m_componentId && (cmp.m_componentVersionId == default(Decimal) || (o as IIdentifiable).VersionIdentifier == cmp.m_componentVersionId)); //Trace.TraceInformation("DePersist {0}:{1}", cmp.m_componentType, cmp.m_componentId); if (dcComp != null) { dcComp = dcComp.Clone() as HealthServiceRecordComponent; } else { if (cmpp is IVersionComponentPersister) { dcComp = (cmpp as IVersionComponentPersister).DePersist(conn, cmp.m_componentId, cmp.m_componentVersionId, cont, cmp.m_roleType, loadFast) as HealthServiceRecordComponent; } else { dcComp = cmpp.DePersist(conn, cmp.m_componentId, cont, cmp.m_roleType, loadFast) as HealthServiceRecordComponent; } if (dcComp != null) { m_alreadyDepersisted.Add(dcComp); } } // Add to the graph if (dcComp != null && dcComp.Site != null) { (dcComp.Site as HealthServiceRecordSite).SiteRoleType = cmp.m_roleType; } else if (dcComp != null) { (cont as HealthServiceRecordContainer).Add(dcComp, Guid.NewGuid().ToString(), cmp.m_roleType, null); } } else { throw new InvalidOperationException(String.Format("Cannot find persister for '{0}'", cmp.m_componentType.FullName)); } #if PERFMON Trace.TraceInformation("EO {0} : {1}", DateTime.Now.ToString("HH:mm:ss.ffff"), cmp.m_roleType.ToString()); #endif } }