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);
         }
     }
 }
Exemplo n.º 2
0
 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);
 }