public TableCompositeColumnForm(TableComposite TableComposite)
            : this()
        {
            _TableComposite = TableComposite;

            this.RefreshForm();
        }
Beispiel #2
0
        /// <summary>
        /// Opens the database making it ready to be accessed.
        /// </summary>
        /// <exception cref="DatabaseSystemException">
        /// The database was already initialized.
        /// or
        /// or
        /// An error occurred when initializing the database.
        /// </exception>
        /// <remarks>
        /// <para>
        /// This method ensures the system components and the data are
        /// ready to allow any connection to be established.
        /// </para>
        /// <para>
        /// After this method successfully exists, the state of <see cref="IsOpen" />
        /// is changed to <c>true</c>.
        /// </para>
        /// </remarks>
        public void Open()
        {
            if (IsOpen)
            {
                throw new DatabaseSystemException("The database was already initialized.");
            }

            try {
                // Check if the state file exists.  If it doesn't, we need to report
                // incorrect version.
                if (!TableComposite.Exists())
                {
                    // If neither store or state file exist, assume database doesn't
                    // exist.
                    throw new DatabaseSystemException(String.Format("The database {0} does not exist.", Name));
                }

                // Open the conglomerate
                TableComposite.Open();

                AssertDataVersion();
            } catch (DatabaseSystemException) {
                throw;
            } catch (Exception e) {
                throw new DatabaseSystemException("An error occurred when initializing the database.", e);
            }

            IsOpen = true;
        }
Beispiel #3
0
        /// <summary>
        /// Closes the database making it not accessible to connections.
        /// </summary>
        /// <exception cref="DatabaseSystemException">
        /// The database is not initialized.
        /// or
        /// An error occurred during database shutdown.
        /// </exception>
        /// <remarks>
        /// Typical implementations of this interface will automatically
        /// invoke the closure of the database on disposal (<see cref="IDisposable.Dispose" />.
        /// </remarks>
        public void Close()
        {
            if (!IsOpen)
            {
                throw new DatabaseSystemException("The database is not initialized.");
            }

            try {
                if (Context.DeleteOnClose())
                {
                    // Delete the tables if the database is set to delete on
                    // shutdown.
                    TableComposite.Delete();
                }
                else
                {
                    // Otherwise close the conglomerate.
                    TableComposite.Close();
                }
            } catch (DatabaseSystemException) {
                throw;
            } catch (Exception e) {
                throw new DatabaseSystemException("An error occurred during database shutdown.", e);
            } finally {
                IsOpen = false;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates the database in the context given, granting the administrative
        /// control to the user identified by the given name and token.
        /// </summary>
        /// <param name="adminName">The name of the administrator.</param>
        /// <param name="token">The toke used to identify the administrator, using the
        /// <paramref name="identification"/> mechanism given.</param>
        /// <param name="identification">The name of the mechanism used to identify the user by the
        /// given token.</param>
        /// <exception cref="DatabaseSystemException">
        /// 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.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If either one of <paramref name="adminName"/> or <paramref name="token"/>
        /// are <c>null</c> or empty.
        /// </exception>
        /// <remarks>
        /// <para>
        /// The properties used to create the database are extracted from
        /// the underlying context (<see cref="DatabaseContext" />).
        /// </para>
        /// <para>
        /// This method does not automatically open the database: to make it accessible
        /// a call to <see cref="Open" /> is required.
        /// </para>
        /// </remarks>
        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);
            }
        }
Beispiel #5
0
 internal void Delete()
 {
     try {
         TableComposite.Delete();
     } catch (DatabaseSystemException) {
         throw;
     } catch (Exception ex) {
         throw new DatabaseSystemException("An error occurred while deleting the database", ex);
     }
 }
Beispiel #6
0
 public void Rollback()
 {
     if (!IsClosed)
     {
         try {
             var touchedTables = TableManager.AccessedTables.ToList();
             TableComposite.Rollback(this, touchedTables, Registry);
         } finally {
             IsClosed = true;
             Finish();
         }
     }
 }
Beispiel #7
0
 public void Commit()
 {
     if (!IsClosed)
     {
         try {
             var touchedTables = TableManager.AccessedTables.ToList();
             var visibleTables = TableManager.GetVisibleTables().ToList();
             var selected      = TableManager.SelectedTables.ToArray();
             TableComposite.Commit(this, visibleTables, selected, touchedTables, Registry, commitActions);
         } finally {
             Finish();
         }
     }
 }
        public void Rollback()
        {
            if (!IsClosed)
            {
                try {
                    State = TransactionState.Rollback;

                    var touchedTables = TableManager.AccessedTables.ToList();
                    TableComposite.Rollback(this, touchedTables, Registry);

                    this.OnEvent(new TransactionEvent(TransactionEventType.Rollback));
                } finally {
                    IsClosed = true;
                    Finish();
                }
            }
        }
Beispiel #9
0
        private void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (IsOpen)
                    {
                        // TODO: Report the error
                    }

                    if (Locker != null)
                    {
                        Locker.Dispose();
                    }

                    if (TableComposite != null)
                    {
                        TableComposite.Dispose();
                    }

                    if (TransactionFactory != null &&
                        (TransactionFactory is IDisposable))
                    {
                        (TransactionFactory as IDisposable).Dispose();
                    }

                    if (Context != null)
                    {
                        Context.Dispose();
                    }

                    if (System != null)
                    {
                        System.RemoveDatabase(this);
                    }
                }

                TransactionFactory = null;
                Locker             = null;
                System             = null;
                TableComposite     = null;
                Context            = null;
                disposed           = true;
            }
        }
        public void Commit()
        {
            if (!IsClosed)
            {
                try {
                    State = TransactionState.Commit;

                    var touchedTables = TableManager.AccessedTables.ToList();
                    var visibleTables = TableManager.GetVisibleTables().ToList();
                    var selected      = TableManager.SelectedTables.ToArray();
                    TableComposite.Commit(this, visibleTables, selected, touchedTables, Registry);

                    this.OnEvent(new TransactionEvent(TransactionEventType.Commit));
                } finally {
                    Finish();
                }
            }
        }
Beispiel #11
0
        private void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (IsOpen)
                    {
                        // TODO: Report the error
                    }

                    if (Locker != null)
                    {
                        Locker.Reset();
                    }

                    if (TableComposite != null)
                    {
                        TableComposite.Dispose();
                    }

                    if (Context != null)
                    {
                        Context.Dispose();
                    }

                    if (System != null)
                    {
                        System.RemoveDatabase(this);
                    }
                }

                Locker         = null;
                System         = null;
                TableComposite = null;
                Context        = null;
                disposed       = true;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Creates the database in the context given, granting the administrative
        /// control to the user identified by the given name and password.
        /// </summary>
        /// <param name="adminName">The name of the administrator.</param>
        /// <param name="adminPassword">The password used to identify the administrator.</param>
        /// <exception cref="DatabaseSystemException">
        /// 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.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If either one of <paramref name="adminName"/> or <paramref name="adminPassword"/>
        /// are <c>null</c> or empty.
        /// </exception>
        /// <remarks>
        /// <para>
        /// The properties used to create the database are extracted from
        /// the underlying context (<see cref="DatabaseContext" />).
        /// </para>
        /// <para>
        /// This method does not automatically open the database: to make it accessible
        /// a call to <see cref="Open" /> is required.
        /// </para>
        /// </remarks>
        /// <seealso cref="IDatabaseContext.Configuration" />
        public void Create(string adminName, string adminPassword)
        {
            if (Context.ReadOnly())
            {
                throw new DatabaseSystemException("Cannot 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()) {
                    using (var context = session.CreateQuery()) {
                        try {
                            session.CurrentSchema(SystemSchema.Name);

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

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

                            context.CreatePublicUser();

                            // Create the system views
                            InformationSchema.CreateViews(context);
                            InformationSchema.GrantToPublic(context);

                            this.CreateAdminUser(context, adminName, adminPassword);

                            SetCurrentDataVersion(context);

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

                            OnDatabaseCreate(context);

                            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);
            }
        }
Beispiel #13
0
 public ILargeObject GetLargeObject(ObjectId objId)
 {
     return(TableComposite.GetLargeObject(objId));
 }
Beispiel #14
0
 public ILargeObject CreateLargeObject(long objectSize, bool compressed)
 {
     return(TableComposite.CreateLargeObject(objectSize, compressed));
 }