/// <summary>
        /// Tries to fetch the <see cref="SchemaInfo"/> with the given <see cref="ShardMap"/> name without
        /// raising any exception if data doesn't exist.
        /// </summary>
        /// <param name="shardMapName">The name of the <see cref="ShardMap"/> whose <see cref="SchemaInfo"/>
        /// will be fetched</param>
        /// <param name="schemaInfo">The <see cref="SchemaInfo"/> that was fetched or null if retrieval failed</param>
        /// <returns>true if schema info exists with given name, false otherwise.</returns>
        public bool TryGet(string shardMapName, out SchemaInfo schemaInfo)
        {
            ExceptionUtils.DisallowNullOrEmptyStringArgument(shardMapName, "shardMapName");

            schemaInfo = null;

            IStoreResults result;

            using (IStoreOperationGlobal op = this.Manager.StoreOperationFactory.CreateFindShardingSchemaInfoGlobalOperation(
                       this.Manager,
                       "TryGet",
                       shardMapName))
            {
                result = op.Do();
            }

            if (result.Result == StoreResult.SchemaInfoNameDoesNotExist)
            {
                return(false);
            }

            schemaInfo = result.StoreSchemaInfoCollection
                         .Select(si => SerializationHelper.DeserializeXmlData <SchemaInfo>(si.ShardingSchemaInfo))
                         .Single();

            return(true);
        }
        /// <summary>
        /// Fetches the <see cref="SchemaInfo"/> stored with the supplied <see cref="ShardMap"/> name.
        /// </summary>
        /// <param name="shardMapName">The name of the <see cref="ShardMap"/> to get.</param>
        /// <returns>SchemaInfo object.</returns>
        public SchemaInfo Get(string shardMapName)
        {
            ExceptionUtils.DisallowNullOrEmptyStringArgument(shardMapName, "shardMapName");

            IStoreResults result;

            using (IStoreOperationGlobal op = this.Manager.StoreOperationFactory.CreateFindShardingSchemaInfoGlobalOperation(
                       this.Manager,
                       "Get",
                       shardMapName))
            {
                result = op.Do();
            }

            if (result.Result == StoreResult.SchemaInfoNameDoesNotExist)
            {
                throw new SchemaInfoException(
                          SchemaInfoErrorCode.SchemaInfoNameDoesNotExist,
                          Errors._Store_SchemaInfo_NameDoesNotExist,
                          "Get",
                          shardMapName);
            }

            return(result.StoreSchemaInfoCollection
                   .Select(si => SerializationHelper.DeserializeXmlData <SchemaInfo>(si.ShardingSchemaInfo))
                   .Single());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ReferenceTableInfo"/> class.
        /// </summary>
        /// <param name="tableName">Reference table name.</param>
        public ReferenceTableInfo(string tableName)
        {
            ExceptionUtils.DisallowNullOrEmptyStringArgument(tableName, "tableName");

            this.SchemaName = "dbo";
            this.TableName  = tableName;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ShardedTableInfo"/> class.
        /// </summary>
        /// <param name="tableName">Sharded table name.</param>
        /// <param name="columnName">Shard key column name.</param>
        public ShardedTableInfo(string tableName, string columnName)
        {
            ExceptionUtils.DisallowNullOrEmptyStringArgument(tableName, "tableName");
            ExceptionUtils.DisallowNullOrEmptyStringArgument(columnName, "columnName");

            this.SchemaName    = "dbo";
            this.TableName     = tableName;
            this.KeyColumnName = columnName;
        }
        /// <summary>
        /// Removes the <see cref="SchemaInfo"/> with the given <see cref="ShardMap"/> name.
        /// </summary>
        /// <param name="shardMapName">The name of the <see cref="ShardMap"/> whose <see cref="SchemaInfo"/>
        /// will be removed</param>
        public void Remove(string shardMapName)
        {
            ExceptionUtils.DisallowNullOrEmptyStringArgument(shardMapName, "shardMapName");

            using (IStoreOperationGlobal op = this.Manager.StoreOperationFactory.CreateRemoveShardingSchemaInfoGlobalOperation(
                       this.Manager,
                       "Remove",
                       shardMapName))
            {
                op.Do();
            }
        }
        /// <summary>
        /// Replaces the <see cref="SchemaInfo"/> with the given <see cref="ShardMap"/> name.
        /// </summary>
        /// <param name="shardMapName">The name of the <see cref="ShardMap"/> whose <see cref="SchemaInfo"/> will be replaced.</param>
        /// <param name="schemaInfo">Sharding schema information.</param>
        public void Replace(string shardMapName, SchemaInfo schemaInfo)
        {
            ExceptionUtils.DisallowNullOrEmptyStringArgument(shardMapName, "shardMapName");
            ExceptionUtils.DisallowNullArgument <SchemaInfo>(schemaInfo, "schemaInfo");

            DefaultStoreSchemaInfo dssi = new DefaultStoreSchemaInfo(
                shardMapName,
                SerializationHelper.SerializeXmlData <SchemaInfo>(schemaInfo));

            using (IStoreOperationGlobal op = this.Manager.StoreOperationFactory.CreateUpdateShardingSchemaInfoGlobalOperation(
                       this.Manager,
                       "Replace",
                       dssi))
            {
                op.Do();
            }
        }