Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to support adding a non-xml BackendProvider #289

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/SIL.LCModel/DomainImpl/CmObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3447,7 +3447,7 @@ int ICmObjectOrIdInternal.GetHvo(IdentityMap identityMap)
// These methods allow a real CmObject to be used where we would sometimes use a surrogate.
#region ICmObjectOrSurrogate Members

string ICmObjectOrSurrogate.XML
string GetStringRepresentation
{
get { return ((ICmObjectInternal)this).ToXmlString(); }
}
Expand All @@ -3462,7 +3462,7 @@ string ICmObjectOrSurrogate.Classname
get { return ClassName; }
}

byte[] ICmObjectOrSurrogate.XMLBytes
byte[] GetByteRepresentation
{
get { return ((ICmObjectInternal)this).ToXmlBytes(); }
}
Expand All @@ -3484,6 +3484,17 @@ bool ICmObjectOrSurrogate.HasObject
get { return true; }
}

/// <summary>
/// The DTO for this class (which came from storage? which can go to storage?)
/// </summary>
ICmObjectDTO ICmObjectOrSurrogate.DTO
{
get
{
return ((BackendProvider)Cache.ServiceLocator.GetInstance<IDataStorer>())
.MakeDTO(this);
}
}
#endregion

#region IReferenceSource Members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
{
DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000001);

var parasToChangeClasses = new List<DomainObjectDTO>();
var parasToChangeClasses = new List<DomainObjectXMLDTO>();
foreach (var stTxtPara in domainObjectDtoRepository.AllInstancesSansSubclasses("StTxtPara"))
{
var paraOwner = domainObjectDtoRepository.GetOwningDTO(stTxtPara);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
{
DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000002);

var footnotesToChangeClasses = new List<DomainObjectDTO>();
var footnotesToChangeClasses = new List<DomainObjectXMLDTO>();
foreach (var footnote in domainObjectDtoRepository.AllInstancesSansSubclasses("StFootnote"))
{
XElement footnoteEl = XElement.Parse(footnote.Xml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
new XElement("AUni", new XAttribute("ws", "en"), "Analysis")),
new XElement("UnderColor", new XAttribute("val", "255")),
new XElement("UnderStyle", new XAttribute("val", "1"))));
domainObjectDtoRepository.Add(new DomainObjectDTO("82290763-1633-4998-8317-0EC3F5027FBD",
domainObjectDtoRepository.Add(new DomainObjectXMLDTO("82290763-1633-4998-8317-0EC3F5027FBD",
"CmPossibility", typeElement.ToString()));

// 3. Move the attributes that are in RnEvent and RnAnalysis into RnGenericRec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
};

//Collect up the ones to be removed.
var goners = new List<DomainObjectDTO>();
var goners = new List<DomainObjectXMLDTO>();
foreach (var annDTO in domainObjectDtoRepository.AllInstancesSansSubclasses("CmBaseAnnotation"))
{
var annElement = XElement.Parse(annDTO.Xml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void PerformMigration(IDomainObjectDTORepository dtoRepos)

// The old objects to be removed go into 'goners'.
// In this case, it is the annotation defn type objects.
var goners = new List<DomainObjectDTO>((int) (dtoRepos.Count*0.80));
DomainObjectDTO dtoGoner;
var goners = new List<DomainObjectXMLDTO>((int) (dtoRepos.Count*0.80));
DomainObjectXMLDTO dtoGoner;
if (dtoRepos.TryGetValue(DataMigrationServices.kSegmentAnnDefnGuid, out dtoGoner))
goners.Add(dtoGoner);
if (dtoRepos.TryGetValue(DataMigrationServices.kTwficAnnDefnGuid, out dtoGoner))
Expand Down Expand Up @@ -245,7 +245,7 @@ public void PerformMigration(IDomainObjectDTORepository dtoRepos)

private static void DeleteCcwgWithGuidIndex(IDomainObjectDTORepository dtoRepos)
{
var goners = new List<DomainObjectDTO>();
var goners = new List<DomainObjectXMLDTO>();
var ccwgs = dtoRepos.AllInstancesSansSubclasses("ConstChartWordGroup");
foreach (var dto in ccwgs)
{
Expand Down Expand Up @@ -277,7 +277,7 @@ private static void DeleteCcwgWithGuidIndex(IDomainObjectDTORepository dtoRepos)
}

private static void DeleteUnneededGoners(IDomainObjectDTORepository dtoRepos,
IEnumerable<DomainObjectDTO> goners, ICollection<string> neededGoners)
IEnumerable<DomainObjectXMLDTO> goners, ICollection<string> neededGoners)
{
// We have run out of memory during this data migration on large projects. (See
// FWR-3849.) One possible reason is that we can make 15000+ copies of LangProject
Expand All @@ -291,10 +291,10 @@ private static void DeleteUnneededGoners(IDomainObjectDTORepository dtoRepos,
Where(t => (t.Attribute("t") != null && t.Attribute("t").Value == "o")).Count();
if (cAnn > 0)
{
var gonersInLangProject = new List<DomainObjectDTO>(cAnn);
var gonersInLangProject = new List<DomainObjectXMLDTO>(cAnn);
foreach (var goner in goners)
{
DomainObjectDTO gonerActual;
DomainObjectXMLDTO gonerActual;
if (!dtoRepos.TryGetValue(goner.Guid, out gonerActual))
continue; // Not in repos.
if (neededGoners.Contains(goner.Guid))
Expand Down Expand Up @@ -329,7 +329,7 @@ private static void SortOutMultipleXficBackrefs(IDomainObjectDTORepository dtoRe
Dictionary<string, byte[]> oldCcas,
Dictionary<Guid, Guid> ccaGuidMap,
IEnumerable<byte[]> oldCcrs,
List<DomainObjectDTO> goners)
List<DomainObjectXMLDTO> goners)
{
// Look for any xfics that have multiple CCA backrefs.
// If we find any, look through backrefs of CCAs and backrefs of xfic.BeginObj
Expand Down Expand Up @@ -674,7 +674,7 @@ private static List<KeyValuePair<byte[], XElement>> ProcessDiscourseData(IDomain
halfBakedCcwgItems, refsFromAppliesTo, oldCCAs, ccaGuidMap, newGuid.ToString().ToLowerInvariant())));

// Add DTO to repos.
dtoRepos.Add(new DomainObjectDTO(newGuid.ToString().ToLowerInvariant(), className, newCCRElement.ToString()));
dtoRepos.Add(new DomainObjectXMLDTO(newGuid.ToString().ToLowerInvariant(), className, newCCRElement.ToString()));
}

return halfBakedCcwgItems;
Expand Down Expand Up @@ -942,7 +942,7 @@ private static IEnumerable<XElement> ConvertCCAsAndAddCCRObjSurElements(
retval.Add(DataMigrationServices.CreateOwningObjSurElement(newGuid));

// Add newly converted CCA to repos.
dtoRepos.Add(new DomainObjectDTO(newGuid, newClassName, newCCAElement.ToString()));
dtoRepos.Add(new DomainObjectXMLDTO(newGuid, newClassName, newCCAElement.ToString()));
}

return retval;
Expand Down Expand Up @@ -1022,7 +1022,7 @@ private static List<XElement> GetAStrElements(byte[] xmlBytes, int ichMin, int i
}

private static void DeleteImmediatelyAllUnlovedCCRs(
IDomainObjectDTORepository dtoRepos, ICollection<DomainObjectDTO> goners,
IDomainObjectDTORepository dtoRepos, ICollection<DomainObjectXMLDTO> goners,
IDictionary<string, int> xficHasTextOrDiscourseBackReference,
ICollection<byte[]> oldCCRs,
IDictionary<string, byte[]> oldCCAs,
Expand Down Expand Up @@ -1060,7 +1060,7 @@ from objsurElement in allChartElements.Descendants("Rows").Elements("objsur")

private static void DeleteImmediatelyBadCca(IDomainObjectDTORepository dtoRepos,
string gonerCcaGuid,
ICollection<DomainObjectDTO> goners,
ICollection<DomainObjectXMLDTO> goners,
IDictionary<Guid, Guid> ccaGuidMap,
IDictionary<string, byte[]> oldCcas,
IDictionary<string, int> xficHasTextOrDiscourseBackReference)
Expand Down Expand Up @@ -1353,7 +1353,7 @@ private static void ProcessParagraphs(
newSegmentElement = DeleteTemporaryAnalyses(newSegmentElement);
// Create a new Segment instance DTO from the 'newSegmentElement',
// and add it to repos.
var newSegDto = new DomainObjectDTO(newSegGuid, "Segment", newSegmentElement.ToString());
var newSegDto = new DomainObjectXMLDTO(newSegGuid, "Segment", newSegmentElement.ToString());
dtoRepos.Add(newSegDto);
}

Expand Down Expand Up @@ -1485,7 +1485,7 @@ private static void CreateTemporaryXfic(bool fWfic, int beginOffset, int endOffs
}

private static void CollectIndirectAnnotations(
IDomainObjectDTORepository dtoRepos, ICollection<DomainObjectDTO> goners,
IDomainObjectDTORepository dtoRepos, ICollection<DomainObjectXMLDTO> goners,
IDictionary<string, byte[]> oldCCAs,
IDictionary<Guid, Guid> ccaGuidMap,
IDictionary<string, int> xficHasTextOrDiscourseBackReference,
Expand Down Expand Up @@ -1632,7 +1632,7 @@ private static void RemoveMismatchedAppliesToRefs(byte[] xmlBytes, ICollection<s
}

private static void CollectBaseAnnotations(
IDomainObjectDTORepository dtoRepos, ICollection<DomainObjectDTO> goners,
IDomainObjectDTORepository dtoRepos, ICollection<DomainObjectXMLDTO> goners,
IDictionary<string, byte[]> oldCCAs,
IDictionary<Guid, Guid> ccaGuidMap,
IDictionary<string, int> xficHasTextOrDiscourseBackReference,
Expand All @@ -1641,7 +1641,7 @@ private static void CollectBaseAnnotations(
IDictionary<string, SortedList<int, List<byte[]>>> paraToDuplicateOldXfics,
IDictionary<string, SortedList<int, byte[]>> paraToOldXfics)
{
var newPunctForms = new Dictionary<string, DomainObjectDTO>();
var newPunctForms = new Dictionary<string, DomainObjectXMLDTO>();
foreach (var baseAnnDto in dtoRepos.AllInstancesSansSubclasses("CmBaseAnnotation"))
{
var surrGuid = GetAnnotationTypeGuid(baseAnnDto.XmlBytes);
Expand Down Expand Up @@ -1712,8 +1712,8 @@ private static string GetAnnotationTypeGuid(byte[] xmlBytes)

private static bool EnsurePficHasInstanceOf(
IDomainObjectDTORepository dtoRepos,
DomainObjectDTO dtoPfic,
IDictionary<string, DomainObjectDTO> newPunctForms)
DomainObjectXMLDTO dtoPfic,
IDictionary<string, DomainObjectXMLDTO> newPunctForms)
{
var pficElement = dtoPfic.XmlBytes;
/*
Expand Down Expand Up @@ -1795,7 +1795,7 @@ private static bool EnsurePficHasInstanceOf(
// then make the new PF object, and return true.
// Find/Create PunctuationForm object that has a Form in the matching IcuLocale & matching string.
var key = icuLocale + "-" + newForm;
DomainObjectDTO dtoMatchingPf;
DomainObjectXMLDTO dtoMatchingPf;
if (!newPunctForms.TryGetValue(key, out dtoMatchingPf))
{
// Create new PunctuationForm dto.
Expand All @@ -1809,7 +1809,7 @@ private static bool EnsurePficHasInstanceOf(
new XElement("Form",
new XElement("Str",
new XElement("Run", new XAttribute("ws", icuLocale), newForm)))));
dtoMatchingPf = new DomainObjectDTO(newPunctFormGuid, className, newPfElement.ToString());
dtoMatchingPf = new DomainObjectXMLDTO(newPunctFormGuid, className, newPfElement.ToString());
// Add new PunctuationForm to dtoRepos.
dtoRepos.Add(dtoMatchingPf);
// Add new PunctuationForm to newPunctForms.
Expand All @@ -1830,7 +1830,7 @@ private static bool EnsurePficHasInstanceOf(
}

private static void MarkParaAsNeedingTokenization(IDomainObjectDTORepository dtoRepos,
DomainObjectDTO paraDto)
DomainObjectXMLDTO paraDto)
{
var stTxtParaBounds = new ElementBounds(paraDto.XmlBytes, s_tagsStTxtPara);
if (!stTxtParaBounds.IsValid)
Expand Down Expand Up @@ -1917,19 +1917,19 @@ private static XElement CreateATranslation(string oldSegGuid, Dictionary<string,
return new XElement(elementName, actualCommentNodes);
}

private static void PreprocessTextTagAnnotation(ICollection<DomainObjectDTO> goners,
private static void PreprocessTextTagAnnotation(ICollection<DomainObjectXMLDTO> goners,
ICollection<byte[]> annElements,
DomainObjectDTO annDto,
DomainObjectXMLDTO annDto,
byte[] annElement)
{
goners.Add(annDto);
annElements.Add(annElement);
}

private static void PreprocessDiscourseAnnotation(ICollection<DomainObjectDTO> goners,
private static void PreprocessDiscourseAnnotation(ICollection<DomainObjectXMLDTO> goners,
IDictionary<string, byte[]> annElements,
IDictionary<Guid, Guid> ccaGuidMap,
DomainObjectDTO annDto, byte[] annElement)
DomainObjectXMLDTO annDto, byte[] annElement)
{
goners.Add(annDto);
var oldGuid = GetGuid(annElement);
Expand All @@ -1939,8 +1939,8 @@ private static void PreprocessDiscourseAnnotation(ICollection<DomainObjectDTO> g
ccaGuidMap.Add(new Guid(oldGuid), Guid.NewGuid());
}

private static void PreprocessDiscourseAnnotation(ICollection<DomainObjectDTO> goners,
ICollection<byte[]> annElements, DomainObjectDTO annDto, byte[] annElement)
private static void PreprocessDiscourseAnnotation(ICollection<DomainObjectXMLDTO> goners,
ICollection<byte[]> annElements, DomainObjectXMLDTO annDto, byte[] annElement)
{
goners.Add(annDto);
var annoBounds = new ElementBounds(annElement, s_tagsCmAnnotation);
Expand All @@ -1952,8 +1952,8 @@ private static void PreprocessDiscourseAnnotation(ICollection<DomainObjectDTO> g
annElements.Add(annElement);
}

private static void PreprocessTranslationOrNoteAnnotation(ICollection<DomainObjectDTO> goners,
Dictionary<string, List<byte[]>> annElements, DomainObjectDTO annDto, byte[] annElement)
private static void PreprocessTranslationOrNoteAnnotation(ICollection<DomainObjectXMLDTO> goners,
Dictionary<string, List<byte[]>> annElements, DomainObjectXMLDTO annDto, byte[] annElement)
{
goners.Add(annDto);
var annoBounds = new ElementBounds(annElement, s_tagsCmAnnotation);
Expand All @@ -1980,10 +1980,10 @@ private static void PreprocessTranslationOrNoteAnnotation(ICollection<DomainObje

private static void PreprocessBaseAnnotation(
IDomainObjectDTORepository dtoRepos,
ICollection<DomainObjectDTO> goners,
ICollection<DomainObjectXMLDTO> goners,
IDictionary<string, SortedList<int, List<byte[]>>> paraToDuplicates,
IDictionary<string, SortedList<int, byte[]>> paraToAnnotation,
DomainObjectDTO baseAnnDto, byte[] annElement, bool checkOnInstanceOf)
DomainObjectXMLDTO baseAnnDto, byte[] annElement, bool checkOnInstanceOf)
{
goners.Add(baseAnnDto);

Expand Down Expand Up @@ -2106,7 +2106,7 @@ private static XElement AddNotes(IDomainObjectDTORepository dtoRepos, string new
new XElement("CmObject"),
new XElement("Note", GetOptionalComment(oldNotePair, "Content")));
// Create new dto and add to repos.
var newNoteDto = new DomainObjectDTO(newNoteGuid, "Note", newNoteElement.ToString());
var newNoteDto = new DomainObjectXMLDTO(newNoteGuid, "Note", newNoteElement.ToString());
dtoRepos.Add(newNoteDto);
}
}
Expand All @@ -2121,7 +2121,7 @@ private static XElement AddSegmentAnalyses(
ICollection<byte[]> oldTextTags,
string newSegmentGuid,
bool isLastOldSegment,
DomainObjectDTO paraDto)
DomainObjectXMLDTO paraDto)
{
XElement retval = null;

Expand Down Expand Up @@ -2288,7 +2288,7 @@ where GetAnnotationTypeGuid(xficKvp.Value) == DataMigrationServices.kTwficAnnDef
new XElement("Tag", DataMigrationServices.CreateReferenceObjSurElement(GetInstanceOfGuid(oldTextTagAnnElement)))));

// Add new DTO to repos.
var newTextTagDto = new DomainObjectDTO(newTextTagGuid, "TextTag", newTextTagElement.ToString());
var newTextTagDto = new DomainObjectXMLDTO(newTextTagGuid, "TextTag", newTextTagElement.ToString());
dtoRepos.Add(newTextTagDto);
// Add new TextTag to owning prop on owner as objsur element.
var owningStTextElement = XElement.Parse(owningStText.Xml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
{
DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000010);

DomainObjectDTO nbkDto = domainObjectDtoRepository.AllInstancesSansSubclasses("RnResearchNbk").First();
DomainObjectXMLDTO nbkDto = domainObjectDtoRepository.AllInstancesSansSubclasses("RnResearchNbk").First();
XElement nbkElem = XElement.Parse(nbkDto.Xml);
var recTypesGuid = (string) nbkElem.XPathSelectElement("RnResearchNbk/RecTypes/objsur").Attribute("guid");
var stack = new Stack<DomainObjectDTO>(domainObjectDtoRepository.GetDirectlyOwnedDTOs(recTypesGuid));
IEnumerable<DomainObjectDTO> recDtos = domainObjectDtoRepository.AllInstancesSansSubclasses("RnGenericRec");
IEnumerable<DomainObjectDTO> overlayDtos = domainObjectDtoRepository.AllInstancesSansSubclasses("CmOverlay");
var stack = new Stack<DomainObjectXMLDTO>(domainObjectDtoRepository.GetDirectlyOwnedDTOs(recTypesGuid));
IEnumerable<DomainObjectXMLDTO> recDtos = domainObjectDtoRepository.AllInstancesSansSubclasses("RnGenericRec");
IEnumerable<DomainObjectXMLDTO> overlayDtos = domainObjectDtoRepository.AllInstancesSansSubclasses("CmOverlay");
while (stack.Count > 0)
{
DomainObjectDTO dto = stack.Pop();
foreach (DomainObjectDTO childDto in domainObjectDtoRepository.GetDirectlyOwnedDTOs(dto.Guid))
DomainObjectXMLDTO dto = stack.Pop();
foreach (DomainObjectXMLDTO childDto in domainObjectDtoRepository.GetDirectlyOwnedDTOs(dto.Guid))
stack.Push(childDto);
XElement posElem = XElement.Parse(dto.Xml);
XElement uniElem = posElem.XPathSelectElement("CmPossibility/Abbreviation/AUni[@ws='en']");
Expand Down Expand Up @@ -70,7 +70,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
}
}

DomainObjectDTO recTypesDto = domainObjectDtoRepository.GetDTO(recTypesGuid);
DomainObjectXMLDTO recTypesDto = domainObjectDtoRepository.GetDTO(recTypesGuid);
DataMigrationServices.ChangeGuid(domainObjectDtoRepository, recTypesDto, "D9D55B12-EA5E-11DE-95EF-0013722F8DEC", overlayDtos);
DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
/// <param name="objElement">Name of the object containing fieldToDelete.</param>
/// <param name="fieldToDelete">The name of the field to delete.</param>
/// ------------------------------------------------------------------------------------
private void RemoveField(DomainObjectDTO dto, XElement objElement, string fieldToDelete)
private void RemoveField(DomainObjectXMLDTO dto, XElement objElement, string fieldToDelete)
{
XElement rmElement = objElement.Element(fieldToDelete);
if (rmElement != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor

// 1) Select the ConstChartWordGroup class objects.
// 2) Convert any with null BeginSegment reference to ConstChartTag objects with null Tag reference.
var objsToChangeClasses = new List<DomainObjectDTO>();
var objsToChangeClasses = new List<DomainObjectXMLDTO>();
foreach (var cellPartDto in domainObjectDtoRepository.AllInstancesSansSubclasses("ConstChartWordGroup"))
{
var rtElement = XElement.Parse(cellPartDto.Xml);
Expand Down Expand Up @@ -72,7 +72,7 @@ public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepositor
/// <param name="objElement">Name of the object containing fieldToDelete.</param>
/// <param name="fieldToDelete">The name of the field to delete.</param>
/// ------------------------------------------------------------------------------------
private void RemoveField(DomainObjectDTO dto, XElement objElement, string fieldToDelete)
private void RemoveField(DomainObjectXMLDTO dto, XElement objElement, string fieldToDelete)
{
XElement rmElement = objElement.Element(fieldToDelete);
if (rmElement != null)
Expand Down
Loading
Loading