/// <summary> /// Creates a new copy of the processTask and all it's arguments in the database, this clone is then hooked up to the /// new LoadMetadata at the specified stage /// </summary> /// <param name="loadMetadata">The new LoadMetadata parent for the clone</param> /// <param name="loadStage">The new load stage to put the clone in </param> /// <returns>the new ProcessTask (the clone has a different ID to the parent)</returns> public ProcessTask CloneToNewLoadMetadataStage(LoadMetadata loadMetadata, LoadStage loadStage) { var cataRepository = ((CatalogueRepository)Repository); //clone only accepts sql connections so make sure we aren't in mysql land or something using (cataRepository.BeginNewTransactedConnection()) { try { //get list of arguments to also clone (will happen outside of transaction ProcessTaskArgument[] toCloneArguments = ProcessTaskArguments.ToArray(); //create a new transaction for all the cloning - note that once all objects are cloned the transaction is committed then all the objects are adjusted outside the transaction ProcessTask clone = new ProcessTask(CatalogueRepository, LoadMetadata, loadStage); CopyShallowValuesTo(clone); //foreach of our child arguments foreach (ProcessTaskArgument argument in toCloneArguments) { //clone it but rewire it to the proper ProcessTask parent (the clone) argument.ShallowClone(clone); } //the values passed into parameter clone.LoadMetadata_ID = loadMetadata.ID; clone.LoadStage = loadStage; clone.SaveToDatabase(); //it worked cataRepository.EndTransactedConnection(true); //return the clone return(clone); } catch (Exception) { cataRepository.EndTransactedConnection(false); throw; } } }
private void CheckForProblemsInSQLFile(ICheckNotifier notifier) { try { var sql = File.ReadAllText(Path); //lets check for any SQL that indicates user is trying to modify a STAGING table in a RAW script (for example) foreach (TableInfo tableInfo in LoadMetadata.GetDistinctTableInfoList(false)) { //for each stage get all the object names that are in that stage foreach (var stage in new[] { LoadStage.AdjustRaw, LoadStage.AdjustStaging, LoadStage.PostLoad }) { //process task belongs in that stage anyway so nothing is prohibited if (stage == (LoadStage == LoadStage.Mounting? LoadStage.AdjustRaw:LoadStage)) { continue; } //figure out what is prohibited string prohibitedSql = tableInfo.GetQuerySyntaxHelper().EnsureFullyQualified(tableInfo.GetDatabaseRuntimeName(stage), null, tableInfo.GetRuntimeName(stage)); //if we reference it, complain if (sql.Contains(prohibitedSql)) { notifier.OnCheckPerformed( new CheckEventArgs( "Sql in file '" + Path + "' contains a reference to '" + prohibitedSql + "' which is prohibited since the ProcessTask ('" + Name + "') runs in LoadStage " + LoadStage, CheckResult.Warning)); } } } } catch (Exception e) { notifier.OnCheckPerformed(new CheckEventArgs("Failed to check the contents of the SQL file '" + Path + "'", CheckResult.Fail, e)); } }
/// <summary> /// Returns all tables loaded by the parent <see cref="LoadMetadata"/> /// </summary> /// <returns></returns> public IEnumerable <TableInfo> GetTableInfos() { return(LoadMetadata.GetDistinctTableInfoList(true)); }