Hello Florian

Le 16/11/2022 à 01:27, Florian Micklich a écrit :

Is it possible to recall the setDatabase method? For example the db settings are set via variables and can be updated by the user during runtime. So I want / have to update the Configuration.current() as well.

Currently setDatabase(…) does not allow allow to change the data source after it has been initialized, for reason given in next paragraph. As a workaround, it is possible to achieve a similar effect by providing a custom implementation of DataSource interface, with a field which is the real PGDataSource (if using PostgreSQL) and with all methods doing redirection to that PGDataSource. That way, the value of that field can be changed and it will be taken in account the next time that DataSource.getConnection() is invoked.

An issue is that the new data source will not be taken in account immediately. SIS keeps JDBC connection open a little bit (in case there is many consecutive uses of EPSG factory, which is often the case at least in SIS internal) and closes it only after 1 minute of inactivity. So the new data source would be taken in account only after the user stay one minute without requesting any EPSG codes. For avoiding this delay, we need to force an immediate release of JDBC resources after the data source changed:

   ConcurrentAuthorityFactory<?> factory = (ConcurrentAuthorityFactory<?>) 
CRS.getAuthorityFactory("EPSG");
   factory.close();

Note: there is also a factory.setTimeout(…) method if you want to change the 1 minute timeout to something else.

Above workaround is not perfect. If there is any CRS cached in memory, they will not be updated by above change. It is technically possible to improve setDatabase(…) for allowing cleaner change, which would include flushing the caches. If there is a need for that, I suggest that we create a JIRA issue.

    Martin

Reply via email to