Merge pull request 'bug_23381' (#4) from bug_23381 into master

Reviewed-on: #4
This commit is contained in:
Fabio Sinibaldi 2022-05-24 16:05:33 +02:00
commit 458df96496
5 changed files with 51 additions and 31 deletions

View File

@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for org.gcube.application.geoportal-service # Changelog for org.gcube.application.geoportal-service
## [v1.0.9] 2021-09-20
- Fixes [#23381](https://support.d4science.org/issues/23381)
## [v1.0.8] 2021-09-20 ## [v1.0.8] 2021-09-20
- Logging - Logging
- Fixes [#22193](https://support.d4science.org/issues/22193) - Fixes [#22193](https://support.d4science.org/issues/22193)

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.application</groupId> <groupId>org.gcube.application</groupId>
<artifactId>geoportal-service</artifactId> <artifactId>geoportal-service</artifactId>
<version>1.0.8</version> <version>1.0.9</version>
<name>Geoportal Service</name> <name>Geoportal Service</name>
<packaging>war</packaging> <packaging>war</packaging>
@ -85,11 +85,13 @@
<dependency> <dependency>
<groupId>org.gcube.application.cms</groupId> <groupId>org.gcube.application.cms</groupId>
<artifactId>geoportal-common</artifactId> <artifactId>geoportal-common</artifactId>
<version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.application.cms</groupId> <groupId>org.gcube.application.cms</groupId>
<artifactId>cms-plugin-framework</artifactId> <artifactId>cms-plugin-framework</artifactId>
<version>1.0.0</version>
</dependency> </dependency>
@ -216,6 +218,7 @@
<dependency> <dependency>
<groupId>org.gcube.application.cms</groupId> <groupId>org.gcube.application.cms</groupId>
<artifactId>concessioni-lifecycle</artifactId> <artifactId>concessioni-lifecycle</artifactId>
<version>1.0.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
@ -240,6 +243,7 @@
<dependency> <dependency>
<groupId>org.gcube.application.cms</groupId> <groupId>org.gcube.application.cms</groupId>
<artifactId>cms-test-commons</artifactId> <artifactId>cms-test-commons</artifactId>
<version>1.0.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@ -17,49 +17,57 @@ import java.util.regex.Pattern;
@Slf4j @Slf4j
public class PostgisDBManager implements PostgisDBManagerI { public class PostgisDBManager implements PostgisDBManagerI {
@Synchronized // @Synchronized
public static PostgisDBManager get() throws SQLException, ConfigurationException { // public static PostgisDBManager get() throws SQLException, ConfigurationException {
if(config==null) { // if(config==null) {
log.debug("Looking for Default Configuration.. "); // log.debug("Looking for Default Configuration.. ");
//
// // TODO GENERIC
// DatabaseConnection defaultConfiguration=
// ImplementationProvider.get().getIsProvider().getIS().queryForDB("postgis", "Concessioni");
//
// log.debug("Found configuration : "+defaultConfiguration);
// config=defaultConfiguration;
// }
// return new PostgisDBManager();
// }
//
//
// TODO GENERIC
DatabaseConnection defaultConfiguration= public static PostgisDBManagerI get() throws SQLException, ConfigurationException {
return get(false);
}
private static PostgisDBManagerI get(boolean autocommit) throws SQLException, ConfigurationException {
DatabaseConnection config=
ImplementationProvider.get().getIsProvider().getIS().queryForDB("postgis", "Concessioni"); ImplementationProvider.get().getIsProvider().getIS().queryForDB("postgis", "Concessioni");
log.debug("Found configuration : "+config);
log.debug("Found configuration : "+defaultConfiguration); PostgisDBManager toReturn=new PostgisDBManager(config);
config=defaultConfiguration;
}
return new PostgisDBManager();
}
public static PostgisDBManagerI get(boolean autocommit) throws SQLException, ConfigurationException {
PostgisDBManager toReturn=get();
toReturn.conn.setAutoCommit(autocommit); toReturn.conn.setAutoCommit(autocommit);
return toReturn; return toReturn;
} }
private static DatabaseConnection config;
// private static DatabaseConnection config;
private static Connection getConnection() throws SQLException {
Connection toReturn= DriverManager.getConnection(config.getUrl(),config.getUser(),config.getPwd());
//TODO configure behaviour
toReturn.setAutoCommit(false);
return toReturn;
}
private Connection conn=null; private Connection conn=null;
private DatabaseConnection config;
private PostgisDBManager(DatabaseConnection config) throws SQLException {
this.config=config;
log.info("Opening connection to {}",config);
conn= DriverManager.getConnection(config.getUrl(),config.getUser(),config.getPwd());
private PostgisDBManager() throws SQLException { //TODO configure behaviour
conn=getConnection(); conn.setAutoCommit(false);
} }
@Override @Override

View File

@ -38,7 +38,7 @@ public class PostgisIndex {
private SDIManager sdiManager; private SDIManager sdiManager;
private String wmsLink=null; private String wmsLink=null;
private static PostgisDBManager getDB() throws ConfigurationException { private static PostgisDBManagerI getDB() throws ConfigurationException {
return ImplementationProvider.get().getDbProvider().getObject(); return ImplementationProvider.get().getDbProvider().getObject();
}; };

View File

@ -1,19 +1,23 @@
package org.gcube.application.geoportal.service.engine.providers; package org.gcube.application.geoportal.service.engine.providers;
import org.gcube.application.geoportal.service.engine.postgis.PostgisDBManager; import org.gcube.application.geoportal.service.engine.postgis.PostgisDBManager;
import org.gcube.application.geoportal.service.engine.postgis.PostgisDBManagerI;
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class PostgisConnectionProvider extends AbstractScopedMap<PostgisDBManager>{ public class PostgisConnectionProvider extends AbstractScopedMap<PostgisDBManagerI>{
public PostgisConnectionProvider() { public PostgisConnectionProvider() {
super("Postgis connection descriptor cache"); super("Postgis connection descriptor cache");
setTTL(Duration.of(30, ChronoUnit.SECONDS));
} }
@Override @Override
protected PostgisDBManager retrieveObject() throws ConfigurationException { protected PostgisDBManagerI retrieveObject() throws ConfigurationException {
try { try {
return PostgisDBManager.get(); return PostgisDBManager.get();
} catch (SQLException throwables) { } catch (SQLException throwables) {
@ -22,7 +26,7 @@ public class PostgisConnectionProvider extends AbstractScopedMap<PostgisDBManage
} }
@Override @Override
protected void dispose(PostgisDBManager toDispose) { protected void dispose(PostgisDBManagerI toDispose) {
// toDispose.close(); // toDispose.close();
} }