Tuesday, 15 September 2015

spring - Switchable Grails DataSource -


We must use many datasets in grails application. Per user i.e per URL session (from logging user's logout) takes the application to different data sources depending on the user's request.

The above link provides a good solution for this. We have modified in that page, with modified dynamic configuration. It's working well

1) But how does the code switch from session to session data source? 2) What is the use of thread local referrer in this code?

Please explain. .

Thank you.

Grails connects requests with thread. A threadlocal variable holds a different value for each thread that it accesses (allows thread security without synchronization).

So, what is this in its flow:

  1. User environment in environment controller Chooses, which controls the user in the session.

  2. Before filer he looks at each request and determines that the user session has a environment if So, he sets the environment holder to indicate that environment because it is a threadlocal , so each thread (in this case: the request) can have its own value is.

  3. When dataSource has reached the beam, its switchable data source will be correct code source to the environment holder Chooses based on the values ​​held in the ThreadLocal value of .

No comments:

Post a Comment