Exemple #1
0
        public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInsert o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInsert)oo;
            //        PersistenceUnitManager persistenceManager = context.getPersistenceStore();
            Net.Vpc.Upa.Entity entity = context.GetPersistenceUnit().GetEntity(o.GetEntity().GetName());
            string             n      = context.GetPersistenceStore().GetValidIdentifier(context.GetPersistenceStore().GetPersistenceName(entity));

            System.Text.StringBuilder sb = new System.Text.StringBuilder("Insert Into " + n);
            sb.Append("(");
            System.Text.StringBuilder sbVals = new System.Text.StringBuilder();
            bool isFirst = true;
            int  max     = o.CountFields();

            for (int i = 0; i < max; i++)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    sb.Append(", ");
                    sbVals.Append(", ");
                }
                sb.Append(sqlManager.GetSQL(o.GetField(i), context, declarations));
                sbVals.Append(sqlManager.GetSQL(o.GetFieldValue(i), context, declarations));
            }
            return(sb.Append(") Values (").Append(sbVals).Append(")").ToString());
        }
 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++;
         }
     }
 }
Exemple #3
0
 public EntityEvent(Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.EventPhase phase)
 {
     this.context         = context;
     this.entity          = context.GetEntity();
     this.parent          = entity.GetParent();
     this.persistenceUnit = context.GetPersistenceUnit();
     this.index           = -1;
     this.oldIndex        = -1;
     this.phase           = phase;
 }
        public virtual void CommitStorage(Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Persistence.PersistenceStore  persistenceStore = context.GetPersistenceStore();
            Net.Vpc.Upa.Persistence.StructureStrategy option           = persistenceStore.GetConnectionProfile().GetStructureStrategy();
            switch (option)
            {
            case Net.Vpc.Upa.Persistence.StructureStrategy.DROP:
            {
                if (!persistenceStore.IsCreatedStorage())
                {
                    persistenceStore.CreateStorage(context);
                }
                else
                {
                    persistenceStore.DropStorage(context);
                    persistenceStore.DropStorage(context);
                    persistenceStore.CreateStorage(context);
                }
                break;
            }

            case Net.Vpc.Upa.Persistence.StructureStrategy.CREATE:
            case Net.Vpc.Upa.Persistence.StructureStrategy.SYNCHRONIZE:
            {
                if (!persistenceStore.IsCreatedStorage())
                {
                    persistenceStore.CreateStorage(context);
                }
                break;
            }

            case Net.Vpc.Upa.Persistence.StructureStrategy.MANDATORY:
            {
                if (!persistenceStore.IsCreatedStorage())
                {
                    throw new Net.Vpc.Upa.Exceptions.NoSuchPersistenceUnitException(context.GetPersistenceUnit().GetName());
                }
                //                        if (!isValidPersistenceUnit()) {
                //                            throw new NoSuchPersistenceUnitException(getName(), null);
                //                        }
                break;
            }

            case Net.Vpc.Upa.Persistence.StructureStrategy.IGNORE:
            {
                //do nothing
                break;
            }
            }
        }
Exemple #5
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);
        }
 public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledDelete o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledDelete)oo;
     Net.Vpc.Upa.Entity        entityManager = context.GetPersistenceUnit().GetEntity(o.GetEntity().GetName());
     System.Text.StringBuilder sb            = new System.Text.StringBuilder("Delete From " + sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(o.GetEntity().GetName()), context, declarations));
     if (o.GetEntityAlias() != null)
     {
         sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(o.GetEntityAlias()), context, declarations));
     }
     if (o.GetCondition() != null && o.GetCondition().IsValid())
     {
         sb.Append(" Where ").Append(sqlManager.GetSQL(o.GetCondition(), context, declarations));
     }
     return(sb.ToString());
 }
Exemple #7
0
        public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)oo;
            Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore    = context.GetPersistenceStore();
            string entityName = o.GetName();

            Net.Vpc.Upa.Entity e = context.GetPersistenceUnit().GetEntity(entityName);
            if (o.IsUseView() && e.NeedsView() && persistenceStore.IsViewSupported())
            {
                return(persistenceStore.GetValidIdentifier(persistenceStore.GetPersistenceName(e, Net.Vpc.Upa.Persistence.PersistenceNameType.IMPLICIT_VIEW)));
            }
            else
            {
                return(persistenceStore.GetValidIdentifier(persistenceStore.GetPersistenceName(e)));
            }
        }
 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();
 }
Exemple #9
0
 protected internal virtual void AppendFrom(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect o, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations)
 {
     Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect entity = o.GetEntity();
     if (entity == null)
     {
         string fns = GetFromNullString();
         if (fns != null)
         {
             sb.Append(" ");
             sb.Append(fns);
         }
     }
     else
     {
         sb.Append(" From ");
         if (entity is Net.Vpc.Upa.Expressions.Select)
         {
             sb.Append(sqlManager.GetSQL(entity, context, declarations));
         }
         else
         {
             Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore             = context.GetPersistenceStore();
             Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName entityName = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)entity;
             Net.Vpc.Upa.Entity e = context.GetPersistenceUnit().GetEntity(entityName.GetName());
             if (entityName.IsUseView() && e.NeedsView() && persistenceStore.IsViewSupported())
             {
                 Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(e.GetName(), true);
                 sb.Append(sqlManager.GetSQL(v, context, declarations));
             }
             else
             {
                 sb.Append(sqlManager.GetSQL(entityName, context, declarations));
             }
         }
     }
     if (o.GetEntityAlias() != null)
     {
         Net.Vpc.Upa.Persistence.PersistenceStore store = context.GetPersistenceStore();
         sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(o.GetEntityAlias()), context, declarations));
     }
 }
        public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate o  = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate)oo;
            Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore = context.GetPersistenceStore();
            Net.Vpc.Upa.PersistenceUnit pu     = context.GetPersistenceUnit();
            Net.Vpc.Upa.Entity          entity = pu.GetEntity(o.GetEntity().GetName());
            //        String persistenceName = persistenceStore.getPersistenceName(entity);
            System.Text.StringBuilder sb = new System.Text.StringBuilder("Update " + sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName()), context, declarations));
            string tableAlias            = o.GetEntityAlias();

            if (tableAlias != null)
            {
                sb.Append(" ");
                sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(tableAlias), context, declarations));
            }
            sb.Append(" Set ");
            bool isFirst = true;
            int  max     = o.CountFields();

            for (int i = 0; i < max; i++)
            {
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar vv = o.GetField(i);
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar ev = null;
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar fv = null;
                if (vv.GetChild() == null)
                {
                    ev = null;
                    fv = vv;
                }
                else
                {
                    ev = vv;
                    fv = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)vv.GetChild();
                }
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression fieldValue = o.GetFieldValue(i);
                //            Object referrer = vv.getReferrer();
                Net.Vpc.Upa.Field  f             = ((Net.Vpc.Upa.Field)fv.GetReferrer());
                Net.Vpc.Upa.Entity entityManager = f.GetEntity();
                System.Collections.Generic.IList <Net.Vpc.Upa.PrimitiveField> primFields = entityManager.ToPrimitiveFields <Net.Vpc.Upa.EntityPart>(new System.Collections.Generic.List <Net.Vpc.Upa.EntityPart>(new[] { (Net.Vpc.Upa.EntityPart)f }));
                foreach (Net.Vpc.Upa.PrimitiveField primField in primFields)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        sb.Append(", ");
                    }
                    if (ev != null)
                    {
                        sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(ev.GetName()), context, declarations)).Append(".");
                    }
                    sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(primField), context, declarations));
                    sb.Append("=").Append("(").Append(sqlManager.GetSQL(fieldValue, context, declarations)).Append(")");
                }
            }
            if (o.GetCondition() != null && o.GetCondition().IsValid())
            {
                sb.Append(" Where ").Append(sqlManager.GetSQL(o.GetCondition(), context, declarations));
            }
            if (persistenceStore.IsViewSupported() && entity.NeedsView() && o.GetEntity().IsUseView())
            {
                string implicitTableAlias = persistenceStore.GetPersistenceName("IT_" + entity.GetName(), Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS);
                sb.Append(" ");
                sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName()), context, declarations)).Append(" ").Append(implicitTableAlias).Append(",").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName(), true), context, declarations)).Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(tableAlias), context, declarations));
            }
            //            if (extraFrom != null)
            return(sb.ToString());
        }
Exemple #11
0
 protected internal virtual object Eval(Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression o, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext)
 {
     if (o == null)
     {
         return(null);
     }
     if (o is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQLFunctionExpression)
     {
         Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQLFunctionExpression s = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQLFunctionExpression)o;
         int      argumentsCount = s.GetArgumentsCount();
         object[] args           = new object[argumentsCount];
         for (int i = 0; i < args.Length; i++)
         {
             args[i] = Eval(s.GetArgument(i), qlContext);
         }
         return(s.GetHandler().Eval(new Net.Vpc.Upa.EvalContext(s.GetName(), args, qlContext.GetPersistenceUnit())));
     }
     if (o is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral)
     {
         return(((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral)o).GetValue());
     }
     if (o is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam)
     {
         return(((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledParam)o).GetValue());
     }
     throw new System.ArgumentException("Unable to evaluate type " + o.GetType() + " :: " + o);
 }
Exemple #12
0
        public virtual string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQLFunctionExpression o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQLFunctionExpression)oo;
            int argumentsCount = o.GetArgumentsCount();

            object[] args = new object[argumentsCount];
            for (int i = 0; i < args.Length; i++)
            {
                args[i] = Eval(o.GetArgument(i), qlContext);
            }
            return(sqlManager.GetMarshallManager().FormatSqlValue(o.GetHandler().Eval(new Net.Vpc.Upa.EvalContext(o.GetName(), args, qlContext.GetPersistenceUnit()))));
        }
Exemple #13
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 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());
 }
Exemple #15
0
 public override int ExecuteNonQuery()
 {
     if (!context.GetPersistenceUnit().GetPersistenceGroup().CurrentSessionExists())
     {
         if (sessionAwareInstance == null)
         {
             sessionAwareInstance = context.GetPersistenceUnit().GetPersistenceGroup().GetContext().MakeSessionAware <Net.Vpc.Upa.Impl.Persistence.DefaultQuery>(this);
         }
         return(sessionAwareInstance.ExecuteNonQuery());
     }
     //
     Net.Vpc.Upa.Impl.Persistence.QueryExecutor queryExecutor = CreateNativeSQL(null);
     return(queryExecutor.Execute().GetResultCount());
 }
Exemple #16
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.UserPrincipal user = qlContext.GetPersistenceUnit().GetUserPrincipal();
     return(sqlManager.GetMarshallManager().FormatSqlValue(user == null ? "anonymous" : user.GetName()));
 }
Exemple #17
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));
 }