KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > tools > components > backend > DatabaseManager


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.tools.components.backend;
26
27 import java.io.File JavaDoc;
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 /**
37  * This class defines a DatabaseManager
38  *
39  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
40  * @version 1.0
41  */

42 public class DatabaseManager extends ComponentManager
43 {
44   /** HSQLDB processes selection */
45   public static final int HSQLDB = 0;
46   /** MYSQL processes selection */
47   public static final int MYSQL = 1;
48
49   private int selection;
50
51   /**
52    * Creates a new <code>DatabaseManager</code> object
53    */

54   public DatabaseManager()
55   {
56     selection = HSQLDB;
57     File JavaDoc file = new File JavaDoc(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   /**
65    * Creates a new <code>DatabaseManager</code> object
66    *
67    * @param selection the process that this database manager will generate
68    */

69   public DatabaseManager(int selection)
70   {
71     this.selection = selection;
72   }
73
74   /**
75    * @see org.objectweb.cjdbc.scenario.tools.components.ComponentManager#instanciateProcess(java.lang.String,
76    * java.lang.String)
77    */

78   public ComponentInterface instanciateProcess(String JavaDoc port, String JavaDoc database)
79       throws Exception JavaDoc
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 JavaDoc("Invalid process selection");
89     }
90   }
91
92   /**
93    * @see org.objectweb.cjdbc.scenario.tools.components.ComponentManager#getDefaultConfigurationFile()
94    */

95   public String JavaDoc getDefaultConfigurationFile()
96   {
97     return "database";
98   }
99
100   /**
101    * @see org.objectweb.cjdbc.scenario.tools.components.ComponentManagerInterface#stopAll()
102    * In Linux, also kills hypersonic processes
103    */

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 JavaDoc e)
113       {
114         e.printStackTrace();
115       }
116   }
117 }
Popular Tags