ticket #1902 has been fixed and DB persistency

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@13455 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Lucio Lelii 2009-07-06 17:36:03 +00:00
parent 8f71c7c245
commit ffe26a19ee
3 changed files with 19 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import java.sql.Statement;
import java.util.List;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.vremanagement.vremodeler.impl.ServiceContext;
import org.gcube.vremanagement.vremodeler.impl.util.Listable;
/**
@ -23,7 +24,7 @@ public class DBInterface {
private static Connection conn;
private static String dbFile = System.getenv("GLOBUS_LOCATION") + File.separator + "etc" + File.separator + "org.gcube.vremanagement.vremodeler" + File.separator + "hsqldb" + File.separator + "vdldb";
private static String dbFile = ServiceContext.getContext().getPersistenceRoot()+ File.separator + "vdldb";
private static GCUBELog logger = new GCUBELog(DBInterface.class);
/**
@ -37,8 +38,10 @@ public class DBInterface {
{
// Load the HSQL Database Engine JDBC driver
// hsqldb.jar should be in the class path or made part of the current jar
try{
Class.forName("org.hsqldb.jdbcDriver");
logger.info(dbFile);
try{
Class.forName("org.hsqldb.jdbcDriver");
}catch(ClassNotFoundException e){throw new SQLException(e.getMessage());}
// connect to the database. This will load the db files and start the
// database if it is not alread running.

View File

@ -1,10 +1,18 @@
package org.gcube.vremanagement.vremodeler.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.commons.io.IOUtils;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.vremanagement.vremodeler.db.DBInterface;
import org.gcube.vremanagement.vremodeler.db.IStoDBUtil;
public class ServiceContext extends GCUBEServiceContext{
private String dbFileName="vdldb.script";
/** Single context instance, created eagerly */
private static ServiceContext cache = new ServiceContext();
@ -18,6 +26,9 @@ public class ServiceContext extends GCUBEServiceContext{
protected String getJNDIName() {return "gcube/vremanagement/vremodeler";}
protected void onReady() throws Exception{
File vredbFile= ServiceContext.getContext().getFile("hsqldb"+File.separator+"vdldb.script", true );
if (!ServiceContext.getContext().getPersistentFile(dbFileName, true).exists())
IOUtils.copy(new FileInputStream(vredbFile), new FileOutputStream(new File(ServiceContext.getContext().getPersistenceRoot()+File.separator+dbFileName)));
try{
logger.info("ready event invoked on " + this.getName());
this.intializeDB();

View File

@ -74,9 +74,9 @@ public class CollectionResourceCreation {
private String transformCollectionResource() throws Exception{
ISClient client= GHNContext.getImplementation(ISClient.class);
GCUBEGenericResourceQuery query= client.getQuery(GCUBEGenericResourceQuery.class);
query.addAtomicConditions(new AtomicCondition("/Profile/Name","ScenarioCollectionInfo"), new AtomicCondition("/Profile/Body/DL/@name",ServiceContext.getContext().getScope().toString()));
query.addAtomicConditions(new AtomicCondition("/Profile/Name","ScenarioCollectionInfo"), new AtomicCondition("/Profile/Body/VRE/@name",ServiceContext.getContext().getScope().toString()));
List<GCUBEGenericResource> list= client.execute(query, ServiceContext.getContext().getScope()) ;
if (list.size()==0) throw new Exception("No GenericResource founded in IS");
if (list.size()==0) throw new Exception("GenericResource ScenarioCollectionInfo not found in IS");
StringWriter sw= new StringWriter();
list.get(0).store(sw);
InputStream is=CollectionResourceCreation.class.getResourceAsStream("/org/gcube/vremanagement/vremodeler/portallayout/xslt/ScenarioCollectionInfoTransformer.xsl");