Ejemplo n.º 1
0
        /// <summary>
        /// Run common artefact import command.
        /// </summary>
        /// <param name="artefact">
        /// The artefact.
        /// </param>
        /// <param name="command">
        /// The command.
        /// </param>
        /// <param name="artefactStoredProcedure">
        /// The artefact stored procedure.
        /// </param>
        /// <returns>
        /// The <see cref="long"/>.
        /// </returns>
        protected long RunIdentifiableArterfactCommand(IIdentifiableObject artefact, DbCommand command, ArtefactProcedurebase artefactStoredProcedure)
        {
            DbParameter idParameter = artefactStoredProcedure.CreateIdParameter(command);

            idParameter.Value = artefact.Id ?? (object)DBNull.Value;

            DbParameter outputParameter = artefactStoredProcedure.CreateOutputParameter(command);

            command.ExecuteNonQuery();

            var artID = (long)outputParameter.Value;

            _annotationInsertEngine.Insert(new DbTransactionState(command.Transaction, this._database), artID, _insertArtefactAnnotation, artefact.Annotations);

            return(artID);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Insert the specified <paramref name="items"/> to the mapping store with <paramref name="state"/>
        /// </summary>
        /// <param name="state">
        ///     The MAPPING STORE connection and transaction state
        /// </param>
        /// <param name="items">
        ///     The items.
        /// </param>
        /// <param name="parentArtefact">
        ///     The primary key of the parent artefact.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{Long}"/>.
        /// </returns>
        public ItemStatusCollection Insert(DbTransactionState state, IEnumerable <IGroup> items, long parentArtefact)
        {
            var storedProcedure = _insertDsdGroup;
            var annotations     = new List <Tuple <long, IGroup> >();
            var groupIds        = new ItemStatusCollection();

            using (DbCommand command = storedProcedure.CreateCommand(state))
            {
                DbParameter dsdParameter = storedProcedure.CreateDsdIdParameter(command);

                DbParameter idParameter = storedProcedure.CreateIdParameter(command);

                DbParameter outputParameter = storedProcedure.CreateOutputParameter(command);

                foreach (var group in items)
                {
                    idParameter.Value  = group.Id;
                    dsdParameter.Value = parentArtefact;

                    command.ExecuteNonQuery();

                    var id = (long)outputParameter.Value;
                    groupIds.Add(new ItemStatus(group.Id, id));
                    if (group.Annotations.Count > 0)
                    {
                        annotations.Add(new Tuple <long, IGroup>(id, group));
                    }
                }
            }

            foreach (var annotation in annotations)
            {
                IAnnotableObject annotableObject = annotation.Item2;
                _annotationInsertEngine.Insert(state, annotation.Item1, _insertGroupAnnotation, annotableObject.Annotations);
            }

            return(groupIds);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The insert.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <param name="itemScheme">
        /// The item scheme.
        /// </param>
        /// <param name="parentArtefact">
        /// The parent artefact.
        /// </param>
        /// <returns>
        /// The <see cref="long"/>.
        /// </returns>
        /// <exception cref="MappingStoreException">
        /// THere was a problem with the <paramref name="component"/> references.
        /// </exception>
        private static long Insert(
            DbTransactionState state, IComponent component, StructureCache itemScheme, long parentArtefact)
        {
            var        conceptStatus  = itemScheme.GetStructure(state, component.ConceptRef);
            ItemStatus conceptID      = ValidateConceptScheme(conceptStatus, component.ConceptRef);
            var        codelistStatus = GetCodelistStatus(state, component, itemScheme);

            var  formats = new List <KeyValuePair <long, ITextFormat> >();
            long compID;
            var  attribute       = component as IAttributeObject;
            var  dimension       = component as IDimension;
            var  storedProcedure = _storedProcedures.InsertComponent;

            using (DbCommand command = storedProcedure.CreateCommand(state))
            {
                DbParameter idParameter = storedProcedure.CreateIdParameter(command);
                idParameter.Value = component.Id;

                SetDsd(parentArtefact, storedProcedure, command);

                SetConcept(storedProcedure, command, conceptID);

                SetComponentType(component, storedProcedure, command);

                SetCodelist(storedProcedure, command, codelistStatus, component);

                DbParameter isFreqDimParameter = storedProcedure.CreateIsFreqDimParameter(command);

                DbParameter isMeasureDimParameter = storedProcedure.CreateIsMeasureDimParameter(command);

                DbParameter attAssLevelParameter = storedProcedure.CreateAttAssLevelParameter(command);

                DbParameter attStatusParameter = storedProcedure.CreateAttStatusParameter(command);

                DbParameter attIsTimeFormatParameter = storedProcedure.CreateAttIsTimeFormatParameter(command);

                DbParameter xsMeasureCodeParameter = storedProcedure.CreateXsMeasureCodeParameter(command);

                DbParameter outputParameter = storedProcedure.CreateOutputParameter(command);

                switch (component.StructureType.EnumType)
                {
                case SdmxStructureEnumType.Dimension:
                case SdmxStructureEnumType.MeasureDimension:
                {
                    SetDimensionParameters(dimension, isFreqDimParameter, isMeasureDimParameter);
                }

                break;

                case SdmxStructureEnumType.TimeDimension:
                    break;

                case SdmxStructureEnumType.DataAttribute:
                {
                    SetAttributeParameters(attribute, attAssLevelParameter, attStatusParameter, attIsTimeFormatParameter);
                }

                break;

                case SdmxStructureEnumType.PrimaryMeasure:
                    break;

                case SdmxStructureEnumType.CrossSectionalMeasure:
                {
                    SetCrossSectionalMeasureParameters(component, xsMeasureCodeParameter);
                }

                break;
                }

                SetCrossSectionalLevels(component, storedProcedure, command);

                command.ExecuteNonQuery();

                compID = (long)outputParameter.Value;

                if (component.Representation != null && component.Representation.TextFormat != null)
                {
                    formats.Add(new KeyValuePair <long, ITextFormat>(compID, component.Representation.TextFormat));
                }
            }

            InsertTextFormats(state, formats);
            _annotationInsertEngine.Insert(state, compID, _insertComponentAnnotation, component.Annotations);
            return(compID);
        }