Hi Martin,

thanks again for all the information.
Now another question came to my mind.

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.



``` 
Configuration.current().setDatabase(ProjTransformation::createDataSource);
``` 

If I call this again with new settings I get:
```
Connection to a SpatialMetadata database is already initialized
``` 

Greetings
Florian



Am Sonntag, dem 30.10.2022 um 21:18 +0100 schrieb Martin Desruisseaux:
> 
>       Hello Florian<br>
>       
> My pleasure if I can be of any help :-)<br>
>       <br>
>       
> Le 30/10/2022 à 13:32, Florian Micklich via user a écrit :<br>
>     <br>
> > 
> >         
> >         What happens (for some reason) the db is not available anymore.
> >         Is there an exception I can catch to handle something like this?<br>
> If SIS needs to use the EPSG database and an error occurred, an 
> org.opengis.util.FactoryException will
>       be thrown (this is a checked exception). The cause of that
>       exception should be the SQLException.<br>
> <br>
>     <br>
> > Is there a method in SIS that I can use to verify that the
> >         DataSource has been set up correctly?<br>
> The easiest way is to request an EPSG code, for example 
> System.out.println(CRS.forCode("EPSG::3395")).
>       This is not fully reliable however for two reasons:<br>
> - If that EPSG code was requested before, SIS may return a
>         cached value, in which case database problem that may have
>         occurred in the meantime will be unnoticed.
> - If the EPSG database is not available at all, SIS fallback on
>         hard-coded values for a few commonly used CRS. The EPSG::3395
>         code is not in current list [1], but it may be in a future
>         version.<br>
>       
> 
> A good way to know the status of Apache SIS is to execute the
>       following code:<br>
> ```
> System.out.println(org.apache.setup.About.configuration());
> > ```
> 
> It should prints a tree. Among the first lines, there is
>       information about the EPSG database used. It should show something
>       like "EPSG database 9.1 on PostgreSQL". If it shows something like
>       "EPSG database subset", then it is not using the database.<br>
>     <br><br>
> > Also thanks for the hint with the index. I see there is also a
> >         prepare.sql script.
> >         Is this also necessary or what is its purpose?<br>
> Not if you create the EPSG tables yourself from the SQL scripts
>       published by EPSG. But SIS has another way to create the EPSG
>       database. You can just give a connection to an initially empty
>       database, i.e. same as what you currently do but without executing
>       any SQL script. If the org.apache.sis.non-free:sis-epsg
>       (instead of sis-embedded) JAR is on
>       the classpath ([2] but without Derby), SIS will automatically
>       execute installation scripts when first needed, including the
>       index creation. However during the installation process, SIS
>       perform a few changes on-the-fly:<br>
> - It creates an "epsg" schema.
> - The "epsg_" prefix is table names is replaced by "epsg.", i.e.
>         the tables are written in "epsg" schema.
> - A few VARCHAR columns which
>         were used as enumerations are replaced by real enumeration (this
>         is slightly more efficient). This is where the "Prepare.sql" script 
> come into play: it
>         creates the enumerations before to run the EPSG scripts.<br>
>       
> 
> All those steps are automatic if sis-epsg
>       is on the classpath and you let SIS creates the "epsg" schema
>       itself when first needed. A message is logged at the INFO level when 
> this creation is
>       running.<br>
>     Martin<br>
>     <br>```
> [1] 
> [https://sis.apache.org/apidocs/org/apache/sis/referencing/CRS.html#forCode(java.lang.String)](https://sis.apache.org/apidocs/org/apache/sis/referencing/CRS.html#forCode(java.lang.String))
> [2] 
> [https://sis.apache.org/epsg.html#maven-epsg](https://sis.apache.org/epsg.html#maven-epsg)
> ```
> 
> <br>
>     <br>

Reply via email to