Hello everyone,

I want to manually setup an EPSG database like mentioned here [1]
and need some more understanding what happens under the hood and how to 
implement it correctly.

I set up the database configuration in my app. How is the connection build up 
to this container?
After configuration, do I have to open & close the connection?



Therefore I use a local docker container with an postgres image after 
downloading the EPSG-v9_9_1-PostgreSQL data:

```
version: "3"
services:
  epsg:
    image: "postgres:14.4-alpine"
    container_name: "epsg"
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: EPSG
      POSTGRES_USER: epsg
      POSTGRES_PASSWORD: epsg

    volumes:
      - 
./scripts/PostgreSQL_Table_Script.sql:/docker-entrypoint-initdb.d/01_PostgreSQL_Table_Script.sql
      - 
./scripts/PostgreSQL_Data_Script.sql:/docker-entrypoint-initdb.d/02_PostgreSQL_Data_Script.sql
      - 
./scripts/PostgreSQL_FKey_Script.sql:/docker-entrypoint-initdb.d/03_PostgreSQL_FKey_Script.sql
      - epsg-data:/var/lib/postgresql/data
volumes:
  epsg-data:

``` 


In my Java App I setup everything:

``` 

import org.postgresql.ds.PGSimpleDataSource;
import org.apache.sis.setup.Configuration;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.function.Supplier;


...


Configuration.current().setDatabase((Supplier<DataSource>) createDataSource());

...

   protected static DataSource createDataSource() {
        PGSimpleDataSource ds = new PGSimpleDataSource();
        String[] serverAddresses = { "192.168.1.100" };
        ds.setServerNames( serverAddresses );
        int[] serverPortNumbers = { 5432 };
        ds.setPortNumbers( serverPortNumbers );
        ds.setDatabaseName( "EPSG" );
        ds.setUser( "epsg" );
        ds.setPassword( "epsg" );
        ds.setReadOnly( true );

        return ds;
    }
```



Greetings
Florian


[1] https://sis.apache.org/epsg.html

Reply via email to