Beispiel #1
0
        /// <summary>
        /// Will set the connection to use the federation member specified by the name and key
        /// </summary>
        /// <param name="federationName">Name of the Federation</param>
        /// <param name="distributionName">Name of the Distribution</param>
        /// <param name="key">Value of the federation key</param>
        /// <remarks>This is a vanity method, this simply calls another publicly available method and is only used for the explicit name if provides (this is so it is clear to a developer the intent of this method)</remarks>
        public static void UseFederation(this System.Data.IDbConnection cnn, string federationName, string distributionName, FedKey key, bool filtered = false)
        {
            switch (key.Type)
            {
            case FedKeyType.fedkeytypeGuid:
                UseFederation(cnn, federationName, distributionName, key.GetValue <Guid>(), filtered);
                break;

            case FedKeyType.fedkeytypeVarbin:
                UseFederation(cnn, federationName, distributionName, key.GetValue <byte[]>(), filtered);
                break;

            case FedKeyType.fedkeytypeInt:
                UseFederation(cnn, federationName, distributionName, key.GetValue <int>(), filtered);
                break;

            case FedKeyType.fedkeytypeBigInt:
            default:
                UseFederation(cnn, federationName, distributionName, key.GetValue <long>(), filtered);
                break;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Executes a query, returning the data typed as per T
 /// </summary>
 /// <remarks>the dynamic param may seem a bit odd, but this works around a major usability issue in vs, if it is Object vs completion gets annoying. Eg type new [space] get new object</remarks>
 /// <returns>A sequence of data of the supplied type; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
 /// created per row, and a direct column-name===member-name mapping is assumed (case insensitive).
 /// </returns>
 public static IEnumerable <T> Query <T>(this IDataProvider provider, string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, int?commandTimeout = null, CommandType?commandType = null
                                         , string federationName = null, string distributionName = null, FedKey key = null, bool filtered = false, bool fanout = false)
 {
     return(QueryCore <T>(provider, sql, param, transaction, buffered, commandTimeout, commandType, false, federationName, distributionName, key, filtered, fanout));
 }
Beispiel #3
0
        /// <summary>
        /// Execute a command that returns multiple result sets, and access each in turn
        /// </summary>
        public static GridDataReader QueryMultiple(this IDataProvider provider, string sql, dynamic param = null, IDbTransaction transaction = null, int?commandTimeout = null, CommandType?commandType = null
                                                   , string federationName = null, string distributionName = null, FedKey key = null, bool filtered = false)
        {
            IDbConnection cnn = transaction == null?provider.Builder.GetConnection() : transaction.Connection;

            try
            {
                if (transaction == null)
                {
                    cnn.Open();
                }
                if (!string.IsNullOrEmpty(federationName) && !string.IsNullOrEmpty(distributionName) && key != null)
                {
                    cnn.UseFederation(federationName, distributionName, key, filtered);
                }

                return(new GridDataReader(cnn, transaction, SqlMapper.QueryMultiple(cnn, sql, param, transaction, commandTimeout, commandType)));
            }
            catch
            {
                if (transaction == null && cnn.State == ConnectionState.Open)
                {
                    cnn.Close();
                }
                throw;
            }
        }
Beispiel #4
0
        private static IEnumerable <T> QueryCore <T>(this IDataProvider provider, string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, int?commandTimeout = null, CommandType?commandType = null, bool isAsync = true
                                                     , string federationName = null, string distributionName = null, FedKey key = null, bool filtered = false, bool fanout = false)
        {
            bool          isFed = !string.IsNullOrEmpty(federationName) && (fanout || (!string.IsNullOrEmpty(distributionName) && key != null));
            IDbConnection cnn   = transaction == null?provider.Builder.GetConnection() : transaction.Connection;

            IEnumerable <T> result = null;

            try
            {
                if (transaction == null)
                {
                    cnn.Open();
                }

                if (isFed)
                {
                    if (fanout)
                    {
                        result = QueryFanout <T>(provider, sql, param, transaction, buffered, commandTimeout, commandType, isAsync, federationName);
                    }
                    else                    //(key != null)
                    {
                        cnn.UseFederation(federationName, distributionName, key, filtered);
                        result = ExecuteQuery <T>(cnn, sql, param, transaction, buffered, commandTimeout, commandType, isAsync);
                    }
                }
                else
                {
                    result = ExecuteQuery <T>(cnn, sql, param, transaction, buffered, commandTimeout, commandType, isAsync);
                }
            }
            finally
            {
                if (transaction == null && cnn.State == ConnectionState.Open)
                {
                    cnn.Close();
                }
            }
            return(result);
        }