protected void CloneAxisAttributesWithoutId(KopieAchse targetItem, IImportedAchse importedAxis) { targetItem.Name = importedAxis.Name; targetItem.Operation = importedAxis.Operation; targetItem.Owner = importedAxis.Owner; targetItem.VersionValidFrom = importedAxis.Version; }
public void BeforeUpdateAchse(Achse targetAchse, KopieAchse kopieAchse) { if (!oldAxisValidFromDict.ContainsKey(targetAchse.BsId)) { oldAxisValidFromDict.Add(targetAchse.BsId, targetAchse.VersionValidFrom); } }
public void BeforeUpdateSegment(AchsenSegment targetSegment, KopieAchse kopieAchse, KopieAchsenSegment kopieSegment) { DateTime oldVersionValidFrom = oldAxisValidFromDict[targetSegment.Achse.BsId]; DateTime newVersionValidFrom = kopieAchse.VersionValidFrom; if (targetSegment.AchsenReferenzen.Count > 0) { foreach (AchsenReferenz achsRef in new List <AchsenReferenz>(targetSegment.AchsenReferenzen)) { ILineString oldRefGeometry = (ILineString)achsRef.Shape; ILineString newSegmentGeometry = GeometryUtils.ConvertMLineStringTo2D(gf, (MLineString)kopieSegment.Shape); GeometryTransformer gt = new GeometryTransformer(oldRefGeometry, newSegmentGeometry); GeometryTransformerResult result = gt.Transform(); switch (result.ResultState) { case GeometryTransformerResultState.Success: { achsRef.Shape = result.NewRefGeometry; Register(achsRef); statistics.UpdatedReferences++; break; } case GeometryTransformerResultState.FailedWouldBeOutside: { RegisterConflict(achsRef, CreateConflict(AchsenUpdateConflict.CONFLICTTYPE_PARTIAL_REFERENCE_OUTSIDE, targetSegment.Id, oldRefGeometry)); RemoveReference(achsRef); statistics.DeletedReferences++; break; } case GeometryTransformerResultState.FailedWouldBeTooShort: { RegisterConflict(achsRef, CreateConflict(AchsenUpdateConflict.CONFLICTTYPE_PARTIAL_REFERENCE_TOOSHORT, targetSegment.Id, oldRefGeometry)); RemoveReference(achsRef); statistics.DeletedReferences++; break; } } } } }
public virtual void Start() { ClearConflicts(); ReadAchsKopieData(); fillAchsenCache(); if (ReferenceUpdater != null) { ReferenceUpdater.CreateValidFromDict(achsenCache.Values); } foreach (KeyValuePair <KopieAchse, HashSet <KopieAchsenSegment> > pair in kopieAchsenToSegmentDict) { KopieAchse kopieAchse = pair.Key; UpdateAchse(kopieAchse, kopieAchse.Operation); } if (ReferenceUpdater != null) { ReferenceUpdater.PostWork(); } }
///// utils protected void ReceivedItem(IImportedItem item) { if (item.Operation == AxisImportOperation.INSERT) // insert? { IKopie kopie = null; Num num = null; switch (Pass) { case AxisImportPass.Achsen: kopie = new KopieAchse(); CloneAxisAttributesWithoutId(kopie as KopieAchse, item as IImportedAchse); num = statistics.NumAxis; break; case AxisImportPass.Segmente: kopie = new KopieAchsenSegment(); CloneSegmentAttributesWithoutId(kopie as KopieAchsenSegment, item as IImportedSegment); num = statistics.NumSegment; break; case AxisImportPass.Sektoren: kopie = new KopieSektor(); CloneSektorAttributesWithoutId(kopie as KopieSektor, item as IImportedSektor); num = statistics.NumSector; break; default: return; } kopie.Id = item.Id; kopie.ImpNr = ImpNr; CurrentSession.Persist(kopie); num.Inserts++; } else // update or delete { IKopie kopie = null; Num num = null; switch (Pass) { case AxisImportPass.Achsen: kopie = CurrentSession.Get <KopieAchse>(item.Id); if (kopie == null) { throw new AxisImportException("Axis " + item.Id + " does not exist in database"); } CloneAxisAttributesWithoutId(kopie as KopieAchse, item as IImportedAchse); num = statistics.NumAxis; break; case AxisImportPass.Segmente: kopie = CurrentSession.Get <KopieAchsenSegment>(item.Id); if (kopie == null) { throw new AxisImportException("Segment " + item.Id + " does not exist in database"); } CloneSegmentAttributesWithoutId(kopie as KopieAchsenSegment, item as IImportedSegment); num = statistics.NumSegment; break; case AxisImportPass.Sektoren: kopie = CurrentSession.Get <KopieSektor>(item.Id); if (kopie == null) { throw new AxisImportException("Sektor " + item.Id + " does not exist in database"); } CloneSektorAttributesWithoutId(kopie as KopieSektor, item as IImportedSektor); num = statistics.NumSector; break; default: return; } kopie.ImpNr = ImpNr; if (item.Operation == AxisImportOperation.UPDATE) { num.Updates++; } else { num.Deletes++; } } HavePersistedRecord(); }
private void ReadAchsKopieData() { // HQL doesnt support left joins for foreign keys that aren't mapped // therefore we need three queries { var list = session.QueryOver <KopieAchse>().Where(ka => ka.Owner == owner).List(); foreach (object obj in list) { KopieAchse achse = (KopieAchse)obj; if (!kopieAchsenToSegmentDict.ContainsKey(achse)) { kopieAchsenToSegmentDict.Add(achse, new HashSet <KopieAchsenSegment>() { }); } else { } } } { var kopieAchseTypeName = typeof(KopieAchse).Name; var kopieAchsenSegmentTypeName = typeof(KopieAchsenSegment).Name; var kopieAchseIdPropertyName = ExpressionHelper.GetPropertyName <KopieAchse, Guid>(ka => ka.Id); var kopieAchsenSegmentAchsenIdPropertyName = ExpressionHelper.GetPropertyName <KopieAchsenSegment, Guid>(kas => kas.AchsenId); var kopieAchseOwnerPropertyName = ExpressionHelper.GetPropertyName <KopieAchse, string>(ka => ka.Owner); var qry = session.CreateQuery(string.Format("from {0} achse, {1} segment where achse.{2} = segment.{3} and achse.{4} = :owner", new string[] { kopieAchseTypeName, kopieAchsenSegmentTypeName, kopieAchseIdPropertyName, kopieAchsenSegmentAchsenIdPropertyName, kopieAchseOwnerPropertyName })); qry.SetString("owner", owner); qry.SetReadOnly(true); var list = qry.List(); foreach (object arr in list) { KopieAchse achse = (KopieAchse)((object[])arr)[0]; KopieAchsenSegment achsenSegment = (KopieAchsenSegment)((object[])arr)[1]; if (!kopieAchsenToSegmentDict.ContainsKey(achse)) { kopieAchsenToSegmentDict.Add(achse, new HashSet <KopieAchsenSegment>() { achsenSegment }); } else { kopieAchsenToSegmentDict[achse].Add(achsenSegment); } if (!kopieSegmentToSektorDict.ContainsKey(achsenSegment)) { kopieSegmentToSektorDict.Add(achsenSegment, new HashSet <KopieSektor>() { }); } } } { var kopieAchseTypeName = typeof(KopieAchse).Name; var kopieAchsenSegmentTypeName = typeof(KopieAchsenSegment).Name; var kopieSektorTypeName = typeof(KopieSektor).Name; var kopieAchseIdPropertyName = ExpressionHelper.GetPropertyName <KopieAchse, Guid>(ka => ka.Id); var kopieAchsenSegmentAchsenIdPropertyName = ExpressionHelper.GetPropertyName <KopieAchsenSegment, Guid>(kas => kas.AchsenId); var kopieAchsenSegmentIdPropertyName = ExpressionHelper.GetPropertyName <KopieAchsenSegment, Guid>(kas => kas.Id); var kopieAchsenSektorSegmentIdPropertyName = ExpressionHelper.GetPropertyName <KopieSektor, Guid>(ks => ks.SegmentId); var kopieAchseOwnerPropertyName = ExpressionHelper.GetPropertyName <KopieAchse, string>(ka => ka.Owner); var qry = session.CreateQuery(string.Format("from {0} achse, {1} segment, {2} sektor where achse.{3} = segment.{4} and segment.{5} = sektor.{6} and achse.{7} = :owner", new string[] { kopieAchseTypeName, kopieAchsenSegmentTypeName, kopieSektorTypeName, kopieAchseIdPropertyName, kopieAchsenSegmentAchsenIdPropertyName, kopieAchsenSegmentIdPropertyName, kopieAchsenSektorSegmentIdPropertyName, kopieAchseOwnerPropertyName })); qry.SetString("owner", owner); qry.SetReadOnly(true); var list = qry.List(); foreach (object arr in list) { KopieAchse achse = (KopieAchse)((object[])arr)[0]; KopieAchsenSegment achsenSegment = (KopieAchsenSegment)((object[])arr)[1]; KopieSektor sektor = (KopieSektor)((object[])arr)[2]; if (!kopieAchsenToSegmentDict.ContainsKey(achse)) { kopieAchsenToSegmentDict.Add(achse, new HashSet <KopieAchsenSegment>() { achsenSegment }); } else { kopieAchsenToSegmentDict[achse].Add(achsenSegment); } if (!kopieSegmentToSektorDict.ContainsKey(achsenSegment)) { kopieSegmentToSektorDict.Add(achsenSegment, new HashSet <KopieSektor>() { sektor }); } else { kopieSegmentToSektorDict[achsenSegment].Add(sektor); } } } }
private AchsenSegment UpdateSegment(Achse achse, KopieAchse kopieAchse, KopieAchsenSegment kopieSegment, int operation) { if (kopieSegment.ImpNr <= lastImpNr) { return(null); } maxImpNr = Math.Max(maxImpNr, kopieSegment.ImpNr); switch (operation) { case AxisImportOperation.DELETE: { AchsenSegment segment = findSegment(achse, kopieSegment); if (segment == null) { return(null); } if (ReferenceUpdater != null) { ReferenceUpdater.BeforeDeleteSegment(segment); } foreach (KopieSektor kopieSektor in kopieSegmentToSektorDict[kopieSegment]) { UpdateSektor(segment, kopieSektor, kopieSektor.Operation); } achse.AchsenSegmente.Remove(segment); session.Delete(segment); statistics.NumSegment.Deletes++; return(null); } case AxisImportOperation.UPDATE: { AchsenSegment segment = findSegment(achse, kopieSegment); if (segment == null) { return(UpdateSegment(achse, kopieAchse, kopieSegment, AxisImportOperation.INSERT)); } if (ReferenceUpdater != null) { ReferenceUpdater.BeforeUpdateSegment(segment, kopieAchse, kopieSegment); } segment = gisKopieMappingEngine.Translate <KopieAchsenSegment, AchsenSegment>(kopieSegment, segment); segment.Shape4d = kopieSegment.Shape; if (segment.Mandant != mandant) { throw new Exception("segment.Mandant != mandant"); } foreach (KopieSektor kopieSektor in kopieSegmentToSektorDict[kopieSegment]) { UpdateSektor(segment, kopieSektor, kopieSektor.Operation); } statistics.NumSegment.Updates++; return(segment); } case AxisImportOperation.INSERT: { if (findSegment(achse, kopieSegment) != null) { throw new Exception("Cannot insert: KopieSegment " + kopieSegment.Id + " already exists in AchsenSegment table!"); } AchsenSegment segment = gisKopieMappingEngine.Translate <KopieAchsenSegment, AchsenSegment>(kopieSegment); segment.BsId = kopieSegment.Id; segment.Shape4d = kopieSegment.Shape; segment.Mandant = mandant; segment.ErfassungsPeriod = erfassungsPeriod; segment.Achse = achse; achse.AchsenSegmente.Add(segment); foreach (KopieSektor kopieSektor in kopieSegmentToSektorDict[kopieSegment]) { UpdateSektor(segment, kopieSektor, kopieSektor.Operation); } if (ReferenceUpdater != null) { ReferenceUpdater.AfterCreateSegment(segment); } statistics.NumSegment.Inserts++; return(segment); } } return(null); }
private Achse UpdateAchse(KopieAchse kopieAchse, int operation) { if (kopieAchse.ImpNr <= lastImpNr) { return(null); } maxImpNr = Math.Max(maxImpNr, kopieAchse.ImpNr); switch (operation) { case AxisImportOperation.DELETE: { Achse achse = lookupAchseByBSID(kopieAchse.Id); if (achse == null) { Loggers.TechLogger.Warn(String.Format("AchsenUpdate Delete: Achse {0} not found", kopieAchse.Id)); return(null); } if (ReferenceUpdater != null) { ReferenceUpdater.BeforeDeleteAchse(achse); } foreach (KopieAchsenSegment kopieSegment in kopieAchsenToSegmentDict[kopieAchse]) { UpdateSegment(achse, kopieAchse, kopieSegment, kopieSegment.Operation); } session.Delete(achse); statistics.NumAchsen.Deletes++; return(null); } case AxisImportOperation.UPDATE: { Achse achse = lookupAchseByBSID(kopieAchse.Id); if (achse == null) { return(UpdateAchse(kopieAchse, AxisImportOperation.INSERT)); } if (ReferenceUpdater != null) { ReferenceUpdater.BeforeUpdateAchse(achse, kopieAchse); } achse = gisKopieMappingEngine.Translate <KopieAchse, Achse>(kopieAchse, achse); if (achse.Mandant != mandant) { throw new Exception("achse.Mandant != mandant"); } foreach (KopieAchsenSegment kopieSegment in kopieAchsenToSegmentDict[kopieAchse]) { UpdateSegment(achse, kopieAchse, kopieSegment, kopieSegment.Operation); } statistics.NumAchsen.Updates++; return(achse); } case AxisImportOperation.INSERT: { if (lookupAchseByBSID(kopieAchse.Id) != null) { throw new Exception("Cannot insert: KopieAchse " + kopieAchse.Id + " already exists in Achsen table!"); } Achse achse = gisKopieMappingEngine.Translate <KopieAchse, Achse>(kopieAchse); achse.BsId = kopieAchse.Id; achse.Mandant = mandant; achse.ErfassungsPeriod = erfassungsPeriod; foreach (KopieAchsenSegment kopieSegment in kopieAchsenToSegmentDict[kopieAchse]) { UpdateSegment(achse, kopieAchse, kopieSegment, kopieSegment.Operation); } session.Persist(achse); statistics.NumAchsen.Inserts++; return(achse); } } return(null); }