Skip to content

NH-3724 - Added support for notification handlers #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

NH-3724 - Added support for notification handlers #363

wants to merge 5 commits into from

Conversation

rjperes
Copy link
Member

@rjperes rjperes commented Oct 18, 2014

Added support for notification handlers (InfoMessage event in most ADO.NET drivers)

Added support for notification handlers (InfoMessage event in most ADO.NET drivers)
@@ -20,6 +20,12 @@ public abstract class DriverBase : IDriver, ISqlParameterFormatter
private int commandTimeout;
private bool prepareSql;

public virtual void AddNotificationHandler(IDbConnection con, Delegate handler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to throw not supported exception

- Base driver throws exception if a handler is passed to it
- Drivers for .NET BCL classes just cast parameters to the expected types and will throw an exception if the type is wrong
@oskarb
Copy link
Member

oskarb commented Oct 22, 2014

Since many providers seems to follow the "InfoMessage" convention set by the providers provided by MS in ADO.NET, and since we're using lots of reflection anyway, I think DriverBase should look for this event to avoid all the duplication. If a handler is set and the InfoMessage event isn't found, DriverBase should throw NotSupportedException, as Alex said. I didn't count, but I think much fewer drivers would need to override.

As I understand this, the application must set a handler of a type that matches the currently used provider. We don't make an effort to abstract to a common delegate definition? Perhaps that is ok. So the value of this is that the application can configure NH to set the delegate on all connections, without having to override the application or implement a connection provider?

@oskarb oskarb added this to the 5.0.0 milestone Oct 22, 2014
@oskarb
Copy link
Member

oskarb commented Oct 22, 2014

For PostgreSQL there are two events. I havent' researched so I'm just gonna ask if you are sure you picked the correct one, or if we should handle both, or if we should pick one depending on type of the configured handler?

Exception is thrown if event is not found
@rjperes
Copy link
Member Author

rjperes commented Oct 23, 2014

@oskarb I updated the pull request as mentioned. As for for PostgreSQL, I think it is the Notification event that we're interested at - I saw lots of examples mentioning it in the same context. For the delegate, I don't think we can abstract it with any class other than Delegate. EventHandler and EventHandler<EventArgs> won't do.


if (prop == null)
{
throw new NotSupportedException("Current driver does not support notifications");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the dot at the end of the message (as recommended by MS).

@oskarb
Copy link
Member

oskarb commented Oct 23, 2014

Please remove the using-declarations that was added by this patch but which are no longer required.

@rjperes
Copy link
Member Author

rjperes commented Oct 23, 2014

Done.

@hazzik
Copy link
Member

hazzik commented Nov 18, 2014

@rjperes can you please update titles of you PRs including title from JIRA? Like "NH-3724 - Handle Information Messages From Server"

@hazzik hazzik changed the title NH-3724 NH-3724 - Added support for notification handlers Apr 6, 2017
@hazzik hazzik modified the milestones: 5.1, 5.0 Aug 3, 2017
@hazzik hazzik modified the milestones: 5.1, 6.0 Dec 23, 2017
@hazzik
Copy link
Member

hazzik commented Apr 10, 2019

Replaced by #2113

@hazzik hazzik closed this Apr 10, 2019
@hazzik hazzik removed this from the 6.0 milestone Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants