Deveel.Data.Database.Create C# (CSharp) Method

Create() public method

Creates the database in the context given, granting the administrative control to the user identified by the given name and token.

The properties used to create the database are extracted from the underlying context (DatabaseContext).

This method does not automatically open the database: to make it accessible a call to Open is required.

/// If the database context is configured to be in read-only model, if it was not possible /// to commit the initial information or if another unhanded error occurred while /// creating the database. /// /// If either one of or /// are null or empty. ///
public Create ( string adminName, string identification, string token ) : void
adminName string The name of the administrator.
identification string The name of the mechanism used to identify the user by the /// given token.
token string The toke used to identify the administrator, using the /// mechanism given.
return void
        public void Create(string adminName, string identification, string token)
        {
            if (Context.ReadOnly())
                throw new DatabaseSystemException("Cannot create database in read-only mode.");

            if (String.IsNullOrEmpty(adminName))
                throw new ArgumentNullException("adminName");
            if (String.IsNullOrEmpty(token))
                throw new ArgumentNullException("token");
            if (String.IsNullOrEmpty(identification))
                throw new ArgumentNullException("identification");

            try {
                // Create the conglomerate
                TableComposite.Create();

                using (var session = this.CreateInitialSystemSession()) {
                    using (var query = session.CreateQuery()) {
                        try {
                            session.CurrentSchema(SystemSchema.Name);

                            OnDatabaseCreate(query);

                            query.CreateAdminUser(adminName, identification, token);

                            OnDatabaseCreated(query);

                            try {
                                // Close and commit this transaction.
                                session.Commit();
                            } catch (TransactionException e) {
                                throw new DatabaseSystemException("Could not commit the initial information", e);
                            }
                        } catch (DatabaseSystemException) {
                            throw;
                        } catch (Exception ex) {
                            throw new DatabaseSystemException("An error occurred while creating the database.", ex);
                        }
                    }
                }

                // Close the conglomerate.
                TableComposite.Close();
            } catch (DatabaseSystemException) {
                throw;
            } catch (Exception e) {
                throw new DatabaseSystemException("An error occurred while creating the database.", e);
            }
        }

Usage Example

Esempio n. 1
0
        protected virtual IDatabase CreateDatabase(IDatabaseContext context)
        {
            var database = new Database(context);
            database.Create(AdminUserName, AdminPassword);
            database.Open();

            return database;
        }
All Usage Examples Of Deveel.Data.Database::Create