public override Net.Vpc.Upa.Expressions.Expression Copy() { Net.Vpc.Upa.Expressions.Update o = new Net.Vpc.Upa.Expressions.Update(); o.AddQuery(this); // o.extraFrom = extraFrom; return(o); }
public Net.Vpc.Upa.Expressions.Update AddQuery(Net.Vpc.Upa.Expressions.Update other) { if (other == null) { return(this); } if (other.entity != null) { entity = (Net.Vpc.Upa.Expressions.EntityName)other.entity.Copy(); } if (other.entityAlias != null) { entityAlias = other.entityAlias; } for (int i = 0; i < (other.fields).Count; i++) { Set(other.GetField(i).GetName(), other.GetFieldValue(i)); } if (other.condition != null) { if (condition == null) { condition = other.condition.Copy(); } else { condition = new Net.Vpc.Upa.Expressions.And(condition, other.condition.Copy()); } } return(this); }
public virtual Net.Vpc.Upa.Impl.Persistence.QueryExecutor Execute() /* throws Net.Vpc.Upa.Exceptions.UPAException */ { int c1 = 0; int c2 = 0; string oldAlias = baseExpression.GetEntityAlias(); if (oldAlias == null) { oldAlias = entity.GetName(); } bool replaceThis = !"this".Equals(oldAlias); if (baseExpression.CountFields() > 0) { if (replaceThis) { Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.ReplaceThisVar(baseExpression, oldAlias, context.GetPersistenceUnit()); } c1 = defaultPersistenceStore.CreateDefaultExecutor(baseExpression, parametersByName, parametersByIndex, updatable, defaultFieldFilter, context).Execute().GetResultCount(); } if ((complexVals).Count > 0) { Net.Vpc.Upa.Expressions.Select q = new Net.Vpc.Upa.Expressions.Select(); foreach (Net.Vpc.Upa.Field primaryField in entity.GetPrimaryFields()) { q.Field(primaryField.GetName()); } foreach (Net.Vpc.Upa.Expressions.VarVal f in complexVals) { Net.Vpc.Upa.Expressions.Expression fieldExpression = f.GetVal(); if (replaceThis) { Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.ReplaceThisVar(fieldExpression, oldAlias, context.GetPersistenceUnit()); } q.Field(fieldExpression, f.GetVar().GetName()); } q.From(entity.GetName(), oldAlias); Net.Vpc.Upa.Expressions.Expression cond = baseExpression.GetCondition(); q.SetWhere(cond == null ? null : cond.Copy()); Net.Vpc.Upa.EntityBuilder eb = entity.GetBuilder(); foreach (Net.Vpc.Upa.Record record in entity.GetPersistenceUnit().CreateQuery(q).GetRecordList()) { Net.Vpc.Upa.Expressions.Update u2 = new Net.Vpc.Upa.Expressions.Update(); u2.Entity(entityName); foreach (Net.Vpc.Upa.Expressions.VarVal f in complexVals) { string fname = f.GetVar().GetName(); u2.Set(fname, record.GetObject <T>(fname)); } Net.Vpc.Upa.Expressions.Expression exprId = eb.ObjectToIdExpression(record, oldAlias); u2.Where(exprId); c2 += defaultPersistenceStore.CreateDefaultExecutor(u2, parametersByName, parametersByIndex, updatable, defaultFieldFilter, context).Execute().GetResultCount(); } } resultCount = System.Math.Max(c1, c2); return(this); }
public CustomUpdateQueryExecutor(Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore defaultPersistenceStore, System.Collections.Generic.IDictionary <string, object> finalHints, Net.Vpc.Upa.Expressions.Update baseExpression, System.Collections.Generic.IDictionary <string, object> parametersByName, System.Collections.Generic.IDictionary <int?, object> parametersByIndex, bool updatable, Net.Vpc.Upa.Filters.FieldFilter defaultFieldFilter, Net.Vpc.Upa.Persistence.EntityExecutionContext context, System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.VarVal> complexVals, Net.Vpc.Upa.Entity entity, string entityName, Net.Vpc.Upa.Persistence.ResultMetaData metadata) { this.defaultPersistenceStore = defaultPersistenceStore; this.finalHints = finalHints; this.baseExpression = baseExpression; this.parametersByName = parametersByName; this.parametersByIndex = parametersByIndex; this.updatable = updatable; this.defaultFieldFilter = defaultFieldFilter; this.context = context; this.complexVals = complexVals; this.entity = entity; this.entityName = entityName; this.metadata = metadata; this.connection = context.GetConnection(); }
public Update(Net.Vpc.Upa.Expressions.Update other) : this() { AddQuery(other); }
protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate CompileUpdate(Net.Vpc.Upa.Expressions.Update 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.CompiledUpdate s = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate(); s.Entity(v.GetEntity().GetName()); Net.Vpc.Upa.Entity entity = manager.GetPersistenceUnit().GetEntity(v.GetEntity().GetName()); for (int i = 0; i < v.CountFields(); i++) { Net.Vpc.Upa.Expressions.Var fvar = v.GetField(i); Net.Vpc.Upa.Expressions.Expression fvalue = v.GetFieldValue(i); s.Set(entity.GetField(fvar.GetName()), manager.TranslateAny(fvalue, declarations)); } s.Where(manager.TranslateAny(v.GetCondition(), declarations)); return(s); }
public virtual int Update(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Record updates, Net.Vpc.Upa.Expressions.Expression condition) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Expressions.Update u = new Net.Vpc.Upa.Expressions.Update().Entity(entity.GetName()); foreach (string fieldName in updates.KeySet()) { Net.Vpc.Upa.Field f = entity.FindField(fieldName); if (f != null && Net.Vpc.Upa.Impl.Util.Filters.Fields2.UPDATE.Accept(f)) { object @value = updates.GetObject <T>(fieldName); if ((f.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType)) { Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)f.GetDataType(); if (e.IsUpdatable()) { Net.Vpc.Upa.Entity masterEntity = context.GetPersistenceUnit().GetEntity(e.GetTargetEntityName()); Net.Vpc.Upa.EntityBuilder mbuilder = masterEntity.GetBuilder(); if (@value is Net.Vpc.Upa.Expressions.Expression) { Net.Vpc.Upa.Expressions.Expression evalue; System.Collections.Generic.IList <Net.Vpc.Upa.Field> sfields = e.GetRelationship().GetSourceRole().GetFields(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> tfields = e.GetRelationship().GetTargetRole().GetFields(); for (int i = 0; i < (sfields).Count; i++) { Net.Vpc.Upa.Field fk = sfields[i]; Net.Vpc.Upa.Field fid = tfields[i]; evalue = ((Net.Vpc.Upa.Expressions.Expression)@value).Copy(); evalue = context.GetPersistenceUnit().GetExpressionManager().ParseExpression(evalue); if (evalue is Net.Vpc.Upa.Expressions.Select) { Net.Vpc.Upa.Expressions.Select svalue = (Net.Vpc.Upa.Expressions.Select)evalue; if (svalue.CountFields() != 1) { throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName()); } if (svalue.GetField(0).GetExpression() is Net.Vpc.Upa.Expressions.Var) { svalue.GetField(0).SetExpression(new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)svalue.GetField(0).GetExpression(), fid.GetName())); } else { throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName()); } } else if (evalue is Net.Vpc.Upa.Expressions.Var) { evalue = (new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)evalue, fk.GetName())); } else if (evalue is Net.Vpc.Upa.Expressions.Param) { } else if (evalue is Net.Vpc.Upa.Expressions.Literal) { } else { throw new System.Exception("Invalid Expression " + evalue + " as formula for field " + f.GetAbsoluteName()); } u.Set(fk.GetName(), evalue); } } else { Net.Vpc.Upa.Key k = null; if (@value is Net.Vpc.Upa.Record) { k = mbuilder.RecordToKey((Net.Vpc.Upa.Record)@value); } else { k = mbuilder.ObjectToKey(@value); } int x = 0; foreach (Net.Vpc.Upa.Field fk in e.GetRelationship().GetSourceRole().GetFields()) { u.Set(fk.GetName(), new Net.Vpc.Upa.Expressions.Param(fk.GetName(), k == null ? null : k.GetObjectAt(x))); x++; } } } } else { Net.Vpc.Upa.Expressions.Expression expression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(null, @value); u.Set(fieldName, expression); } } } u.Where(condition); return(context.GetPersistenceStore().CreateQuery(u, context).ExecuteNonQuery()); }
public virtual Net.Vpc.Upa.Query CreateQuery(Net.Vpc.Upa.Entity e, Net.Vpc.Upa.Expressions.Update query, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { return(context.GetPersistenceStore().CreateQuery(e, query, context)); }