/// <summary>
        /// Returns an account data database partition
        /// </summary>
        /// <returns></returns>
        public static SqlPartition SelectSharedDatabasePartition(string partitionName)
        {
            SqlPartition response = new SqlPartition();

            //SQL Statement =============================================================
            string SqlStatement =
                "SELECT TOP 1 name, create_date from sys.databases where name = '" + partitionName + "'";

            //SqlCommand sqlCommand = new SqlCommand(SqlStatement, Sahara.Core.Settings.Azure.Databases.DatabaseConnections.MasterSqlConnection);
            SqlCommand sqlCommand = Settings.Azure.Databases.DatabaseConnections.MasterSqlConnection.CreateCommand();

            sqlCommand.CommandText = SqlStatement.ToString();


            sqlCommand.Connection.OpenWithRetry();
            SqlDataReader reader = sqlCommand.ExecuteReaderWithRetry();

            while (reader.Read())
            {
                response = new SqlPartition {
                    Name = reader["name"].ToString(), CreatedDate = (DateTime)reader["create_date"]
                };
            }

            sqlCommand.Connection.Close();

            return(response);
        }
Esempio n. 2
0
        public static SqlPartition GetSqlPartition(string partitionName, bool useCachedVersion = true) //bool includeSchemas, bool useCachedVersion = true) //bool includeTenants, bool useCachedVersion = true)
        {
            var partition = new SqlPartition();

            //DataCache dataCache = new DataCache(NamedCache.Short);
            //string cacheId = AccountPartitionsCacheID.Detail(partitionName, includeTenants);
            object cachedAccountPartition = null;

            if (useCachedVersion)
            {
                //Check the cache first
                //cachedAccountPartition = dataCache.Get(cacheId);
            }

            if (cachedAccountPartition == null)
            {
                partition             = SqlPartitioning.GetPartition(partitionName);
                partition.TenantCount = SqlPartitioning.GetPartitionTenantCount(partitionName);

                /*
                 * if (includeSchemas)
                 * {
                 *  //Get list of all schemas
                 *  var schemas = Sql.Statements.SelectStatements.SelectSharedDatabaseUniqueSchemas(partitionName);
                 *  partition.Schemas = schemas;
                 * }
                 */

                /*
                 * if (includeTenants)
                 * {
                 *  foreach (string schema in schemas)
                 *  {
                 *      //convert each schema back to an AccountID and get each account
                 *      string accountID = Sahara.Core.Common.Methods.SchemaNames.FromAccountSchemaName(schema).ToString();
                 *      //partition.Tenants.Add(Sahara.Accounts.Core.Management.AccountManager.GetAccountByID(accountID, false));
                 *      //partition.Tenants.Add(AccountManager.GetAccount(accountID));
                 *  }
                 * }*/

                //store data into cache
                //dataCache.Put(cacheId, partition);
            }
            else
            {
                //use cached version
                partition = (SqlPartition)cachedAccountPartition;
            }

            return(partition);
        }