The default implementation of a database in a system.
This class implements the IDatabase contract, that is backed by a IDatabaseContext for configurations and services, provides functionalities for the management of data in the relational model.
Inheritance: IDatabase
Example #1
0
        protected virtual IDatabase CreateDatabase(IDatabaseContext context)
        {
            var database = new Database(context);
            database.Create(AdminUserName, AdminPassword);
            database.Open();

            return database;
        }
        public TableSourceComposite(Database database)
        {
            Database = database;

            tempStoreSystem = new InMemoryStorageSystem();
            objectStates = new List<TransactionObjectState>();

            StateStoreName = String.Format("{0}{1}", database.Name, StateStorePostfix);

            Setup();
        }
Example #3
0
        internal Transaction(Database database, int commitId, IsolationLevel isolation, IEnumerable<TableSource> committedTables, IEnumerable<IIndexSet> indexSets)
        {
            CommitId = commitId;
            Database = database;
            Isolation = isolation;

            InitManagers();

            Registry = new TransactionRegistry(this);
            tableManager.AddVisibleTables(committedTables, indexSets);

            AddInternalTables();

            TableState = new OldNewTableState();

            IsClosed = false;

            Database.TransactionFactory.OpenTransactions.AddTransaction(this);

            currentSchema = database.DatabaseContext.DefaultSchema();
            readOnly = dbReadOnly = database.DatabaseContext.ReadOnly();
            autoCommit = database.DatabaseContext.AutoCommit();
            ignoreCase = database.DatabaseContext.IgnoreIdentifiersCase();
        }
        public void TestSetup()
        {
            testSequenceName = ObjectName.Parse("APP.test_sequence");

            var dbConfig = Configuration.Configuration.Empty;
            dbConfig.SetValue(DatabaseConfigKeys.DatabaseName, "testdb");

            var systemContext = new SystemContext(Configuration.Configuration.SystemDefault);
            var dbContext = new DatabaseContext(systemContext, dbConfig);
            var database = new Database(dbContext);
            database.Create("SA", "12345");
            database.Open();

            transaction = database.CreateTransaction(TransactionIsolation.Serializable);

            if (TestContext.CurrentContext.Test.Name != "CreateNormalSequence") {
                var seqInfo = new SequenceInfo(testSequenceName, new SqlNumber(0), new SqlNumber(1), new SqlNumber(0), new SqlNumber(Int64.MaxValue), 126);
                transaction.CreateSequence(seqInfo);
            }
        }
Example #5
0
 internal Transaction(Database database, int commitId, IsolationLevel isolation)
     : this(database, commitId, isolation, new TableSource[0], new IIndexSet[0])
 {
 }
Example #6
0
 public DatabaseTransactionFactory(Database database)
 {
     this.database = database;
     OpenTransactions = new TransactionCollection();
 }
Example #7
0
        internal void RemoveDatabase(Database database)
        {
            lock (this) {

                databases.Remove(database.Name);
            }
        }
Example #8
0
        public IDatabase CreateDatabase(IConfiguration configuration, string adminUser, string identification, string token)
        {
            lock (this) {
                if (configuration == null)
                    throw new ArgumentNullException("configuration");

                var databaseName = configuration.GetString("database.name");
                if (String.IsNullOrEmpty(databaseName))
                    throw new ArgumentException("The configuration must specify a database name.");

                if (DatabaseExists(databaseName))
                    throw new InvalidOperationException(String.Format("Database '{0}' already exists in the system.", databaseName));

                var dbContext = Context.CreateDatabaseContext(configuration);
                var database = new Database(this, dbContext);

                if (database.Exists)
                    throw new InvalidOperationException(String.Format("The database '{0}' was already created.", databaseName));

                database.Create(adminUser, identification, token);
                database.Open();

                if (databases == null)
                    databases = new Dictionary<string, Database>();

                databases[databaseName] = database;

                return database;
            }
        }
Example #9
0
            private void Dispose(bool disposing)
            {
                if (disposing) {
                    if (OpenTransactions != null) {
                        foreach (var transaction in OpenTransactions) {
                            if (transaction != null)
                                transaction.Dispose();
                        }

                        OpenTransactions.Clear();
                    }
                }

                database = null;
                OpenTransactions = null;
            }