protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLessThan CompileLessThan(Net.Vpc.Upa.Expressions.LessThan v, Net.Vpc.Upa.Impl.Uql.ExpressionTranslationManager manager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations)
 {
     if (v == null)
     {
         return(null);
     }
     Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression left  = manager.TranslateAny(v.GetLeft(), declarations);
     Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression right = manager.TranslateAny(v.GetRight(), declarations);
     Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLessThan          s     = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLessThan(left, right);
     //        s.setDeclarationList(declarations);
     return(s);
 }
Пример #2
0
        public virtual Net.Vpc.Upa.Expressions.Expression RecordToExpression(Net.Vpc.Upa.Record record, string alias) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            if (record == null)
            {
                return(null);
            }
            Net.Vpc.Upa.Expressions.Expression a = null;
            foreach (System.Collections.Generic.KeyValuePair <string, object> entry in record.EntrySet())
            {
                string            key    = (entry).Key;
                object            @value = (entry).Value;
                Net.Vpc.Upa.Field field  = GetEntity().GetField(key);
                if (!field.IsUnspecifiedValue(@value))
                {
                    Net.Vpc.Upa.Expressions.Expression e = null;
                    Net.Vpc.Upa.Expressions.Var        p = new Net.Vpc.Upa.Expressions.Var(Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(alias) ? GetEntity().GetName() : alias);
                    switch (field.GetSearchOperator())
                    {
                    case Net.Vpc.Upa.SearchOperator.DEFAULT:
                    case Net.Vpc.Upa.SearchOperator.EQ:
                    {
                        if (field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType)
                        {
                            Net.Vpc.Upa.Types.ManyToOneType et   = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType();
                            Net.Vpc.Upa.Key foreignKey           = et.GetRelationship().GetTargetRole().GetEntity().GetBuilder().ObjectToKey(@value);
                            Net.Vpc.Upa.Expressions.Expression b = null;
                            int i = 0;
                            foreach (Net.Vpc.Upa.Field df in et.GetRelationship().GetSourceRole().GetFields())
                            {
                                e = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)p.Copy(), df.GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(foreignKey.GetObjectAt(i)));
                                b = b == null ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.And(b, e);
                                i++;
                            }
                        }
                        else
                        {
                            e = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value));
                        }
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.NE:
                    {
                        e = new Net.Vpc.Upa.Expressions.Different(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value));
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.GT:
                    {
                        e = new Net.Vpc.Upa.Expressions.GreaterThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value));
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.GTE:
                    {
                        e = new Net.Vpc.Upa.Expressions.GreaterEqualThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value));
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.LT:
                    {
                        e = new Net.Vpc.Upa.Expressions.LessThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value));
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.LTE:
                    {
                        e = new Net.Vpc.Upa.Expressions.LessEqualThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value));
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.CONTAINS:
                    {
                        e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral("%" + @value + "%"));
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.STARTS_WITH:
                    {
                        e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value + "%"));
                        break;
                    }

                    case Net.Vpc.Upa.SearchOperator.ENDS_WITH:
                    {
                        e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral("%" + @value));
                        break;
                    }
                    }
                    if (e != null)
                    {
                        a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(a, e);
                    }
                }
            }
            return(a);
        }
Пример #3
0
 private object GetNavigateKey(Net.Vpc.Upa.Entity entity, object id, char @operator) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> pk = entity.GetPrimaryFields();
     if ((pk).Count == 1)
     {
         Net.Vpc.Upa.Expressions.Select s = new Net.Vpc.Upa.Expressions.Select().From(entity.GetName());
         s.From(entity.GetName());
         string fieldName = pk[0].GetName();
         if (id != null)
         {
             object[] @value = entity.GetBuilder().IdToKey(id).GetValue();
             if (@operator == '<')
             {
                 s.Field(new Net.Vpc.Upa.Expressions.Max(new Net.Vpc.Upa.Expressions.Var(fieldName)), "next");
                 s.SetWhere(new Net.Vpc.Upa.Expressions.LessThan(new Net.Vpc.Upa.Expressions.Var(fieldName), new Net.Vpc.Upa.Expressions.Param(null, @value[0])));
             }
             else if (@operator == '>')
             {
                 s.Field(new Net.Vpc.Upa.Expressions.Min(new Net.Vpc.Upa.Expressions.Var(fieldName)), "next");
                 s.SetWhere(new Net.Vpc.Upa.Expressions.GreaterThan(new Net.Vpc.Upa.Expressions.Var(fieldName), new Net.Vpc.Upa.Expressions.Param(null, @value[0])));
             }
             else
             {
                 throw new System.Exception("WouldNeverBeThrownException");
             }
         }
         else
         {
             if (@operator == '<')
             {
                 s.Field(new Net.Vpc.Upa.Expressions.Min(new Net.Vpc.Upa.Expressions.Var(fieldName)), "next");
             }
             else if (@operator == '>')
             {
                 s.Field(new Net.Vpc.Upa.Expressions.Max(new Net.Vpc.Upa.Expressions.Var(fieldName)), "next");
             }
             else
             {
                 throw new System.Exception("WouldNeverBeThrownException");
             }
         }
         Net.Vpc.Upa.Record next = entity.GetPersistenceUnit().CreateQuery(s).GetRecord();
         if (next != null)
         {
             object o = next.GetObject <T>("next");
             if (o != null)
             {
                 return(entity.CreateId(o));
             }
         }
         return(null);
     }
     else
     {
         object[] v;
         Net.Vpc.Upa.Expressions.Select sb = new Net.Vpc.Upa.Expressions.Select();
         sb.Top(1);
         foreach (Net.Vpc.Upa.Field aPk in pk)
         {
             sb.Field(new Net.Vpc.Upa.Expressions.Var(aPk.GetName()));
         }
         sb.From(entity.GetName());
         if (id != null)
         {
             object[] @value = entity.GetBuilder().IdToKey(id).GetValue();
             Net.Vpc.Upa.Expressions.Expression or = null;
             for (int i = 0; i < (pk).Count; i++)
             {
                 Net.Vpc.Upa.Field pki = pk[i];
                 Net.Vpc.Upa.Expressions.Expression a = null;
                 for (int j = 0; j < i; j++)
                 {
                     Net.Vpc.Upa.Field pkj = pk[j];
                     Net.Vpc.Upa.Expressions.Expression e = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(pkj.GetName()), (new Net.Vpc.Upa.Expressions.Param(null, @value[j]))));
                     a = (a == null) ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(a, e);
                 }
                 Net.Vpc.Upa.Expressions.Expression e2 = new Net.Vpc.Upa.Expressions.LessThan(new Net.Vpc.Upa.Expressions.Var(pki.GetName()), new Net.Vpc.Upa.Expressions.Param(null, @value[i]));
                 a  = (a == null) ? ((Net.Vpc.Upa.Expressions.Expression)(e2)) : new Net.Vpc.Upa.Expressions.And(a, e2);
                 or = or == null ? ((Net.Vpc.Upa.Expressions.Expression)(a)) : new Net.Vpc.Upa.Expressions.Or(or, a);
             }
             sb.SetWhere(or);
         }
         foreach (Net.Vpc.Upa.Field aPk in pk)
         {
             sb.OrderBy(new Net.Vpc.Upa.Expressions.Var(aPk.GetName()), @operator == '>');
         }
         Net.Vpc.Upa.Record r = entity.GetPersistenceUnit().CreateQuery(sb).GetRecord();
         if (r != null)
         {
             object[] k = new object[(pk).Count];
             for (int i = 0; i < k.Length; i++)
             {
                 k[i] = r.GetObject <T>(pk[i].GetName());
             }
             return(entity.CreateId(k));
         }
     }
     return(null);
 }