public virtual Net.Vpc.Upa.Expressions.Expression GetViewElementExpressionAt(int updatableTableIndex, Net.Vpc.Upa.Expressions.Expression expression) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { System.Collections.Generic.IList <Net.Vpc.Upa.Field> pf = GetEntity().GetPrimaryFields(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> pft = updatableTables[updatableTableIndex].GetPrimaryFields(); Net.Vpc.Upa.Expressions.Expression[] pfte = new Net.Vpc.Upa.Expressions.Expression[(pft).Count]; for (int i = 0; i < pfte.Length; i++) { Net.Vpc.Upa.Field f = pft[i]; pfte[i] = new Net.Vpc.Upa.Expressions.Var(f.GetName()); } Net.Vpc.Upa.Expressions.Uplet ut = new Net.Vpc.Upa.Expressions.Uplet(pfte); Net.Vpc.Upa.Expressions.Expression[] pfe = new Net.Vpc.Upa.Expressions.Expression[(pf).Count - 1]; for (int i = 0; i < pfe.Length; i++) { Net.Vpc.Upa.Field f = pf[i + 1]; pfe[i] = new Net.Vpc.Upa.Expressions.Var(f.GetName()); } Net.Vpc.Upa.Expressions.Expression w = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(pf[0].GetName()), new Net.Vpc.Upa.Expressions.Literal(updatableTables[updatableTableIndex].GetName())); if (expression != null) { w = new Net.Vpc.Upa.Expressions.And(w, expression); } Net.Vpc.Upa.Expressions.Select q = new Net.Vpc.Upa.Expressions.Select().From(GetEntity().GetName()).Uplet(pfe).Where(w); return(new Net.Vpc.Upa.Expressions.InSelection(ut, q)); }
public virtual Net.Vpc.Upa.Impl.Persistence.RebuildExpressionInfo RebuildExpression(Net.Vpc.Upa.ExpressionFormula persistFormula) { Net.Vpc.Upa.Expressions.Expression e = ((Net.Vpc.Upa.ExpressionFormula)persistFormula).GetExpression(); Net.Vpc.Upa.Impl.Persistence.RebuildExpressionInfo rr = new Net.Vpc.Upa.Impl.Persistence.RebuildExpressionInfo(); rr.initialFormula = ((Net.Vpc.Upa.ExpressionFormula)persistFormula); Net.Vpc.Upa.Expressions.Expression e0 = e; Net.Vpc.Upa.Persistence.ExpressionCompilerConfig config = new Net.Vpc.Upa.Persistence.ExpressionCompilerConfig(); config.SetExpandEntityFilter(false); //this is needed not to fire "this" alias usage exception config.SetThisAlias("this"); config.BindAliastoEntity("this", field.GetEntity().GetName()); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression ce = null; Net.Vpc.Upa.ExpressionManager expressionManager = field.GetEntity().GetPersistenceUnit().GetExpressionManager(); try { ce = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression)expressionManager.CompileExpression(e, config); } catch (System.ArgumentException ex) { if ((ex).Message.StartsWith("No enclosing Select found for")) { Net.Vpc.Upa.Expressions.Select ss = new Net.Vpc.Upa.Expressions.Select(); ss.Field(e).From(field.GetEntity().GetName(), "this2"); Net.Vpc.Upa.Expressions.Expression w = null; foreach (Net.Vpc.Upa.Field primaryField in field.GetEntity().GetPrimaryFields()) { Net.Vpc.Upa.Expressions.Expression pfe = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.UserExpression("this." + primaryField.GetName()), new Net.Vpc.Upa.Expressions.UserExpression("this2." + primaryField.GetName())); if (w == null) { w = pfe; } else { w = new Net.Vpc.Upa.Expressions.And(w, pfe); } } Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.ReplaceThisVar(ss, "this2", expressionManager); ss.Where(w); e = ss; } else { throw ex; } } //throw new IllegalArgumentException("No enclosing Select found for " + v) if (ce == null) { ce = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression)expressionManager.CompileExpression(e, config); rr.compiledExpression = ce; rr.rebuiltFormula = (new Net.Vpc.Upa.ExpressionFormula(e)); } else { rr.compiledExpression = ce; } rr.expression = e; return(rr); }
public override void OnPreUpdateFormula(Net.Vpc.Upa.Callbacks.UpdateFormulaEvent @event) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext = @event.GetContext(); Net.Vpc.Upa.Relationship r = relation; System.Collections.Generic.IList <Net.Vpc.Upa.Field> fs = r.GetSourceRole().GetFields(); Net.Vpc.Upa.Expressions.Expression cond = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(fs[0].GetName()), Net.Vpc.Upa.Expressions.Literal.NULL); if (@event.GetFilterExpression() != null) { cond = new Net.Vpc.Upa.Expressions.And(cond, @event.GetFilterExpression()); } System.Collections.Generic.IList <object> keys = relation.GetSourceRole().GetEntity().CreateQueryBuilder().ByExpression(cond).GetIdList <K>(); foreach (object key in keys) { support.ValidatePathField(key, executionContext); support.ValidateChildren(key, executionContext); } }
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"); }
public override sealed void OnUpdate(Net.Vpc.Upa.Callbacks.UpdateEvent @event) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { // validate old references Net.Vpc.Upa.Persistence.EntityExecutionContext executioncontext = @event.GetContext(); string name = @event.GetTrigger().GetName(); System.Collections.Generic.ICollection <Net.Vpc.Upa.Key> collection = executioncontext.GetObject <T>(name + ":toUpdate"); if (collection == null) { return; } executioncontext.Remove(name + ":toUpdate"); Net.Vpc.Upa.Expressions.IdCollectionExpression inColl = null; if (!(collection.Count == 0)) { inColl = CreateInCollection(@event.GetEntity(), collection); AfterUpdateHelper(@event, inColl); } // validate old references if (AcceptUpdateTableOlderValuesHelper(@event)) { Net.Vpc.Upa.Expressions.Expression newUpdates = null; if (inColl != null) { Net.Vpc.Upa.Expressions.Expression translated = TranslateExpression(@event.GetFilterExpression()); if (translated != null) { newUpdates = new Net.Vpc.Upa.Expressions.And(new Net.Vpc.Upa.Expressions.Not(inColl), translated); } else { newUpdates = new Net.Vpc.Upa.Expressions.Not(inColl); } } else { newUpdates = TranslateExpression(@event.GetFilterExpression()); } AfterUpdateHelper(@event, newUpdates); } }
public virtual Net.Vpc.Upa.Expressions.Expression CreateFindEntityByMainPathExpression(string mainFieldPath, string entityAlias) { Net.Vpc.Upa.Entity entity = GetEntity(); Net.Vpc.Upa.RelationshipRole detailRole = GetTreeRelationship().GetSourceRole(); if (Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(mainFieldPath)) { return(null); } string mainFieldName = entity.GetMainField().GetName(); object mainFieldValue = null; object parent = null; string[] parentAndName = Net.Vpc.Upa.Impl.Util.StringUtils.Split(mainFieldPath, GetHierarchyPathSeparator()[0], false); if (parentAndName != null) { parent = FindEntityByMainPath(parentAndName[0]); mainFieldValue = parentAndName[1]; } else { mainFieldValue = mainFieldPath; } Net.Vpc.Upa.Expressions.Expression expr = null; if (entityAlias == null) { entityAlias = entity.GetName(); } expr = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entityAlias), mainFieldName), mainFieldValue); Net.Vpc.Upa.Key entityToKey = parent == null ? null : entity.GetBuilder().ObjectToKey(parent); System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = detailRole.GetFields(); for (int index = 0; index < (primaryFields).Count; index++) { Net.Vpc.Upa.Field field = primaryFields[index]; expr = new Net.Vpc.Upa.Expressions.And(expr, new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entityAlias), field.GetName()), entityToKey == null ? null : entityToKey.GetObjectAt(index))); } return(expr); }
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); }
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); }
public virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAnd CompileAnd(Net.Vpc.Upa.Expressions.And 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.CompiledAnd s = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAnd(left, right); // s.setDeclarationList(new ExpressionDeclarationList(declarations)); return(s); }