org.h2.tools.DeleteDbFiles Java Examples
The following examples show how to use
org.h2.tools.DeleteDbFiles.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: H2DatabaseImageMatcher.java From JImageHash with MIT License | 6 votes |
/** * Drop all data in the tables and delete the database files. This method * currently only supports h2 databases. After this method terminates * successfully all further method calls of this object will throw an * SQLException if applicable. * * <p> * Calling this method will close() all database connections. Therefore calling * close() on this object is not necessary. * * @throws SQLException if an SQL error occurs * @since 3.0.0 */ public void deleteDatabase() throws SQLException { try (Statement stm = conn.createStatement()) { String url = conn.getMetaData().getURL(); String needle = "jdbc:h2:"; if (url.startsWith(needle)) { int dbNameIndex = url.lastIndexOf("/"); String path = url.substring(needle.length(), dbNameIndex); String dbName = url.substring(dbNameIndex + 1); close(); DeleteDbFiles.execute(path, dbName, true); } else { String msg = "deleteDatabase currently not supported for non h2 drivers."; LOG.severe(msg); throw new UnsupportedOperationException(msg); } } }
Example #2
Source File: CamelSqlTest.java From jbpm-work-items with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { DeleteDbFiles.execute("~", "jbpm-db-test", true); setupDb(); context = setupWithPoolingDataSource("org.jbpm.contrib.camel-workitem"); SimpleRegistry simpleRegistry = new SimpleRegistry(); simpleRegistry.put("jdbc/testDS1", context.get(DATASOURCE)); handler = new SQLCamelWorkitemHandler("queryResult", new DefaultCamelContext(simpleRegistry)); }
Example #3
Source File: H2DatabaseImageMatcherTest.java From JImageHash with MIT License | 5 votes |
@Test public void deserializeNotPresent() throws ClassNotFoundException, SQLException { String user = "rootTest"; String password = ""; String dbName = "testSerializeNotPresent"; try { TypedImageMatcher deserialized = H2DatabaseImageMatcher.getFromDatabase(dbName, user, password, 0); assertNull(deserialized); } finally { DeleteDbFiles.execute("~", dbName, true); } }
Example #4
Source File: CompactLocalH2.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public boolean execute() throws Exception { DataServer server = Config.currentNode().getData(); if (null == server) { logger.print("not config dataServer."); return false; } if (!BooleanUtils.isTrue(server.getEnable())) { logger.print("data server not enable."); return false; } if (Servers.dataServerIsRunning()) { logger.print("data server is running, must stop data server first."); return false; } /* 需要注入驱动程序 */ // Class.forName(SlicePropertiesBuilder.driver_h2).newInstance(); DriverManager.registerDriver(new org.h2.Driver()); logger.print("compact data start at {}.", DateTools.format(start)); String dir = StringUtils.replace(Config.base(), "\\", "/") + "/local/repository/data"; String url = "jdbc:h2:" + dir + "/X;FILE_LOCK=NO"; String backup = dir + "/backup.sql"; Script.process(url, "sa", Config.token().getPassword(), backup, "", ""); DeleteDbFiles.execute(dir, "X", true); RunScript.execute(url, "sa", Config.token().getPassword(), backup, null, false); FileUtils.delete(backup); Date end = new Date(); System.out.println(String.format("compact data completed at %s, elapsed:%dms.", DateTools.format(end), end.getTime() - start.getTime())); return true; }
Example #5
Source File: ExecuteSqlWorkItemHandlerTest.java From jbpm-work-items with Apache License 2.0 | 5 votes |
@Override protected void finalize() throws Throwable { if (realH2Server != null) { System.out.println("Stopping H2 Server..."); realH2Server.stop(); } DeleteDbFiles.execute("", "target/executeSql-data", true); super.finalize(); }
Example #6
Source File: CamelSqlTest.java From jbpm-work-items with Apache License 2.0 | 5 votes |
@After public void cleanup() { PersistenceUtil.cleanUp(context); DeleteDbFiles.execute("~", "jbpm-db-test", true); }
Example #7
Source File: JPAWorkItemHandlerTest.java From jbpm-work-items with Apache License 2.0 | 5 votes |
@Override protected void finalize() throws Throwable { if (realH2Server != null) { System.out.println("Stopping H2 Server..."); realH2Server.stop(); } DeleteDbFiles.execute("", "target/jpa-wih", true); super.finalize(); }
Example #8
Source File: H2DataSource.java From account-provisioning-for-google-apps with Apache License 2.0 | 5 votes |
/** * Deletes the database files. Should be called with no active connections. * * @throws Exception if there are active connections. */ private void deleteDatabseFiles() throws Exception { if (connectionPool.getActiveConnections() != 0) { throw new Exception( "Should not try to delete database files while there are active connections."); } logger.log(Level.INFO, "Deleting database files at: " + databasePath + databaseName); DeleteDbFiles.execute(databasePath, databaseName, true); }
Example #9
Source File: LiquibaseH2IT.java From liquibase-spatial with Apache License 2.0 | 4 votes |
@BeforeMethod public void beforeMethod() throws SQLException { DeleteDbFiles.execute("./target", getDatabaseName(), true); getConnection().close(); }
Example #10
Source File: LiquibaseH2IT.java From liquibase-spatial with Apache License 2.0 | 4 votes |
@AfterMethod public void afterMethod() throws SQLException { DeleteDbFiles.execute("./target", getDatabaseName(), true); }