001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.timer.jdbc;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.util.Properties;
021: import java.sql.SQLException;
022: import java.sql.Connection;
023: import java.sql.DriverManager;
024:
025: import org.apache.derby.jdbc.EmbeddedDataSource;
026:
027: /**
028: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
029: */
030: public class DerbyJDBCWorkerPersistenceTest extends
031: JDBCWorkerPersistenceTestAbstract {
032: private static final String SYSTEM_HOME = "derby.system.home";
033: private static final String SHUTDOWN_ALL = "jdbc:derby:;shutdown=true";
034:
035: private File systemDir;
036:
037: private void connect() throws SQLException {
038: Connection c = DriverManager
039: .getConnection("jdbc:derby:testdb;create=true");
040: c.close();
041: }
042:
043: protected void setUp() throws Exception {
044: useSequence = false;
045: try {
046: systemDir = File.createTempFile("derbyTest", ".tmp");
047: systemDir.delete();
048: systemDir.mkdirs();
049: } catch (Exception e) {
050: delete(systemDir);
051: throw e;
052: }
053: String derbyDir = "var/dbderby";
054: File derby = new File(systemDir, derbyDir);
055: System.setProperty(SYSTEM_HOME, derby.getAbsolutePath());
056:
057: // set the magic system property that causes derby to use explicity
058: // file sync instead of relying on vm support for file open rws
059: System.setProperty("derby.storage.fileSyncTransactionLog",
060: "true");
061:
062: // load the Embedded driver to initialize the home
063: new org.apache.derby.jdbc.EmbeddedDriver();
064:
065: EmbeddedDataSource datasource = new EmbeddedDataSource();
066: datasource.setDatabaseName("SystemDatabase");
067: datasource.setCreateDatabase("create");
068: try {
069: Connection c = datasource.getConnection();
070: c.close();
071: } catch (SQLException e) {
072: while (e.getNextException() != null) {
073: e.printStackTrace();
074: e = e.getNextException();
075: }
076: throw e;
077: }
078: this .datasource = datasource;
079: // assertTrue(new File(systemDir, derbyDir + "/derby.log").exists());
080: super .setUp();
081: }
082:
083: protected void tearDown() throws Exception {
084: // ((EmbeddedDataSource)datasource).setShutdownDatabase("shutdown");
085: try {
086: DriverManager.getConnection(SHUTDOWN_ALL, null, null);
087: } catch (SQLException e) {
088: //ignore.. expected??
089: }
090: // Connection c = datasource.getConnection();
091: // c.close();
092: delete(systemDir);
093: super .tearDown();
094: // Thread.sleep(5000);
095: }
096:
097: private void delete(File file) throws IOException {
098: if (file == null) {
099: return;
100: }
101:
102: File[] files = file.listFiles();
103: if (files != null) {
104: for (int i = 0; i < files.length; i++) {
105: delete(files[i]);
106: }
107: }
108: file.delete();
109: }
110:
111: }
|