diff --git a/src/org/gcube/vremanagement/vremodeler/db/DBInterface.java b/src/org/gcube/vremanagement/vremodeler/db/DBInterface.java index 456df43..0cc3513 100644 --- a/src/org/gcube/vremanagement/vremodeler/db/DBInterface.java +++ b/src/org/gcube/vremanagement/vremodeler/db/DBInterface.java @@ -8,7 +8,7 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.List; +import java.util.Hashtable; import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.vremanagement.vremodeler.impl.ServiceContext; @@ -21,8 +21,7 @@ import org.gcube.vremanagement.vremodeler.impl.util.Listable; */ public class DBInterface { - - private static Connection conn; + private static Hashtable< String, Connection> connectionMapping= new Hashtable(); private static String dbFile = ServiceContext.getContext().getPersistenceRoot()+ File.separator + "vreModelerDB"; @@ -34,14 +33,14 @@ public class DBInterface { */ public static boolean dbAlreadyCreated(){ - File file= new File(dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-")+".script"); + File file= new File(dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-")+".data"); logger.trace("the db "+file.getName()+" exists ?"+ file.exists()); return file.exists(); } public static Connection connect() throws SQLException{ - if(conn==null) + if(connectionMapping.get(ServiceContext.getContext().getScope().toString())==null) { // Load the HSQL Database Engine JDBC driver // hsqldb.jar should be in the class path or made part of the current jar @@ -57,35 +56,36 @@ public class DBInterface { // It can contain directory names relative to the // current working directory - dbFile=dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-"); - conn = DriverManager.getConnection("jdbc:hsqldb:file:" - + dbFile, // filenames + + Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:" + + dbFile+ServiceContext.getContext().getScope().toString().replace("/", "-"), // filenames "sa", // username ""); // password - + + connectionMapping.put(ServiceContext.getContext().getScope().toString(), conn); + } - return conn; + return connectionMapping.get(ServiceContext.getContext().getScope().toString()); } public static Connection getConnection(){ - return conn; + return connectionMapping.get(ServiceContext.getContext().getScope().toString()); } /** * * @param query */ - public static synchronized void ExecuteUpdate(String query) throws GCUBEFault{ + public static synchronized void ExecuteUpdate(String query) throws Exception{ Statement st = null; - + Connection conn= getConnection(); try{ st = conn.createStatement(); // statement objects can be reused with st.executeUpdate(query); st.close(); - }catch(SQLException e){//logger.error("error executing Query", e); - throw new GCUBEFault(e);} + }catch(SQLException e){throw e;} } @@ -95,6 +95,8 @@ public class DBInterface { if (values==null) throw new GCUBEFault(); Statement st = null; + Connection conn= getConnection(); + try{ st = conn.createStatement(); // statement objects can be reused with }catch(SQLException e){//logger.error("error creating SQL statement"); @@ -146,6 +148,7 @@ public class DBInterface { */ public static synchronized void insertInto(String table, String[]... rows) throws GCUBEFault { + Connection conn= getConnection(); Statement st = null; try{ @@ -198,7 +201,8 @@ public class DBInterface { Statement st = null; ResultSet rs = null; - + Connection conn= getConnection(); + st = conn.createStatement(); // statement objects can be reused with @@ -218,12 +222,14 @@ public class DBInterface { */ public static void deleteAll(String table) throws SQLException{ String query="DELETE FROM "+table.toUpperCase(); + Connection conn= getConnection(); Statement st=conn.createStatement(); st.executeUpdate(query); st.close(); } public static void close() throws SQLException{ + Connection conn= getConnection(); if (conn!=null){ conn.close(); conn=null; diff --git a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java index 533c947..2c72836 100644 --- a/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java +++ b/src/org/gcube/vremanagement/vremodeler/db/IStoDBUtil.java @@ -71,7 +71,6 @@ public class IStoDBUtil { logger.trace(line); DBInterface.ExecuteUpdate(line); } - DBInterface.close(); }catch (Exception e){ logger.error("error creating tables",e); throw new GCUBEFault(e); } @@ -115,7 +114,6 @@ public class IStoDBUtil { DBInterface.deleteAll(FunctionalityHandler.portletTableName); DBInterface.deleteAll(FunctionalityHandler.serviceTableName); DBInterface.deleteAll(FunctionalityHandler.functionalityTableName); - DBInterface.close(); }catch (SQLException e){ logger.error("error cleaning sqlDB",e); throw new GCUBEFault(e); } @@ -145,9 +143,8 @@ public class IStoDBUtil { try{ DBInterface.connect(); DBInterface.insertInto("NEEDEDRESOURCES", values.toArray(new String[0][0])); - DBInterface.close(); }catch (SQLException e){ - logger.error("VDLModel: DB error ",e); + logger.error("error inserting Generic resource in the DB ",e); throw new GCUBEFault(e); } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java b/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java index ce9165d..7fdc44d 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ModelerService.java @@ -518,8 +518,8 @@ public class ModelerService { try{ DBInterface.ExecuteUpdate("UPDATE VRE SET STATUS='"+DEPLOYING+"' WHERE VRE.id='"+resourceID+"';"); - } catch (GCUBEFault e) { - logger.error("HSQLDB Error ",e); + } catch (Exception e) { + logger.error("DB Error ",e); throw new GCUBEUnrecoverableFault(e); } diff --git a/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java b/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java index 6e4bebf..36c7843 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java @@ -41,6 +41,7 @@ public class ServiceContext extends GCUBEServiceContext{ logger.info("ready event invoked on " + this.getName()); this.intializeDB(); }catch (Exception e){ + logger.error("error initializing VREModeler",e); this.setStatus(Status.FAILED); throw e; } @@ -48,8 +49,7 @@ public class ServiceContext extends GCUBEServiceContext{ protected void intializeDB() throws Exception{ ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class); - for (GCUBEScope scope : ServiceContext.getContext().getStartScopes()){ - if (scope.isInfrastructure()) continue; + for (GCUBEScope scope : ServiceContext.getContext().getInstance().getScopes().values()){ ServiceContext.getContext().setScope(scope); GCUBESecurityManager secMan= new GCUBESecurityManagerImpl(){ @Override diff --git a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java index b2cd04e..0e6c8dc 100644 --- a/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java +++ b/src/org/gcube/vremanagement/vremodeler/impl/thread/DeployVRE.java @@ -115,7 +115,7 @@ public class DeployVRE extends Thread{ } vreName= resGenericInfo.getString(1); - } catch (SQLException e) { + } catch (Exception e) { logger.error("HSQLDB Error "+e); throw new GCUBEFault(e); } diff --git a/src/org/gcube/vremanagement/vremodeler/resources/handlers/FunctionalityHandler.java b/src/org/gcube/vremanagement/vremodeler/resources/handlers/FunctionalityHandler.java index 298225f..c0254a2 100644 --- a/src/org/gcube/vremanagement/vremodeler/resources/handlers/FunctionalityHandler.java +++ b/src/org/gcube/vremanagement/vremodeler/resources/handlers/FunctionalityHandler.java @@ -5,7 +5,6 @@ import java.sql.PreparedStatement; import java.sql.Types; import org.gcube.common.core.contexts.GHNContext; -import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.informationsystem.client.AtomicCondition; import org.gcube.common.core.informationsystem.client.ISClient; import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery; @@ -65,10 +64,11 @@ public class FunctionalityHandler implements ResourceHandler