Skip to content

Build in Remote Execution

Jean-Pierre Bachmann edited this page Feb 2, 2020 · 1 revision

YAORM has build in support for Remote execution of queries by using the RemotingStrategy / RemotingStrategyExternal.

The RemotingStrategy is the base class that inherts from IDatabaseStrategy and can be injected into the DbAccessLayer. The RemotingStrategy will then act like a other database (must be defined by supplying a DbAccessType). You have to overwrite ether the EnumerateCommand (common wrapper for IEnumerable<IEnumerable<IDataRecord>> <-> IDataReader) or the ExecuteReader (base method returning a IDataReader) and the ExecuteQuery & ExecuteScalar methods. All methods will be handled a RemotingDbCommand (inherts from IDBCommand) that wraps the command.

To Support multicommand & Transactions you must attach yourself to the corresponding events in the Events object. The flow is as following:

It is not assured that the event ParameterCreated is allways called after a connection was opened. The flow is always for one execution of "Database.Run"

  1. Ether ParameterCreated (multiple) or CommandCreated (once)
  2. ConnectionCreated
  3. ConnectionOpened
  4. Ether ParameterCreated (multiple) or CommandCreated (once)
  5. TransactionCreated (if in transaction)
  6. CommandPrepare

Then ether ExecuteReader, ExecuteScalar or ExecuteQuery is called to obtain a result. If this is a MultiCommand run it starts again at pt. 4. After all commands are executed:

  1. TransactionCommit or TransactionRollback
  2. ConnectionClosed

To ensure that all commands in a Transaction or connection are executed as such, you can make use of the RemotingStrategyExternal. This class wraps all those events and provide a more streamlined pattern. The RemotingStrategyExternal will take care of the connection and transaction boundaries by associating each connection, Transaction and Command with its own ID, all you have to do is provide them. For this you must overwrite its abstract methods and call/send the information passed to them to your external device. On your external device you can pass those info to an single instance of RemotingConsumerServer. It handles the ID generation and the execution of commands all on its own. With the RemotingConsumerServer and the RemotingStrategyExternal all you have to do is sending the provided data to the devices/server.

Clone this wiki locally