private Net.Vpc.Upa.Query Build() { // if (query == null) { string entityName = entity.GetName(); Net.Vpc.Upa.Expressions.Select s = (new Net.Vpc.Upa.Expressions.Select()).From(entityName, entityAlias); if (GetFieldFilter() != null) { foreach (Net.Vpc.Upa.Field field in entity.GetFields(GetFieldFilter())) { if (field != null) { s.Field(new Net.Vpc.Upa.Expressions.Var(field.GetName()), field.GetName()); } } } Net.Vpc.Upa.Expressions.Expression criteria = null; if (GetId() != null) { Net.Vpc.Upa.Expressions.Expression e = entity.GetBuilder().IdToExpression(GetId(), entityName); criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e); } if (GetKey() != null) { Net.Vpc.Upa.Expressions.Expression e = (entity.GetBuilder().IdToExpression(entity.GetBuilder().KeyToId(GetKey()), entityName)); criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e); } if (GetPrototype() != null) { Net.Vpc.Upa.Expressions.Expression e = entity.GetBuilder().ObjectToExpression(GetPrototype(), true, entityName); criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e); } if (GetRecordPrototype() != null) { Net.Vpc.Upa.Expressions.Expression e = (entity.GetBuilder().RecordToExpression(GetRecordPrototype(), entityName)); criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e); } if (GetExpression() != null) { Net.Vpc.Upa.Expressions.Expression e = GetExpression(); criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e); } s.SetWhere(criteria); s.OrderBy(GetOrder()); query = entity.CreateQuery(s); foreach (System.Collections.Generic.KeyValuePair <string, object> e in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, object> >(paramsByName)) { query.SetParameter((e).Key, (e).Value); } foreach (System.Collections.Generic.KeyValuePair <int?, object> e in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <int?, object> >(paramsByIndex)) { query.SetParameter(((e).Key).Value, (e).Value); } query.SetUpdatable(this.IsUpdatable()); if (hints != null) { foreach (System.Collections.Generic.KeyValuePair <string, object> h in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, object> >(hints)) { query.SetHint((h).Key, (h).Value); } } // } return(query); }
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); }