Changeset 60
- Timestamp:
- 02/26/10 23:13:22 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
kahina/trunk/src/org/kahina/core/KahinaRunner.java
r52 r60 9 9 { 10 10 KahinaInstance kahina = new KahinaInstance(new DbDataManager(new DatabaseHandler())); 11 System.err.println("Test."); 11 12 } 12 13 } kahina/trunk/src/org/kahina/io/database/DatabaseHandler.java
r54 r60 152 152 { 153 153 Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); 154 File file = File.createTempFile("kahinadb", null);154 final File file = File.createTempFile("kahinadb", null); 155 155 deleteRecursively(file); 156 156 connection = DriverManager.getConnection("jdbc:derby:" + file.getPath() 157 157 + ";create=true"); 158 // db.deleteOnExit(); // should work but doesn't 158 Runtime.getRuntime().addShutdownHook(new Thread() { 159 160 @Override 161 public void run() 162 { 163 try 164 { 165 if (!connection.isClosed()) 166 { 167 connection.close(); 168 } 169 } catch (SQLException e) 170 { 171 // do nothing 172 } 173 deleteRecursively(file); 174 } 175 176 }); 159 177 Statement statement = connection.createStatement(); 160 178 try … … 169 187 .executeUpdate("CREATE TABLE data (id BIGINT NOT NULL , value VARCHAR(32) NOT NULL, PRIMARY KEY (id))"); 170 188 statement.close(); 189 } 190 191 /** 192 * Closes the underlying database connection. This method should always be 193 * invoked as soon as this handler is no longer needed. 194 */ 195 public void close() 196 { 197 try 198 { 199 connection.close(); 200 } catch (SQLException e) 201 { 202 throw new KahinaException("Failed to close database handler.", e); 203 } 171 204 } 172 205
