Exemple #1
0
        /// <summary>
        /// Prepare and Open runtime cursor
        /// </summary>
        /// <param name="runtimeCursor"></param>
        private void PrepareAndOpenCursor(RuntimeCursor runtimeCursor, bool openTransaction)
        {
            GatewayResult result = null;

            runtimeCursor.CursorDefinition.StartPosition   = new DbPos(true);
            runtimeCursor.CursorDefinition.CurrentPosition = new DbPos(true);

            result = GatewayCommandsFactory.CreateCursorPrepareCommand(runtimeCursor, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                if (openTransaction)
                {
                    result = GatewayCommandsFactory.CreateGatewayCommandOpenTransaction(ClientManager.Instance.LocalManager).Execute();
                }
                if (result.Success)
                {
                    result = GatewayCommandsFactory.CreateCursorOpenCommand(runtimeCursor, ClientManager.Instance.LocalManager).Execute();
                }
            }

            if (!result.Success)
            {
                throw new DataSourceConversionFailedException(runtimeCursor.CursorDefinition.DataSourceDefinition.Name, result.ErrorDescription);
            }
        }
        /// <summary>
        /// Create cursor Open sommand.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <param name="localManager"></param>
        /// <returns></returns>
        public static GatewayCommandCursorOpen CreateCursorOpenCommand(RuntimeCursor runtimeCursor, LocalManager localManager, bool ValueInGatewayFormat)
        {
            GatewayCommandCursorOpen cursorOpenCommand = CreateCursorOpenCommand(runtimeCursor, localManager);

            cursorOpenCommand.ValueInGatewayFormat = ValueInGatewayFormat;

            return(cursorOpenCommand);
        }
        /// <summary>
        /// Create Cursor Insert Commmand.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <param name="localManager"></param>
        /// <returns></returns>
        public static GatewayCommandCursorInsertRecord CreateCursorInsertCommand(RuntimeCursor runtimeCursor, LocalManager localManager)
        {
            GatewayCommandCursorInsertRecord cursorInsertCommand = new GatewayCommandCursorInsertRecord();

            cursorInsertCommand.RuntimeCursor = runtimeCursor;
            cursorInsertCommand.LocalManager  = localManager;

            return(cursorInsertCommand);
        }
        /// <summary>
        /// Create Cursor Release command.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <param name="localManager"></param>
        public static GatewayCommandRelease CreateCursorReleaseCommand(RuntimeCursor runtimeCursor, LocalManager localManager)
        {
            GatewayCommandRelease cursorReleaseCommand = new GatewayCommandRelease();

            cursorReleaseCommand.RuntimeCursor = runtimeCursor;
            cursorReleaseCommand.LocalManager  = localManager;

            return(cursorReleaseCommand);
        }
        /// <summary>
        /// Create cursor Open sommand.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <param name="localManager"></param>
        /// <returns></returns>
        public static GatewayCommandCursorOpen CreateCursorOpenCommand(RuntimeCursor runtimeCursor, LocalManager localManager)
        {
            GatewayCommandCursorOpen cursorOpenCommand = new GatewayCommandCursorOpen();

            cursorOpenCommand.RuntimeCursor = runtimeCursor;
            cursorOpenCommand.LocalManager  = localManager;

            return(cursorOpenCommand);
        }
        /// <summary>
        /// Create Cursor Fetch command.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <param name="localManager"></param>
        /// <returns></returns>
        public static GatewayCommandFetch CreateCursorFetchCommand(RuntimeCursor runtimeCursor, LocalManager localManager)
        {
            GatewayCommandFetch cursorFetchCommand = new GatewayCommandFetch();

            cursorFetchCommand.RuntimeCursor = runtimeCursor;
            cursorFetchCommand.LocalManager  = localManager;

            return(cursorFetchCommand);
        }
Exemple #7
0
        /// <summary>
        /// override - build also the locate cursor
        /// </summary>
        public void BuildLocateCursor()
        {
            Order locateDirection = Order.Ascending;

            // get the locate order value
            if (LocalDataviewManager.Task.checkIfExistProp(PropInterface.PROP_TYPE_TASK_PROPERTIES_LOCATE_ORDER))
            {
                locateDirection = (Order)LocalDataviewManager.Task.getProp(PropInterface.PROP_TYPE_TASK_PROPERTIES_LOCATE_ORDER).getValue()[0];
            }

            LocateCursor = CursorBuilder.Build(this, locateDirection);
        }
Exemple #8
0
        /// <summary>
        /// Build Current values for Runtime cursor.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <param name="record"></param>
        private void BuildCurrentValues(RuntimeCursor runtimeCursor, RecordForDataViewToDataSource record)
        {
            for (int j = 0; j < destinationDataSourceDefinition.Fields.Count; j++)
            {
                DBField dbfield    = destinationDataSourceDefinition.Fields[j];
                bool    fieldExist = false;

                //Check if current Dbfield exist in the selected column list.
                foreach (DBField destinationDbField in destinationColumnList)
                {
                    if (dbfield.Name == destinationDbField.Name)
                    {
                        fieldExist = true;
                        break;
                    }
                }

                //If field is selected then set the value of that field in the runtime cursor.
                if (fieldExist)
                {
                    runtimeCursor.CursorDefinition.IsFieldUpdated[j] = true;

                    //Convert values of fields of record.
                    int recordFieldIndex;
                    destinationToSourceFieldIndexMapping.TryGetValue(dbfield.Name, out recordFieldIndex);

                    runtimeCursor.RuntimeCursorData.CurrentValues[j].IsNull = record.IsNull(recordFieldIndex);

                    if (record.IsNull(recordFieldIndex))
                    {
                        if (!dbfield.AllowNull)
                        {
                            runtimeCursor.RuntimeCursorData.CurrentValues[j].Value  = dbfield.DefaultValue;
                            runtimeCursor.RuntimeCursorData.CurrentValues[j].IsNull = false;
                        }
                    }
                    else
                    {
                        runtimeCursor.RuntimeCursorData.CurrentValues[j].Value = record.GetFieldValue(recordFieldIndex);
                    }
                }
                else
                {
                    runtimeCursor.CursorDefinition.IsFieldUpdated[j]        = false;
                    runtimeCursor.RuntimeCursorData.CurrentValues[j].IsNull = true;
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Fetech the values from source datasource, convert fetched values and insert values in destination dataSource.
        /// </summary>
        /// <param name="fromDataSourceDefinition"></param>
        /// <param name="toDataSourceDefinition"></param>
        private void ConvertAndInsertValues(DataSourceDefinition fromDataSourceDefinition, DataSourceDefinition toDataSourceDefinition)
        {
            GatewayResult result = null;

            MainCursorBuilder cursorBuilder = new MainCursorBuilder(null);

            RuntimeCursor fromRuntimeCursor = cursorBuilder.Build(fromDataSourceDefinition, Access.Read);
            RuntimeCursor toRuntimeCursor   = cursorBuilder.Build(toDataSourceDefinition, Access.Write);

            //Prepare and open source and destnation runtime cursor.
            PrepareAndOpenCursor(fromRuntimeCursor, true);
            PrepareAndOpenCursor(toRuntimeCursor, false);

            //Create fetch command
            GatewayCommandFetch fetchCommand = GatewayCommandsFactory.CreateCursorFetchCommand(fromRuntimeCursor, ClientManager.Instance.LocalManager);

            while (true)
            {
                //Fetch record from source table
                result = fetchCommand.Execute();
                if (!result.Success)
                {
                    if (result.ErrorCode == GatewayErrorCode.NoRecord)
                    {
                        break;
                    }
                    else
                    {
                        throw new DataSourceConversionFailedException(fromDataSourceDefinition.Name, result.ErrorDescription);
                    }
                }

                //Convert values of fields of source table.
                ConvertFields(fromDataSourceDefinition, toDataSourceDefinition, fromRuntimeCursor.RuntimeCursorData.CurrentValues, toRuntimeCursor.RuntimeCursorData.CurrentValues);

                for (int i = 0; i < toDataSourceDefinition.Fields.Count; i++)
                {
                    toRuntimeCursor.CursorDefinition.IsFieldUpdated[i] = true;
                }

                //Insert converted values into temporary table.
                result = GatewayCommandsFactory.CreateCursorInsertCommand(toRuntimeCursor, ClientManager.Instance.LocalManager).Execute();
            }

            // release and close source and destnation runtime cursor.
            ReleaseAndCloseCursor(fromRuntimeCursor, true);
            ReleaseAndCloseCursor(toRuntimeCursor, false);
        }
Exemple #10
0
        /// <summary>
        /// Returns gateway adapter cursor according to its runtime cursor
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <returns></returns>
        internal GatewayAdapterCursor GetCursor(RuntimeCursor runtimeCursor)
        {
            if (gatewayAdapterCursors.ContainsKey(runtimeCursor))
            {
                GatewayAdapterCursor gatewayAdapterCursor = gatewayAdapterCursors[runtimeCursor];

                //This change is done to execute unit test. Because for unit test each command refers different runtime cursor.
                // So to get correct Cursor definition copy CursorDefinition from RunTimeCursor To Gateway cursor.
                if (!runtimeCursor.CursorDefinition.Equals(gatewayAdapterCursor.Definition))
                {
                    gatewayAdapterCursor.Definition = runtimeCursor.CursorDefinition;
                }

                return(gatewayAdapterCursor);
            }

            return(null);
        }
Exemple #11
0
        /// <summary>
        /// Close and Relaese runtime cursor.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        private void ReleaseAndCloseCursor(RuntimeCursor runtimeCursor, bool closeTransaction)
        {
            GatewayResult result = null;

            result = GatewayCommandsFactory.CreateCursorCloseCommand(runtimeCursor, ClientManager.Instance.LocalManager).Execute();
            if (result.Success)
            {
                if (closeTransaction)
                {
                    result = GatewayCommandsFactory.CreateGatewayCommandCloseTransaction(ClientManager.Instance.LocalManager).Execute();
                }
                if (result.Success)
                {
                    result = GatewayCommandsFactory.CreateCursorReleaseCommand(runtimeCursor, ClientManager.Instance.LocalManager).Execute();
                }
            }

            if (!result.Success)
            {
                throw new DataSourceConversionFailedException(runtimeCursor.CursorDefinition.DataSourceDefinition.Name, result.ErrorDescription);
            }
        }
Exemple #12
0
        /// <summary>
        /// Build the ranges using the unique key segments.
        /// </summary>
        /// <param name="record"></param>
        /// <param name="runtimeCursor"></param>
        /// <returns></returns>
        private void BuildRanges(RecordForDataViewToDataSource record, RuntimeCursor runtimeCursor)
        {
            int recordFieldIndex = 0;

            if (uniqueKey != null)
            {
                runtimeCursor.RuntimeCursorData.Ranges = new List <RangeData>();

                foreach (DBSegment segment in uniqueKey.Segments)
                {
                    for (int fldIndex = 0; fldIndex < destinationColumnList.Count; fldIndex++)
                    {
                        DBField dbField = destinationColumnList[fldIndex];

                        if (dbField.Equals(segment.Field))
                        {
                            RangeData rngData = new RangeData();
                            rngData.FieldIndex = dbField.IndexInRecord;

                            rngData.Max.Type    = RangeType.RangeParam;
                            rngData.Max.Discard = false;

                            rngData.Min.Type    = RangeType.RangeParam;
                            rngData.Min.Discard = false;

                            FieldValue fieldValue = new FieldValue();
                            destinationToSourceFieldIndexMapping.TryGetValue(dbField.Name, out recordFieldIndex);
                            fieldValue.Value = record.GetFieldValue(recordFieldIndex);

                            rngData.Max.Value = fieldValue;
                            rngData.Min.Value = fieldValue;

                            runtimeCursor.RuntimeCursorData.Ranges.Add(rngData);
                            break;
                        }
                    }
                }
            }
        }
Exemple #13
0
 /// <summary>
 /// Removes the specific cursor from the cursors dictionary
 /// </summary>
 /// <param name="runtimeCursor"></param>
 internal void RemoveCursor(RuntimeCursor runtimeCursor)
 {
     Debug.Assert(gatewayAdapterCursors.ContainsKey(runtimeCursor));
     gatewayAdapterCursors.Remove(runtimeCursor);
 }
Exemple #14
0
 /// <summary>
 /// Adds the specific cursor to the cursors dictionary
 /// </summary>
 /// <param name="runtimeCursor"></param>
 /// <param name="gatewayAdapterCursor"></param>
 internal void AddCursor(RuntimeCursor runtimeCursor, GatewayAdapterCursor gatewayAdapterCursor)
 {
     Debug.Assert(!gatewayAdapterCursors.ContainsKey(runtimeCursor));
     gatewayAdapterCursors.Add(runtimeCursor, gatewayAdapterCursor);
 }
Exemple #15
0
 /// <summary>
 /// builder for the cursor
 /// </summary>
 public void BuildCursor()
 {
     CurrentCursor = defaultCursor = CursorBuilder.Build(this);
 }
        /// <summary>
        /// Create Cursor update command.
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <param name="localManager"></param>
        /// <returns></returns>
        public static GatewayCommandCursorUpdateRecord CreateGatewayCommandCursorUpdateRecord(RuntimeCursor runtimeCursor, LocalManager localManager)
        {
            GatewayCommandCursorUpdateRecord cursorUpdateCommand = new GatewayCommandCursorUpdateRecord();

            cursorUpdateCommand.RuntimeCursor = runtimeCursor;

            // execute the command
            cursorUpdateCommand.LocalManager = localManager;

            return(cursorUpdateCommand);
        }
Exemple #17
0
        /// <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);
        }