protected internal virtual int ValidateCustomUpdaterFormula(System.Collections.Generic.ISet <Net.Vpc.Upa.Field> fields) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { System.Collections.Generic.HashSet <Net.Vpc.Upa.CustomUpdaterFormula> unique = new System.Collections.Generic.HashSet <Net.Vpc.Upa.CustomUpdaterFormula>(); foreach (Net.Vpc.Upa.Field field in fields) { Net.Vpc.Upa.CustomUpdaterFormula c = (Net.Vpc.Upa.CustomUpdaterFormula)(onPersist ? field.GetPersistFormula() : field.GetUpdateFormula()); unique.Add(c); } foreach (Net.Vpc.Upa.CustomUpdaterFormula f in unique) { f.UpdateFormula(fields, expr, context); } return((int)entity.GetEntityCount(expr)); }
private string GetNewValue(Net.Vpc.Upa.Field field) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Entity entity = field.GetEntity(); string idName = field.GetName(); Net.Vpc.Upa.Entity seq = entity.GetPersistenceUnit().GetEntity(Net.Vpc.Upa.Impl.PrivateSequence.ENTITY_NAME); Net.Vpc.Upa.Impl.SequenceManager sm = new Net.Vpc.Upa.Impl.EntitySequenceManager(seq); string sequenceGroup = Eval(field, this.group, "{#}"); while (true) { string nextIdString = Eval(field, this.format, sm.NextValue(name, sequenceGroup, this.initialValue, this.allocationSize)); long count = entity.GetEntityCount(new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(idName), nextIdString)); if (count == 0) { return(nextIdString); } } }
public int NextValue0(string name, string pattern, int initialValue, int increment, bool autoCreate) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.PrivateSequence r = autoCreate ? GetOrCreateSequence(name, pattern, initialValue, increment) : GetSequence(name, pattern); if (r.IsLocked() && !r.GetLockUserId().Equals(entity.GetPersistenceUnit().GetUserPrincipal().GetName())) { throw new Net.Vpc.Upa.Exceptions.UPAException("Already locked"); } int v = r.GetValue(); r.SetValue(v + r.GetIncrement()); r.SetLocked(false); r.SetLockUserId(null); r.SetLockDate(null); Net.Vpc.Upa.Expressions.Expression idToExpression = entity.GetBuilder().IdToExpression(entity.CreateId(name, pattern), entity.GetName()); Net.Vpc.Upa.Expressions.And condition = new Net.Vpc.Upa.Expressions.And(idToExpression, new Net.Vpc.Upa.Expressions.Or(new Net.Vpc.Upa.Expressions.Different(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entity.GetName()), "locked"), Net.Vpc.Upa.Expressions.Literal.TRUE), new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entity.GetName()), "lockUserId"), new Net.Vpc.Upa.Expressions.Param("lockUserId", entity.GetPersistenceUnit().GetUserPrincipal().GetName())))); Net.Vpc.Upa.QueryBuilder q = null; try { q = entity.CreateQueryBuilder().ByExpression(condition); q.SetUpdatable(true); int oldValue; foreach (Net.Vpc.Upa.Impl.PrivateSequence s in q.GetEntityList <Net.Vpc.Upa.Impl.PrivateSequence>()) { oldValue = s.GetValue(); s.SetValue(oldValue + s.GetIncrement()); q.UpdateCurrent(); // System.out.println(">>>>>>>>>>>>>>>>>>> nextValue(" + name + "," + pattern + ") =>> "+oldValue); return(oldValue); } } finally { if (q != null) { q.Close(); } } //not found ! //check if problem of locking if (entity.GetEntityCount(new Net.Vpc.Upa.Expressions.And(idToExpression, new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var("locked"), Net.Vpc.Upa.Expressions.Literal.TRUE))) > 0) { throw new Net.Vpc.Upa.Exceptions.UPAException("Already locked"); } throw new Net.Vpc.Upa.Exceptions.UPAException("Unexpected error"); }
public virtual void CheckRemove(Net.Vpc.Upa.Expressions.Expression condition, bool recurse) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (entity.GetEntityCount(condition) == 0) { //nothing to remove!! return; } if (!IsDeleteSupported()) { throw new Net.Vpc.Upa.Exceptions.UndeletableRecordException(entity); } if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedRemove(entity)) { throw new Net.Vpc.Upa.Exceptions.DeleteRecordNotAllowedException(entity); } Net.Vpc.Upa.Expressions.Expression e = GetFullNonDeletableRecordsExpression(); if (e != null && e.IsValid()) { Net.Vpc.Upa.Expressions.Expression a = (condition == null) ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(condition, e); if (entity.GetEntityCount(a) > 0) { throw new Net.Vpc.Upa.Exceptions.UndeletableRecordException(entity); } } Net.Vpc.Upa.Entity p = entity.GetParentEntity(); if (p != null) { Net.Vpc.Upa.Expressions.Expression ss = entity.ChildToParentExpression(condition); // p.getShield().checkRemove(ss, recurse); p.GetShield().CheckUpdate(p.GetBuilder().CreateRecord(), ss); } CheckVeto(Net.Vpc.Upa.VetoableOperation.checkDelete, condition, recurse); }