public virtual Net.Vpc.Upa.QualifiedIdentifier GetViewElementKey(Net.Vpc.Upa.QualifiedIdentifier viewKey) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Entity viewElementTable = GetPersistenceUnit().GetEntity(viewKey.GetKey().GetStringAt(0)); System.Collections.Generic.IList <Net.Vpc.Upa.Field> fields = viewElementTable.GetPrimaryFields(); object[] elemKeyVals = new object[(fields).Count]; object[] viewKeyVals = viewKey.GetKey().GetValue(); System.Array.Copy(viewKeyVals, 1, elemKeyVals, 0, elemKeyVals.Length); return(new Net.Vpc.Upa.QualifiedIdentifier(viewElementTable, viewElementTable.CreateId(elemKeyVals))); }
public override K Parse(Net.Vpc.Upa.Persistence.QueryResult result) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { object[] keyObj = new object[columns]; for (int i = 0; i < columns; i++) { keyObj[i] = result.Read <T>(i); } return((K)entity.CreateId(keyObj)); }
public virtual Net.Vpc.Upa.Impl.PrivateSequence GetOrCreateSequence(string name, string pattern, int initialValue, int increment) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { // System.out.println(">>>>>>>>>>>>>>>>>>> getOrCreateSequence("+name+","+pattern+")"); Net.Vpc.Upa.Impl.PrivateSequence r = entity.CreateQueryBuilder().ById(entity.CreateId(name, pattern)).GetEntity <R>(); if (r == null) { CreateSequence(name, pattern, initialValue, increment); r = entity.CreateQueryBuilder().ById(entity.CreateId(name, pattern)).GetEntity <R>(); } return(r); }
public override object GetObjectForArray(object[] @value) { return(entity.CreateId(@value)); }
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); }
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); }