Example #1
0
 public virtual Net.Vpc.Upa.Impl.PrivateSequence GetSequence(string name, string pattern) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Impl.PrivateSequence r = entity.CreateQueryBuilder().ById(entity.CreateId(name, pattern)).GetEntity <R>();
     if (r == null)
     {
         throw new Net.Vpc.Upa.Exceptions.UPAException("Sequence " + pattern + " not found");
     }
     return(r);
 }
Example #2
0
 public virtual int GetCurrentValue(string name, string pattern) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Impl.PrivateSequence r = entity.CreateQueryBuilder().ById(entity.CreateId(name, pattern)).GetEntity <R>();
     if (r == null)
     {
         return(-1);
     }
     return(r.GetValue());
 }
Example #3
0
 public virtual Net.Vpc.Upa.Impl.PrivateSequence GetOrCreateSequence(string name, string pattern, int initialValue, int increment) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     //        System.out.println(">>>>>>>>>>>>>>>>>>> getOrCreateSequence("+name+","+pattern+")");
     Net.Vpc.Upa.Impl.PrivateSequence r = entity.CreateQueryBuilder().ById(entity.CreateId(name, pattern)).GetEntity <R>();
     if (r == null)
     {
         CreateSequence(name, pattern, initialValue, increment);
         r = entity.CreateQueryBuilder().ById(entity.CreateId(name, pattern)).GetEntity <R>();
     }
     return(r);
 }
Example #4
0
 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());
 }
Example #5
0
 public virtual void CreateSequence(string name, string pattern, int initialValue, int increment) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (increment == 0)
     {
         throw new System.ArgumentException("increment zero");
     }
     Net.Vpc.Upa.Impl.PrivateSequence r = (Net.Vpc.Upa.Impl.PrivateSequence)entity.GetBuilder().CreateObject <R>();
     r.SetName(name);
     r.SetGroup(pattern);
     r.SetLocked(false);
     r.SetValue(initialValue);
     r.SetIncrement(increment);
     entity.Persist(r);
 }
Example #6
0
        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);
        }
Example #7
0
        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");
        }
Example #8
0
 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));
 }
Example #9
0
 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());
 }