KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > timer > jdbc > DerbyJDBCWorkerPersistenceTest


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

17 package org.apache.geronimo.timer.jdbc;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.util.Properties JavaDoc;
22 import java.sql.SQLException JavaDoc;
23 import java.sql.Connection JavaDoc;
24 import java.sql.DriverManager JavaDoc;
25
26 import org.apache.derby.jdbc.EmbeddedDataSource;
27
28 /**
29  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
30  */

31 public class DerbyJDBCWorkerPersistenceTest extends JDBCWorkerPersistenceTestAbstract {
32     private static final String JavaDoc SYSTEM_HOME = "derby.system.home";
33     private static final String JavaDoc SHUTDOWN_ALL = "jdbc:derby:;shutdown=true";
34
35     private File JavaDoc systemDir;
36
37
38     private void connect() throws SQLException JavaDoc {
39         Connection JavaDoc c = DriverManager.getConnection("jdbc:derby:testdb;create=true");
40         c.close();
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         useSequence = false;
45         try {
46             systemDir = File.createTempFile("derbyTest", ".tmp");
47             systemDir.delete();
48             systemDir.mkdirs();
49         } catch (Exception JavaDoc e) {
50             delete(systemDir);
51             throw e;
52         }
53         String JavaDoc derbyDir = "var/dbderby";
54         File JavaDoc derby = new File JavaDoc(systemDir, derbyDir);
55         System.setProperty(SYSTEM_HOME, derby.getAbsolutePath());
56
57         // set the magic system property that causes derby to use explicity
58
// file sync instead of relying on vm support for file open rws
59
System.setProperty("derby.storage.fileSyncTransactionLog", "true");
60
61         // load the Embedded driver to initialize the home
62
new org.apache.derby.jdbc.EmbeddedDriver();
63
64         EmbeddedDataSource datasource = new EmbeddedDataSource();
65         datasource.setDatabaseName("SystemDatabase");
66         datasource.setCreateDatabase("create");
67         try {
68             Connection JavaDoc c = datasource.getConnection();
69             c.close();
70         } catch (SQLException JavaDoc e) {
71             while (e.getNextException() != null) {
72                 e.printStackTrace();
73                 e = e.getNextException();
74             }
75             throw e;
76         }
77         this.datasource = datasource;
78 // assertTrue(new File(systemDir, derbyDir + "/derby.log").exists());
79
super.setUp();
80     }
81
82     protected void tearDown() throws Exception JavaDoc {
83 // ((EmbeddedDataSource)datasource).setShutdownDatabase("shutdown");
84
try {
85             DriverManager.getConnection(SHUTDOWN_ALL, null, null);
86         } catch (SQLException JavaDoc e) {
87             //ignore.. expected??
88
}
89 // Connection c = datasource.getConnection();
90
// c.close();
91
delete(systemDir);
92         super.tearDown();
93 // Thread.sleep(5000);
94
}
95
96     private void delete(File JavaDoc file) throws IOException JavaDoc {
97         if (file == null) {
98             return;
99         }
100
101         File JavaDoc[] files = file.listFiles();
102         if (files != null) {
103             for (int i = 0; i < files.length; i++) {
104                 delete(files[i]);
105             }
106         }
107         file.delete();
108     }
109
110 }
111
Popular Tags