I do not think anyone is answering you as the answer depends on how you
are using the database and what your expectations are?

If your application is using the database all the time it is worth making
use of a connection pool, to recycle connections, rather than connect to
the database directly.

If your application is in a shared environment like JavaEE you may wish to
look up a JNDI data source and share the database connections with the rest
of the application?

If your code only talks to the database for a bit, and then is quiet it may
be kind to do as you say and create the dataStore, use the connections for
a bit, and then dispose of everything until next time.
--
Jody Garnett


On Jan 14, 2024 at 3:33:14 AM, sunish <sunish.ku...@gmail.com> wrote:

> Hello,
>
> I am developing an application using Geotools. The framework used for the
> application is Quarkus. The application connects to the PostGIS database.
>
> Since it is a web application I want to minimize the overheads in
> connecting to the database in each request. I want to reuse an already
> connected database.
>
> I have maintained an application level DataStore object which gets created
> when the application starts up.
>
> Map<String, Object> params = new HashMap<>();
> params.put("dbtype", "postgis");
> params.put("host", this.dbConfig.getHost());
> params.put("port", this.dbConfig.getPort());
> params.put("schema", "public");
> params.put("database" ,this.dbConfig.getDatabase());
> params.put("user", this.dbConfig.getUser());
> params.put("passwd", this.dbConfig.getPassword());
> params.put("preparedStatements", true);
> params.put("encode functions", true);
>
> try {
>     this.dataStore = (JDBCDataStore) DataStoreFinder.getDataStore(params);
> } catch (IOException e) {
>
> Logger.getLogger(DataSourceService.class.getName()).warning(e.getMessage());
> } catch (SQLException e) {
>
> Logger.getLogger(DataSourceService.class.getName()).warning(e.getMessage());
> }
> ---------
>
> Then I am using the dataStore object in the rest of the places.
>
> Is this the proper way of doing  or should I use DataStoreFinder each time
> to find the datastore and dispose of the data store at the end of
> processing request?
> Can I plug connection pools like HikariCP to get datastore out of that
> connection?
>
> When I leave the application idle for a long time I am getting  this error.
>
> java.sql.SQLException: An I/O error occurred while sending to the backend.
>
> Please suggest the best way of doing it.
>
> Thanks in advance.
>
> Sunish.
>
>
>
>
>
> _______________________________________________
> GeoTools-GT2-Users mailing list
> GeoTools-GT2-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to