Reputation: 55
I'm calling procedure that returns different data in result set based on request type. For this purpose I use stored-proc-outbound-gateway. Request type is passed to procedure, but inside mapper it isn't available.
I could use ColumnMetaData to process resultSet, but I would prefer to have specific request type mappers. Other solution is to have as many gateways as request types, but maybe there are something better.
Could I specify which mapper to use, based on payload, in stored-proc-outbound-gateway?
Upvotes: 1
Views: 83
Reputation: 121177
Well, to be honest if I were you I'd really make separate components for particular types. In the future the logic might be more complex and that would be easier to modify particular function than try to figure out how to come up with all those if..else
.
Nevertheless your request is different...
As you see there is only one possible hook for you there - RowMapper
injection for particular procedure param.
I can suggest the solution like RoutingRowMapper
, which will consult some ThreadLocal
variable to select the proper RowMapper
to delegate.
The idea is picked up from the AbstractRoutingDataSource
. Also there is something like SimpleRoutingConnectionFactory
in the Spring AMQP.
The ThreadLocal
you can populate before stored-proc-outbound-gateway
and that really can be your desired type.
Another trick might be based on the result from the procedure where ResultSet
contains a column with a hint which target RowMapper
to choose.
In any way your task can be achieved only via composite RowMapper
. The stored-proc-outbound-gateway
doesn't have any logic to tackle and won't. It's just not its responsibility.
Upvotes: 0