Repository navigation
Type handler redo - #3956
Type handler redo#3956
Conversation
|
@vonzshik don't worry too much about compilation issues and small fixes - this isn't ready for that kind of review yet anyway, I'll clean all that up before marking this ready for review. The thing I'm a bit stuck on is what I wrote above; right now I don't see how I can avoid duplicating lots of resolution code in order to support the necessary conversions between NpgsqlDbType/DbType/ClrType/DataTypeName for NpgsqlParameter, so in effect we'd have two duplicate paths: one to get a type handler given e.g. a NpgsqlDbType, and another to get "type mapping info" given a NpgsqlDbType, which would allow NpgsqlParameter to know which DbType/ClrType/DataTypeName corresponds. Anything else seems like it would have to degrade perf in the type handler path (which is the critical path), which I don't really want to do for the far less important NpgsqlParameter conversions. Let me know if you have any bright ideas. |
|
OK, this is now almost ready - there are a couple failing tests around some exotic features, but I'm pushing to get general feedback/review. Overall I hoped this would end up nicer than it did. I do think it still considerably improves the codebase, but am open if any of you guys don't like this - don't be afraid to say.
Let me know what you think... |
NinoFloris
left a comment
There was a problem hiding this comment.
There are no more type handler factories, and lots of tricky logic to manage mappings is now gone - that's the good part. Handlers are just instantiated directly in resolvers, in that sense everything is much simpler and more flexible.
This is really nice to see, cleans up this area a lot.
However, there are still various scenarios beyond resolving a handler which make life difficult:
And this is pretty ugly indeed...
From your earlier comment
The thing I'm a bit stuck on is what I wrote above; right now I don't see how I can avoid duplicating lots of resolution code in order to support the necessary conversions between NpgsqlDbType/DbType/ClrType/DataTypeName for NpgsqlParameter
Is this auto filling of the other 'type' fields an ado.net spec thing? Does something like dapper depend on it? I would be completely fine explaining to users 'since pg has an extensible type system we can't say much about these things until we can talk to the pg instance via a connection'. We could always add a static method on some support class ResolveTypeInfo(param, conn) if it's really needed in weird corner cases and ask people to call that?
I'm not quite sure how standard/mandatory this is or who is using it... FWIW here is a place in EFCore.PG where we depend on it in order to generate the array NpgsqlDbType value given a DbType.
Would that significantly help the situation though? Even if we did this only when a connection is set, we'd still need to have the logic resolving a mapping (as opposed to a handler), so the resolver would still need to look very similar to today, except that that static methods would be instance methods right? Also, doing this only when there's a connection would mean that NpgsqlParameter needs to be able to access the connection, which isn't the case today (it knows its NpgsqlParameterCollection, but the latter doesn't know in which command/connection it is). |
|
@NinoFloris note the removal of the write lock in a later commit here.. ConnectorTypeMapper now only ever updates a single ConcurrentDictionary at a time (as part of the simplification here), so an additional write lock doesn't seem necessary. |
The multiplexing type mapper still references the original connector instance from which it was created (even if it's already dispoed and never used), and the resolvers reference that connector as well, and its DatabaseInfo. So when reloading types, we need to replace that connector's DatabaseInfo as well.
|
Finished the last two disabled tests, so AFAIK all current functionality should be preserved after this PR. |
For #3953, any/all feedback welcome!
This is currently in a half-half state: reading and writing does go through the new system, but the old system is still in place to make sure everything compiles and most tests run. I suggest looking at BuiltInTypeHandlerResolver to get a sense of it, and work out from there.
I reimplemented enum handling (which was a bit tricky but OK). But one problematic aspect is converting NpgsqlDbType/DbType/ClrType/DataTypeName on NpgsqlParameter (i.e. when you set DbType on NpgsqlParameter, all the rest are supposed to be populated accordingly). The problem with this is that it's supposed to work without any connection (i.e. free-floating NpgsqlParameter instance). Up to now this has been implemented at the global type mapper level, but we no longer have type mappings to support that. We could still have an API on ITypeHandlerResolverFactory to do these translations, but then we'd have to basically repeat all the type mappings again: once to get a type handler (for normal operation), once to get the conversion (for NpgsqlParameter). Basically I don't have any good ideas how to do this yet.