コード例 #1
0
 public static void EnsureDatabaseExists(
     this IGlobalAdminDatabaseCommands self,
     string name,
     bool ignoreFailures = false)
 {
     throw new CodeOmitted();
 }
コード例 #2
0
        ///<summary>
        /// Ensures that the database exists, creating it if needed
        ///</summary>
        /// <remarks>
        /// This operation happens _outside_ of any transaction
        /// </remarks>
        public static void EnsureDatabaseExists(this IGlobalAdminDatabaseCommands self, string name, bool ignoreFailures = false)
        {
            var serverClient = self.Commands.ForSystemDatabase() as ServerClient;

            if (serverClient == null)
            {
                throw new InvalidOperationException("Multiple databases are not supported in the embedded API currently");
            }

            serverClient.ForceReadFromMaster();

            var doc = MultiDatabase.CreateDatabaseDocument(name);

            try
            {
                if (serverClient.Get(doc.Id) != null)
                {
                    return;
                }

                serverClient.GlobalAdmin.CreateDatabase(doc);
            }
            catch (Exception)
            {
                if (ignoreFailures == false)
                {
                    throw;
                }
            }

            try
            {
                new RavenDocumentsByEntityName().Execute(serverClient.ForDatabase(name), new DocumentConvention());
            }
            catch (Exception)
            {
                // we really don't care if this fails, and it might, if the user doesn't have permissions on the new db
            }
        }