Dear Martin,
On 3 February 2018 at 12:20, Martin Desruisseaux <
[email protected]> wrote:
>
> No public API yet, but there is an internal class in
> org.apache.sis.internal.metadata.sql:
>
> DataSource ds = Initializer.getDataSource();
>
> Everything under "org.apache.sis.internal" packages is non-committed API
> (excluded from Javadoc); in Java 9, they would be inaccessible from other
> modules. We have not yet determined what could be a public API for fetching
> this DataSource, mostly because I'm not sure what would be the most
> standard approach. A common answer is "use JNDI" (this is the way to do in
> a container like Tomcat), but I'm not aware of a standard JNDI
> implementation in standalone Java. Suggestions are welcome!
>
I think that JNDI may be relevant to specify the database used by a
specific SIS deployment.
For the user case I was describing, I think the method you cited
(Initializer.getDataSource()) is more than enough (and also generic), as I
just want to launch queries against the configured database (whichever it
is).
However, it will be useless if it is not visible on Java 9. In any case,
now I realise that for a particular deployment, if I know I will be using
epsg with derby, I can just create a new data source to "SpatialMetadata"
database, using Java standard procedures.
final Class<?> c =
Class.forName("org.apache.derby.jdbc.EmbeddedDataSource", true,
AppSis.class.getClassLoader());
final DataSource ds = (DataSource) c.newInstance();
final Class<?>[] args = {String.class};
c.getMethod("setDatabaseName", args).invoke(ds, "SpatialMetadata");
c.getMethod("setDataSourceName", args).invoke(ds, "Apache SIS
spatial metadata");
Connection c = ds.getConnection();
c.createStatement().executeQuery("SELECT * FROM ...");
Do you know if this approach has any harmful side effects (besides the
weakness of hard-coding the database name)?
Thanks for your help,
César
--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
César Martínez Izquierdo
GIS developer
- - - - - - - - - - - - - - - - - - - -
SCOLAB: http://www.scolab.es
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -