connection request/close fixed
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@129877 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d96572a771
commit
5c28cbf40c
6
pom.xml
6
pom.xml
|
@ -107,12 +107,6 @@
|
|||
<version>3.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.datacatalogue.ckanutillibrary;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
@ -18,8 +19,6 @@ import javax.net.ssl.HttpsURLConnection;
|
|||
import net.htmlparser.jericho.Renderer;
|
||||
import net.htmlparser.jericho.Segment;
|
||||
import net.htmlparser.jericho.Source;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.models.CKanUserWrapper;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
|
||||
|
@ -61,9 +60,6 @@ public class CKanUtilsImpl implements CKanUtils{
|
|||
private String PORTLET_URL_FOR_SCOPE;
|
||||
private String CKAN_TOKEN_SYS;
|
||||
|
||||
// use connections pool (multiple threads can use this CKanUtilsImpl instance)
|
||||
private BasicDataSource connectionPool;
|
||||
|
||||
// ckan client
|
||||
private CkanClient client;
|
||||
|
||||
|
@ -89,15 +85,6 @@ public class CKanUtilsImpl implements CKanUtils{
|
|||
logger.debug("Plain sys admin token first 3 chars are " + CKAN_TOKEN_SYS.substring(0, 3));
|
||||
logger.debug("Plain db password first 3 chars are " + CKAN_DB_PASSWORD.substring(0, 3));
|
||||
|
||||
// create connection pool
|
||||
String url = "jdbc:postgresql://" + CKAN_DB_URL + ":" + CKAN_DB_PORT + "/" + CKAN_DB_NAME;
|
||||
connectionPool = new BasicDataSource();
|
||||
connectionPool.setDriverClassName("org.postgresql.Driver");
|
||||
connectionPool.setUsername(CKAN_DB_USER);
|
||||
connectionPool.setPassword(CKAN_DB_PASSWORD);
|
||||
connectionPool.setUrl(url);
|
||||
connectionPool.setInitialSize(20);
|
||||
|
||||
// build the client
|
||||
client = new CkanClient(CKAN_CATALOGUE_URL);
|
||||
|
||||
|
@ -107,11 +94,16 @@ public class CKanUtilsImpl implements CKanUtils{
|
|||
* Retrieve connection from the pool
|
||||
* @return a connection available within the pool
|
||||
* @throws SQLException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private Connection getConnection() throws SQLException{
|
||||
private Connection getConnection() throws SQLException, ClassNotFoundException{
|
||||
|
||||
logger.debug("CONNECTION REQUEST");
|
||||
return connectionPool.getConnection();
|
||||
// create db connection
|
||||
Class.forName("org.postgresql.Driver");
|
||||
Connection connection = DriverManager.getConnection(
|
||||
"jdbc:postgresql://" + CKAN_DB_URL + ":" + CKAN_DB_PORT + "/" + CKAN_DB_NAME, CKAN_DB_USER, CKAN_DB_PASSWORD);
|
||||
return connection;
|
||||
|
||||
}
|
||||
|
||||
|
@ -346,7 +338,7 @@ public class CKanUtilsImpl implements CKanUtils{
|
|||
public String getCatalogueUrl() {
|
||||
return CKAN_CATALOGUE_URL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getPortletUrl() {
|
||||
|
@ -684,11 +676,11 @@ public class CKanUtilsImpl implements CKanUtils{
|
|||
CkanDataset dataset = client.getDataset(datasetIdOrName);
|
||||
|
||||
if(dataset != null){
|
||||
|
||||
|
||||
if(withoutHost)
|
||||
return "/dataset/" + dataset.getName();
|
||||
else
|
||||
return CKAN_CATALOGUE_URL + "/dataset/" + dataset.getName();
|
||||
return CKAN_CATALOGUE_URL + "/dataset/" + dataset.getName();
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Error while retrieving dataset with id/name=" + datasetIdOrName, e);
|
||||
|
@ -826,6 +818,5 @@ public class CKanUtilsImpl implements CKanUtils{
|
|||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
logger.debug("Closing connection pool on finalize()");
|
||||
connectionPool.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue