public override void OnPersist(Net.Vpc.Upa.Callbacks.PersistEvent @event) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { object parent_id = relation.ExtractId(@event.GetPersistedRecord()); string path = support.GetHierarchyPathSeparator() + support.ToStringId(@event.GetPersistedId()); string pathFieldName = support.GetHierarchyPathField(); Net.Vpc.Upa.Entity entity = relation.GetSourceRole().GetEntity(); if (parent_id != null) { Net.Vpc.Upa.Record r = entity.CreateQueryBuilder().ByExpression(entity.GetBuilder().IdToExpression(parent_id, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(pathFieldName)).GetRecord(); if (r != null) { path = r.GetString(pathFieldName) + path; } } @event.GetPersistedRecord().SetString(pathFieldName, path); Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext = @event.GetContext(); Net.Vpc.Upa.Persistence.EntityExecutionContext updateContext = executionContext.GetPersistenceUnit().GetFactory().CreateObject <Net.Vpc.Upa.Persistence.EntityExecutionContext>(typeof(Net.Vpc.Upa.Persistence.EntityExecutionContext)); updateContext.InitPersistenceUnit(executionContext.GetPersistenceUnit(), executionContext.GetPersistenceStore(), Net.Vpc.Upa.Persistence.ContextOperation.UPDATE); Net.Vpc.Upa.Record u2 = entity.GetBuilder().CreateRecord(); u2.SetString(pathFieldName, path); entity.UpdateCore(u2, entity.GetBuilder().IdToExpression(@event.GetPersistedId(), entity.GetName()), updateContext); }
protected internal virtual void ValidatePathField(object id, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { System.Collections.Generic.IList <Net.Vpc.Upa.Field> lfs = GetTreeRelationship().GetSourceRole().GetFields(); object[] parent_id = new object[(lfs).Count]; Net.Vpc.Upa.Record values = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(id, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.Regular().And(Net.Vpc.Upa.Filters.Fields.ByList(lfs))).GetRecord(); if (values == null) { parent_id = null; } else { for (int i = 0; i < parent_id.Length; i++) { Net.Vpc.Upa.Field field = lfs[i]; parent_id[i] = values.GetObject <T>(field.GetName()); if (parent_id[i] != null) { continue; } parent_id = null; break; } } string path = ToStringId(id); if (parent_id != null) { Net.Vpc.Upa.Record r = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(GetEntity().CreateId(parent_id), null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(GetHierarchyPathField())).GetRecord(); if (r != null) { path = r.GetString(GetHierarchyPathField()) + GetHierarchyPathSeparator() + path; } } Net.Vpc.Upa.Record r2 = GetEntity().GetBuilder().CreateRecord(); r2.SetString(GetHierarchyPathField(), path); GetEntity().UpdateCore(r2, GetEntity().GetBuilder().IdToExpression(id, GetEntity().GetName()), executionContext); }