Пример #1
0
        public virtual int CompareTo(object other)
        {
            if (other == this)
            {
                return(0);
            }
            if (other == null)
            {
                return(1);
            }
            Net.Vpc.Upa.Field          f    = (Net.Vpc.Upa.Field)other;
            Net.Vpc.Upa.NamingStrategy comp = GetEntity().GetPersistenceUnit().GetNamingStrategy();
            string s1 = entity != null?comp.GetUniformValue(entity.GetName()) : "";

            string s2 = f.GetName() != null?comp.GetUniformValue(f.GetEntity().GetName()) : "";

            int i = s1.CompareTo(s2);

            if (i != 0)
            {
                return(i);
            }
            else
            {
                string s3 = GetName() != null?comp.GetUniformValue(GetName()) : "";

                string s4 = f.GetName() != null?comp.GetUniformValue(f.GetName()) : "";

                i = s3.CompareTo(s4);
                return(i);
            }
        }
 public virtual void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (new System.Nullable <bool>(false).Equals(context.GetConnection().GetProperty(identityConstraintsEnabledProperty)))
     {
         return;
     }
     context.AddGeneratedValue(field.GetName(), field.GetDataType());
     //manual id values are ignored
     record.Remove(field.GetName());
 }
Пример #3
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));
 }
Пример #4
0
        public virtual Net.Vpc.Upa.Types.I18NString GetFieldString(Net.Vpc.Upa.Field field)
        {
            Net.Vpc.Upa.Entity entityName = (field != null) ? (field.GetEntity() != null) ? field.GetEntity() : field.GetEntity() : null;
            string             fieldName  = (field != null) ? field.GetName() : null;

            return(GetFieldListString(entityName).Append(Key(fieldName)));
        }
Пример #5
0
        public virtual string GetNewValue(Net.Vpc.Upa.Field field) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Entity entity = field.GetEntity();
            string             idName = field.GetName();
            string             goodId = null;

            for (int i = 0; i < asynchNbrTry; i++)
            {
                System.Collections.Generic.SortedSet <string> requestedIds = new System.Collections.Generic.SortedSet <string>();
                Net.Vpc.Upa.Expressions.InCollection          idsSet       = new Net.Vpc.Upa.Expressions.InCollection(new Net.Vpc.Upa.Expressions.Var(idName));
                for (int j = 0; j < synchNbrTry; j++)
                {
                    string id = (string)GenerateValue(field);
                    idsSet.Add(new Net.Vpc.Upa.Expressions.Literal(id));
                    requestedIds.Add(id);
                }
                System.Collections.Generic.IList <Net.Vpc.Upa.Record> recordList = entity.CreateQuery((new Net.Vpc.Upa.Expressions.Select()).From(entity.GetName()).Field(new Net.Vpc.Upa.Expressions.Var(idName)).Where(idsSet)).GetRecordList();
                System.Collections.Generic.SortedSet <string>         foundIds   = new System.Collections.Generic.SortedSet <string>();
                foreach (Net.Vpc.Upa.Record record in recordList)
                {
                    foundIds.Add(record.GetString());
                }
                Net.Vpc.Upa.Impl.FwkConvertUtils.SetRemoveRange(requestedIds, foundIds);
                if ((requestedIds.Count == 0))
                {
                    continue;
                }
                goodId = Net.Vpc.Upa.Impl.FwkConvertUtils.CollectionSetFirst <string>(requestedIds);
                break;
            }
            return(goodId);
        }
Пример #6
0
 public virtual Net.Vpc.Upa.Expressions.Expression GetViewElementExpressionAt(int updatableTableIndex, Net.Vpc.Upa.Expressions.Expression expression) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> pf  = GetEntity().GetPrimaryFields();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> pft = updatableTables[updatableTableIndex].GetPrimaryFields();
     Net.Vpc.Upa.Expressions.Expression[] pfte = new Net.Vpc.Upa.Expressions.Expression[(pft).Count];
     for (int i = 0; i < pfte.Length; i++)
     {
         Net.Vpc.Upa.Field f = pft[i];
         pfte[i] = new Net.Vpc.Upa.Expressions.Var(f.GetName());
     }
     Net.Vpc.Upa.Expressions.Uplet        ut  = new Net.Vpc.Upa.Expressions.Uplet(pfte);
     Net.Vpc.Upa.Expressions.Expression[] pfe = new Net.Vpc.Upa.Expressions.Expression[(pf).Count - 1];
     for (int i = 0; i < pfe.Length; i++)
     {
         Net.Vpc.Upa.Field f = pf[i + 1];
         pfe[i] = new Net.Vpc.Upa.Expressions.Var(f.GetName());
     }
     Net.Vpc.Upa.Expressions.Expression w = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(pf[0].GetName()), new Net.Vpc.Upa.Expressions.Literal(updatableTables[updatableTableIndex].GetName()));
     if (expression != null)
     {
         w = new Net.Vpc.Upa.Expressions.And(w, expression);
     }
     Net.Vpc.Upa.Expressions.Select q = new Net.Vpc.Upa.Expressions.Select().From(GetEntity().GetName()).Uplet(pfe).Where(w);
     return(new Net.Vpc.Upa.Expressions.InSelection(ut, q));
 }
        public virtual void PrepareFieldForPersist(Net.Vpc.Upa.Field field, object @value, Net.Vpc.Upa.Record userRecord, Net.Vpc.Upa.Record persistentRecord, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> insertNonNullable, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> insertWithDefaultValue) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            object userValue      = null;
            bool   userValueFound = false;

            if (!(@value is Net.Vpc.Upa.Expressions.Expression))
            {
                userValueFound = true;
                userValue      = @value;
            }
            else if (@value is Net.Vpc.Upa.Expressions.Param)
            {
                object o = ((Net.Vpc.Upa.Expressions.Param)@value).GetValue();
                //            if (o instanceof String) {
                userValue      = o;
                userValueFound = true;
            }
            else if (@value is Net.Vpc.Upa.Expressions.Literal)
            {
                object o = ((Net.Vpc.Upa.Expressions.Literal)@value).GetValue();
                //            if (o instanceof String) {
                userValue      = o;
                userValueFound = true;
            }
            //            }
            if (userValueFound)
            {
                Net.Vpc.Upa.Types.DataTypeTransform typeTransform      = Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(field);
                Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform t = Net.Vpc.Upa.Impl.Util.UPAUtils.FindPasswordTransform(typeTransform);
                object v = ConvertCypherValue(t.GetCipherValue(), field.GetDataType());
                if (Net.Vpc.Upa.Impl.Util.UPAUtils.Equals(userValue, v))
                {
                    return;
                }
                //ignore insert
                userRecord.SetObject(field.GetName(), v);
            }
            else
            {
                log.TraceEvent(System.Diagnostics.TraceEventType.Error, 100, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Inserting non user value to password, hashing will be ignored", null));
            }
            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);
            persistentRecord.SetObject(field.GetName(), valueExpression);
        }
Пример #8
0
        public virtual object GetMainProperty(object @object) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Field mf = GetEntity().GetMainField();
            object            v  = GetProperty(@object, mf.GetName());

            if (v != null && mf.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType && !Net.Vpc.Upa.Impl.Util.UPAUtils.IsSimpleFieldType(v.GetType()))
            {
                Net.Vpc.Upa.Entity t = ((Net.Vpc.Upa.Types.ManyToOneType)mf.GetDataType()).GetRelationship().GetTargetEntity();
                return(t.GetMainFieldValue(v));
            }
            return(v);
        }
 private void BindRelation(Net.Vpc.Upa.Entity masterEntity)
 {
     Net.Vpc.Upa.Types.DataType dataType = field.GetDataType();
     if (dataType is Net.Vpc.Upa.Impl.SerializableOrManyToOneType)
     {
         field.SetDataType(new Net.Vpc.Upa.Types.ManyToOneType(dataType.GetName(), dataType.GetPlatformType(), masterEntity.GetName(), true, dataType.IsNullable()));
         field.SetTypeTransform(null);
         field.SetTypeTransform(new Net.Vpc.Upa.Impl.Transform.IdentityDataTypeTransform(field.GetDataType()));
         Net.Vpc.Upa.DefaultRelationshipDescriptor relationDescriptor = new Net.Vpc.Upa.DefaultRelationshipDescriptor();
         relationDescriptor.SetBaseField(field.GetName());
         relationDescriptor.SetTargetEntityType(masterEntity.GetEntityType());
         relationDescriptor.SetTargetEntity(masterEntity.GetName());
         relationDescriptor.SetSourceEntityType(field.GetEntity().GetEntityType());
         relationDescriptor.SetSourceEntity(field.GetEntity().GetName());
         field.GetPersistenceUnit().AddRelationship(relationDescriptor);
     }
 }
Пример #10
0
        private string GetNewValue(Net.Vpc.Upa.Field field) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Entity entity = field.GetEntity();
            string             idName = field.GetName();

            Net.Vpc.Upa.Entity seq = entity.GetPersistenceUnit().GetEntity(Net.Vpc.Upa.Impl.PrivateSequence.ENTITY_NAME);
            Net.Vpc.Upa.Impl.SequenceManager sm = new Net.Vpc.Upa.Impl.EntitySequenceManager(seq);
            string sequenceGroup = Eval(field, this.group, "{#}");

            while (true)
            {
                string nextIdString = Eval(field, this.format, sm.NextValue(name, sequenceGroup, this.initialValue, this.allocationSize));
                long   count        = entity.GetEntityCount(new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(idName), nextIdString));
                if (count == 0)
                {
                    return(nextIdString);
                }
            }
        }
 public TableSequenceIdentityPersister(Net.Vpc.Upa.Field field, Net.Vpc.Upa.Sequence sequence)
 {
     this.initialValue   = sequence == null ? 1 : sequence.GetInitialValue();
     this.allocationSize = (sequence == null) ? 50 : sequence.GetAllocationSize();
     this.name           = (sequence == null) ? null : sequence.GetName();
     this.group          = (sequence == null) ? null : sequence.GetGroup();
     this.format         = (sequence == null) ? null : sequence.GetFormat();
     this.field          = field;
     if (this.format == null)
     {
         this.format = "{#}";
     }
     if (this.group == null)
     {
         this.group = format;
     }
     if (this.name == null)
     {
         this.name = field.GetEntity().GetName() + "." + field.GetName();
     }
 }
        public virtual void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            object o = record.GetObject <T>(field.GetName());

            Net.Vpc.Upa.Key key = relationshipTargetConverter.ObjectToKey(o);
            if (key == null)
            {
                foreach (Net.Vpc.Upa.Field ff in flatFields)
                {
                    record.SetObject(ff.GetName(), ff.GetUnspecifiedValueDecoded());
                }
            }
            else
            {
                int i = 0;
                foreach (Net.Vpc.Upa.Field ff in flatFields)
                {
                    record.SetObject(ff.GetName(), key.GetObjectAt(i));
                    i++;
                }
            }
        }
Пример #13
0
        protected internal virtual void ValidatePathField(object id, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> lfs = GetTreeRelationship().GetSourceRole().GetFields();
            object[]           parent_id = new object[(lfs).Count];
            Net.Vpc.Upa.Record values    = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(id, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.Regular().And(Net.Vpc.Upa.Filters.Fields.ByList(lfs))).GetRecord();
            if (values == null)
            {
                parent_id = null;
            }
            else
            {
                for (int i = 0; i < parent_id.Length; i++)
                {
                    Net.Vpc.Upa.Field field = lfs[i];
                    parent_id[i] = values.GetObject <T>(field.GetName());
                    if (parent_id[i] != null)
                    {
                        continue;
                    }
                    parent_id = null;
                    break;
                }
            }
            string path = ToStringId(id);

            if (parent_id != null)
            {
                Net.Vpc.Upa.Record r = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(GetEntity().CreateId(parent_id), null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(GetHierarchyPathField())).GetRecord();
                if (r != null)
                {
                    path = r.GetString(GetHierarchyPathField()) + GetHierarchyPathSeparator() + path;
                }
            }
            Net.Vpc.Upa.Record r2 = GetEntity().GetBuilder().CreateRecord();
            r2.SetString(GetHierarchyPathField(), path);
            GetEntity().UpdateCore(r2, GetEntity().GetBuilder().IdToExpression(id, GetEntity().GetName()), executionContext);
        }
Пример #14
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));
 }
Пример #15
0
        public virtual void UnregisterField(Net.Vpc.Upa.Field item)
        {
            Net.Vpc.Upa.Entity  entity = item.GetEntity();
            Net.Vpc.Upa.Package module = entity.GetParent();
            string s = (module == null ? "/" : module.GetPath() + "/") + entity.GetName() + "/" + item.GetName();

            fields.Remove(s);
        }
Пример #16
0
        public virtual Net.Vpc.Upa.Expressions.Expression CreateFindEntityByMainPathExpression(string mainFieldPath, string entityAlias)
        {
            Net.Vpc.Upa.Entity           entity     = GetEntity();
            Net.Vpc.Upa.RelationshipRole detailRole = GetTreeRelationship().GetSourceRole();
            if (Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(mainFieldPath))
            {
                return(null);
            }
            string mainFieldName  = entity.GetMainField().GetName();
            object mainFieldValue = null;
            object parent         = null;

            string[] parentAndName = Net.Vpc.Upa.Impl.Util.StringUtils.Split(mainFieldPath, GetHierarchyPathSeparator()[0], false);
            if (parentAndName != null)
            {
                parent         = FindEntityByMainPath(parentAndName[0]);
                mainFieldValue = parentAndName[1];
            }
            else
            {
                mainFieldValue = mainFieldPath;
            }
            Net.Vpc.Upa.Expressions.Expression expr = null;
            if (entityAlias == null)
            {
                entityAlias = entity.GetName();
            }
            expr = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entityAlias), mainFieldName), mainFieldValue);
            Net.Vpc.Upa.Key entityToKey = parent == null ? null : entity.GetBuilder().ObjectToKey(parent);
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = detailRole.GetFields();
            for (int index = 0; index < (primaryFields).Count; index++)
            {
                Net.Vpc.Upa.Field field = primaryFields[index];
                expr = new Net.Vpc.Upa.Expressions.And(expr, new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entityAlias), field.GetName()), entityToKey == null ? null : entityToKey.GetObjectAt(index)));
            }
            return(expr);
        }
 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);
 }
Пример #18
0
        public MultiRecordList(Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor, bool forUpdate)  : base(queryExecutor)
        {
            this.forUpdate      = forUpdate;
            this.fields         = queryExecutor.GetFields();
            this.entities       = new Net.Vpc.Upa.Entity[this.fields.Length];
            this.recordName     = new string[this.fields.Length];
            this.currentRecords = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Persistence.MultiRecordListTracker>();
            this.setterToProp   = new System.Collections.Generic.Dictionary <string, System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking> >();
            int fieldsCount = fields.Length;

            for (int i = 0; i < fieldsCount; i++)
            {
                Net.Vpc.Upa.Impl.Persistence.NativeField namedExpression = fields[i];
                Net.Vpc.Upa.Field field = namedExpression.GetField();
                entities[i] = field == null ? null : field.GetEntity();
                if (namedExpression.GetGroupName() != null)
                {
                    recordName[i] = namedExpression.GetGroupName();
                }
                else if (entities[i] != null)
                {
                    recordName[i] = entities[i].GetName();
                }
                System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking> stringFieldTrackingMap = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking> >(setterToProp, recordName[i]);
                if (stringFieldTrackingMap == null)
                {
                    stringFieldTrackingMap      = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Impl.Persistence.FieldTracking>();
                    setterToProp[recordName[i]] = stringFieldTrackingMap;
                }
                if (field != null)
                {
                    Net.Vpc.Upa.Impl.Persistence.FieldTracking t = new Net.Vpc.Upa.Impl.Persistence.FieldTracking(field.GetName(), Net.Vpc.Upa.Impl.Util.PlatformUtils.SetterName(field.GetName()), i);
                    stringFieldTrackingMap[t.GetSetterMethodName()] = t;
                }
            }
            columns = this.fields.Length;
        }
Пример #19
0
 protected internal virtual void ValidateChildren(object key, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Record r = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(key, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(GetHierarchyPathField())).GetRecord();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> lfs = GetTreeRelationship().GetSourceRole().GetFields();
     Net.Vpc.Upa.Expressions.Concat concat = new Net.Vpc.Upa.Expressions.Concat();
     concat.Add(new Net.Vpc.Upa.Expressions.Literal(r.GetString(GetHierarchyPathField()), GetEntity().GetField(GetHierarchyPathField()).GetDataType()));
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = GetEntity().GetPrimaryFields();
     foreach (Net.Vpc.Upa.Field f in primaryFields)
     {
         concat.Add(new Net.Vpc.Upa.Expressions.Literal(GetHierarchyPathSeparator()));
         Net.Vpc.Upa.Types.DataType         t    = f.GetDataType();
         Net.Vpc.Upa.Expressions.Var        var  = new Net.Vpc.Upa.Expressions.Var(f.GetName());
         Net.Vpc.Upa.Expressions.Expression svar = null;
         if (t is Net.Vpc.Upa.Types.StringType)
         {
             svar = var;
         }
         else if (t is Net.Vpc.Upa.Types.IntType)
         {
             svar = new Net.Vpc.Upa.Expressions.I2V(var);
         }
         else if (t is Net.Vpc.Upa.Types.LongType)
         {
             svar = new Net.Vpc.Upa.Expressions.I2V(var);
         }
         else if (t is Net.Vpc.Upa.Types.DoubleType)
         {
             svar = new Net.Vpc.Upa.Expressions.D2V(var);
         }
         else if (t is Net.Vpc.Upa.Types.FloatType)
         {
             svar = new Net.Vpc.Upa.Expressions.D2V(var);
         }
         else
         {
             throw new System.ArgumentException("Unsupported ");
         }
         concat.Add(svar);
     }
     Net.Vpc.Upa.Record s = GetEntity().GetBuilder().CreateRecord();
     s.SetObject(GetHierarchyPathField(), concat);
     Net.Vpc.Upa.Expressions.Expression p   = null;
     Net.Vpc.Upa.Relationship           rel = GetTreeRelationship();
     object[] kvalue = GetEntity().GetBuilder().IdToKey(key).GetValue();
     for (int i = 0; i < rel.Size(); i++)
     {
         Net.Vpc.Upa.Field field = lfs[i];
         Net.Vpc.Upa.Expressions.Expression e = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(field.GetName()), new Net.Vpc.Upa.Expressions.Literal(kvalue[i], field.GetDataType())));
         p = p == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(p, e);
     }
     GetEntity().UpdateCore(s, p, executionContext);
     System.Collections.Generic.IList <object> children = GetEntity().CreateQueryBuilder().ByExpression(p).GetIdList <K>();
     foreach (object aChildren in children)
     {
         ValidateChildren(aChildren, executionContext);
     }
 }
Пример #20
0
 public virtual void Synchronize()
 {
     if (field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType)
     {
         Net.Vpc.Upa.Types.ManyToOneType t        = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType();
         Net.Vpc.Upa.Relationship        relation = t.GetRelationship();
         if (relation == null)
         {
             throw new Net.Vpc.Upa.Exceptions.UPAException("MissingRelationForField", field);
         }
         Net.Vpc.Upa.RelationshipRole       detailRole = relation.GetSourceRole();
         Net.Vpc.Upa.RelationshipUpdateType u          = detailRole.GetRelationshipUpdateType();
         if (u == Net.Vpc.Upa.RelationshipUpdateType.COMPOSED)
         {
             persistFieldPersister = new Net.Vpc.Upa.Impl.Persistence.ComposedToFlatFieldPersister(field);
             updateFieldPersister  = new Net.Vpc.Upa.Impl.Persistence.ComposedToFlatFieldPersister(field);
         }
         persistFormulaPass = 0;
         updateFormulaPass  = 0;
         postPersistFormula = false;
         postUpdateFormula  = false;
         return;
     }
     Net.Vpc.Upa.Formula persistFormula = field.GetPersistFormula();
     if (persistFormula != null)
     {
         if (persistFormula is Net.Vpc.Upa.Sequence)
         {
             persistFieldPersister = UpdateFieldPersister(persistFieldPersister, persistenceStore.CreatePersistSequenceGenerator(field));
             persistFormulaPass    = 0;
             postPersistFormula    = false;
         }
         else if (persistFormula is Net.Vpc.Upa.ExpressionFormula)
         {
             Net.Vpc.Upa.Impl.Persistence.RebuildExpressionInfo re = RebuildExpression((Net.Vpc.Upa.ExpressionFormula)persistFormula);
             if (re.rebuiltFormula != null)
             {
                 field.SetPersistFormula(re.rebuiltFormula);
             }
             bool complex = re.compiledExpression.FindFirstExpression <T>(Net.Vpc.Upa.Impl.Uql.Compiledfilters.CompiledExpressionHelper.THIS_VAR_FILTER) != default(T);
             persistFormulaPass = field.GetPersistFormulaOrder();
             if (!complex && persistFormulaPass == 0)
             {
                 insertExpression      = re.expression;
                 persistFieldPersister = UpdateFieldPersister(persistFieldPersister, new Net.Vpc.Upa.Impl.Persistence.ExpressionFieldPersister(field.GetName(), re.expression));
                 postPersistFormula    = false;
             }
             else
             {
                 postPersistFormula = true;
             }
         }
         else
         {
             postPersistFormula = true;
         }
     }
     else
     {
         postPersistFormula = false;
     }
     Net.Vpc.Upa.Formula updateFormula = field.GetUpdateFormula();
     if (updateFormula != null)
     {
         if (updateFormula is Net.Vpc.Upa.Sequence)
         {
             updateFieldPersister = UpdateFieldPersister(updateFieldPersister, persistenceStore.CreateUpdateSequenceGenerator(field));
             updateFormulaPass    = 0;
             postUpdateFormula    = false;
         }
         else if (updateFormula is Net.Vpc.Upa.ExpressionFormula)
         {
             Net.Vpc.Upa.Impl.Persistence.RebuildExpressionInfo re = RebuildExpression((Net.Vpc.Upa.ExpressionFormula)persistFormula);
             if (re.rebuiltFormula != null)
             {
                 field.SetUpdateFormula(re.rebuiltFormula);
             }
             //                List<DefaultCompiledExpression> complex = re.compiledExpression.findExpressionsList(CompiledExpressionHelper.THIS_VAR_FILTER);
             updateFormulaPass = field.GetUpdateFormulaOrder();
             if (updateFormulaPass == 0)
             {
                 updateExpression     = re.expression;
                 updateFieldPersister = UpdateFieldPersister(updateFieldPersister, new Net.Vpc.Upa.Impl.Persistence.ExpressionFieldPersister(field.GetName(), re.expression));
                 postUpdateFormula    = false;
             }
             else
             {
                 postUpdateFormula = true;
             }
         }
         else
         {
             postUpdateFormula = true;
         }
     }
     else
     {
         postUpdateFormula = true;
     }
     Net.Vpc.Upa.Formula selectFormula = field.GetSelectFormula();
     if (selectFormula != null)
     {
         if (selectFormula is Net.Vpc.Upa.ExpressionFormula)
         {
             findtExpression = ((Net.Vpc.Upa.ExpressionFormula)selectFormula).GetExpression();
         }
         else if (selectFormula is Net.Vpc.Upa.Sequence)
         {
             throw new System.ArgumentException("Sequences are not supported as Select Expressions");
         }
         else if (updateFormula is Net.Vpc.Upa.CustomUpdaterFormula)
         {
             throw new System.ArgumentException("CustomUpdaterFormulas are not supported as Select Expressions");
         }
     }
 }
Пример #21
0
 public virtual Net.Vpc.Upa.Expressions.Expression CreateFindImmediateChildrenExpression(string alias, object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> parentFields = GetTreeRelationship().GetSourceRole().GetFields();
     Net.Vpc.Upa.Expressions.Expression a = null;
     Net.Vpc.Upa.Key key = GetEntity().GetBuilder().IdToKey(id);
     for (int i = 0; i < (parentFields).Count; i++)
     {
         Net.Vpc.Upa.Field                  field = parentFields[i];
         Net.Vpc.Upa.Expressions.Var        v     = new Net.Vpc.Upa.Expressions.Var(alias == null ? null : new Net.Vpc.Upa.Expressions.Var(alias), field.GetName());
         Net.Vpc.Upa.Expressions.Expression e     = (new Net.Vpc.Upa.Expressions.Equals(v, new Net.Vpc.Upa.Expressions.Literal(key.GetObjectAt(i), field.GetDataType())));
         a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(a, e);
     }
     return(a);
 }
Пример #22
0
 private string GetFieldName(Net.Vpc.Upa.Field field)
 {
     return((absoluteNames) ? field.GetAbsoluteName() : field.GetName());
 }
Пример #23
0
 public virtual string GetPersistenceName(object source, Net.Vpc.Upa.Persistence.PersistenceNameType spec) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.PersistenceNameType> types = new System.Collections.Generic.List <Net.Vpc.Upa.Persistence.PersistenceNameType>();
     Net.Vpc.Upa.Impl.Persistence.UPAObjectAndSpec upaObjectAndSpec = new Net.Vpc.Upa.Impl.Persistence.UPAObjectAndSpec(source, spec);
     if (source is Net.Vpc.Upa.Entity)
     {
         Net.Vpc.Upa.Entity v = (Net.Vpc.Upa.Entity)source;
         if (spec == null)
         {
             string p = v.GetPersistenceName();
             if (p == null)
             {
                 p = v.GetName();
             }
             foreach (Net.Vpc.Upa.Extensions.EntityExtensionDefinition extension in v.GetExtensionDefinitions())
             {
                 if (extension is Net.Vpc.Upa.Extensions.ViewEntityExtensionDefinition)
                 {
                     types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.VIEW);
                 }
                 if (extension is Net.Vpc.Upa.Extensions.UnionEntityExtensionDefinition)
                 {
                     types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.UNION_TABLE);
                 }
             }
             types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.TABLE);
             return(ValidatePersistenceName(p, Net.Vpc.Upa.Persistence.PersistenceNameType.TABLE, v.GetName(), upaObjectAndSpec, types));
         }
         if (Net.Vpc.Upa.Persistence.PersistenceNameType.PK_CONSTRAINT.Equals(spec))
         {
             string p = v.GetShortName();
             if (p == null)
             {
                 p = v.GetPersistenceName();
             }
             if (p == null)
             {
                 p = v.GetName();
             }
             types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.PK_CONSTRAINT);
             return(ValidatePersistenceName("PK_" + p, Net.Vpc.Upa.Persistence.PersistenceNameType.PK_CONSTRAINT, v.GetName(), upaObjectAndSpec, types));
         }
         if (Net.Vpc.Upa.Persistence.PersistenceNameType.IMPLICIT_VIEW.Equals(spec))
         {
             string p = v.GetPersistenceName();
             if (p == null)
             {
                 p = v.GetName();
             }
             types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.IMPLICIT_VIEW);
             types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.TABLE);
             return(ValidatePersistenceName(p + "_IV", Net.Vpc.Upa.Persistence.PersistenceNameType.IMPLICIT_VIEW, v.GetName(), upaObjectAndSpec, types));
         }
     }
     if (source is Net.Vpc.Upa.Index)
     {
         Net.Vpc.Upa.Index v = (Net.Vpc.Upa.Index)source;
         string            p = v.GetPersistenceName();
         if (p == null)
         {
             p = v.GetName();
         }
         if (p == null)
         {
             string sn = v.GetEntity().GetShortName();
             if (sn == null)
             {
                 sn = v.GetEntity().GetName();
             }
             System.Text.StringBuilder sb = new System.Text.StringBuilder("IX_").Append(sn);
             foreach (string field in v.GetFieldNames())
             {
                 sb.Append("_").Append(field);
             }
             p = sb.ToString();
         }
         types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.INDEX);
         return(ValidatePersistenceName(p, Net.Vpc.Upa.Persistence.PersistenceNameType.INDEX, v.GetName(), upaObjectAndSpec, types));
     }
     if (source is Net.Vpc.Upa.Relationship)
     {
         Net.Vpc.Upa.Relationship v = (Net.Vpc.Upa.Relationship)source;
         string p = v.GetPersistenceName();
         if (p == null)
         {
             p = v.GetName();
         }
         types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.FK_CONSTRAINT);
         return(ValidatePersistenceName(p, Net.Vpc.Upa.Persistence.PersistenceNameType.FK_CONSTRAINT, v.GetName(), upaObjectAndSpec, types));
     }
     if (source is Net.Vpc.Upa.PrimitiveField)
     {
         Net.Vpc.Upa.Field v = (Net.Vpc.Upa.Field)source;
         string            p = v.GetPersistenceName();
         if (p == null)
         {
             p = v.GetName();
         }
         types.Add(Net.Vpc.Upa.Persistence.PersistenceNameType.COLUMN);
         return(ValidatePersistenceName(p, Net.Vpc.Upa.Persistence.PersistenceNameType.COLUMN, v.GetEntity().GetName() + "." + v.GetName(), upaObjectAndSpec, types));
     }
     if (source is string)
     {
         if (Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS.Equals(spec))
         {
             return(ValidatePersistenceName((string)source, Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS, "aliasName", upaObjectAndSpec, types));
         }
         else
         {
             return(ValidatePersistenceName((string)source, Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS, null, upaObjectAndSpec, types));
         }
     }
     throw new System.ArgumentException("No Supported");
 }
 public virtual void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     record.Remove(field.GetName());
     record.SetObject(field.GetName(), GetNewValue(field, record, context));
 }
Пример #25
0
        public virtual void RegisterField(Net.Vpc.Upa.Field item)
        {
            Net.Vpc.Upa.Impl.DefaultEntity entity = (Net.Vpc.Upa.Impl.DefaultEntity)item.GetEntity();
            Net.Vpc.Upa.Package            module = entity.GetParent();
            string s = (module == null ? "/" : module.GetPath() + "/") + entity.GetName() + "/" + item.GetName();

            fields[s] = item;
            entity.fieldsMap[entity.GetPersistenceUnit().GetNamingStrategy().GetUniformValue(item.GetName())] = (Net.Vpc.Upa.Field)item;
        }
 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 Net.Vpc.Upa.Expressions.CompiledExpression CreateConditionForDeepSearch(Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression alias, Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression id, bool includeId, Net.Vpc.Upa.Field field, string pathSep) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     alias = alias.Copy();
     if (alias is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)
     {
         Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar cv = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)alias;
         if (cv.GetReferrer() is Net.Vpc.Upa.Entity)
         {
             Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(field.GetName());
             ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)alias).SetChild(v);
         }
         else
         {
             throw new System.ArgumentException("Expected " + field.GetEntity().GetName() + " var name");
         }
     }
     else
     {
         throw new System.ArgumentException("Expected " + field.GetEntity().GetName() + " var name");
     }
     id = id.Copy();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = field.GetEntity().GetPrimaryFields();
     if ((primaryFields).Count > 1)
     {
         throw new System.ArgumentException("Composite ID unsupported for function treeancestor");
     }
     Net.Vpc.Upa.Types.DataType pkType = primaryFields[0].GetDataType();
     Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression strId = null;
     if (pkType is Net.Vpc.Upa.Types.IntType)
     {
         strId = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(id);
     }
     else if (pkType is Net.Vpc.Upa.Types.LongType)
     {
         strId = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(id);
     }
     else if (pkType is Net.Vpc.Upa.Types.ShortType)
     {
         strId = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(id);
     }
     else if (pkType is Net.Vpc.Upa.Types.ByteType)
     {
         strId = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(id);
     }
     else if (pkType is Net.Vpc.Upa.Types.FloatType)
     {
         strId = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledD2V(id);
     }
     else if (pkType is Net.Vpc.Upa.Types.DoubleType)
     {
         strId = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledD2V(id);
     }
     else if (pkType is Net.Vpc.Upa.Types.StringType)
     {
         strId = id;
     }
     else
     {
         strId = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledCast(id, Net.Vpc.Upa.Impl.Transform.IdentityDataTypeTransform.STRING);
     }
     if (includeId)
     {
         return(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledOr(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLike(alias.Copy(), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledConcat(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral("%" + pathSep), strId.Copy())), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLike(alias.Copy(), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledConcat(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral("%" + pathSep), strId.Copy(), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(pathSep + "%")))));
     }
     else
     {
         return(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLike(alias.Copy(), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledConcat(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral("%" + pathSep), strId.Copy(), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(pathSep + "%"))));
     }
 }
 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();
 }
Пример #29
0
        public virtual bool ContainsField(Net.Vpc.Upa.Field item)
        {
            Net.Vpc.Upa.Entity  entity = item.GetEntity();
            Net.Vpc.Upa.Package module = entity.GetParent();
            string s = (module == null ? "/" : module.GetPath() + "/") + entity.GetName() + "/" + item.GetName();

            return(fields.ContainsKey(s));
        }
Пример #30
0
 public virtual long GetNewValue(Net.Vpc.Upa.Field field) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity             entity = field.GetEntity();
     Net.Vpc.Upa.Expressions.Select s      = new Net.Vpc.Upa.Expressions.Select().From(entity.GetName());
     s.Field(new Net.Vpc.Upa.Expressions.Plus(new Net.Vpc.Upa.Expressions.Coalesce(new Net.Vpc.Upa.Expressions.Max(new Net.Vpc.Upa.Expressions.Var(field.GetName())), new Net.Vpc.Upa.Expressions.Literal(0)), new Net.Vpc.Upa.Expressions.Literal(1)), "next");
     Net.Vpc.Upa.Record next = field.GetPersistenceUnit().CreateQuery(s).GetRecord();
     if (next != null)
     {
         return(next.GetLong("next"));
     }
     else
     {
         return(0);
     }
 }