Exemple #1
0
        public void CreateWithPks_Valid(DatabaseType dbType)
        {
            CreateTable(dbType);

            _table.CreatePrimaryKey(new [] { _table.DiscoverColumn("name") });
            GetImplementer().CreateTrigger(new ThrowImmediatelyCheckNotifier());

            Assert.AreEqual(TriggerStatus.Enabled, GetImplementer().GetTriggerStatus());
            Assert.AreEqual(true, GetImplementer().CheckUpdateTriggerIsEnabledAndHasExpectedBody());
        }
 private void CreateIndex(DiscoveredTable table, DiscoveredColumn onColumn, string configurationName)
 {
     try
     {
         table.CreatePrimaryKey(onColumn);
     }
     catch (Exception e)
     {
         throw new Exception("Failed to create unique primary key on the results of AggregateConfiguration " + configurationName, e);
     }
 }
Exemple #3
0
        public void SetUpDle()
        {
            var rootFolder = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
            var subdir     = rootFolder.CreateSubdirectory("TestsRequiringADle");

            LoadDirectory = LoadDirectory.CreateDirectoryStructure(rootFolder, subdir.FullName, true);

            LiveTable = CreateDataset <Demography>(500, 5000, new Random(190));
            LiveTable.CreatePrimaryKey(new DiscoveredColumn[] {
                LiveTable.DiscoverColumn("chi"),
                LiveTable.DiscoverColumn("dtCreated"),
                LiveTable.DiscoverColumn("hb_extract")
            });

            TestCatalogue = Import(LiveTable);
            RowsBefore    = 5000;

            TestLoadMetadata = new LoadMetadata(CatalogueRepository, "Loading Test Catalogue");
            TestLoadMetadata.LocationOfFlatFiles = LoadDirectory.RootPath.FullName;
            TestLoadMetadata.SaveToDatabase();


            //make the load load the table
            TestCatalogue.LoadMetadata_ID = TestLoadMetadata.ID;
            TestCatalogue.SaveToDatabase();

            var csvProcessTask = new ProcessTask(CatalogueRepository, TestLoadMetadata, LoadStage.Mounting);
            var args           = csvProcessTask.CreateArgumentsForClassIfNotExists <AnySeparatorFileAttacher>();

            csvProcessTask.Path            = typeof(AnySeparatorFileAttacher).FullName;
            csvProcessTask.ProcessTaskType = ProcessTaskType.Attacher;
            csvProcessTask.SaveToDatabase();

            var filePattern = args.Single(a => a.Name == "FilePattern");

            filePattern.SetValue("*.csv");
            filePattern.SaveToDatabase();

            var tableToLoad = args.Single(a => a.Name == "TableToLoad");

            tableToLoad.SetValue(TestCatalogue.GetTableInfoList(false).Single());
            tableToLoad.SaveToDatabase();

            var separator = args.Single(a => a.Name == "Separator");

            separator.SetValue(",");
            separator.SaveToDatabase();

            var ignoreDataLoadRunIDCol = args.Single(a => a.Name == "IgnoreColumns");

            ignoreDataLoadRunIDCol.SetValue("hic_dataLoadRunID");
            ignoreDataLoadRunIDCol.SaveToDatabase();


            //Get DleRunner to run pre load checks (includes trigger creation etc)
            var runner = new DleRunner(new DleOptions()
            {
                LoadMetadata = TestLoadMetadata.ID, Command = CommandLineActivity.check
            });

            runner.Run(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), new AcceptAllCheckNotifier(), new GracefulCancellationToken());
        }
        public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny)
        {
            try
            {
                if (_managedConnection != null)
                {
                    //if there was an error
                    if (pipelineFailureExceptionIfAny != null)
                    {
                        _managedConnection.ManagedTransaction.AbandonAndCloseConnection();

                        listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Transaction rolled back sucessfully"));

                        if (_bulkcopy != null)
                        {
                            _bulkcopy.Dispose();
                        }
                    }
                    else
                    {
                        _managedConnection.ManagedTransaction.CommitAndCloseConnection();

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

                        listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Transaction committed sucessfully"));
                    }
                }
            }
            catch (Exception e)
            {
                listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "Commit failed on transaction (probably there was a previous error?)", e));
            }

            //if we have a primary key to create
            if (pipelineFailureExceptionIfAny == null && _primaryKey != null && _primaryKey.Any() && discoveredTable != null && discoveredTable.Exists())
            {
                //Find the columns in the destination
                var allColumns = discoveredTable.DiscoverColumns();

                //if there are not yet any primary keys
                if (allColumns.All(c => !c.IsPrimaryKey))
                {
                    //find the columns the user decorated in his DataTable
                    DiscoveredColumn[] pkColumnsToCreate = allColumns.Where(c => _primaryKey.Any(pk => pk.Equals(c.GetRuntimeName(), StringComparison.CurrentCultureIgnoreCase))).ToArray();

                    //make sure we found all of them
                    if (pkColumnsToCreate.Length != _primaryKey.Count)
                    {
                        throw new Exception("Could not find primary key column(s) " + string.Join(",", _primaryKey) + " in table " + discoveredTable);
                    }

                    //create the primary key to match user provided columns
                    discoveredTable.CreatePrimaryKey(AlterTimeout, pkColumnsToCreate);
                }
            }

            EndAuditIfExists();
        }