public virtual bool IsAllowedKey(Net.Vpc.Upa.Entity e, string key) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (key == null) { return(true); } return(IsAllowedKey(e.GetPersistenceUnit().GetPersistenceGroup(), e.GetAbsoluteName() + "." + key)); }
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); }
private bool Build() { if (this.fieldNames == null) { idEntity = entity.GetPersistenceUnit().FindEntity(idType); if (idEntity != null) { isEntityKey = true; System.Collections.Generic.IList <string> fn = new System.Collections.Generic.List <string>(); // for (Field primaryField : entity.getPrimaryFields()) { // fn.add(primaryField.getName()); // } this.fieldNames = fn.ToArray(); } else { bnfo = Net.Vpc.Upa.Impl.Util.PlatformBeanTypeRepository.GetInstance().GetBeanType(idType); System.Collections.Generic.ISet <string> fn = bnfo.GetPropertyNames(); this.fieldNames = fn.ToArray(); } } return(isEntityKey); }
protected internal virtual object GetNewValue(Net.Vpc.Upa.Field field, Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Entity entity = field.GetEntity(); Net.Vpc.Upa.Entity seq = entity.GetPersistenceUnit().GetEntity(Net.Vpc.Upa.Impl.PrivateSequence.ENTITY_NAME); Net.Vpc.Upa.Impl.SequenceManager sm = new Net.Vpc.Upa.Impl.EntitySequenceManager(seq); string groupString = Eval(this.group, "{#}", record); // String fieldName = field.getName(); // while (true) { object nextValue = GetNewValue(sm, groupString, record); // long count = entity.getEntityCount(new Equals(new Var(fieldName), nextValue)); // if (count == 0) { return(nextValue); }
public FormulaUpdateProcessor(bool onPersist, System.Collections.Generic.IList <Net.Vpc.Upa.Field> fields, Net.Vpc.Upa.Expressions.Expression expr, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityOperationManager epm) { this.entityOperationManager = epm; this.entity = entity; this.expr = expr; this.context = context; this.onPersist = onPersist; this.persistenceUnit = entity.GetPersistenceUnit(); foreach (Net.Vpc.Upa.Field field in fields) { AddField(field); } isUpdateComplexValuesStatementSupported = persistenceUnit.GetPersistenceStore().GetProperties().GetBoolean("isUpdateComplexValuesStatementSupported", false); isUpdateComplexValuesIncludingUpdatedTableSupported = persistenceUnit.GetPersistenceStore().GetProperties().GetBoolean("isUpdateComplexValuesIncludingUpdatedTableSupported", false); }
public static Net.Vpc.Upa.Relationship GetTreeRelationName(Net.Vpc.Upa.Entity e) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Relationship r = null; foreach (Net.Vpc.Upa.Relationship relation in e.GetPersistenceUnit().GetRelationshipsBySource(e)) { if (relation.GetTargetRole().GetEntity().Equals(e)) { if (r != null) { throw new System.Exception("Ambiguity in resolving tree relation"); } r = relation; } } return(r); }
private bool ProcessRelation(bool throwErrors) { if (!Build(throwErrors)) { return(false); } Net.Vpc.Upa.PersistenceUnit pu = sourceEntity.GetPersistenceUnit(); if (relation == null) { Net.Vpc.Upa.DefaultRelationshipDescriptor rd = new Net.Vpc.Upa.DefaultRelationshipDescriptor(); rd.SetName(relationDescriptor.GetName()); rd.SetBaseField(relationDescriptor.GetBaseField()); rd.SetRelationshipType(relationDescriptor.GetRelationshipType()); rd.SetSourceEntity(sourceEntity.GetName()); rd.SetTargetEntity(targetEntity.GetName()); rd.SetSourceFields(sourceFieldNames.ToArray()); rd.SetFilter(relationDescriptor.GetFilter()); rd.SetHierarchy(relationDescriptor.IsHierarchy()); rd.SetHierarchyPathField(relationDescriptor.GetHierarchyPathField()); rd.SetHierarchyPathSeparator(relationDescriptor.GetHierarchyPathSeparator()); rd.SetNullable(relationDescriptor.IsNullable()); relation = ((Net.Vpc.Upa.Impl.DefaultPersistenceUnit)pu).AddRelationshipImmediate(rd); } else { if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(relationDescriptor.GetName())) { relation.SetName(relationDescriptor.GetName()); } relation.SetRelationshipType(relationDescriptor.GetRelationshipType() == default(Net.Vpc.Upa.RelationshipType) ? Net.Vpc.Upa.RelationshipType.DEFAULT : relationDescriptor.GetRelationshipType()); relation.GetSourceRole().SetEntityField(manyToOneField); relation.GetSourceRole().SetRelationshipUpdateType(sourceUpdateType); System.Collections.Generic.IList <Net.Vpc.Upa.Field> slaveFields = new System.Collections.Generic.List <Net.Vpc.Upa.Field>(); foreach (string n in sourceFieldNames) { Net.Vpc.Upa.Field f = sourceEntity.GetField(n); slaveFields.Add(f); } relation.GetSourceRole().SetFields(slaveFields.ToArray()); relation.GetTargetRole().SetEntityField(null); relation.GetTargetRole().SetRelationshipUpdateType(Net.Vpc.Upa.Impl.Util.PlatformUtils.GetUndefinedValue <Net.Vpc.Upa.RelationshipUpdateType>(typeof(Net.Vpc.Upa.RelationshipUpdateType))); relation.SetFilter(filter); relation.SetNullable(nullable); } return(true); }
private string GetNewValue(Net.Vpc.Upa.Field field) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Entity entity = field.GetEntity(); string idName = field.GetName(); Net.Vpc.Upa.Entity seq = entity.GetPersistenceUnit().GetEntity(Net.Vpc.Upa.Impl.PrivateSequence.ENTITY_NAME); Net.Vpc.Upa.Impl.SequenceManager sm = new Net.Vpc.Upa.Impl.EntitySequenceManager(seq); string sequenceGroup = Eval(field, this.group, "{#}"); while (true) { string nextIdString = Eval(field, this.format, sm.NextValue(name, sequenceGroup, this.initialValue, this.allocationSize)); long count = entity.GetEntityCount(new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(idName), nextIdString)); if (count == 0) { return(nextIdString); } } }
public virtual void Install(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityOperationManager entityOperationManager, Net.Vpc.Upa.Extensions.EntityExtensionDefinition spec) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { this.spec = spec; this.entity = entity; this.persistenceUnit = entity.GetPersistenceUnit(); }
public virtual bool IsLockedBySelf(string name, string pattern) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { return(IsLockedBy(name, pattern, entity.GetPersistenceUnit().GetUserPrincipal().GetName())); }
public virtual void FireBeforePersist(object objectId, Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { // Object methodExecId = Math.random(); // log.log(Level.FINE,"enter {} {}", new Object[]{key, record}); //Log.method_enter(methodExecId, getName(), key, record); // entity.preInsertRecord(key, record, context); Net.Vpc.Upa.Callbacks.PersistEvent @event = null; if (entity.GetPersistenceUnit().IsTriggersEnabled()) { foreach (Net.Vpc.Upa.Callbacks.Trigger et in entity.GetSoftTriggers()) { Net.Vpc.Upa.Impl.DefaultTrigger t = (Net.Vpc.Upa.Impl.DefaultTrigger)et; // Log.log(EditorConstants.Logs.TRIGGER, "<START " + getName() + ".firePreInsertTable> " + t.toString()); try { Net.Vpc.Upa.Callbacks.EntityListener li = t.GetListener(); if (@event == null) { @event = new Net.Vpc.Upa.Callbacks.PersistEvent(objectId, record, context, Net.Vpc.Upa.EventPhase.BEFORE); } @event.SetTrigger(et); li.OnPrePersist(@event); } catch (Net.Vpc.Upa.Exceptions.UPAException ex) { //do some thing log.TraceEvent(System.Diagnostics.TraceEventType.Error, 100, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("problem when executing trigger " + t.GetName() + ".onPrePersist(" + t.GetEntity().GetName() + "," + objectId + ")", ex)); // Log.bug(e); throw ex; } } } // Log.log(EditorConstants.Logs.TRIGGER, "<END " + getName() + ".firePreInsertTable> " + t.toString()); if (@event == null) { @event = new Net.Vpc.Upa.Callbacks.PersistEvent(objectId, record, context, Net.Vpc.Upa.EventPhase.BEFORE); } foreach (Net.Vpc.Upa.Callback invoker in persistenceUnitListenerManager.GetPreCallbacks(Net.Vpc.Upa.CallbackType.ON_PERSIST, Net.Vpc.Upa.ObjectType.ENTITY, @event.GetEntity().GetName(), Net.Vpc.Upa.Impl.Event.PersistenceUnitListenerManager.DEFAULT_SYSTEM)) { invoker.Invoke(@event); } foreach (Net.Vpc.Upa.PreparedCallback invoker in persistenceUnitListenerManager.GetPostPreparedCallbacks(Net.Vpc.Upa.CallbackType.ON_PERSIST, Net.Vpc.Upa.ObjectType.ENTITY, @event.GetEntity().GetName(), Net.Vpc.Upa.Impl.Event.PersistenceUnitListenerManager.DEFAULT_SYSTEM)) { invoker.Prepare(@event); } }
public virtual bool IsPersistEnabled() /* throws Net.Vpc.Upa.Exceptions.UPAException */ { return(IsPersistSupported() && entity.GetPersistenceUnit().GetSecurityManager().IsAllowedPersist(entity) && IsNoVeto(Net.Vpc.Upa.VetoableOperation.persistEnabled)); }
public override string GetSQL(object o, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledKeyEnumerationExpression ee = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledKeyEnumerationExpression)o; Net.Vpc.Upa.Entity entity = null; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar compiledVar = null; if (ee.GetAlias() != null) { compiledVar = ee.GetAlias(); entity = (compiledVar.GetReferrer() is Net.Vpc.Upa.Entity) ? ((Net.Vpc.Upa.Entity)compiledVar.GetReferrer()) : null; } else { //check if alias System.Collections.Generic.IList <Net.Vpc.Upa.Impl.Uql.ExpressionDeclaration> dvalues = ee.GetDeclarations(null); if (dvalues != null) { foreach (Net.Vpc.Upa.Impl.Uql.ExpressionDeclaration @ref in dvalues) { switch (@ref.GetReferrerType()) { case Net.Vpc.Upa.Impl.Uql.DecObjectType.ENTITY: { entity = qlContext.GetPersistenceUnit().GetEntity((string)@ref.GetReferrerName()); break; } } } } } if (entity == null) { throw new System.ArgumentException("Key enumeration must by associated to and entity"); } if ((ee.GetKeys().Count == 0)) { return(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(1), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(2)), qlContext, declarations)); } System.Collections.Generic.IList <Net.Vpc.Upa.Field> pfs = entity.GetPrimaryFields(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression o2 = null; foreach (object key in ee.GetKeys()) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression a = null; bool processed = false; if (entity.GetPersistenceUnit().ContainsEntity(entity.GetIdType())) { if (!entity.GetIdType().IsInstanceOfType(key)) { //primitive seen as entity? // A's id is A.b where b is an entity //TODO fix all cases! if ((entity.GetPrimaryFields()).Count == 1) { Net.Vpc.Upa.Types.ManyToOneType et = (Net.Vpc.Upa.Types.ManyToOneType)entity.GetPrimaryFields()[0].GetDataType(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> ff = et.GetRelationship().GetSourceRole().GetFields(); Net.Vpc.Upa.Key key2 = et.GetRelationship().GetTargetEntity().GetBuilder().IdToKey(key); for (int j = 0; j < (ff).Count; j++) { Net.Vpc.Upa.Field f = ff[j]; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar rr = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(f); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar p2 = compiledVar == null ? null : (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)compiledVar.Copy(); if (p2 == null) { p2 = rr; } else { p2.SetChild(rr); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals(p2, new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(key2.GetObjectAt(j), Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(f))); if (a == null) { a = v; } else { a = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAnd(a, v); } } if (o2 == null) { o2 = a; } else { o2 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledOr(o2, a); } processed = true; } } } if (!processed) { Net.Vpc.Upa.Key uKey = entity.GetBuilder().IdToKey(key); for (int j = 0; j < (pfs).Count; j++) { Net.Vpc.Upa.Field f = pfs[j]; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar rr = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(f); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar p2 = compiledVar == null ? null : (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)compiledVar.Copy(); if (p2 == null) { p2 = rr; } else { p2.SetChild(rr); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals(p2, new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(uKey.GetObjectAt(j), Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(f))); if (a == null) { a = v; } else { a = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAnd(a, v); } } if (o2 == null) { o2 = a; } else { o2 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledOr(o2, a); } } } return(sqlManager.GetSQL(o2, qlContext, declarations)); }
public override Net.Vpc.Upa.PersistenceUnit GetPersistenceUnit() { return(entity.GetPersistenceUnit()); }
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); }