protected internal virtual void ValidateChildren(object key, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Record r = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(key, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(GetHierarchyPathField())).GetRecord(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> lfs = GetTreeRelationship().GetSourceRole().GetFields(); Net.Vpc.Upa.Expressions.Concat concat = new Net.Vpc.Upa.Expressions.Concat(); concat.Add(new Net.Vpc.Upa.Expressions.Literal(r.GetString(GetHierarchyPathField()), GetEntity().GetField(GetHierarchyPathField()).GetDataType())); System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = GetEntity().GetPrimaryFields(); foreach (Net.Vpc.Upa.Field f in primaryFields) { concat.Add(new Net.Vpc.Upa.Expressions.Literal(GetHierarchyPathSeparator())); Net.Vpc.Upa.Types.DataType t = f.GetDataType(); Net.Vpc.Upa.Expressions.Var var = new Net.Vpc.Upa.Expressions.Var(f.GetName()); Net.Vpc.Upa.Expressions.Expression svar = null; if (t is Net.Vpc.Upa.Types.StringType) { svar = var; } else if (t is Net.Vpc.Upa.Types.IntType) { svar = new Net.Vpc.Upa.Expressions.I2V(var); } else if (t is Net.Vpc.Upa.Types.LongType) { svar = new Net.Vpc.Upa.Expressions.I2V(var); } else if (t is Net.Vpc.Upa.Types.DoubleType) { svar = new Net.Vpc.Upa.Expressions.D2V(var); } else if (t is Net.Vpc.Upa.Types.FloatType) { svar = new Net.Vpc.Upa.Expressions.D2V(var); } else { throw new System.ArgumentException("Unsupported "); } concat.Add(svar); } Net.Vpc.Upa.Record s = GetEntity().GetBuilder().CreateRecord(); s.SetObject(GetHierarchyPathField(), concat); Net.Vpc.Upa.Expressions.Expression p = null; Net.Vpc.Upa.Relationship rel = GetTreeRelationship(); object[] kvalue = GetEntity().GetBuilder().IdToKey(key).GetValue(); for (int i = 0; i < rel.Size(); i++) { Net.Vpc.Upa.Field field = lfs[i]; Net.Vpc.Upa.Expressions.Expression e = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(field.GetName()), new Net.Vpc.Upa.Expressions.Literal(kvalue[i], field.GetDataType()))); p = p == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(p, e); } GetEntity().UpdateCore(s, p, executionContext); System.Collections.Generic.IList <object> children = GetEntity().CreateQueryBuilder().ByExpression(p).GetIdList <K>(); foreach (object aChildren in children) { ValidateChildren(aChildren, executionContext); } }
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); }