/// <summary> /// open local tables /// </summary> /// <returns></returns> private GatewayResult OpenTables() { GatewayResult retVal = new GatewayResult(); foreach (DataSourceReference dataSourceRef in Task.DataSourceReferences) { if (dataSourceRef.IsLocal) { String fileName; if (dataSourceRef.NameExpression > 0) { Task.EvaluateExpressionAsUnicode(dataSourceRef.NameExpression, out fileName); } else { fileName = dataSourceRef.DataSourceDefinition.Name; } //create gw open command GatewayCommandFileOpen fileOpenCommand = GatewayCommandsFactory.CreateFileOpenCommand(fileName, dataSourceRef.DataSourceDefinition, dataSourceRef.Access, ClientManager.Instance.LocalManager); retVal = fileOpenCommand.Execute(); if (!retVal.Success) { break; } } } return(retVal); }
/// <summary> /// Convert DataSource from old DataSourceDefinition to new DataSourceDefinition. It create temporaryDataSource definition and perform all operations /// on temporary DataSourcedefinition and return it. /// </summary> /// <param name="fromDataSourceDefinition"></param> /// <param name="toDataSourceDefinition"></param> /// <returns>Temporary DataSourceDefinition</returns> private DataSourceDefinition ConvertDataSource(DataSourceDefinition fromDataSourceDefinition, DataSourceDefinition toDataSourceDefinition) { Logger.Instance.WriteSupportToLog("convertDataSource():>>>> ", true); Logger.Instance.WriteSupportToLog(String.Format("convertDataSource(): converting table {0}", fromDataSourceDefinition.Name), true); GatewayResult result = null; string temporaryTableName = GetTemporaryTableName(fromDataSourceDefinition.Id); DataSourceDefinition temporaryDataSourceDefinition = (DataSourceDefinition)toDataSourceDefinition.Clone(); temporaryDataSourceDefinition.Name = temporaryTableName; // In order to genearte temporary key name for the temporary dbh set magic key mask on the keys. for (int keyIndex = 0; keyIndex < temporaryDataSourceDefinition.Keys.Count; keyIndex++) { DBKey key = temporaryDataSourceDefinition.Keys[keyIndex]; key.SetMask(KeyMasks.MagicKeyMask); } // Delete temporary table, if exists result = GatewayCommandsFactory.CreateFileDeleteCommand(temporaryTableName, temporaryDataSourceDefinition, ClientManager.Instance.LocalManager).Execute(); if (!result.Success && result.ErrorCode != GatewayErrorCode.FileNotExist) { throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription); } // Open source and temporary table temporaryDataSourceDefinition.SetMask(DbhMask.CheckExistMask); result = GatewayCommandsFactory.CreateFileOpenCommand(temporaryTableName, temporaryDataSourceDefinition, Access.Write, ClientManager.Instance.LocalManager).Execute(); if (result.Success) { result = GatewayCommandsFactory.CreateFileOpenCommand(fromDataSourceDefinition.Name, fromDataSourceDefinition, Access.Read, ClientManager.Instance.LocalManager).Execute(); } if (!result.Success) { throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription); } //Convert values of source table and insert it into temporary table ConvertAndInsertValues(fromDataSourceDefinition, temporaryDataSourceDefinition); //Close source and temporary table result = GatewayCommandsFactory.CreateFileCloseCommand(temporaryDataSourceDefinition, ClientManager.Instance.LocalManager).Execute(); if (result.Success) { GatewayCommandsFactory.CreateFileCloseCommand(fromDataSourceDefinition, ClientManager.Instance.LocalManager).Execute(); } if (!result.Success) { throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription); } Logger.Instance.WriteSupportToLog("convertDataSource():<<<< ", true); return(temporaryDataSourceDefinition); }
internal GatewayResult OpenDataSource() { var dataSourceRef = DataSourceViewDefinition.TaskDataSource; string fileName = dataSourceRef.DataSourceDefinition.Name; var command = GatewayCommandsFactory.CreateFileOpenCommand(fileName, dataSourceRef.DataSourceDefinition, dataSourceRef.Access, this.LocalDataviewManager.LocalManager); var retVal = command.Execute(); return(retVal); }
/// <summary> /// Update dataview to DataSource. /// </summary> private ReturnResultBase UpdateDataViewToDataSource() { bool transactionOpened = false; string error = string.Empty; string dataSourceName = ClientManager.Instance.getEnvParamsTable().translate(updateDataViewToDataSourceCommand.DestDataSourceName); if (string.IsNullOrEmpty(dataSourceName)) { dataSourceName = destinationDataSourceDefinition.Name; } GatewayResult result = GatewayCommandsFactory.CreateFileExistCommand(dataSourceName, destinationDataSourceDefinition, ClientManager.Instance.LocalManager).Execute(); bool insertMode = !result.Success; if (!insertMode) { uniqueKey = GetUniqueKey(); if (uniqueKey == null) { error = "DataViewToDataSource - When using the DataViewtoDataSource function, a unique index must be defined in the destination data source ."; Logger.Instance.WriteExceptionToLog(error); ClientManager.Instance.ErrorToBeWrittenInServerLog = error; return(new ReturnResult(MsgInterface.STR_DATAVIEW_TO_DATASOURCE_OPERATION_FAILED)); } else if (!CheckDestinationColumnListContainUniqueKeyColumns()) { error = "DataViewToDataSource - When using the DataViewtoDataSource function, all the segments of the unique index must be selected."; Logger.Instance.WriteExceptionToLog(error); ClientManager.Instance.ErrorToBeWrittenInServerLog = error; return(new ReturnResult(MsgInterface.STR_DATAVIEW_TO_DATASOURCE_OPERATION_FAILED)); } } result = GatewayCommandsFactory.CreateFileOpenCommand(dataSourceName, destinationDataSourceDefinition, Access.Write, ClientManager.Instance.LocalManager).Execute(); if (result.Success) { //Build the runtime cursor. MainCursorBuilder cursorBuilder = new MainCursorBuilder(null); RuntimeCursor destinationRuntimeCursor = cursorBuilder.Build(destinationDataSourceDefinition, Access.Write); destinationRuntimeCursor.CursorDefinition.StartPosition = new DbPos(true); destinationRuntimeCursor.CursorDefinition.CurrentPosition = new DbPos(true); // Prepare the cursor. result = GatewayCommandsFactory.CreateCursorPrepareCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute(); if (result.Success) { //If tansaction is not open then open the transaction. if (TaskTransactionManager.LocalOpenedTransactionsCount == 0) { result = GatewayCommandsFactory.CreateGatewayCommandOpenTransaction(ClientManager.Instance.LocalManager).Execute(); transactionOpened = true; } if (result.Success) { SetDataToRuntimeParser(); RecordForDataViewToDataSource record = GetRecord(); while (record != null) { BuildCurrentValues(destinationRuntimeCursor, record); result = GatewayCommandsFactory.CreateCursorInsertCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager, true).Execute(); if (!result.Success) { if (result.ErrorCode == GatewayErrorCode.DuplicateKey) { if (!insertMode) { //Build the ranges using unique key segments value. BuildRanges(record, destinationRuntimeCursor); //Open the cursor and apply the ranges. result = GatewayCommandsFactory.CreateCursorOpenCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager, true).Execute(); if (result.Success) { //Fetch the record result = GatewayCommandsFactory.CreateCursorFetchCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute(); BuildCurrentValues(destinationRuntimeCursor, record); //If record found, that means record with same key value exists, so update the current record with destination record. if (result.Success) { result = GatewayCommandsFactory.CreateGatewayCommandCursorUpdateRecord(destinationRuntimeCursor, ClientManager.Instance.LocalManager, true).Execute(); } else { if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog)) { ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n"; } ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription; } //Close the cursor. GatewayCommandsFactory.CreateCursorCloseCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute(); } else { if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog)) { ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n"; } ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription; } } else { if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog)) { ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n"; } ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription; record = GetRecord(); continue; } } else { if (!string.IsNullOrEmpty(ClientManager.Instance.ErrorToBeWrittenInServerLog)) { ClientManager.Instance.ErrorToBeWrittenInServerLog += "\r\n"; } ClientManager.Instance.ErrorToBeWrittenInServerLog += result.ErrorDescription; break; } } record = GetRecord(); } //If transaction is opened , then close the transaction. If any error occurs then abort the transation else do commit. if (transactionOpened) { GatewayCommandCloseTransaction closeTransactionCommand = GatewayCommandsFactory.CreateGatewayCommandCloseTransaction(ClientManager.Instance.LocalManager); if (result.Success) { closeTransactionCommand.TransactionModes = TransactionModes.Commit; } else { closeTransactionCommand.TransactionModes = TransactionModes.Abort; } closeTransactionCommand.Execute(); } //Release the cursor and close the file. GatewayCommandsFactory.CreateCursorReleaseCommand(destinationRuntimeCursor, ClientManager.Instance.LocalManager).Execute(); GatewayCommandsFactory.CreateFileCloseCommand(destinationDataSourceDefinition, ClientManager.Instance.LocalManager).Execute(); } else { ClientManager.Instance.ErrorToBeWrittenInServerLog = result.ErrorDescription; } } else { ClientManager.Instance.ErrorToBeWrittenInServerLog = result.ErrorDescription; } } else { ClientManager.Instance.ErrorToBeWrittenInServerLog = result.ErrorDescription; } return(result); }