示例#1
0
        public void CreateSimpleTableAsAdmin()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var tableInfo = new TableInfo(tableName);
            tableInfo.AddColumn("a", PrimitiveTypes.Integer(), true);
            tableInfo.AddColumn("b", PrimitiveTypes.String());

            using (var session = Database.CreateUserSession(AdminUserName, AdminPassword)) {
                using (var context = new SessionQueryContext(session)) {
                    Assert.DoesNotThrow(() => {
                        context.CreateTable(tableInfo);
                    });
                }

                Assert.DoesNotThrow(() => session.Commit());
            }

            using (var session = Database.CreateUserSession(AdminUserName, AdminPassword)) {
                using (var context = new SessionQueryContext(session)) {
                    bool exists = false;
                    Assert.DoesNotThrow(() => exists = context.TableExists(tableName));
                    Assert.IsTrue(exists);
                }
            }
        }
示例#2
0
        public static User Authenticate(this IDatabase database, string username, string password, ConnectionEndPoint endPoint)
        {
            // Create a temporary connection for authentication only...
            using (var session = database.CreateSystemSession()) {
                session.CurrentSchema(SystemSchema.Name);
                session.ExclusiveLock();

                using (var queryContext = new SessionQueryContext(session)) {
                    return queryContext.Authenticate(username, password, endPoint);
                }
            }
        }
        protected override IQueryContext CreateQueryContext(IDatabase database)
        {
            // We first create the table in another context...
            using (var session = database.CreateUserSession(AdminUserName, AdminPassword)) {
                using (var context = new SessionQueryContext(session)) {
                    var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
                    tableInfo.AddColumn("a", PrimitiveTypes.Integer());
                    tableInfo.AddColumn("b", PrimitiveTypes.String(), false);

                    context.CreateTable(tableInfo, false, false);
                }

                session.Commit();
            }

            return base.CreateQueryContext(database);
        }
示例#4
0
        protected virtual IQueryContext OnAuthenticate(string defaultSchema, string username, string password)
        {
            var user = Database.Authenticate(username, password, RemoteEndPoint);

            if (user == null)
                return null;

            var connection = Database.CreateUserSession(user);

            // Put the connection in exclusive mode
            connection.ExclusiveLock();

            var context = new SessionQueryContext(connection);

            try {
                // By default, connections are auto-commit
                connection.AutoCommit(true);

                // Set the default schema for this connection if it exists
                if (context.SchemaExists(defaultSchema)) {
                    context.CurrentSchema(defaultSchema);
                } else {
                    // TODO: Log the warning..

                    // If we can't change to the schema then change to the APP schema
                    connection.CurrentSchema(Database.DatabaseContext.DefaultSchema());
                }
            } finally {
                try {
                    connection.Commit();
                } catch (TransactionException e) {
                    // TODO: Log the warning
                }
            }

            return context;
        }
示例#5
0
        public void Create(string adminName, string adminPassword)
        {
            if (DatabaseContext.ReadOnly())
                throw new DatabaseSystemException("Can not create database in Read only mode.");

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

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

                using (var session = this.CreateInitialSystemSession()) {
                    session.AutoCommit(false);

                    using (var context = new SessionQueryContext(session)) {
                        session.ExclusiveLock();
                        session.CurrentSchema(SystemSchema.Name);

                        // Create the schema information tables
                        CreateSchemata(context);

                        // The system tables that are present in every conglomerate.
                        SystemSchema.CreateTables(context);

                        // Create the system views
                        // TODO: InformationSchema.CreateSystemViews(session);

                        this.CreateAdminUser(context, adminName, adminPassword);

                        SetCurrentDataVersion(context);

                        // Set all default system procedures.
                        // TODO: SystemSchema.SetupSystemFunctions(session, username);

                        try {
                            // Close and commit this transaction.
                            session.Commit();
                        } catch (TransactionException e) {
                            throw new DatabaseSystemException("Could not commit the initial information", e);
                        }
                    }
                }

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