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 int Delete(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Expressions.Expression condition, bool recurse, Net.Vpc.Upa.RemoveTrace deleteInfo) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (entity.GetShield().IsTransient()) { return(0); } Net.Vpc.Upa.Expressions.Delete stmt = (new Net.Vpc.Upa.Expressions.Delete()).From(entity.GetName()).Where(condition); return(context.GetPersistenceStore().CreateQuery(stmt, context).ExecuteNonQuery()); }
public virtual int Reset(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (entity.GetShield().IsTransient()) { return(0); } Net.Vpc.Upa.Expressions.Delete stmt = (new Net.Vpc.Upa.Expressions.Delete()).From(entity.GetName()); return(context.GetPersistenceStore().CreateQuery(stmt, context).ExecuteNonQuery()); }
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 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); }
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); }
public virtual bool Accept(Net.Vpc.Upa.Entity entity) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { object source = entity.GetEntityDescriptor().GetSource(); if (rootClass != null && (source == null || !rootClass.IsAssignableFrom(source.GetType()))) { return(false); } Net.Vpc.Upa.EntityShield v = entity.GetShield(); if (IsAcceptCloneable() && !v.IsCloneSupported()) { return(false); } if (IsRejectCloneable() && v.IsCloneSupported()) { return(false); } if (IsAcceptKeyEditable() && !v.IsKeyEditionSupported()) { return(false); } if (IsRejectKeyEditable() && v.IsKeyEditionSupported()) { return(false); } if (IsAcceptRenamable() && !v.IsRenameSupported()) { return(false); } if (IsRejectRenamable() && v.IsRenameSupported()) { return(false); } if (IsAcceptClear() && !v.IsClearSupported()) { return(false); } if (IsRejectClear() && v.IsClearSupported()) { return(false); } if (IsAcceptDeletable() && !v.IsDeleteSupported()) { return(false); } if (IsRejectDeletable() && v.IsDeleteSupported()) { return(false); } try { if (IsAcceptEmpty() && !entity.IsEmpty()) { return(false); } } catch (Net.Vpc.Upa.Exceptions.UPAException e) { return(false); } try { if (IsRejectEmpty() && entity.IsEmpty()) { return(false); } } catch (Net.Vpc.Upa.Exceptions.UPAException e) { return(false); } if (IsAcceptPersistable() && !v.IsPersistSupported()) { return(false); } if (IsRejectPersistable() && v.IsPersistSupported()) { return(false); } if (IsAcceptNavigatable() && !v.IsNavigateSupported()) { return(false); } if (IsRejectNavigatable() && v.IsNavigateSupported()) { return(false); } // if(isAcceptPrintable() && !v.isPrintSupported()){ // return false; // } // if(isRejectPrintable() && v.isPrintSupported()){ // return false; // } if (IsAcceptKeyGeneratable() && !v.IsGeneratedId()) { return(false); } if (IsRejectKeyGeneratable() && v.IsGeneratedId()) { return(false); } if (IsAcceptSystem() && !v.IsSystem()) { return(false); } if (IsRejectSystem() && v.IsSystem()) { return(false); } if (IsAcceptPrivate() && !v.IsPrivate()) { return(false); } if (IsRejectPrivate() && v.IsPrivate()) { return(false); } if (IsAcceptTransient() && !v.IsTransient()) { return(false); } if (IsRejectTransient() && v.IsTransient()) { return(false); } if (IsAcceptUpdatable() && !v.IsUpdateSupported()) { return(false); } if (IsRejectUpdatable() && v.IsUpdateSupported()) { return(false); } if (IsAcceptValidatable() && !v.IsUpdateFormulaSupported()) { return(false); } if (IsRejectValidatable() && v.IsUpdateFormulaSupported()) { return(false); } return(true); }