public DatabaseSnapshot createSnapshot(liquibase.database.Database database, string schema, java.util.Set listeners)
        {
            DatabaseSnapshot snapshot = new DatabaseSnapshot(database, schema);

            OleDbConnection conn = ((AdoConnection)database.getConnection()).GetUnderlyingConnection();

             string[] restrictions = new string[4];
             restrictions[3] = "Table";

             DataTable tables = conn.GetSchema("Tables", restrictions);

             foreach (DataRow row in tables.Rows) {
                 Table table =  new Table(row.Field<String>("TABLE_NAME"));
                 table.setSchema(row.Field<String>("TABLE_SCHEMA"));

                 snapshot.getTables().add(table);

                 DataTable tableInfo = conn.GetSchema("Columns", new string[4] { null, null, table.getName(), null });

                 foreach (DataRow colRow in tableInfo.Rows) {
                     Column column = new Column();
                     column.setName(colRow.Field<string>("COLUMN_NAME"));
                     column.setTable(table);
                     //column.setTypeName(colRow.Field<string>("DATA_TYPE"));
                     //column.setColumnSize(colRow.Field<int>("NUMERIC_SCALE"));

                     table.getColumns().add(column);
                 }
             }

            return snapshot;
        }
Example #2
0
        /// <summary>
        /// Initialize DatabaseSentinel for sourceDatabase and destinationDatabase
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public void Initialize(SourceDatabase source, DestinationDatabase destination)
        {
            //
            // Create database snapshot
            // To store record which has been mapped
            DatabaseSnapshot sourceDatabaseSnapshot = new DatabaseSnapshot(source);
            DatabaseSnapshot destDatabaseSnapshot   = new DatabaseSnapshot(destination);


            //
            // Get all table of destination database
            // Validate source table, and destination table
            List <string> listTables = destination.GetListTableHasPrimaryKey();

            foreach (string table in listTables)
            {
                try
                {
                    this.Initialize(table, sourceDatabaseSnapshot, destDatabaseSnapshot, destDatabaseSnapshot);
                }
                catch (Exception excSaveSnapshot)
                {
                    LogService.Log.Error("Can not save snapshot of table " + table + ". Please check your schema again.", excSaveSnapshot);
                    Environment.Exit(0);
                }
            }


            //
            // Save snapshot
            this._databaseSnapshot = destDatabaseSnapshot;
        }
Example #3
0
        /// <summary>
        /// Returns a snapshot of the RAM database. If the usage when converted to an int is greater than 0
        /// </summary>
        /// <param name="snapshotUsage"></param>
        /// <returns></returns>
        public DatabaseSnapshot GetDatabaseSnapshot(databaseSnapshotUsage snapshotUsage)
        {
            DatabaseSnapshot returnSnapshot;

            if (!useRAMOnly)
            {
                throw new Exception("Snapshots are not used when committing to the database and as such this method should not be called.");
            }

            lock (databaseSnapshotLocker)
            {
                if (snapshotUsage == databaseSnapshotUsage.UseMostRecent || !databaseChangesSinceLastSnapshot)
                {
                    //Else if just the most recent snapshot has been requested or there have been no changes
                    if (currentDatabaseSnapshot == null)
                    {
                        returnSnapshot          = new DatabaseSnapshot(this);
                        currentDatabaseSnapshot = returnSnapshot;
                    }
                    else
                    {
                        returnSnapshot = currentDatabaseSnapshot;
                    }
                }
                else if (snapshotUsage == databaseSnapshotUsage.CreateNew)
                {
                    //If a new snapshot has been requested and there have been database changes since the last snapshot
                    returnSnapshot          = new DatabaseSnapshot(this);
                    currentDatabaseSnapshot = returnSnapshot;
                }
                else if ((int)snapshotUsage > 0)
                {
                    //Else if a recent snapshot has been requested within a specific timeframe
                    if (currentDatabaseSnapshot.SnapshotCreationTime > DateTime.Now.AddSeconds(-(int)snapshotUsage))
                    {
                        if (currentDatabaseSnapshot == null)
                        {
                            returnSnapshot          = new DatabaseSnapshot(this);
                            currentDatabaseSnapshot = returnSnapshot;
                        }
                        else
                        {
                            returnSnapshot = currentDatabaseSnapshot;
                        }
                    }
                    else
                    {
                        returnSnapshot          = new DatabaseSnapshot(this);
                        currentDatabaseSnapshot = returnSnapshot;
                    }
                }
                else
                {
                    throw new Exception("Unable to determine correct database snapshot usage.");
                }
            }

            return(returnSnapshot);
        }
Example #4
0
        /// <summary>
        /// Initialize hasMapped dictionary with tableName
        /// To determinate which record has been mapped
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        protected void Initialize(string tableName, DatabaseSnapshot sourceSnapshot, DatabaseSnapshot destSnapshot, DatabaseSnapshot outputSnapshot)
        {
            //TableSnapshot sourceTable = sourceSnapshot.GetTableSnapshot(tableName);
            TableSnapshot destTable = destSnapshot.GetTableSnapshot(tableName);

            ////
            //// Get common record from source table and destTable
            //// Then try to save to database
            //TableSnapshot commonTable = TableSnapshot.GetCommonRecord(sourceTable, destTable);
            //if (commonTable.IsEmpty == false)
            //{
            //    this._listTableToCheck.Add(tableName);
            //}
            if (destTable.IsEmpty == false)
            {
                this._listTableToCheck.Add(tableName);
            }

            //
            // Add
            outputSnapshot.Add(destTable);
            LogService.Log.Info("Saved snapshot of table : " + tableName);
        }
Example #5
0
        public DatabaseSnapshot createSnapshot(liquibase.database.Database database, string schema, java.util.Set listeners)
        {
            DatabaseSnapshot snapshot = new DatabaseSnapshot(database, schema);

            OleDbConnection conn = ((AdoConnection)database.getConnection()).GetUnderlyingConnection();

            string[] restrictions = new string[4];
            restrictions[3] = "Table";

            DataTable tables = conn.GetSchema("Tables", restrictions);

            foreach (DataRow row in tables.Rows)
            {
                Table table = new Table(row.Field <String>("TABLE_NAME"));
                table.setSchema(row.Field <String>("TABLE_SCHEMA"));

                snapshot.getTables().add(table);

                DataTable tableInfo = conn.GetSchema("Columns", new string[4] {
                    null, null, table.getName(), null
                });

                foreach (DataRow colRow in tableInfo.Rows)
                {
                    Column column = new Column();
                    column.setName(colRow.Field <string>("COLUMN_NAME"));
                    column.setTable(table);
                    //column.setTypeName(colRow.Field<string>("DATA_TYPE"));
                    //column.setColumnSize(colRow.Field<int>("NUMERIC_SCALE"));

                    table.getColumns().add(column);
                }
            }

            return(snapshot);
        }