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);
 }
 public virtual Net.Vpc.Upa.Expressions.Expression GetFullNonDeletableRecordsExpression() /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity parent            = entity.GetParentEntity();
     Net.Vpc.Upa.Expressions.Expression a = GetNonDeletableRecordsExpression();
     Net.Vpc.Upa.Expressions.Expression b = parent == null ? null : entity.ParentToChildExpression(parent.GetShield().GetFullNonUpdatableRecordsExpression());
     a = (a == null) ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.Or(a, b);
     return((a == null || !a.IsValid()) ? null : a);
 }
 public virtual Net.Vpc.Upa.Expressions.Expression GetFullNonUpdatableRecordsExpression() /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity parent            = entity.GetParentEntity();
     Net.Vpc.Upa.Expressions.Expression a = GetNonUpdatableRecordsExpression();
     //if hierarchical entity then ignore parent
     Net.Vpc.Upa.Expressions.Expression b = (parent == null || parent.GetName().Equals(entity.GetName())) ? null : entity.ParentToChildExpression(parent.GetShield().GetFullNonUpdatableRecordsExpression());
     a = (a == null) ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.Or(a, b);
     return((a == null || !a.IsValid()) ? null : a);
 }
Beispiel #4
0
 public override string ToString()
 {
     System.Text.StringBuilder sb = new System.Text.StringBuilder("Delete From " + entity);
     if (entityAlias != null)
     {
         sb.Append(" ").Append(Net.Vpc.Upa.Expressions.ExpressionHelper.EscapeIdentifier(entityAlias));
     }
     if (condition != null && condition.IsValid())
     {
         sb.Append(" Where ").Append(GetCondition().ToString());
     }
     return(sb.ToString());
 }
Beispiel #5
0
        public override bool IsValid()
        {
            int  max   = GetArgumentsCount();
            bool valid = false;

            for (int i = 0; i < max; i++)
            {
                Net.Vpc.Upa.Expressions.Expression e = GetArgument(i);
                if (e.IsValid())
                {
                    valid = true;
                }
            }
            return(valid);
        }
Beispiel #6
0
        public override string ToString()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string valueString           = System.Convert.ToString(entity);
            string aliasString           = GetEntityAlias();
            string joinKey = "Inner Join";

            switch (GetJoinType())
            {
            case Net.Vpc.Upa.Expressions.JoinType.INNER_JOIN:
                joinKey = "Inner Join";
                break;

            case Net.Vpc.Upa.Expressions.JoinType.FULL_JOIN:
                joinKey = "Full Join";
                break;

            case Net.Vpc.Upa.Expressions.JoinType.LEFT_JOIN:
                joinKey = "Left Join";
                break;

            case Net.Vpc.Upa.Expressions.JoinType.RIGHT_JOIN:
                joinKey = "Right Join";
                break;

            case Net.Vpc.Upa.Expressions.JoinType.CROSS_JOIN:
                joinKey = "Cross Join";
                break;
            }
            sb.Append(" ").Append(joinKey).Append(" ").Append(valueString);
            if (aliasString != null && !valueString.Equals(aliasString))
            {
                sb.Append(" ").Append(aliasString);
            }
            if (condition != null && condition.IsValid())
            {
                sb.Append(" On ").Append(condition);
            }
            return(sb.ToString());
        }
 public virtual bool IsUpdatableRecord(object id)
 {
     try {
         if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedUpdate(entity))
         {
             return(false);
         }
         Net.Vpc.Upa.Expressions.Expression e = GetFullNonUpdatableRecordsExpression();
         if (e != null && e.IsValid())
         {
             Net.Vpc.Upa.Expressions.Expression a = new Net.Vpc.Upa.Expressions.And(entity.GetBuilder().IdToExpression(id, null), e);
             if (entity.GetEntityCount(a) > 0)
             {
                 return(false);
             }
         }
         CheckVeto(Net.Vpc.Upa.VetoableOperation.updatableRecord, id);
         return(true);
     } catch (Net.Vpc.Upa.Exceptions.UPAException e) {
     }
     // e.printStackTrace(); //To change body of catch statement use
     // Options | File Templates.
     return(false);
 }
 /**
  * Check for the faisabilty of the rename operation. When oldId is null, the
  * verification is done for ALL keys (rname should be supported+enabled for
  * the curent user) When newId is null, the verification is done only on
  * oldId
  *
  * @param oldId old id
  * @param newId new id
  * @throws net.vpc.upa.exceptions.UPAException :
  * RenameRecordNotAllowedException, UnrenamableRecordException,
  * RenameRecordOldKeyNotFoundException, RenameRecordNewKeyInUseException
  */
 public virtual void CheckRename(object oldId, object newId) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedRename(entity))
     {
         throw new Net.Vpc.Upa.Exceptions.RenameRecordNotAllowedException(entity);
     }
     if (!IsRenameSupported())
     {
         throw new Net.Vpc.Upa.Exceptions.UnrenamableRecordException(entity);
     }
     if (oldId != null)
     {
         Net.Vpc.Upa.Expressions.Expression e = GetFullNonRenamableRecordsExpression();
         if (e != null && e.IsValid())
         {
             Net.Vpc.Upa.Expressions.And a = new Net.Vpc.Upa.Expressions.And(entity.GetBuilder().IdToExpression(oldId, null), e);
             if (entity.GetEntityCount(a) > 0)
             {
                 throw new Net.Vpc.Upa.Exceptions.UnrenamableRecordException(entity);
             }
         }
         object o = entity.CreateQueryBuilder().ById(oldId).SetFieldFilter(Net.Vpc.Upa.Impl.Util.Filters.Fields2.PERSISTENT_NON_FORMULA).GetEntity <R>();
         if (o == null)
         {
             throw new Net.Vpc.Upa.Exceptions.RenameRecordOldKeyNotFoundException(entity);
         }
     }
     if (newId != null)
     {
         if (entity.Contains(newId))
         {
             throw new Net.Vpc.Upa.Exceptions.RenameRecordNewKeyInUseException(entity);
         }
     }
     CheckVeto(Net.Vpc.Upa.VetoableOperation.checkRename, oldId, newId);
 }
Beispiel #9
0
 public override bool IsValid()
 {
     return((left != null && left.IsValid()) && (min != null && min.IsValid()) && (max != null && max.IsValid()));
 }
Beispiel #10
0
 public override bool IsValid()
 {
     return(expression.IsValid());
 }
 public override bool IsValid()
 {
     return((left == null || left.IsValid()) && (right == null || right.IsValid()));
 }
Beispiel #12
0
        public override string ToString()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder("Select ");
            if (top > 0)
            {
                sb.Append(" TOP ").Append(top);
            }
            if (distinct)
            {
                sb.Append(" DISTINCT");
            }
            sb.Append(" ");
            string aliasString = null;
            string valueString = null;
            bool   started     = false;

            if (CountFields() == 0)
            {
                sb.Append("...");
            }
            else
            {
                for (int i = 0; i < CountFields(); i++)
                {
                    Net.Vpc.Upa.Expressions.QueryField fi = GetField(i);
                    Net.Vpc.Upa.Expressions.Expression e  = fi.GetExpression();
                    valueString = System.Convert.ToString(e);
                    aliasString = fi.GetAlias();
                    if (started)
                    {
                        sb.Append(",");
                    }
                    else
                    {
                        started = true;
                    }
                    if (aliasString == null)
                    {
                        sb.Append(valueString);
                    }
                    else
                    {
                        sb.Append(valueString);
                        sb.Append(" ");
                        sb.Append(Net.Vpc.Upa.Expressions.ExpressionHelper.EscapeIdentifier(aliasString));
                    }
                }
            }
            if (GetEntity() == null)
            {
            }
            else
            {
                sb.Append(" From ");
                if (GetEntity() is Net.Vpc.Upa.Expressions.Select)
                {
                    sb.Append(GetEntity().ToString());
                }
                else
                {
                    Net.Vpc.Upa.Expressions.EntityName entityName = (Net.Vpc.Upa.Expressions.EntityName)GetEntity();
                    sb.Append(entityName);
                }
            }
            if (GetEntityAlias() != null)
            {
                sb.Append(" ").Append(Net.Vpc.Upa.Expressions.ExpressionHelper.EscapeIdentifier(GetEntityAlias()));
            }
            for (int i = 0; i < CountJoins(); i++)
            {
                Net.Vpc.Upa.Expressions.JoinCriteria e = GetJoin(i);
                sb.Append(" ").Append(e);
            }
            Net.Vpc.Upa.Expressions.Expression c = GetWhere();
            if (c != null && c.IsValid())
            {
                sb.Append(" Where ").Append(c);
            }
            if (CountGroupByItems() > 0)
            {
                sb.Append(" ");
                int maxGroups = CountGroupByItems();
                sb.Append("Group By ");
                for (int i = 0; i < maxGroups; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(GetGroupBy(i));
                }
            }
            int maxOrders = CountOrderByItems();

            if (maxOrders > 0)
            {
                sb.Append(" ");
                sb.Append("Order By ");
                for (int i = 0; i < maxOrders; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(GetOrderBy(i));
                    if (IsOrderAscending(i))
                    {
                        sb.Append(" Asc ");
                    }
                    else
                    {
                        sb.Append(" Desc ");
                    }
                }
            }
            return(sb.ToString());
        }
 public virtual void CheckPersist(Net.Vpc.Upa.Record record) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedPersist(entity))
     {
         throw new Net.Vpc.Upa.Exceptions.PersistRecordNotAllowedException(entity);
     }
     if (!IsPersistSupported())
     {
         throw new Net.Vpc.Upa.Exceptions.PersistRecordNotAllowedException(entity);
     }
     if (record != null)
     {
         // check parent is not read only
         if (entity.GetParentEntity() != null)
         {
             Net.Vpc.Upa.Expressions.Expression parentUnupdatable = entity.GetParentEntity().GetShield().GetFullNonUpdatableRecordsExpression();
             if (parentUnupdatable != null && parentUnupdatable.IsValid())
             {
                 Net.Vpc.Upa.Relationship r = entity.GetCompositionRelation();
                 System.Collections.Generic.IList <Net.Vpc.Upa.Field> df = r.GetSourceRole().GetFields();
                 System.Collections.Generic.IList <Net.Vpc.Upa.Field> mf = r.GetTargetRole().GetFields();
                 object[] pko = new object[(mf).Count];
                 for (int i = 0; i < pko.Length; i++)
                 {
                     pko[i] = record.GetObject <T>(df[i].GetName());
                 }
                 object pk = entity.CreateId(pko);
                 long   c  = entity.GetParentEntity().GetEntityCount(new Net.Vpc.Upa.Expressions.And(parentUnupdatable, entity.GetParentEntity().GetBuilder().IdToExpression(pk, null)));
                 if (c > 0)
                 {
                     throw new Net.Vpc.Upa.Exceptions.UnupdatableRecordException(entity.GetParentEntity());
                 }
             }
         }
         bool keyGenerated = IsGeneratedId();
         Net.Vpc.Upa.Expressions.Expression keyExpresson = null;
         if (!keyGenerated)
         {
             object key = entity.GetBuilder().RecordToId(record);
             keyExpresson = entity.GetBuilder().IdToExpression(key, null);
         }
         Net.Vpc.Upa.Entity p = entity.GetParentEntity();
         if (p != null)
         {
             //Expression ss = childToParentExpression(toExpression(key));
             Net.Vpc.Upa.Expressions.Expression ss = entity.ChildToParentExpression(record);
             if (ss != null)
             {
                 p.GetShield().CheckUpdate(null, ss);
             }
         }
         System.Collections.Generic.IList <Net.Vpc.Upa.Index> uniqueIndexes = entity.GetIndexes(true);
         if ((uniqueIndexes.Count == 0))
         {
             if (!keyGenerated)
             {
                 if (entity.GetEntityCount(keyExpresson) > 0)
                 {
                     throw new Net.Vpc.Upa.Exceptions.InsertRecordDuplicateKeyException(entity);
                 }
             }
         }
         else
         {
             Net.Vpc.Upa.Expressions.Expression or = null;
             if (!keyGenerated)
             {
                 or = keyExpresson;
             }
             foreach (Net.Vpc.Upa.Index index in uniqueIndexes)
             {
                 Net.Vpc.Upa.Field[] f = index.GetFields();
                 Net.Vpc.Upa.Expressions.Expression e1 = null;
                 if (f.Length == 1)
                 {
                     e1 = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(f[0].GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(record.GetObject <T>(f[0].GetName())));
                 }
                 else
                 {
                     Net.Vpc.Upa.Expressions.Expression a = null;
                     foreach (Net.Vpc.Upa.Field aF in f)
                     {
                         Net.Vpc.Upa.Expressions.Expression b = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(aF.GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(record.GetObject <T>(aF.GetName()))));
                         a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.And(a, b);
                     }
                     e1 = a;
                 }
                 or = or == null ? ((Net.Vpc.Upa.Expressions.Expression)(e1)) : new Net.Vpc.Upa.Expressions.Or(or, e1);
             }
             if (entity.GetEntityCount(or) > 0)
             {
                 // finer lookup of problem
                 if (!keyGenerated)
                 {
                     if (entity.GetEntityCount(keyExpresson) > 0)
                     {
                         throw new Net.Vpc.Upa.Exceptions.InsertRecordDuplicateKeyException(entity);
                     }
                 }
                 foreach (Net.Vpc.Upa.Index index in uniqueIndexes)
                 {
                     Net.Vpc.Upa.Field[] f = index.GetFields();
                     Net.Vpc.Upa.Expressions.Expression e1 = null;
                     if (f.Length == 1)
                     {
                         e1 = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(f[0].GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(record.GetObject <T>(f[0].GetName())));
                     }
                     else
                     {
                         Net.Vpc.Upa.Expressions.Expression a = null;
                         foreach (Net.Vpc.Upa.Field aF in f)
                         {
                             Net.Vpc.Upa.Expressions.Expression b = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(aF.GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(record.GetObject <T>(aF.GetName()))));
                             a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.And(a, b);
                         }
                         e1 = a;
                     }
                     if (entity.GetEntityCount(e1) > 0)
                     {
                         throw new Net.Vpc.Upa.Exceptions.InsertRecordDuplicateUniqueFieldsException(entity, index, record.GetObject <T>(f[0].GetName()));
                     }
                 }
                 throw new System.Exception("WouldNeverBeThrownException");
             }
         }
     }
     CheckVeto(Net.Vpc.Upa.VetoableOperation.checkPersist, record);
 }
        public virtual void CheckUpdate(Net.Vpc.Upa.Record updates, Net.Vpc.Upa.Expressions.Expression condition) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedUpdate(entity))
            {
                throw new Net.Vpc.Upa.Exceptions.UpdateRecordNotAllowedException(entity);
            }
            if (!IsUpdateSupported())
            {
                throw new Net.Vpc.Upa.Exceptions.UnupdatableRecordException(entity);
            }
            Net.Vpc.Upa.Expressions.Expression e = GetFullNonUpdatableRecordsExpression();
            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.UnupdatableRecordException(entity);
                }
            }
            long updated = 0;

            if ((updated = entity.GetEntityCount(condition)) == 0)
            {
                throw new Net.Vpc.Upa.Exceptions.UpdateRecordKeyNotFoundException(entity, condition);
            }
            //TODO c koa cet unique fields qui n'impose pas toutes les validations
            if (false)
            {
                return;
            }
            else if (updated == 1)
            {
                if (condition != null)
                {
                    if (updates != null)
                    {
                        Net.Vpc.Upa.Expressions.Expression or = null;
                        foreach (Net.Vpc.Upa.Index index in entity.GetIndexes(true))
                        {
                            Net.Vpc.Upa.Field[] f = index.GetFields();
                            Net.Vpc.Upa.Expressions.Expression a = null;
                            int found = 0;
                            foreach (Net.Vpc.Upa.Field aF in f)
                            {
                                if (updates.IsSet(aF.GetName()))
                                {
                                    found++;
                                    Net.Vpc.Upa.Expressions.Expression b = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(aF.GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(updates.GetObject <T>(aF.GetName()))));
                                    a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.And(a, b);
                                }
                            }
                            if (found != 0 && found != f.Length)
                            {
                                throw new Net.Vpc.Upa.Exceptions.UPAException("NotFound");
                            }
                            else if (found == f.Length)
                            {
                                or = or == null ? ((Net.Vpc.Upa.Expressions.Expression)(a)) : new Net.Vpc.Upa.Expressions.Or(or, a);
                            }
                        }
                        if (or != null)
                        {
                            Net.Vpc.Upa.Expressions.And and = new Net.Vpc.Upa.Expressions.And(new Net.Vpc.Upa.Expressions.Not(condition), or);
                            if (entity.GetEntityCount(and) > 0)
                            {
                                throw new Net.Vpc.Upa.Exceptions.UpdateRecordDuplicateKeyException(entity);
                            }
                        }
                    }
                }
            }
            else
            {
                if (updates != null)
                {
                    foreach (Net.Vpc.Upa.Index index in entity.GetIndexes(true))
                    {
                        Net.Vpc.Upa.Field[] f = index.GetFields();
                        foreach (Net.Vpc.Upa.Field aF in f)
                        {
                            if (updates.IsSet(aF.GetName()))
                            {
                                throw new Net.Vpc.Upa.Exceptions.UpdateRecordDuplicateKeyException(entity);
                            }
                        }
                    }
                }
            }
            Net.Vpc.Upa.Entity p = entity.GetParentEntity();
            if (p != null)
            {
                Net.Vpc.Upa.Expressions.Expression ss = entity.ChildToParentExpression(condition);
                try {
                    p.GetShield().CheckUpdate(null, ss);
                } catch (Net.Vpc.Upa.Exceptions.UpdateRecordKeyNotFoundException ex) {
                    log.Warning(entity.GetName() + "'s parent seems not to be resolvable for condition (" + condition + "): " + ex);
                }
            }
            //ignore if parent not found!
            CheckVeto(Net.Vpc.Upa.VetoableOperation.checkUpdate, updates, condition);
        }
Beispiel #15
0
 public override bool IsValid()
 {
     return(entityName.IsValid() && ancestorExpression.IsValid() && childExpression.IsValid());
 }