Example #1
0
        public override void SetValue(object value, IValueFields valueFields)
        {
            IEntityManagerSession entityManagerSession = Context.CommandContext.GetSession <IEntityManagerSession>();

            if (entityManagerSession == null)
            {
                throw new ActivitiException("Cannot set JPA variable: " + typeof(IEntityManagerSession) + " not configured");
            }
            else
            {
                // Before we set the value we must flush all pending changes from
                // the entitymanager
                // If we don't do this, in some cases the primary key will not yet
                // be set in the object
                // which will cause exceptions down the road.
                entityManagerSession.Flush();
            }

            if (value != null)
            {
                string className = mappings.GetJPAClassString(value);
                string idString  = mappings.GetJPAIdString(value);
                valueFields.TextValue  = className;
                valueFields.TextValue2 = idString;
            }
            else
            {
                valueFields.TextValue  = null;
                valueFields.TextValue2 = null;
            }
        }
        public override void SetValue(object value, IValueFields valueFields)
        {
            IEntityManagerSession entityManagerSession = Context.CommandContext.GetSession <IEntityManagerSession>();

            if (entityManagerSession == null)
            {
                throw new ActivitiException("Cannot set JPA variable: " + typeof(IEntityManagerSession) + " not configured");
            }
            else
            {
                // Before we set the value we must flush all pending changes from
                // the entitymanager
                // If we don't do this, in some cases the primary key will not yet
                // be set in the object
                // which will cause exceptions down the road.
                entityManagerSession.Flush();
            }

            if (value is IList <object> && ((IList <object>)value).Count > 0)
            {
                IList <object> list = (IList <object>)value;
                IList <string> ids  = new List <string>();

                string type = mappings.GetJPAClassString(list[0]);
                foreach (object entry in list)
                {
                    ids.Add(mappings.GetJPAIdString(entry));
                }

                // Store type in text field and the ID's as a serialized array
                valueFields.Bytes     = SerializeIds(ids);
                valueFields.TextValue = type;
            }
            else if (value == null)
            {
                valueFields.Bytes     = null;
                valueFields.TextValue = null;
            }
            else
            {
                throw new ActivitiIllegalArgumentException("Value is not a list of JPA entities: " + value);
            }
        }