Clover coverage report - Replica - 1.0-Alpha
Coverage timestamp: Dom Fev 1 2004 17:00:58 WET
file stats: LOC: 150   Methods: 10
NCLOC: 78   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
StartupDatabaseCommand.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * Replica is published under the terms
 3   
  * of the Apache Software License.
 4   
  */
 5   
 package replica.server.commands;
 6   
 
 7   
 import java.util.StringTokenizer;
 8   
 
 9   
 import org.hsqldb.Server;
 10   
 import org.springframework.jdbc.datasource.DriverManagerDataSource;
 11   
 
 12   
 import replica.core.ApplicationMessage;
 13   
 
 14   
 /**
 15   
  * 
 16   
  * @author Pedro Costa
 17   
  * @author Helder Silva
 18   
  * @since 31/Jan/2004
 19   
  */
 20   
 public class StartupDatabaseCommand extends LoggedInCommand {
 21   
     
 22   
     int port = 9001;
 23   
     ShutdownDatabaseCommand shutdownDatabaseCommand;
 24   
     DriverManagerDataSource dataSource;
 25   
     String name = "mydb";
 26   
 
 27   
     /**
 28   
      * 
 29   
      */
 30  0
     public StartupDatabaseCommand() {
 31  0
         super();
 32   
     }
 33   
 
 34   
     /* (non-Javadoc)
 35   
      * @see replica.server.commands.LoggedInCommand#internalExecute(replica.core.ApplicationMessage)
 36   
      */
 37  0
     protected Object internalExecute(ApplicationMessage arg) {
 38   
         
 39  0
         String c = arg.getBody().toString().trim();
 40   
         
 41  0
         if( c.endsWith(";") )
 42  0
             c = c.substring(0,c.length()-1);
 43   
         
 44  0
         StringTokenizer tokenizer = new StringTokenizer(c);
 45  0
         tokenizer.nextToken(); // ignore
 46   
         
 47  0
         String sec = tokenizer.nextToken();
 48   
         
 49  0
         if( sec.equalsIgnoreCase("database") ) // ignore
 50  0
             sec = tokenizer.nextToken();
 51   
         
 52  0
         int port = getPort();
 53   
         
 54  0
         if( sec.equalsIgnoreCase("ON") ){
 55  0
             String portStr = tokenizer.nextToken();
 56  0
             if( portStr.equalsIgnoreCase("PORT") ) //ignore
 57  0
                 portStr = tokenizer.nextToken();
 58  0
             try{
 59  0
                 port = Integer.parseInt(portStr);
 60   
             }
 61   
             catch(NumberFormatException e){
 62  0
                 return "Invalid port number : [" + portStr + "].";
 63   
             }
 64   
         }
 65   
         
 66  0
         String name = getName();
 67   
         
 68  0
         if( tokenizer.hasMoreTokens() ){
 69  0
             String nToken = tokenizer.nextToken();
 70  0
             if( nToken.equalsIgnoreCase("as") )
 71  0
                 name = tokenizer.nextToken();
 72   
         }
 73   
         
 74  0
         Server server = new Server();
 75  0
         server.setPort(port);
 76   
         
 77  0
         if( name != null && name.trim().length() > 0 ){
 78  0
             server.putPropertiesFromString("database.0="+name);
 79  0
             server.setDatabaseName(0, name);
 80   
         }
 81   
             
 82  0
         server.start();
 83   
         
 84  0
         getDataSource().setDriverClassName("org.hsqldb.jdbcDriver");
 85  0
         getDataSource().setUrl("jdbc:hsqldb:hsql://localhost:"+port+
 86   
             (name==null?"":"/"+name) );
 87   
         
 88  0
         getShutdownDatabaseCommand().setServer(server);
 89   
         
 90  0
         return "Database started on port " + port + ".";
 91   
     }
 92   
 
 93   
     /**
 94   
      * @return
 95   
      */
 96  0
     public int getPort() {
 97  0
         return port;
 98   
     }
 99   
 
 100   
     /**
 101   
      * @param i
 102   
      */
 103  0
     public void setPort(int i) {
 104  0
         port = i;
 105   
     }
 106   
 
 107   
     /**
 108   
      * @return
 109   
      */
 110  0
     public ShutdownDatabaseCommand getShutdownDatabaseCommand() {
 111  0
         return shutdownDatabaseCommand;
 112   
     }
 113   
 
 114   
     /**
 115   
      * @param command
 116   
      */
 117  0
     public void setShutdownDatabaseCommand(ShutdownDatabaseCommand command) {
 118  0
         shutdownDatabaseCommand = command;
 119   
     }
 120   
 
 121   
     /**
 122   
      * @return
 123   
      */
 124  0
     public DriverManagerDataSource getDataSource() {
 125  0
         return dataSource;
 126   
     }
 127   
 
 128   
     /**
 129   
      * @param source
 130   
      */
 131  0
     public void setDataSource(DriverManagerDataSource source) {
 132  0
         dataSource = source;
 133   
     }
 134   
 
 135   
     /**
 136   
      * @return
 137   
      */
 138  0
     public String getName() {
 139  0
         return name;
 140   
     }
 141   
 
 142   
     /**
 143   
      * @param string
 144   
      */
 145  0
     public void setName(String string) {
 146  0
         name = string;
 147   
     }
 148   
 
 149   
 }
 150