1 17 package org.apache.geronimo.timer.jdbc; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.Properties ; 22 import java.sql.SQLException ; 23 import java.sql.Connection ; 24 import java.sql.DriverManager ; 25 26 import org.apache.derby.jdbc.EmbeddedDataSource; 27 28 31 public class DerbyJDBCWorkerPersistenceTest extends JDBCWorkerPersistenceTestAbstract { 32 private static final String SYSTEM_HOME = "derby.system.home"; 33 private static final String SHUTDOWN_ALL = "jdbc:derby:;shutdown=true"; 34 35 private File systemDir; 36 37 38 private void connect() throws SQLException { 39 Connection c = DriverManager.getConnection("jdbc:derby:testdb;create=true"); 40 c.close(); 41 } 42 43 protected void setUp() throws Exception { 44 useSequence = false; 45 try { 46 systemDir = File.createTempFile("derbyTest", ".tmp"); 47 systemDir.delete(); 48 systemDir.mkdirs(); 49 } catch (Exception e) { 50 delete(systemDir); 51 throw e; 52 } 53 String derbyDir = "var/dbderby"; 54 File derby = new File (systemDir, derbyDir); 55 System.setProperty(SYSTEM_HOME, derby.getAbsolutePath()); 56 57 System.setProperty("derby.storage.fileSyncTransactionLog", "true"); 60 61 new org.apache.derby.jdbc.EmbeddedDriver(); 63 64 EmbeddedDataSource datasource = new EmbeddedDataSource(); 65 datasource.setDatabaseName("SystemDatabase"); 66 datasource.setCreateDatabase("create"); 67 try { 68 Connection c = datasource.getConnection(); 69 c.close(); 70 } catch (SQLException e) { 71 while (e.getNextException() != null) { 72 e.printStackTrace(); 73 e = e.getNextException(); 74 } 75 throw e; 76 } 77 this.datasource = datasource; 78 super.setUp(); 80 } 81 82 protected void tearDown() throws Exception { 83 try { 85 DriverManager.getConnection(SHUTDOWN_ALL, null, null); 86 } catch (SQLException e) { 87 } 89 delete(systemDir); 92 super.tearDown(); 93 } 95 96 private void delete(File file) throws IOException { 97 if (file == null) { 98 return; 99 } 100 101 File [] 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 |