Ejemplo n.º 1
0
 public virtual object CreateId(params object [] idValues)
 {
     if ((entity.GetPrimaryFields()).Count != idValues.Length)
     {
         throw new System.ArgumentException("Invalid Key Size. Expected " + (entity.GetPrimaryFields()).Count + " but found " + idValues.Length);
     }
     return(new Net.Vpc.Upa.Impl.DefaultKey(idValues));
 }
Ejemplo n.º 2
0
        public virtual R IdToObject <R>(object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            if (id == null)
            {
                return(default(R));
            }
            Net.Vpc.Upa.Entity entity = GetEntity();
            R r = CreateObject <R>();

            Net.Vpc.Upa.Record ur = ObjectToRecord(r, true);
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = entity.GetPrimaryFields();
            if (id == null)
            {
                foreach (Net.Vpc.Upa.Field aF in primaryFields)
                {
                    ur.SetObject(aF.GetName(), null);
                }
            }
            else
            {
                object[] uk = entity.GetBuilder().GetKey(id).GetValue();
                for (int i = 0; i < (primaryFields).Count; i++)
                {
                    ur.SetObject(primaryFields[i].GetName(), uk[i]);
                }
            }
            return(r);
        }
Ejemplo n.º 3
0
 public override string GetDescription()
 {
     if (desc == null)
     {
         try {
             Net.Vpc.Upa.Entity _entity = GetEntity();
             Net.Vpc.Upa.Key    ukey    = _entity.GetBuilder().IdToKey(key);
             System.Collections.Generic.IList <Net.Vpc.Upa.Field> f = _entity.GetPrimaryFields();
             System.Text.StringBuilder descsb = new System.Text.StringBuilder();
             object[] values = ukey.GetValue();
             for (int i = 0; i < (f).Count; i++)
             {
                 if (i > 0)
                 {
                     descsb.Append(" ");
                     descsb.Append(" and ");
                     descsb.Append(" ");
                 }
                 if (values[i] == null)
                 {
                     descsb.Append(f[i].GetI18NString()).Append(" undefined operator ");
                 }
                 else
                 {
                     descsb.Append(f[i].GetI18NString()).Append(" = ").Append(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(values[i], Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(f[i])).ToString());
                 }
             }
             desc = descsb.ToString();
         } catch (Net.Vpc.Upa.Exceptions.UPAException ex) {
             desc = "";
         }
     }
     return(desc);
 }
 private Net.Vpc.Upa.Expressions.IdCollectionExpression CreateInCollection(Net.Vpc.Upa.Entity entity, System.Collections.Generic.ICollection <Net.Vpc.Upa.Key> collection) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> pfs = entity.GetPrimaryFields();
     Net.Vpc.Upa.Expressions.Var[] v = new Net.Vpc.Upa.Expressions.Var[(pfs).Count];
     for (int i = 0; i < (pfs).Count; i++)
     {
         v[i] = new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(pfs[i].GetEntity().GetName()), pfs[i].GetName());
     }
     if ((pfs).Count == 1)
     {
         Net.Vpc.Upa.Expressions.IdCollectionExpression inColl = new Net.Vpc.Upa.Expressions.IdCollectionExpression(v[0]);
         //inColl.setClientProperty(DefaultEntity.EXPRESSION_SURELY_EXISTS, true);
         foreach (Net.Vpc.Upa.Key k in collection)
         {
             inColl.Add(new Net.Vpc.Upa.Expressions.Literal(k.GetObject(), pfs[0].GetDataType()));
         }
         return(inColl);
     }
     else
     {
         Net.Vpc.Upa.Expressions.IdCollectionExpression inColl = new Net.Vpc.Upa.Expressions.IdCollectionExpression(v);
         //inColl.setClientProperty(DefaultEntity.EXPRESSION_SURELY_EXISTS, true);
         foreach (Net.Vpc.Upa.Key k in collection)
         {
             Net.Vpc.Upa.Expressions.Literal[] l = new Net.Vpc.Upa.Expressions.Literal[(pfs).Count];
             for (int j = 0; j < (pfs).Count; j++)
             {
                 l[j] = new Net.Vpc.Upa.Expressions.Literal(k.GetObjectAt(j), pfs[j].GetDataType());
             }
             inColl.Add(l);
         }
         return(inColl);
     }
 }
Ejemplo n.º 5
0
 public virtual Net.Vpc.Upa.Key ObjectToKey(object @object) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (@object == null)
     {
         return(null);
     }
     if (@object is Net.Vpc.Upa.Record)
     {
         return(RecordToKey((Net.Vpc.Upa.Record)@object));
     }
     Net.Vpc.Upa.Entity entity = GetEntity();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> f = entity.GetPrimaryFields();
     object[] rawKey = new object[(f).Count];
     for (int i = 0; i < rawKey.Length; i++)
     {
         Net.Vpc.Upa.Field field = f[i];
         string            name  = field.GetName();
         if (!entity.GetBeanType().IsDefaultValue(@object, name))
         {
             rawKey[i] = GetProperty(@object, name);
         }
         else
         {
             return(null);
         }
     }
     return(entity.GetBuilder().CreateKey(rawKey));
 }
Ejemplo n.º 6
0
 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)));
 }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 private static string[] ConstructorFieldNames(Net.Vpc.Upa.Entity entity) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = entity.GetPrimaryFields();
     string[] fs = new string[(primaryFields).Count];
     for (int i = 0; i < fs.Length; i++)
     {
         fs[i] = primaryFields[i].GetName();
     }
     return(fs);
 }
Ejemplo n.º 9
0
 private static Net.Vpc.Upa.Types.DataType[] ConstructorFieldTypes(Net.Vpc.Upa.Entity entity) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = entity.GetPrimaryFields();
     Net.Vpc.Upa.Types.DataType[] dt = new Net.Vpc.Upa.Types.DataType[(primaryFields).Count];
     for (int i = 0; i < dt.Length; i++)
     {
         dt[i] = primaryFields[i].GetDataType();
     }
     return(dt);
 }
Ejemplo n.º 10
0
 public override object GetValue(Net.Vpc.Upa.Entity entity, string fieldName) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> f = entity.GetPrimaryFields();
     for (int i = 0; i < (f).Count; i++)
     {
         if (f[i].GetName().Equals(fieldName))
         {
             return(@value[i]);
         }
     }
     throw new System.ArgumentException("Either key " + ToString() + " or fieldName " + fieldName + " does not refer to entity " + entity.GetName());
 }
Ejemplo n.º 11
0
 public virtual object GetValue(string fieldName) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> f = entity.GetPrimaryFields();
     Net.Vpc.Upa.Key uKey = GetKey();
     for (int i = 0; i < (f).Count; i++)
     {
         if (f[i].GetName().Equals(fieldName))
         {
             return(uKey.GetObjectAt(i));
         }
     }
     throw new Net.Vpc.Upa.Exceptions.IllegalArgumentException("Either key " + ToString() + " or fieldName " + fieldName + " does not refer to entity " + entity.GetName());
 }
Ejemplo n.º 12
0
 public virtual string ViewElementFieldToViewField(Net.Vpc.Upa.Entity viewElementTable, string viewElementField) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> pf            = viewElementTable.GetPrimaryFields();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = GetEntity().GetPrimaryFields();
     for (int i = 0; i < (pf).Count; i++)
     {
         if (viewElementField.Equals(pf[i].GetName()))
         {
             return(primaryFields[i + 1].GetName());
         }
     }
     return(null);
 }
Ejemplo n.º 13
0
 public override void CommitModelChanges() /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity entity = GetEntity();
     if ((entity.GetPrimaryFields().Count == 0))
     {
         Net.Vpc.Upa.Field field = entity.AddField("SGLcode", null, Net.Vpc.Upa.FlagSets.Of <E>(Net.Vpc.Upa.UserFieldModifier.ID), null, 0, new Net.Vpc.Upa.Types.IntType(0, 0, false, false), -1);
         field.SetAccessLevel(Net.Vpc.Upa.AccessLevel.PRIVATE);
         field.SetPersistFormula(new Net.Vpc.Upa.Sequence(Net.Vpc.Upa.SequenceStrategy.AUTO));
     }
     if (!entity.GetUserExcludeModifiers().Contains(Net.Vpc.Upa.EntityModifier.NAVIGATE))
     {
         entity.GetModifiers().Add(Net.Vpc.Upa.EntityModifier.NAVIGATE);
     }
 }
Ejemplo n.º 14
0
 public virtual bool IsGeneratedId()
 {
     foreach (Net.Vpc.Upa.Field field in entity.GetPrimaryFields())
     {
         if (field.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST_FORMULA))
         {
             if (field.GetPersistFormula() is Net.Vpc.Upa.Sequence)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 15
0
 public override void Persist(Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, Net.Vpc.Upa.PersistenceState status) /* throws System.Exception, Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity entity = (Net.Vpc.Upa.Entity)@object;
     Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore store = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)executionContext.GetPersistenceStore();
     if ((entity.GetPrimaryFields()).Count > 0)
     {
         log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Commit {0} / {1} : found {2}, persist", null, new object[] { @object, typedObject, status }));
         Net.Vpc.Upa.Persistence.UConnection b = executionContext.GetConnection();
         foreach (Net.Vpc.Upa.PrimitiveField primaryField in entity.GetPrimitiveFields(Net.Vpc.Upa.Filters.Fields.Id()))
         {
             Net.Vpc.Upa.Impl.Persistence.ColumnDesc cd = store.LoadColumnDesc(primaryField, b.GetMetadataAccessibleConnection());
             if (cd.IsNullable() != null && (cd.IsNullable()).Value)
             {
                 b.ExecuteNonQuery(store.GetAlterTableAlterColumnNullStatement(primaryField, false), null, null);
             }
         }
         b.ExecuteNonQuery(store.GetCreateTablePKConstraintStatement(entity), null, null);
     }
 }
Ejemplo n.º 16
0
 public virtual Net.Vpc.Upa.Record IdToRecord(object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (id == null)
     {
         return(null);
     }
     Net.Vpc.Upa.Entity entity = GetEntity();
     Net.Vpc.Upa.Record ur     = CreateRecord();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = entity.GetPrimaryFields();
     //        if (k == null) {
     //            for (Field aF : primaryFields) {
     //                ur.setObject(aF.getName(), null);
     //            }
     //        } else {
     object[] uk = entity.GetBuilder().GetKey(id).GetValue();
     for (int i = 0; i < (primaryFields).Count; i++)
     {
         ur.SetObject(primaryFields[i].GetName(), uk[i]);
     }
     //        }
     return(ur);
 }
Ejemplo n.º 17
0
 public virtual Net.Vpc.Upa.Key RecordToKey(Net.Vpc.Upa.Record record) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (record == null)
     {
         return(null);
     }
     Net.Vpc.Upa.Entity entity = GetEntity();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> f = entity.GetPrimaryFields();
     object[] rawKey = new object[(f).Count];
     for (int i = 0; i < rawKey.Length; i++)
     {
         Net.Vpc.Upa.Field field = f[i];
         string            name  = field.GetName();
         if (record.IsSet(name))
         {
             rawKey[i] = record.GetObject <T>(name);
         }
         else
         {
             return(entity.GetBuilder().CreateKey((object[])null));
         }
     }
     return(entity.GetBuilder().CreateKey(rawKey));
 }
Ejemplo n.º 18
0
        public virtual void CommitModelChanged() /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Entity sourceEntity = GetSourceRole().GetEntity();
            Net.Vpc.Upa.Entity targetEntity = GetTargetRole().GetEntity();
            if (sourceEntity == null || targetEntity == null)
            {
                throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidRelationDefinition");
            }
            if (!sourceEntity.GetUserExcludeModifiers().Contains(Net.Vpc.Upa.EntityModifier.VALIDATE_PERSIST))
            {
                sourceEntity.GetModifiers().Add(Net.Vpc.Upa.EntityModifier.VALIDATE_PERSIST);
            }
            if (!sourceEntity.GetUserExcludeModifiers().Contains(Net.Vpc.Upa.EntityModifier.VALIDATE_UPDATE))
            {
                sourceEntity.GetModifiers().Add(Net.Vpc.Upa.EntityModifier.VALIDATE_UPDATE);
            }
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> sourceFieldsList = sourceRole.GetFields();
            Net.Vpc.Upa.Field[] sourceFields = sourceFieldsList.ToArray();
            Net.Vpc.Upa.KeyType keyType      = new Net.Vpc.Upa.KeyType(targetEntity, filter, false);
            SetDataType(keyType);
            tuningMaxInline = GetPersistenceUnit().GetProperties().GetInt((typeof(Net.Vpc.Upa.Relationship)).FullName + ".maxInline", 10);
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> targetFieldsList = targetEntity.GetPrimaryFields();
            Net.Vpc.Upa.Field[] targetFields = targetFieldsList.ToArray();
            ;
            // some checks
            if (sourceFields.Length == 0)
            {
                throw new System.ArgumentException("No source fields are specified");
            }
            if (targetFields.Length == 0)
            {
                throw new System.ArgumentException("Target Entity " + targetEntity.GetName() + " has no primary fields");
            }
            if (sourceFields.Length != targetFields.Length)
            {
                throw new System.ArgumentException("source fields and target fields have not the same count");
            }
            sourceEntity.AddDependencyOnEntity(targetEntity.GetName());
            if (dataType == null)
            {
                dataType = targetEntity.GetDataType();
            }
            if (dataType.IsNullable() != nullable)
            {
                Net.Vpc.Upa.Types.DataType trCloned = (Net.Vpc.Upa.Types.DataType)dataType.Copy();
                trCloned.SetNullable(nullable);
                dataType = trCloned;
            }
            this.sourceToTargetKeyMap = new System.Collections.Generic.Dictionary <string, string>(sourceFields.Length);
            this.targetToSourceKeyMap = new System.Collections.Generic.Dictionary <string, string>(sourceFields.Length);
            //        if ((theSourceTable  instanceof View))
            //            this.type = 0;
            for (int i = 0; i < sourceFields.Length; i++)
            {
                if (sourceFields[i].GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.TRANSIENT) && this.relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT)
                {
                    //Log. System.err.println("Type should be VIEW for " + getName());
                    this.relationType = Net.Vpc.Upa.RelationshipType.TRANSIENT;
                }
                else if (sourceFields[i].GetUpdateFormula() != null && this.relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT && this.relationType != Net.Vpc.Upa.RelationshipType.SHADOW_ASSOCIATION)
                {
                    // Log. System.err.println("Type should be either VIEW or SHADOW for " + name);
                    this.relationType = Net.Vpc.Upa.RelationshipType.SHADOW_ASSOCIATION;
                }
                this.sourceToTargetKeyMap[sourceFields[i].GetName()] = targetFields[i].GetName();
                this.targetToSourceKeyMap[targetFields[i].GetName()] = sourceFields[i].GetName();
                //            targetFields[i].addManyToOneRelation(this);
                ((Net.Vpc.Upa.Impl.AbstractField)sourceFields[i]).SetEffectiveModifiers(sourceFields[i].GetModifiers().Add(Net.Vpc.Upa.FieldModifier.FOREIGN));
                ((Net.Vpc.Upa.Impl.AbstractField)targetFields[i]).SetEffectiveModifiers(targetFields[i].GetModifiers().Add(Net.Vpc.Upa.FieldModifier.REFERENCED));
                //            if (sourceFields[i].getTitle() == null) {
                //                sourceFields[i].setTitle(targetFields[i].getTitle());
                //            }
                if (sourceFields[i].GetDataType() == null)
                {
                    Net.Vpc.Upa.Types.DataType tr = targetFields[i].GetDataType();
                    if (tr.IsNullable() == nullable)
                    {
                        sourceFields[i].SetDataType(tr);
                    }
                    else
                    {
                        Net.Vpc.Upa.Types.DataType trCloned = (Net.Vpc.Upa.Types.DataType)tr.Copy();
                        trCloned.SetNullable(nullable);
                        sourceFields[i].SetDataType(trCloned);
                    }
                }
            }
            if (GetSourceRole().GetEntityField() != null)
            {
                Net.Vpc.Upa.Field          sourceEntityField = GetSourceRole().GetEntityField();
                Net.Vpc.Upa.Types.DataType dt = sourceEntityField.GetDataType();
                if (dt is Net.Vpc.Upa.Types.ManyToOneType)
                {
                    Net.Vpc.Upa.Types.ManyToOneType edt = (Net.Vpc.Upa.Types.ManyToOneType)dt;
                    edt.SetRelationship(this);
                }
            }
            if (GetTargetRole().GetEntityField() != null)
            {
                Net.Vpc.Upa.Field          targetEntityField = GetTargetRole().GetEntityField();
                Net.Vpc.Upa.Types.DataType dt = targetEntityField.GetDataType();
                if (dt is Net.Vpc.Upa.Types.ManyToOneType)
                {
                    Net.Vpc.Upa.Types.ManyToOneType edt = (Net.Vpc.Upa.Types.ManyToOneType)dt;
                    edt.SetRelationship(this);
                }
            }
            this.sourceToTargetKeyMap = Net.Vpc.Upa.Impl.Util.PlatformUtils.UnmodifiableMap <string, string>(sourceToTargetKeyMap);
            this.targetToSourceKeyMap = Net.Vpc.Upa.Impl.Util.PlatformUtils.UnmodifiableMap <string, string>(targetToSourceKeyMap);
            SetI18NString(new Net.Vpc.Upa.Types.I18NString("Relationship").Append(GetName()));
            SetTitle(GetI18NString().Append(".title"));
            SetDescription(GetI18NString().Append(".desc"));
            System.Text.StringBuilder preferredPersistenceName = new System.Text.StringBuilder((GetName()).Length);
            for (int i = 0; i < (GetName()).Length; i++)
            {
                if (Net.Vpc.Upa.Expressions.ExpressionHelper.IsIdentifierPart(GetName()[i]))
                {
                    preferredPersistenceName.Append(GetName()[i]);
                }
                else
                {
                    preferredPersistenceName.Append('_');
                }
            }
            SetPersistenceName(preferredPersistenceName.ToString());
            if (GetRelationshipType() == Net.Vpc.Upa.RelationshipType.COMPOSITION)
            {
                ((Net.Vpc.Upa.Impl.DefaultEntity)sourceEntity).SetCompositionRelationship(this);
            }
            targetRole.SetFields(targetFields);
            Net.Vpc.Upa.Impl.Util.UPAUtils.Prepare(GetPersistenceUnit(), targetRole, this.GetName() + "_" + targetRole.GetRelationshipRoleType());
            Net.Vpc.Upa.Impl.Util.UPAUtils.Prepare(GetPersistenceUnit(), sourceRole, this.GetName() + "_" + sourceRole.GetRelationshipRoleType());
            if ((((GetTargetRole().GetEntity().GetExtensionDefinitions <Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition>(typeof(Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition))).Count > 0) || ((GetSourceRole().GetEntity().GetExtensionDefinitions <Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition>(typeof(Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition))).Count > 0)) && relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT)
            {
                throw new System.ArgumentException(this + " : Relationship Type must be TYPE_VIEW");
            }
            if (((GetTargetRole().GetEntity().GetShield().IsTransient()) || (GetSourceRole().GetEntity().GetShield().IsTransient())) && relationType != Net.Vpc.Upa.RelationshipType.TRANSIENT)
            {
                throw new System.ArgumentException(this + " : Relationship Type must be TYPE_VIEW");
            }
            Net.Vpc.Upa.FlagSet <Net.Vpc.Upa.FieldModifier> modifierstoRemove = Net.Vpc.Upa.FlagSets.OfType <Net.Vpc.Upa.FieldModifier>().AddAll(Net.Vpc.Upa.FieldModifier.PERSIST, Net.Vpc.Upa.FieldModifier.PERSIST_DEFAULT, Net.Vpc.Upa.FieldModifier.PERSIST_FORMULA, Net.Vpc.Upa.FieldModifier.PERSIST_SEQUENCE, Net.Vpc.Upa.FieldModifier.UPDATE, Net.Vpc.Upa.FieldModifier.UPDATE_DEFAULT, Net.Vpc.Upa.FieldModifier.UPDATE_FORMULA, Net.Vpc.Upa.FieldModifier.UPDATE_SEQUENCE);
            switch (GetSourceRole().GetRelationshipUpdateType())
            {
            case Net.Vpc.Upa.RelationshipUpdateType.FLAT:
            {
                Net.Vpc.Upa.Field f = GetSourceRole().GetEntityField();
                if (f != null)
                {
                    ((Net.Vpc.Upa.Impl.AbstractField)f).SetEffectiveModifiers(f.GetModifiers().RemoveAll(modifierstoRemove));
                }
                break;
            }

            case Net.Vpc.Upa.RelationshipUpdateType.COMPOSED:
            {
                System.Collections.Generic.IList <Net.Vpc.Upa.Field> fields = GetSourceRole().GetFields();
                if (fields != null)
                {
                    foreach (Net.Vpc.Upa.Field f in fields)
                    {
                        ((Net.Vpc.Upa.Impl.AbstractField)f).SetEffectiveModifiers(f.GetModifiers().RemoveAll(modifierstoRemove));
                    }
                }
                break;
            }
            }
        }
 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);
 }
Ejemplo n.º 20
0
 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 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));
        }
Ejemplo n.º 22
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);
 }
Ejemplo n.º 23
0
 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);
 }