KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ant > StopHsqldbTask


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.ant;
19
20 import java.sql.Connection JavaDoc;
21 import java.sql.DriverManager JavaDoc;
22 import java.sql.SQLException JavaDoc;
23
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Task;
26
27 /**
28  * Ant Task to stop HSQLDB
29  * @author Dave Johnson
30  */

31 public class StopHsqldbTask extends Task
32 {
33     private String JavaDoc port = null;
34     public void execute() throws BuildException
35     {
36         try
37         {
38             if (port==null)
39             {
40                 throw new BuildException("missing port attribute");
41             }
42             System.out.println("Stopping HSQLDB at port " + port);
43             final Connection JavaDoc con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:"+port);
44             con.createStatement().execute("SHUTDOWN");
45         }
46         catch (SQLException JavaDoc e)
47         {
48             throw new BuildException(e.getMessage());
49         }
50     }
51     /**
52      * @return Returns the port.
53      */

54     public String JavaDoc getPort()
55     {
56         return port;
57     }
58     /**
59      * @param port The port to set.
60      */

61     public void setPort(String JavaDoc port)
62     {
63         this.port = port;
64     }
65 }
66
Popular Tags