} // end of ValidateFieldMapOnCQ /// <summary> /// Execute the Query and migrate the data /// </summary> /// <param name="baseEntityName">Base Entity Name</param> private void MigrateData(string baseEntityName, string baseEntityWitName) { Session cqSession = m_cqConnection.GetUserSession(); OAdQuerydef qryDef = m_cqConnection.QueryDefinition; // edit the query and add dbid field // dbid is suppose to be unique within a Entity CQWrapper.BuildField(qryDef, "dbid"); // prepare result set OAdResultset result = CQWrapper.BuildResultSet(cqSession, qryDef); // process records for base entity CQEntity baseEntityRecords = m_cqParams.entityRecords[baseEntityName]; // enable record count before execute so that no of records can be fetched CQWrapper.EnableRecordCount(result); // execute the query CQWrapper.ExecuteResultSet(result); int columnCount = CQWrapper.GetResultSetColumnCount(result); // lookup for dbid column bool dbidExist = false; int dbidColumnIndex = 0; for (int colIter = 1; colIter <= columnCount; colIter++) { if (string.Equals(CQWrapper.GetColumnLabel(result, colIter), "dbid", StringComparison.OrdinalIgnoreCase)) { dbidExist = true; dbidColumnIndex = colIter; break; } } if (!dbidExist) { // neither query contain dbid nor can be edited to include a new column string errMsg = UtilityMethods.Format(CQResource.CQ_NO_DBID_IN_QUERY, m_cqConnection.QueryName, m_convParams.ConfigFile); PostMigrationReport.WriteIssue(null, null, RepStatus.Failed, ReportIssueType.Critical, String.Empty, baseEntityName, IssueGroup.Config, errMsg); Logger.Write(LogSource.CQ, TraceLevel.Error, errMsg); throw new ConverterException(errMsg); } // start the progress thread for updating the progress m_progressThread = new Thread(new ThreadStart(CQConverter.UpdateProgress)); m_progressThread.Name = "Progress"; try { // get the work item helper handle TotalRecords = CQWrapper.GetRecordCount(result); m_progressThread.Start(); while (CQWrapper.ResultSetMoveNext(result) == CQConstants.SUCCESS) { string dbid = (string)CQWrapper.GetColumnValue(result, dbidColumnIndex); // create a CQEntity for that CQEntityRec record = new CQEntityRec(int.Parse(dbid), baseEntityName, m_cqParams); try { // populate and migrate the record and all referenced records RecordsProcessed++; baseEntityRecords.AddRecord(record); if (record.Populate() == false && m_cqParams.exitOnError == true) { return; // stop processing more records } } catch (ConverterException conEx) { // log the error and continue with next item string errMsg = UtilityMethods.Format(CQResource.CQ_WI_READ_FAILED, dbid, conEx.Message); ReportWorkItemFailure(errMsg, dbid, baseEntityName, baseEntityWitName, m_cqParams.exitOnError); if (m_cqParams.exitOnError == true) { // throw the error back .. should not continue with the current record throw; } } } } finally { // terminate the progress thread m_progressThread.Abort(); Thread.Sleep(5000); // allow the display thread to stop } } // end of MigrateData