예제 #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());
        }
예제 #2
0
 public virtual int Reset(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (entity.GetShield().IsTransient())
     {
         return(0);
     }
     Net.Vpc.Upa.Expressions.Delete stmt = (new Net.Vpc.Upa.Expressions.Delete()).From(entity.GetName());
     return(context.GetPersistenceStore().CreateQuery(stmt, context).ExecuteNonQuery());
 }
 public virtual int Delete(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Expressions.Expression condition, bool recurse, Net.Vpc.Upa.RemoveTrace deleteInfo) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (entity.GetShield().IsTransient())
     {
         return(0);
     }
     Net.Vpc.Upa.Expressions.Delete stmt = (new Net.Vpc.Upa.Expressions.Delete()).From(entity.GetName()).Where(condition);
     return(context.GetPersistenceStore().CreateQuery(stmt, context).ExecuteNonQuery());
 }
예제 #4
0
        public override 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.CompiledInCollection o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInCollection)oo;
            Net.Vpc.Upa.Persistence.PersistenceStore qlm = qlContext.GetPersistenceStore();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int mySize = o.GetRightSize();

            if (mySize == 0)
            {
                sb.Append("1 <> 1");
            }
            else
            {
                if (mySize == 1)
                {
                    sb.Append(sqlManager.GetSQL(o.GetLeft(), qlContext, declarations));
                    Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression e = o.GetRight(0);
                    if (e == null || (e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral && ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral)e).GetValue() == null))
                    {
                        sb.Append(" Is Null");
                    }
                    else
                    {
                        sb.Append(" = ");
                        sb.Append(sqlManager.GetSQL(e, qlContext, declarations));
                    }
                }
                else
                {
                    sb.Append(sqlManager.GetSQL(o.GetLeft(), qlContext, declarations));
                    sb.Append(" In (");
                    for (int i = 0; i < mySize; i++)
                    {
                        if (i > 0)
                        {
                            sb.Append(",");
                        }
                        Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression e = o.GetRight(i);
                        if (e == null)
                        {
                            sb.Append("Null");
                        }
                        else
                        {
                            sb.Append(sqlManager.GetSQL(e, qlContext, declarations));
                        }
                    }
                    sb.Append(")");
                }
            }
            return('(' + sb.ToString() + ')');
        }
        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;
            }
            }
        }
예제 #6
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)));
            }
        }
예제 #7
0
        public virtual void CommitStorage(Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore = context.GetPersistenceStore();
            //should verify if not yet stored
            switch (@object.GetPersistenceState())
            {
            case Net.Vpc.Upa.PersistenceState.VALID:
            {
                //do nothing
                break;
            }

            case Net.Vpc.Upa.PersistenceState.TRANSIENT:
            {
                switch (type)
                {
                case Net.Vpc.Upa.Impl.OnHoldCommitActionType.CREATE:
                {
                    persistenceStore.AlterPersistenceUnitAddObject(@object);
                    break;
                }

                case Net.Vpc.Upa.Impl.OnHoldCommitActionType.REMOVE:
                {
                    persistenceStore.AlterPersistenceUnitRemoveObject(@object);
                    break;
                }

                case Net.Vpc.Upa.Impl.OnHoldCommitActionType.UPDATE:
                {
                    persistenceStore.AlterPersistenceUnitUpdateObject(old, @object, updates);
                    break;
                }
                }
                new Net.Vpc.Upa.Impl.Util.DefaultBeanAdapter(@object).SetProperty("persistenceState", Net.Vpc.Upa.PersistenceState.VALID);
                break;
            }

            default:
            {
                throw new Net.Vpc.Upa.Exceptions.UPAException(new Net.Vpc.Upa.Types.I18NString("Unexpected"));
            }
            }
        }
예제 #8
0
        protected internal virtual void AppendJoins(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)
        {
            for (int i = 0; i < o.CountJoins(); i++)
            {
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria e = o.GetJoin(i);
                //            String _valueString = sqlManager.getSQL(e.getEntity(), context, declarations);
                string _aliasString = e.GetEntityAlias();
                string _joinKey     = "Inner Join";
                switch (e.GetJoinType())
                {
                case Net.Vpc.Upa.Expressions.JoinType.INNER_JOIN:
                    _joinKey = "Inner Join";
                    break;

                case Net.Vpc.Upa.Expressions.JoinType.FULL_JOIN:
                    _joinKey = "Full Join";
                    break;

                case Net.Vpc.Upa.Expressions.JoinType.LEFT_JOIN:
                    _joinKey = "Left Join";
                    break;

                case Net.Vpc.Upa.Expressions.JoinType.RIGHT_JOIN:
                    _joinKey = "Right Join";
                    break;

                case Net.Vpc.Upa.Expressions.JoinType.CROSS_JOIN:
                    _joinKey = "Cross Join";
                    break;
                }
                sb.Append(" ").Append(_joinKey).Append(" ").Append(sqlManager.GetSQL(e.GetEntity(), context, declarations));
                if (_aliasString != null)
                {
                    Net.Vpc.Upa.Persistence.PersistenceStore store = context.GetPersistenceStore();
                    //                String goodAlias = store.getPersistenceName(, PersistenceNameType.ALIAS);
                    sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(_aliasString), context, declarations));
                }
                if (e.GetCondition() != null && e.GetCondition().IsValid())
                {
                    sb.Append(" On ").Append(sqlManager.GetSQL(e.GetCondition(), context, declarations));
                }
            }
        }
예제 #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 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();
 }
예제 #11
0
 public DefaultQuery(Net.Vpc.Upa.Expressions.EntityStatement query, Net.Vpc.Upa.Entity defaultEntity, Net.Vpc.Upa.Persistence.EntityExecutionContext context)
 {
     this.query = query;
     if (defaultEntity != null)
     {
         if (query is Net.Vpc.Upa.Expressions.Select)
         {
             Net.Vpc.Upa.Expressions.Select select = (Net.Vpc.Upa.Expressions.Select)query;
             if (select.GetEntity() == null)
             {
                 select.From(defaultEntity.GetName());
             }
         }
         else if (query is Net.Vpc.Upa.Expressions.Insert)
         {
             if (((Net.Vpc.Upa.Expressions.Insert)query).GetEntity() == null)
             {
                 ((Net.Vpc.Upa.Expressions.Insert)query).Into(defaultEntity.GetName());
             }
         }
         else if (query is Net.Vpc.Upa.Expressions.Update)
         {
             if (((Net.Vpc.Upa.Expressions.Update)query).GetEntity() == null)
             {
                 ((Net.Vpc.Upa.Expressions.Update)query).Entity(defaultEntity.GetName());
             }
         }
         else if (query is Net.Vpc.Upa.Expressions.Delete)
         {
             if (((Net.Vpc.Upa.Expressions.Delete)query).GetEntity() == null)
             {
                 ((Net.Vpc.Upa.Expressions.Delete)query).From(defaultEntity.GetName());
             }
         }
     }
     this.context = context;
     //        this.cquery = (CompiledEntityStatement) query.copy();
     //        this.defaultEntity = defaultEntity;
     store = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)context.GetPersistenceStore();
 }
예제 #12
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);
        }
예제 #13
0
        public override 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.CompiledVar o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)oo;
            Net.Vpc.Upa.Persistence.PersistenceStore            persistenceStore = qlContext.GetPersistenceStore();
            object referrer = o.GetReferrer();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (referrer is Net.Vpc.Upa.Field)
            {
                Net.Vpc.Upa.Field field = (Net.Vpc.Upa.Field)referrer;
                string            name  = persistenceStore.GetPersistenceName(field);
                sb.Append(persistenceStore.GetValidIdentifier(name));
            }
            else if (referrer is Net.Vpc.Upa.Entity)
            {
                Net.Vpc.Upa.Entity entity = (Net.Vpc.Upa.Entity)referrer;
                //            if ("this".equals(o.getName())) {
                //                throw new IllegalArgumentException("Unexpected this alias");
                //                //this must be resolved to the ancestor alias
                //                ExpressionDeclarationList declarationList = o.getDeclarationList();
                //                name = persistenceManager.getPersistenceName(declarationList.getValue(null).getName(), PersistenceNameStrategyNames.ALIAS);
                //            } else {
                string name = persistenceStore.GetPersistenceName(o.GetName(), Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS);
                sb.Append(persistenceStore.GetValidIdentifier(name));
            }
            else
            {
                string name = persistenceStore.GetPersistenceName(o.GetName(), Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS);
                sb.Append(persistenceStore.GetValidIdentifier(name));
            }
            if (o.GetChild() != null)
            {
                string cc = GetSQL(o.GetChild(), qlContext, sqlManager, declarations);
                sb.Append(".").Append(cc);
            }
            return(sb.ToString());
        }
예제 #14
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.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());
        }
 public virtual Net.Vpc.Upa.Query CreateQuery(Net.Vpc.Upa.Entity e, Net.Vpc.Upa.Expressions.Delete query, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     return(context.GetPersistenceStore().CreateQuery(e, query, context));
 }
 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());
 }
예제 #17
0
 public override void Persist(Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, Net.Vpc.Upa.PersistenceState status) /* throws System.Exception, Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Relationship relation = (Net.Vpc.Upa.Relationship)@object;
     Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore persistenceUnitManager = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)executionContext.GetPersistenceStore();
     log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Commit {0} / {1} : found {2}, persist", null, new object[] { @object, typedObject, status }));
     if (!relation.IsTransient() && persistenceUnitManager.IsReferencingSupported())
     {
         Net.Vpc.Upa.Persistence.UConnection b = executionContext.GetConnection();
         b.ExecuteNonQuery(persistenceUnitManager.GetCreateRelationshipStatement(relation), null, null);
     }
 }
        public override void Persist(Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, Net.Vpc.Upa.PersistenceState status) /* throws System.Exception, Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.PrimitiveField field = (Net.Vpc.Upa.PrimitiveField)@object;
            Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore persistenceUnitManager = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)executionContext.GetPersistenceStore();
            log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Commit {0} / {1} : found {2}, persist", null, new object[] { @object, typedObject, status }));
            string q = persistenceUnitManager.GetAlterTableAddColumnStatement(field, executionContext);

            Net.Vpc.Upa.Persistence.UConnection b = executionContext.GetConnection();
            b.ExecuteNonQuery(q, null, null);
        }
 public override void Persist(Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, Net.Vpc.Upa.PersistenceState status) /* throws System.Exception, Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity entity = (Net.Vpc.Upa.Entity)@object;
     Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore persistenceUnitManager = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)executionContext.GetPersistenceStore();
     if (persistenceUnitManager.IsViewSupported() && entity.NeedsView())
     {
         log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Commit {0} / {1} : found {2}, persist", null, new object[] { @object, typedObject, status }));
         Net.Vpc.Upa.Persistence.UConnection b = executionContext.GetConnection();
         b.ExecuteNonQuery(persistenceUnitManager.GetCreateImplicitViewStatement(entity, executionContext), null, null);
     }
 }
예제 #20
0
 public override void Persist(Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, Net.Vpc.Upa.PersistenceState status) /* throws System.Exception, Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Index index = (Net.Vpc.Upa.Index)@object;
     Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore persistenceUnitManager = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)executionContext.GetPersistenceStore();
     if (!persistenceUnitManager.IsView(index.GetEntity()))
     {
         log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Commit {0} / {1} : found {2}, persist", null, new object[] { @object, typedObject, status }));
         Net.Vpc.Upa.Persistence.UConnection b = executionContext.GetConnection();
         if (status == Net.Vpc.Upa.PersistenceState.DIRTY)
         {
             b.ExecuteNonQuery(persistenceUnitManager.GetDropIndexStatement(index), null, null);
         }
         b.ExecuteNonQuery(persistenceUnitManager.GetCreateIndexStatement(index), null, null);
     }
 }
예제 #21
0
 public override void Persist(Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, Net.Vpc.Upa.PersistenceState status) /* throws System.Exception, Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity entity = (Net.Vpc.Upa.Entity)@object;
     Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore store = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)executionContext.GetPersistenceStore();
     if ((entity.GetPrimaryFields()).Count > 0)
     {
         log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Commit {0} / {1} : found {2}, persist", null, new object[] { @object, typedObject, status }));
         Net.Vpc.Upa.Persistence.UConnection b = executionContext.GetConnection();
         foreach (Net.Vpc.Upa.PrimitiveField primaryField in entity.GetPrimitiveFields(Net.Vpc.Upa.Filters.Fields.Id()))
         {
             Net.Vpc.Upa.Impl.Persistence.ColumnDesc cd = store.LoadColumnDesc(primaryField, b.GetMetadataAccessibleConnection());
             if (cd.IsNullable() != null && (cd.IsNullable()).Value)
             {
                 b.ExecuteNonQuery(store.GetAlterTableAlterColumnNullStatement(primaryField, false), null, null);
             }
         }
         b.ExecuteNonQuery(store.GetCreateTablePKConstraintStatement(entity), null, null);
     }
 }
예제 #22
0
 public override void Persist(Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, Net.Vpc.Upa.PersistenceState status) /* throws System.Exception, Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity entityManager = (Net.Vpc.Upa.Entity)@object;
     Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore persistenceUnitManager = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)executionContext.GetPersistenceStore();
     log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Commit {0} / {1} : found {2}, persist", null, new object[] { @object, typedObject, status }));
     Net.Vpc.Upa.Persistence.UConnection b = executionContext.GetConnection();
     System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ViewEntityExtension> specSupport = entityManager.GetExtensions <Net.Vpc.Upa.Persistence.ViewEntityExtension>(typeof(Net.Vpc.Upa.Persistence.ViewEntityExtension));
     foreach (Net.Vpc.Upa.Persistence.ViewEntityExtension ss in specSupport)
     {
         b.ExecuteNonQuery(persistenceUnitManager.GetCreateViewStatement(entityManager, ss.GetQuery(), executionContext), null, null);
     }
     System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.UnionEntityExtension> uspecSupport = entityManager.GetExtensions <Net.Vpc.Upa.Persistence.UnionEntityExtension>(typeof(Net.Vpc.Upa.Persistence.UnionEntityExtension));
     foreach (Net.Vpc.Upa.Persistence.UnionEntityExtension ss in uspecSupport)
     {
         b.ExecuteNonQuery(persistenceUnitManager.GetCreateViewStatement(entityManager, ss.GetQuery(), executionContext), null, null);
     }
     System.Collections.Generic.IList <Net.Vpc.Upa.Extensions.FilterEntityExtensionDefinition> fspecSupport = entityManager.GetExtensionDefinitions <Net.Vpc.Upa.Extensions.FilterEntityExtensionDefinition>(typeof(Net.Vpc.Upa.Extensions.FilterEntityExtensionDefinition));
     foreach (Net.Vpc.Upa.Extensions.FilterEntityExtensionDefinition ss in fspecSupport)
     {
         b.ExecuteNonQuery(persistenceUnitManager.GetCreateViewStatement(entityManager, ss.GetQuery(), executionContext), null, null);
     }
 }