/// <summary>
 /// Retrieve the <see cref="ICodelistMutableObject"/> from Mapping Store.
 /// </summary>
 /// <param name="maintainableRef">
 ///     The maintainable reference which may contain ID, AGENCY ID and/or VERSION.
 /// </param>
 /// <param name="detail">
 ///     The <see cref="StructureQueryDetail"/> which controls if the output will include details or not.
 /// </param>
 /// <param name="dataflowRef">
 ///     The dataflow Ref.
 /// </param>
 /// <param name="conceptId">
 ///     The concept Id.
 /// </param>
 /// <param name="isTranscoded">
 ///     The is Transcoded.
 /// </param>
 /// <param name="allowedDataflows">The allowed dataflows.</param>
 /// <returns>
 /// The <see cref="ISet{ICodelistMutableObject}"/>.
 /// </returns>
 public ISet<ICodelistMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IMaintainableRefObject dataflowRef, string conceptId, bool isTranscoded, IList<IMaintainableRefObject> allowedDataflows)
 {
     var sqlQuery = new ArtefactSqlQuery(this.SqlQueryInfoForAll, maintainableRef);
     return this.RetrieveArtefacts(sqlQuery, detail, retrieveDetails: (o, l) => this.FillCodes(o, l, dataflowRef, conceptId, isTranscoded, allowedDataflows));
 }
        /// <summary>
        /// Retrieve the <see cref="ICodelistMutableObject"/> from Mapping Store.
        /// </summary>
        /// <param name="maintainableRef">
        /// The maintainable reference which may contain ID, AGENCY ID and/or VERSION.
        /// </param>
        /// <param name="detail">
        /// The <see cref="StructureQueryDetail"/> which controls if the output will include details or not.
        /// </param>
        /// <param name="subset">
        /// The subset.
        /// </param>
        /// <returns>
        /// The <see cref="ISet{ICodelistMutableObject}"/>.
        /// </returns>
        public ISet<ICodelistMutableObject> Retrieve(IMaintainableRefObject maintainableRef, ComplexStructureQueryDetailEnumType detail, IList<string> subset)
        {
            var sqlQuery = new ArtefactSqlQuery(this.SqlQueryInfoForAll, maintainableRef);
            Func<ICodelistMutableObject, long, ICodelistMutableObject> hashMethod = (itemSchemeBean, parentSysId) => this.FillCodesHash(itemSchemeBean, parentSysId, subset);
            Func<ICodelistMutableObject, long, ICodelistMutableObject> whereInMethod = (itemSchemeBean, parentSysId) => this.FillCodes(itemSchemeBean, parentSysId, subset);
            Func<ICodelistMutableObject, long, ICodelistMutableObject> selected = whereInMethod;

            switch (this.MappingStoreDb.ProviderName)
            {
                case MappingStoreDefaultConstants.SqlServerProvider:

                    // SQL server performs very bad with 'IN'
                    selected = hashMethod;

                    break;
                case MappingStoreDefaultConstants.MySqlProvider:
                    if (subset.Count > 2000)
                    {
                        selected = hashMethod;
                    }

                    break;
                case MappingStoreDefaultConstants.OracleProvider:
                case MappingStoreDefaultConstants.OracleProviderOdp:
                    if (subset.Count > 4000)
                    {
                        selected = hashMethod;
                    }

                    break;
                default:
                    if (subset.Count > 1000)
                    {
                        selected = hashMethod;
                    }

                    break;
            }

            return this.RetrieveArtefacts(sqlQuery, detail, retrieveDetails: selected);
        }