public virtual int LockValue(string name, string pattern) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.PrivateSequence r = GetSequence(name, pattern); if (r.IsLocked()) { throw new Net.Vpc.Upa.Exceptions.UPAException("Already locked"); } r.SetLocked(true); r.SetLockUserId(entity.GetPersistenceUnit().GetUserPrincipal().GetName()); r.SetLockDate(new Net.Vpc.Upa.Types.DateTime()); entity.CreateUpdateQuery().SetValues(r).ById(entity.CreateId(name, pattern)); return(r.GetValue()); }
public virtual int Unlock(string name, string pattern) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.PrivateSequence r = GetSequence(name, pattern); if (!r.IsLocked()) { throw new Net.Vpc.Upa.Exceptions.UPAException("not locked"); } if (!r.GetLockUserId().Equals(entity.GetPersistenceUnit().GetUserPrincipal().GetName())) { throw new Net.Vpc.Upa.Exceptions.UPAException("locked by others"); } int v = r.GetValue(); r.SetLocked(false); r.SetLockUserId(null); r.SetLockDate(null); entity.CreateUpdateQuery().SetValues(r).ById(entity.CreateId(pattern)); return(v); }
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 bool IsLockedBy(string name, string pattern, string user) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.PrivateSequence r = GetSequence(name, pattern); return(r.IsLocked() && r.GetLockUserId().Equals(user)); }
public virtual bool IsLocked(string name, string pattern) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.PrivateSequence r = GetSequence(name, pattern); return(r.IsLocked()); }