Fixing DB creation

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@111672 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-02-04 16:45:06 +00:00
parent 82725241a1
commit 25516a32ba
1 changed files with 13 additions and 3 deletions

View File

@ -13,6 +13,8 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -58,9 +60,17 @@ public class JDBCPersistenceConnector extends PersistenceConnector {
try {
Path currentAbsolutePath = Paths.get(".").toAbsolutePath().normalize();
logger.debug(String.format("Current Absolute Path : %s",currentAbsolutePath));
String effectiveJDBCURL = String.format("%s%s/%s", jdbcURL, currentAbsolutePath.toString(), dbName);
String path = ".";
ApplicationContext ctx = ContextProvider.get();
if(ctx == null){
Path currentAbsolutePath = Paths.get(".").toAbsolutePath().normalize();
logger.debug(String.format("Current Absolute Path : %s",currentAbsolutePath));
path = currentAbsolutePath.toString();
}else {
path = ctx.application().getContextPath();
}
String effectiveJDBCURL = String.format("%s%s/%s", jdbcURL, path, dbName);
logger.debug(String.format("DB URL : %s", effectiveJDBCURL));
connection = DriverManager.getConnection(effectiveJDBCURL, username, password);
} catch (SQLException e) {
logger.error(String.format("Unable to connect to JDBC URL : %s", jdbcURL));