Ejemplo n.º 1
0
 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> persistNonNullable, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> persistWithDefaultValue) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType();
     if (e.IsUpdatable())
     {
         Net.Vpc.Upa.Entity masterEntity = executionContext.GetPersistenceUnit().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())
         {
             persistNonNullable.Remove(fk);
             persistWithDefaultValue.Remove(fk);
             persistentRecord.SetObject(fk.GetName(), k == null ? null : k.GetObjectAt(x));
             x++;
         }
     }
 }
Ejemplo n.º 2
0
 public virtual void CreateSequence(string name, string pattern, int initialValue, int increment) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (increment == 0)
     {
         throw new System.ArgumentException("increment zero");
     }
     Net.Vpc.Upa.Impl.PrivateSequence r = (Net.Vpc.Upa.Impl.PrivateSequence)entity.GetBuilder().CreateObject <R>();
     r.SetName(name);
     r.SetGroup(pattern);
     r.SetLocked(false);
     r.SetValue(initialValue);
     r.SetIncrement(increment);
     entity.Persist(r);
 }
Ejemplo n.º 3
0
 public virtual Net.Vpc.Upa.Key GetKey(object id)
 {
     if (id == null)
     {
         return(null);
     }
     if (Build())
     {
         //            Object[] value = new Object[fieldNames.length];
         //            EntityBuilder entityFactory = idEntity.getBuilder();
         //            for (int i = 0; i < value.length; i++) {
         //                value[i] = entityFactory.getProperty(key, fieldNames[i]);
         //            }
         if (!idType.IsInstanceOfType(id))
         {
             Net.Vpc.Upa.Entity ee = entity.GetPersistenceUnit().FindEntity(idType);
             if (ee != null)
             {
                 //check assume this is the id of the entity ee
                 id = ee.GetBuilder().IdToObject <R>(id);
             }
         }
         return(CreateKey(new object[] { id }));
     }
     else
     {
         object[] @value = new object[fieldNames.Length];
         for (int i = 0; i < @value.Length; i++)
         {
             @value[i] = bnfo.GetProperty(id, fieldNames[i]);
         }
         return(CreateKey(@value));
     }
 }
Ejemplo n.º 4
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);
 }
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 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.º 7
0
        public override R RecordToObject <R>(Net.Vpc.Upa.Record record)
        {
            if (record is Net.Vpc.Upa.Impl.BeanAdapterRecord)
            {
                Net.Vpc.Upa.Impl.BeanAdapterRecord g = (Net.Vpc.Upa.Impl.BeanAdapterRecord)record;
                return((R)g.UserObject());
            }
            object obj = CreateObject <R>();

            Net.Vpc.Upa.Record ur = ObjectToRecord(obj, true);
            foreach (string k in record.KeySet())
            {
                object o = record.GetObject <T>(k);
                if (o is Net.Vpc.Upa.Record)
                {
                    Net.Vpc.Upa.Field          f  = entity.FindField(k);
                    Net.Vpc.Upa.Types.DataType dt = f.GetDataType();
                    if (dt is Net.Vpc.Upa.Types.ManyToOneType)
                    {
                        Net.Vpc.Upa.Entity oe = ((Net.Vpc.Upa.Types.ManyToOneType)dt).GetRelationship().GetTargetEntity();
                        o = oe.GetBuilder().RecordToObject <R>((Net.Vpc.Upa.Record)o);
                    }
                }
                ur.SetObject(k, o);
            }
            //        ur.setAll(unstructuredRecord);
            return((R)obj);
        }
Ejemplo n.º 8
0
 public virtual void CheckRemove(Net.Vpc.Upa.Expressions.Expression condition, bool recurse) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (entity.GetEntityCount(condition) == 0)
     {
         //nothing to remove!!
         return;
     }
     if (!IsDeleteSupported())
     {
         throw new Net.Vpc.Upa.Exceptions.UndeletableRecordException(entity);
     }
     if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedRemove(entity))
     {
         throw new Net.Vpc.Upa.Exceptions.DeleteRecordNotAllowedException(entity);
     }
     Net.Vpc.Upa.Expressions.Expression e = GetFullNonDeletableRecordsExpression();
     if (e != null && e.IsValid())
     {
         Net.Vpc.Upa.Expressions.Expression a = (condition == null) ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(condition, e);
         if (entity.GetEntityCount(a) > 0)
         {
             throw new Net.Vpc.Upa.Exceptions.UndeletableRecordException(entity);
         }
     }
     Net.Vpc.Upa.Entity p = entity.GetParentEntity();
     if (p != null)
     {
         Net.Vpc.Upa.Expressions.Expression ss = entity.ChildToParentExpression(condition);
         //            p.getShield().checkRemove(ss, recurse);
         p.GetShield().CheckUpdate(p.GetBuilder().CreateRecord(), ss);
     }
     CheckVeto(Net.Vpc.Upa.VetoableOperation.checkDelete, condition, recurse);
 }
        public virtual void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            //K key = entity.getBuilder().recordToId(record);
            Net.Vpc.Upa.Entity entity = context.GetEntity();
            object             key    = entity.NextId <K>();

            entity.GetBuilder().SetRecordId(record, key);
        }
 public ComposedToFlatFieldPersister(Net.Vpc.Upa.Field field)
 {
     this.field = field;
     Net.Vpc.Upa.Types.ManyToOneType t       = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType();
     Net.Vpc.Upa.Entity           master     = t.GetRelationship().GetTargetRole().GetEntity();
     Net.Vpc.Upa.RelationshipRole detailRole = t.GetRelationship().GetSourceRole();
     flatFields = detailRole.GetFields();
     relationshipTargetConverter = master.GetBuilder();
 }
Ejemplo n.º 11
0
        public TypeInfo(string binding, Net.Vpc.Upa.Entity entity)
        {
            this.binding = binding;
            int dotPos = binding == null ? -1 : binding.LastIndexOf('.');

            if (dotPos > 0)
            {
                this.parentBinding = binding.Substring(0, dotPos);
                this.bindingName   = binding.Substring(dotPos + 1);
            }
            this.entity = entity;
            if (entity != null)
            {
                entityFactory   = entity.GetBuilder();
                entityConverter = entity.GetBuilder();
                entityType      = entity.GetEntityType();
            }
        }
Ejemplo n.º 12
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);
        }
 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();
 }
Ejemplo n.º 14
0
        public override void OnPersist(Net.Vpc.Upa.Callbacks.PersistEvent @event) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            object parent_id     = relation.ExtractId(@event.GetPersistedRecord());
            string path          = support.GetHierarchyPathSeparator() + support.ToStringId(@event.GetPersistedId());
            string pathFieldName = support.GetHierarchyPathField();

            Net.Vpc.Upa.Entity entity = relation.GetSourceRole().GetEntity();
            if (parent_id != null)
            {
                Net.Vpc.Upa.Record r = entity.CreateQueryBuilder().ByExpression(entity.GetBuilder().IdToExpression(parent_id, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(pathFieldName)).GetRecord();
                if (r != null)
                {
                    path = r.GetString(pathFieldName) + path;
                }
            }
            @event.GetPersistedRecord().SetString(pathFieldName, path);
            Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext = @event.GetContext();
            Net.Vpc.Upa.Persistence.EntityExecutionContext updateContext    = executionContext.GetPersistenceUnit().GetFactory().CreateObject <Net.Vpc.Upa.Persistence.EntityExecutionContext>(typeof(Net.Vpc.Upa.Persistence.EntityExecutionContext));
            updateContext.InitPersistenceUnit(executionContext.GetPersistenceUnit(), executionContext.GetPersistenceStore(), Net.Vpc.Upa.Persistence.ContextOperation.UPDATE);
            Net.Vpc.Upa.Record u2 = entity.GetBuilder().CreateRecord();
            u2.SetString(pathFieldName, path);
            entity.UpdateCore(u2, entity.GetBuilder().IdToExpression(@event.GetPersistedId(), entity.GetName()), updateContext);
        }
Ejemplo n.º 15
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.º 16
0
        protected internal virtual int ValidateCustomFormula(System.Collections.Generic.ISet <Net.Vpc.Upa.Field> fields) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            //                        if (monitor != null) {
            //                            if (monitor.isStopped()) {
            //                                return;
            //                            }
            //                            monitor.stepIn(keysToUpdate.size());
            //                        }
            int x = 0;

            foreach (object aKeysToUpdate in GetKeysToUpdate())
            {
                //                            if (monitor != null) {
                //                                if (monitor.isStopped()) {
                //                                    return;
                //                                }
                //                                monitor.progress(String.valueOf(validationPass.pass), "Passe "
                //                                        + (validationPass.pass + 1), null);
                //                            }
                // System.out.println("ITERATIVE_VALIDATION = " +
                // validationPass.pass+" : "+validationPass.fields+" :
                // "+keysToUpdate[r]);
                Net.Vpc.Upa.Record u = entity.GetBuilder().CreateRecord();
                foreach (Net.Vpc.Upa.Field field in fields)
                {
                    Net.Vpc.Upa.CustomFormula cf = (Net.Vpc.Upa.CustomFormula)(onPersist ? field.GetPersistFormula() : field.GetUpdateFormula());
                    object v = cf.GetValue(field, aKeysToUpdate, context);
                    u.SetObject(field.GetName(), new Net.Vpc.Upa.Expressions.Cast(new Net.Vpc.Upa.Expressions.Param(null, v), field.GetDataType()));
                }
                x += entity.UpdateCore(u, entity.GetBuilder().IdToExpression(aKeysToUpdate, entity.GetName()), context);
            }
            //                        if (monitor != null) {
            //                            monitor.stepOut();
            //                        }
            return(x);
        }
Ejemplo n.º 17
0
 /**
  * @param oldId
  * @param newId
  * @throws net.vpc.upa.exceptions.UPAException
  * CloneRecordNotAllowedException, CloneRecordNotAllowedException,
  * CloneRecordNotAllowedException, CloneRecordOldKeyNotFoundException,
  * CloneRecordNewKeyInUseException
  */
 public virtual void CheckClone(object oldId, object newId) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedClone(entity))
     {
         throw new Net.Vpc.Upa.Exceptions.CloneRecordNotAllowedException(entity);
     }
     if (!IsCloneSupported())
     {
         throw new Net.Vpc.Upa.Exceptions.CloneRecordNotAllowedException(entity);
     }
     if (oldId != null)
     {
         Net.Vpc.Upa.Expressions.Expression e = GetFullNonCloneableRecordsExpression();
         if (e != null && e.IsValid())
         {
             Net.Vpc.Upa.Expressions.And a = new Net.Vpc.Upa.Expressions.And(entity.GetBuilder().IdToExpression(oldId, null), e);
             if (entity.GetEntityCount(a) > 0)
             {
                 throw new Net.Vpc.Upa.Exceptions.CloneRecordNotAllowedException(entity);
             }
         }
         object o = entity.CreateQueryBuilder().ById(oldId).SetFieldFilter(Net.Vpc.Upa.Impl.Util.Filters.Fields2.PERSISTENT_NON_FORMULA).GetEntity <R>();
         if (o == null)
         {
             throw new Net.Vpc.Upa.Exceptions.CloneRecordOldKeyNotFoundException(entity);
         }
     }
     if (newId != null)
     {
         if (entity.Contains(newId))
         {
             throw new Net.Vpc.Upa.Exceptions.CloneRecordNewKeyInUseException(entity);
         }
     }
     CheckVeto(Net.Vpc.Upa.VetoableOperation.checkClone, oldId, newId);
 }
 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);
 }
Ejemplo n.º 19
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.º 20
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);
        }
Ejemplo n.º 21
0
        private Net.Vpc.Upa.Query Build()
        {
            //        if (query == null) {
            string entityName = entity.GetName();

            Net.Vpc.Upa.Expressions.Select s = (new Net.Vpc.Upa.Expressions.Select()).From(entityName, entityAlias);
            if (GetFieldFilter() != null)
            {
                foreach (Net.Vpc.Upa.Field field in entity.GetFields(GetFieldFilter()))
                {
                    if (field != null)
                    {
                        s.Field(new Net.Vpc.Upa.Expressions.Var(field.GetName()), field.GetName());
                    }
                }
            }
            Net.Vpc.Upa.Expressions.Expression criteria = null;
            if (GetId() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = entity.GetBuilder().IdToExpression(GetId(), entityName);
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetKey() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = (entity.GetBuilder().IdToExpression(entity.GetBuilder().KeyToId(GetKey()), entityName));
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetPrototype() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = entity.GetBuilder().ObjectToExpression(GetPrototype(), true, entityName);
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetRecordPrototype() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = (entity.GetBuilder().RecordToExpression(GetRecordPrototype(), entityName));
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            if (GetExpression() != null)
            {
                Net.Vpc.Upa.Expressions.Expression e = GetExpression();
                criteria = criteria == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(criteria, e);
            }
            s.SetWhere(criteria);
            s.OrderBy(GetOrder());
            query = entity.CreateQuery(s);
            foreach (System.Collections.Generic.KeyValuePair <string, object> e in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, object> >(paramsByName))
            {
                query.SetParameter((e).Key, (e).Value);
            }
            foreach (System.Collections.Generic.KeyValuePair <int?, object> e in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <int?, object> >(paramsByIndex))
            {
                query.SetParameter(((e).Key).Value, (e).Value);
            }
            query.SetUpdatable(this.IsUpdatable());
            if (hints != null)
            {
                foreach (System.Collections.Generic.KeyValuePair <string, object> h in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, object> >(hints))
                {
                    query.SetHint((h).Key, (h).Value);
                }
            }
            //        }
            return(query);
        }
Ejemplo n.º 22
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);
 }
Ejemplo n.º 23
0
 public virtual K Convert(Net.Vpc.Upa.Key key)
 {
     return((K)entity.GetBuilder().KeyToId(key));
 }
 public virtual int Update(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Record updates, Net.Vpc.Upa.Expressions.Expression condition) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Expressions.Update u = new Net.Vpc.Upa.Expressions.Update().Entity(entity.GetName());
     foreach (string fieldName in updates.KeySet())
     {
         Net.Vpc.Upa.Field f = entity.FindField(fieldName);
         if (f != null && Net.Vpc.Upa.Impl.Util.Filters.Fields2.UPDATE.Accept(f))
         {
             object @value = updates.GetObject <T>(fieldName);
             if ((f.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType))
             {
                 Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)f.GetDataType();
                 if (e.IsUpdatable())
                 {
                     Net.Vpc.Upa.Entity        masterEntity = context.GetPersistenceUnit().GetEntity(e.GetTargetEntityName());
                     Net.Vpc.Upa.EntityBuilder mbuilder     = masterEntity.GetBuilder();
                     if (@value is Net.Vpc.Upa.Expressions.Expression)
                     {
                         Net.Vpc.Upa.Expressions.Expression evalue;
                         System.Collections.Generic.IList <Net.Vpc.Upa.Field> sfields = e.GetRelationship().GetSourceRole().GetFields();
                         System.Collections.Generic.IList <Net.Vpc.Upa.Field> tfields = e.GetRelationship().GetTargetRole().GetFields();
                         for (int i = 0; i < (sfields).Count; i++)
                         {
                             Net.Vpc.Upa.Field fk  = sfields[i];
                             Net.Vpc.Upa.Field fid = tfields[i];
                             evalue = ((Net.Vpc.Upa.Expressions.Expression)@value).Copy();
                             evalue = context.GetPersistenceUnit().GetExpressionManager().ParseExpression(evalue);
                             if (evalue is Net.Vpc.Upa.Expressions.Select)
                             {
                                 Net.Vpc.Upa.Expressions.Select svalue = (Net.Vpc.Upa.Expressions.Select)evalue;
                                 if (svalue.CountFields() != 1)
                                 {
                                     throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName());
                                 }
                                 if (svalue.GetField(0).GetExpression() is Net.Vpc.Upa.Expressions.Var)
                                 {
                                     svalue.GetField(0).SetExpression(new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)svalue.GetField(0).GetExpression(), fid.GetName()));
                                 }
                                 else
                                 {
                                     throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName());
                                 }
                             }
                             else if (evalue is Net.Vpc.Upa.Expressions.Var)
                             {
                                 evalue = (new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)evalue, fk.GetName()));
                             }
                             else if (evalue is Net.Vpc.Upa.Expressions.Param)
                             {
                             }
                             else if (evalue is Net.Vpc.Upa.Expressions.Literal)
                             {
                             }
                             else
                             {
                                 throw new System.Exception("Invalid Expression " + evalue + " as formula for field " + f.GetAbsoluteName());
                             }
                             u.Set(fk.GetName(), evalue);
                         }
                     }
                     else
                     {
                         Net.Vpc.Upa.Key k = null;
                         if (@value is Net.Vpc.Upa.Record)
                         {
                             k = mbuilder.RecordToKey((Net.Vpc.Upa.Record)@value);
                         }
                         else
                         {
                             k = mbuilder.ObjectToKey(@value);
                         }
                         int x = 0;
                         foreach (Net.Vpc.Upa.Field fk in e.GetRelationship().GetSourceRole().GetFields())
                         {
                             u.Set(fk.GetName(), new Net.Vpc.Upa.Expressions.Param(fk.GetName(), k == null ? null : k.GetObjectAt(x)));
                             x++;
                         }
                     }
                 }
             }
             else
             {
                 Net.Vpc.Upa.Expressions.Expression expression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(null, @value);
                 u.Set(fieldName, expression);
             }
         }
     }
     u.Where(condition);
     return(context.GetPersistenceStore().CreateQuery(u, context).ExecuteNonQuery());
 }
Ejemplo n.º 25
0
 public virtual Net.Vpc.Upa.Key Convert(K id)
 {
     return(entity.GetBuilder().IdToKey(id));
 }
Ejemplo n.º 26
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));
 }
Ejemplo n.º 27
0
 public DefaultQualifiedRecord(Net.Vpc.Upa.Entity entity)  : this(entity, entity.GetBuilder().CreateRecord())
 {
 }
        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.º 29
0
 public virtual Net.Vpc.Upa.Key GetKey() /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     return(entity.GetBuilder().IdToKey(id));
 }
Ejemplo n.º 30
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);
 }