KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > harness > shutdown


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

21
22 package org.apache.derbyTesting.functionTests.harness;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.DriverManager JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.sql.SQLWarning JavaDoc;
28 import java.util.*;
29 import java.io.*;
30
31 import org.apache.derby.tools.JDBCDisplayUtil;
32
33 /*
34  **
35  ** shutdown
36  **
37  ** force a shutdown after a test complete to guarantee shutdown
38  ** which doesn't always seem to happen with useprocess=false
39  **
40  */

41 public class shutdown
42 {
43  
44     static String JavaDoc shutdownurl;
45     static String JavaDoc driver = "org.apache.derby.jdbc.EmbeddedDriver";
46     static String JavaDoc systemHome;
47
48     public static void main(String JavaDoc[] args) throws SQLException JavaDoc,
49         InterruptedException JavaDoc, Exception JavaDoc
50     {
51         systemHome = args[0];
52         shutdownurl = args[1];
53         try
54         {
55             doit();
56         }
57         catch(Exception JavaDoc e)
58         {
59             System.out.println("Exception in shutdown: " + e);
60         }
61     }
62
63     public static void doit() throws SQLException JavaDoc,
64         InterruptedException JavaDoc, Exception JavaDoc
65     {
66         Connection JavaDoc conn = null;
67         boolean finished = false;
68         Date d = new Date();
69
70         Properties sp = System.getProperties();
71         if (systemHome == null)
72         {
73             systemHome = sp.getProperty("user.dir") + File.separatorChar +
74             "testCSHome";
75             sp.put("derby.system.home", systemHome);
76             System.setProperties(sp);
77         }
78         boolean useprocess = true;
79         String JavaDoc up = sp.getProperty("useprocess");
80         if (up != null && up.equals("false"))
81             useprocess = false;
82
83         PrintStream stdout = System.out;
84         PrintStream stderr = System.err;
85
86         Class.forName(driver).newInstance();
87
88         try
89         {
90             conn = DriverManager.getConnection(shutdownurl);
91         }
92         catch (SQLException JavaDoc se)
93         {
94             if (se.getSQLState().equals("08006"))
95             {
96                 // It was already shutdown
97
//System.out.println("Shutdown with: " + shutdownurl);
98
}
99             else
100             {
101                 System.out.println("shutdown failed for " + shutdownurl);
102                 JDBCDisplayUtil.ShowException(System.out, se);
103                 System.exit(1);
104             }
105         }
106     }
107 }
108
Popular Tags