public virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression CompileExpression(Net.Vpc.Upa.Expressions.Expression expression, Net.Vpc.Upa.Persistence.ExpressionCompilerConfig config) { if (/*IsLoggable=*/ true) { } //expected api 1.2.1 // log.log(Level.FINE,"Compiling Expression " + expression); if (expression == null) { throw new System.NullReferenceException("Null Expression could not be compiled"); } Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList dec = new Net.Vpc.Upa.Impl.Uql.DefaultExpressionDeclarationList(null); if (config.GetAliasToEntityContext() != null) { foreach (System.Collections.Generic.KeyValuePair <string, string> entry in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, string> >(config.GetAliasToEntityContext())) { // check entity existence persistenceUnit.GetEntity((entry).Value); dec.ExportDeclaration((entry).Key, Net.Vpc.Upa.Impl.Uql.DecObjectType.ENTITY, (entry).Value, null); } } Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression s = TranslateAny(expression, dec); if (s is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryStatement) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryStatement qs = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryStatement)s; System.Collections.Generic.IList <Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryField> fields = qs.GetFields(); for (int i = 0; i < (fields).Count; i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryField field = fields[i]; field.SetIndex(i); } } return(s); }
protected internal virtual Net.Vpc.Upa.Expressions.Expression EvalVar(Net.Vpc.Upa.Expressions.Var expression) { if (expression.GetApplier() == null) { //this is the very root string name = expression.GetName(); if (vars.ContainsKey(name)) { return(new Net.Vpc.Upa.Expressions.Literal(Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(vars, name), null)); } } else { Net.Vpc.Upa.Expressions.Expression x = expression.GetApplier(); // no need for evalVar() in post order DFS if (x is Net.Vpc.Upa.Expressions.Literal) { object v = ((Net.Vpc.Upa.Expressions.Literal)x).GetValue(); if (v == null) { return(Net.Vpc.Upa.Expressions.Literal.NULL); } else if (v is Net.Vpc.Upa.Record) { Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)v; return(new Net.Vpc.Upa.Expressions.Literal(r.GetObject <object>(expression.GetName()), null)); } else if (v is System.Collections.IDictionary) { System.Collections.IDictionary r = (System.Collections.IDictionary)v; return(new Net.Vpc.Upa.Expressions.Literal(Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue0(r, expression.GetName()), null)); } else { Net.Vpc.Upa.Entity entity = pu.GetEntity(v.GetType()); Net.Vpc.Upa.Field field = entity.GetField(expression.GetName()); Net.Vpc.Upa.Record r = entity.GetBuilder().ObjectToRecord(v); return(new Net.Vpc.Upa.Expressions.Literal(r.GetObject <object>(field.GetName()), null)); } } } return(expression); }
public virtual void Process() { Net.Vpc.Upa.Types.DataType dataType = field.GetDataType(); if (dataType is Net.Vpc.Upa.Impl.SerializableOrManyToOneType) { Net.Vpc.Upa.Impl.SerializableOrManyToOneType master = (Net.Vpc.Upa.Impl.SerializableOrManyToOneType)dataType; relationshipTargetEntityType = master.GetEntityType(); if (persistenceUnit.ContainsEntity(relationshipTargetEntityType)) { Net.Vpc.Upa.Entity tt = persistenceUnit.GetEntity(relationshipTargetEntityType); BindRelation(tt); } else { persistenceUnit.AddDefinitionListener(relationshipTargetEntityType, this, true); persistenceUnit.AddPersistenceUnitListener(this); } } }
public virtual void Insert(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Record originalRecord, Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.PersistenceUnit pu = context.GetPersistenceUnit(); Net.Vpc.Upa.Expressions.Insert insert = new Net.Vpc.Upa.Expressions.Insert().Into(entity.GetName()); foreach (System.Collections.Generic.KeyValuePair <string, object> entry in record.EntrySet()) { object @value = (entry).Value; string key = (entry).Key; Net.Vpc.Upa.Field field = entity.FindField(key); //should process specific entity fields if ((field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType)) { Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType(); if (e.IsUpdatable()) { Net.Vpc.Upa.Entity masterEntity = pu.GetEntity(e.GetTargetEntityName()); Net.Vpc.Upa.Key k = null; if (@value is Net.Vpc.Upa.Record) { k = masterEntity.GetBuilder().RecordToKey((Net.Vpc.Upa.Record)@value); } else { k = masterEntity.GetBuilder().ObjectToKey(@value); } int x = 0; foreach (Net.Vpc.Upa.Field fk in e.GetRelationship().GetSourceRole().GetFields()) { insert.Set(fk.GetName(), new Net.Vpc.Upa.Expressions.Param(fk.GetName(), k.GetObjectAt(x))); x++; } } } else { Net.Vpc.Upa.Expressions.Expression valueExpression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(field.GetName(), @value); insert.Set(key, valueExpression); } } context.GetPersistenceStore().CreateQuery(insert, context).ExecuteNonQuery(); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate)oo; Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore = context.GetPersistenceStore(); Net.Vpc.Upa.PersistenceUnit pu = context.GetPersistenceUnit(); Net.Vpc.Upa.Entity entity = pu.GetEntity(o.GetEntity().GetName()); // String persistenceName = persistenceStore.getPersistenceName(entity); System.Text.StringBuilder sb = new System.Text.StringBuilder("Update " + sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName()), context, declarations)); string tableAlias = o.GetEntityAlias(); if (tableAlias != null) { sb.Append(" "); sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(tableAlias), context, declarations)); } sb.Append(" Set "); bool isFirst = true; int max = o.CountFields(); for (int i = 0; i < max; i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar vv = o.GetField(i); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar ev = null; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar fv = null; if (vv.GetChild() == null) { ev = null; fv = vv; } else { ev = vv; fv = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)vv.GetChild(); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression fieldValue = o.GetFieldValue(i); // Object referrer = vv.getReferrer(); Net.Vpc.Upa.Field f = ((Net.Vpc.Upa.Field)fv.GetReferrer()); Net.Vpc.Upa.Entity entityManager = f.GetEntity(); System.Collections.Generic.IList <Net.Vpc.Upa.PrimitiveField> primFields = entityManager.ToPrimitiveFields <Net.Vpc.Upa.EntityPart>(new System.Collections.Generic.List <Net.Vpc.Upa.EntityPart>(new[] { (Net.Vpc.Upa.EntityPart)f })); foreach (Net.Vpc.Upa.PrimitiveField primField in primFields) { if (isFirst) { isFirst = false; } else { sb.Append(", "); } if (ev != null) { sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(ev.GetName()), context, declarations)).Append("."); } sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(primField), context, declarations)); sb.Append("=").Append("(").Append(sqlManager.GetSQL(fieldValue, context, declarations)).Append(")"); } } if (o.GetCondition() != null && o.GetCondition().IsValid()) { sb.Append(" Where ").Append(sqlManager.GetSQL(o.GetCondition(), context, declarations)); } if (persistenceStore.IsViewSupported() && entity.NeedsView() && o.GetEntity().IsUseView()) { string implicitTableAlias = persistenceStore.GetPersistenceName("IT_" + entity.GetName(), Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS); sb.Append(" "); sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName()), context, declarations)).Append(" ").Append(implicitTableAlias).Append(",").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName(), true), context, declarations)).Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(tableAlias), context, declarations)); } // if (extraFrom != null) return(sb.ToString()); }
protected internal virtual System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> CreateResultFields(Net.Vpc.Upa.Expressions.Expression expression, string alias, Net.Vpc.Upa.Filters.FieldFilter fieldFilter, System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context) { expression = expressionManager.ParseExpression(expression); System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> results = new System.Collections.Generic.List <Net.Vpc.Upa.Persistence.ResultField>(); if (expression is Net.Vpc.Upa.Expressions.Var) { Net.Vpc.Upa.Expressions.Var v = (Net.Vpc.Upa.Expressions.Var)expression; Net.Vpc.Upa.Expressions.Expression parent = v.GetApplier(); if (parent != null) { System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> parentResults = CreateResultFields(parent, null, fieldFilter, context); int size = (parentResults).Count; foreach (Net.Vpc.Upa.Persistence.ResultField p in parentResults) { if (size > 1) { v = (Net.Vpc.Upa.Expressions.Var)v.Copy(); } if (p.GetExpression() != parent) { //change parent v.SetApplier((Net.Vpc.Upa.Expressions.Var)p.GetExpression()); } if (p.GetEntity() != null) { if (v.GetName().Equals("*")) { foreach (Net.Vpc.Upa.Field field in p.GetEntity().GetFields(fieldFilter)) { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else { Net.Vpc.Upa.Field field = p.GetEntity().GetField(v.GetName()); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else if (p.GetField() != null) { if (p.GetField().GetDataType() is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Entity entity = ((Net.Vpc.Upa.Types.ManyToOneType)p.GetField().GetDataType()).GetTargetEntity(); if (v.GetName().Equals("*")) { foreach (Net.Vpc.Upa.Field field in entity.GetFields(fieldFilter)) { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else { Net.Vpc.Upa.Field field = entity.GetField(v.GetName()); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } } else { string name = v.GetName(); System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery> declarations = FindDeclarations(context); Net.Vpc.Upa.Expressions.NameOrQuery r = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Expressions.NameOrQuery>(declarations, name); if (r != null) { if (r is Net.Vpc.Upa.Expressions.EntityName) { Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName()); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, entity.GetDataType(), null, entity)); } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } else { if ("*".Equals(name)) { foreach (System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> entry in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> >(declarations)) { r = (entry).Value; if (r is Net.Vpc.Upa.Expressions.EntityName) { Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName()); Net.Vpc.Upa.Field field = entity.FindField(name); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); break; } } } else { Net.Vpc.Upa.Field field = null; foreach (System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> entry in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> >(declarations)) { r = (entry).Value; if (r is Net.Vpc.Upa.Expressions.EntityName) { Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName()); field = entity.FindField(name); break; } } if (field != null) { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } } } return(results); } results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(expression, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); return(results); }
public virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression TranslateExpression(object x, Net.Vpc.Upa.Impl.Uql.ExpressionTranslationManager manager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Expressions.IdExpression o = (Net.Vpc.Upa.Expressions.IdExpression)x; Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression ret = null; Net.Vpc.Upa.Entity entity = null; if (o.GetEntity() != null) { entity = o.GetEntity(); } Net.Vpc.Upa.PersistenceUnit persistenceUnit = manager.GetPersistenceUnit(); if (entity == null && o.GetEntityName() != null) { entity = persistenceUnit.GetEntity(o.GetEntityName()); } if (entity == null && o.GetAlias() != null) { //check if alias System.Collections.Generic.IList <Net.Vpc.Upa.Impl.Uql.ExpressionDeclaration> dvalues = declarations.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 = persistenceUnit.GetEntity((string)@ref.GetReferrerName()); break; } } } } } if (entity == null && o.GetAlias() != null) { //check if entity if (persistenceUnit.ContainsEntity(o.GetAlias())) { entity = persistenceUnit.GetEntity(o.GetAlias()); } } if (entity == null) { throw new System.ArgumentException("Key enumeration must by associated to and entity"); } Net.Vpc.Upa.Key key = entity.GetBuilder().IdToKey(o.GetId()); object[] values = key == null ? null : key.GetValue(); Net.Vpc.Upa.Entity entity1 = o.GetEntity(); System.Collections.Generic.IList <Net.Vpc.Upa.PrimitiveField> f = entity1.ToPrimitiveFields <Net.Vpc.Upa.Field>(entity1.GetPrimaryFields()); for (int i = 0; i < (f).Count; i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar ppp = o.GetAlias() == null ? null : new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(o.GetAlias()); if (ppp == null) { ppp = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(f[i].GetName()); } else { ppp.SetChild(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(f[i].GetName())); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals e = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals(ppp, new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(values == null ? null : values[i], Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(f[i]))); ret = (ret == null) ? ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression)(e)) : new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAnd(ret, e); } if (ret == null) { ret = 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(1)); } return(ret); }
public virtual Net.Vpc.Upa.Expressions.CompiledExpression Update(Net.Vpc.Upa.Expressions.CompiledExpression e) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.IsHierarchyDescendentCompiled o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.IsHierarchyDescendentCompiled)e; Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression c = o.GetChildExpression(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression p = o.GetAncestorExpression(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName n = o.GetEntityName(); Net.Vpc.Upa.Entity treeEntity = null; Net.Vpc.Upa.Field treeField = null; if (c is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar) { object childReferrer = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)c).GetFinest().GetReferrer(); if (childReferrer != null) { if (childReferrer is Net.Vpc.Upa.Entity) { if (treeEntity == null) { treeEntity = (Net.Vpc.Upa.Entity)childReferrer; } else { if (!treeEntity.GetName().Equals(((Net.Vpc.Upa.Entity)childReferrer).GetName())) { throw new System.ArgumentException("Ambiguous or Invalid Type " + treeEntity.GetName() + " in TreeEntity near " + e); } } } } } else if (c is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam) { object co = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam)c).GetValue(); if (co != null && persistenceUnit.ContainsEntity(co.GetType())) { Net.Vpc.Upa.Entity rr = persistenceUnit.GetEntity(co.GetType()); if (treeEntity == null) { treeEntity = rr; } ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam)c).SetValue(rr.GetBuilder().ObjectToId(co)); } } // Object co = ((CompiledParam) c).getEffectiveDataType(); if (p is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar) { object parentReferrer = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)p).GetFinest().GetReferrer(); if (parentReferrer != null) { if (parentReferrer is Net.Vpc.Upa.Entity) { if (treeEntity == null) { treeEntity = (Net.Vpc.Upa.Entity)parentReferrer; } else { if (!treeEntity.GetName().Equals(((Net.Vpc.Upa.Entity)parentReferrer).GetName())) { throw new System.ArgumentException("Ambiguous or Invalid Type " + treeEntity.GetName() + " in TreeEntity near " + e); } } } } } else if (p is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam) { object co = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam)p).GetValue(); if (co != null && persistenceUnit.ContainsEntity(co.GetType())) { Net.Vpc.Upa.Entity rr = persistenceUnit.FindEntity(co.GetType()); if (treeEntity == null) { treeEntity = rr; } ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam)p).SetValue(rr.GetBuilder().ObjectToId(co)); if ((rr.GetPrimaryFields()).Count > 1) { throw new System.ArgumentException("Not supported"); } ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam)p).SetTypeTransform(Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(rr.GetPrimaryFields()[0])); } } // Object co = ((CompiledParam) c).getEffectiveDataType(); if (treeEntity == null) { treeEntity = persistenceUnit.GetEntity(n.GetName()); } Net.Vpc.Upa.Relationship t = Net.Vpc.Upa.Impl.Extension.HierarchicalRelationshipSupport.GetTreeRelationName(treeEntity); if (t == null) { throw new System.ArgumentException("Hierarchy Relationship not found"); } Net.Vpc.Upa.Extensions.HierarchyExtension s = t.GetHierarchyExtension(); if (s == null) { throw new System.ArgumentException("Not a valid TreeEntity"); } Net.Vpc.Upa.Field pathField = treeEntity.GetField(s.GetHierarchyPathField()); string pathSep = s.GetHierarchyPathSeparator(); return(CreateConditionForDeepSearch(c, (Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression)p, true, pathField, pathSep)); }
private bool Build(bool throwErrors) { if (sourceEntity == null) { if (relationDescriptor.GetSourceEntity() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetSourceEntity())) { sourceEntity = persistenceUnit.GetEntity(relationDescriptor.GetSourceEntity()); } } } if (sourceEntity == null) { if (relationDescriptor.GetSourceEntityType() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetSourceEntityType())) { sourceEntity = persistenceUnit.GetEntity(relationDescriptor.GetSourceEntityType()); } } } if (targetEntity == null) { if (relationDescriptor.GetTargetEntity() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetTargetEntity())) { targetEntity = persistenceUnit.GetEntity(relationDescriptor.GetTargetEntity()); } } } if (targetEntity == null) { if (relationDescriptor.GetTargetEntityType() != null) { if (persistenceUnit.ContainsEntity(relationDescriptor.GetTargetEntityType())) { targetEntity = persistenceUnit.GetEntity(relationDescriptor.GetTargetEntityType()); } } } if (sourceEntity == null) { if (throwErrors) { throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidRelationEntityNotFound", relationDescriptor.GetSourceEntityType()); } else { return(false); } } if (targetEntity == null) { if (throwErrors) { throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidRelationEntityNotFound", relationDescriptor.GetTargetEntityType()); } else { return(false); } } sourceUpdateType = Net.Vpc.Upa.RelationshipUpdateType.FLAT; sourceFieldNames = new System.Collections.Generic.List <string>(); if (relationDescriptor.GetBaseField() == null) { Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(sourceFieldNames, new System.Collections.Generic.List <string>(relationDescriptor.GetSourceFields())); if (relationDescriptor.GetMappedTo() != null && relationDescriptor.GetMappedTo().Length > 0) { if (relationDescriptor.GetMappedTo().Length > 1) { throw new System.ArgumentException("mappedTo cannot only apply to single Entity Field"); } manyToOneField = sourceEntity.GetField(relationDescriptor.GetMappedTo()[0]); } } else { Net.Vpc.Upa.Field baseField = sourceEntity.GetField(relationDescriptor.GetBaseField()); Net.Vpc.Upa.Types.DataType baseFieldType = baseField.GetDataType(); if (baseFieldType is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Types.ManyToOneType et = (Net.Vpc.Upa.Types.ManyToOneType)baseFieldType; if (et.GetTargetEntityName() == null || (et.GetTargetEntityName().Length == 0)) { et.SetTargetEntityName(targetEntity.GetName()); } sourceUpdateType = Net.Vpc.Upa.RelationshipUpdateType.COMPOSED; System.Collections.Generic.IList <Net.Vpc.Upa.Field> masterPK = targetEntity.GetPrimaryFields(); if (relationDescriptor.GetMappedTo() == null || relationDescriptor.GetMappedTo().Length == 0) { if ((masterPK.Count == 0)) { if (throwErrors) { throw new Net.Vpc.Upa.Exceptions.UPAException("PrimaryFieldsNotFoundException", targetEntity.GetName()); } else { return(false); } } else { foreach (Net.Vpc.Upa.Field masterField in masterPK) { string f = masterField.GetName(); if ((f).Length == 1) { f = f.ToUpper(); } else if ((f).Length > 1) { f = f.Substring(0, 1).ToUpper() + f.Substring(1); } string extraName = baseField.GetName() + f; sourceFieldNames.Add(extraName); } } } else { Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(sourceFieldNames, new System.Collections.Generic.List <string>(relationDescriptor.GetMappedTo())); } if ((sourceFieldNames).Count != (masterPK).Count) { if (throwErrors) { throw new System.ArgumentException("Incorrect parameters"); } else { return(false); } } if ((sourceFieldNames.Count == 0)) { if (throwErrors) { throw new System.ArgumentException("Incorrect parameters"); } else { return(false); } } for (int i = 0; i < (sourceFieldNames).Count; i++) { string extraName = sourceFieldNames[i]; Net.Vpc.Upa.Field idField = sourceEntity.FindField(extraName); if (idField == null) { Net.Vpc.Upa.Types.DataType dt = (Net.Vpc.Upa.Types.DataType)masterPK[i].GetDataType().Copy(); bool nullable = baseFieldType.IsNullable(); dt.SetNullable(nullable); idField = sourceEntity.AddField(extraName, "system", Net.Vpc.Upa.FlagSets.Of <E>(Net.Vpc.Upa.UserFieldModifier.SYSTEM), Net.Vpc.Upa.FlagSets.Of <E>(Net.Vpc.Upa.UserFieldModifier.UPDATE), null, dt, -1); idField.SetAccessLevel(Net.Vpc.Upa.AccessLevel.PRIVATE); } else { idField.SetUserExcludeModifiers(idField.GetUserExcludeModifiers().Add(Net.Vpc.Upa.UserFieldModifier.UPDATE)); } } manyToOneField = baseField; } else { sourceFieldNames.Add(baseField.GetName()); if (relationDescriptor.GetMappedTo() != null && relationDescriptor.GetMappedTo().Length > 0) { if (relationDescriptor.GetMappedTo().Length > 1) { throw new System.ArgumentException("mappedTo cannot only apply to single Entity Field"); } manyToOneField = sourceEntity.GetField(relationDescriptor.GetMappedTo()[0]); } } } nullable = true; //TODO FIX ME for (int i = 0; i < (sourceFieldNames).Count; i++) { Net.Vpc.Upa.Field slaveField = sourceEntity.GetField(sourceFieldNames[i]); Net.Vpc.Upa.Types.DataType dataType = slaveField.GetDataType(); if (dataType == null) { //inherit master DataType if ((targetEntity.GetPrimaryFields()).Count > i) { Net.Vpc.Upa.Types.DataType d = targetEntity.GetPrimaryFields()[i].GetDataType(); d = (Net.Vpc.Upa.Types.DataType)d.Copy(); d.SetNullable(nullable); slaveField.SetDataType(d); //reset transform! slaveField.SetTypeTransform(null); } else { throw new System.ArgumentException("Invalid Relation"); } } } filter = relationDescriptor.GetFilter(); // if (baseFieldType instanceof ManyToOneType) { // manyToOneField = baseField; // } else if (sourceFieldNames.size() == 1) { // DataType slaveType = slaveField.getDataType(); // if (slaveType instanceof ManyToOneType) { // manyToOneField = slaveField; // } // } return(true); }