1 24 25 package org.objectweb.cjdbc.scenario.tools.components.backend; 26 27 import java.io.File ; 28 29 import org.objectweb.cjdbc.scenario.tools.ScenarioConstants; 30 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 31 import org.objectweb.cjdbc.scenario.tools.components.ComponentInterface; 32 import org.objectweb.cjdbc.scenario.tools.components.ComponentManager; 33 import org.objectweb.cjdbc.scenario.tools.components.backend.hsqldb.HypersonicProcess; 34 import org.objectweb.cjdbc.scenario.tools.util.KillJava; 35 36 42 public class DatabaseManager extends ComponentManager 43 { 44 45 public static final int HSQLDB = 0; 46 47 public static final int MYSQL = 1; 48 49 private int selection; 50 51 54 public DatabaseManager() 55 { 56 selection = HSQLDB; 57 File file = new File (ScenarioConstants.PROCESS_DIRECTORY); 58 if (file.exists()) 59 if (!ScenarioUtility.deleteDir(file)) 60 System.out 61 .println("Database Manager could not delete previous files..."); 62 } 63 64 69 public DatabaseManager(int selection) 70 { 71 this.selection = selection; 72 } 73 74 78 public ComponentInterface instanciateProcess(String port, String database) 79 throws Exception 80 { 81 switch (selection) 82 { 83 case HSQLDB : 84 ComponentInterface object = new HypersonicProcess(port, database); 85 waitForStarted(port); 86 return object; 87 default : 88 throw new Exception ("Invalid process selection"); 89 } 90 } 91 92 95 public String getDefaultConfigurationFile() 96 { 97 return "database"; 98 } 99 100 104 public void stopAll() 105 { 106 super.stopAll(); 107 if (System.getProperty("os.name").equals("Linux")) 108 try 109 { 110 new KillJava().execute(); 111 } 112 catch (Exception e) 113 { 114 e.printStackTrace(); 115 } 116 } 117 } | Popular Tags |