org.h2.tools.Script Java Examples

The following examples show how to use org.h2.tools.Script. 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: AbstractJobPersistenceTest.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * Test that a persisted job executes normally and can be retrieved from the perisstence store.
 * @throws Exception if any error occurs.
 */
@Test(timeout = 10000)
public void testSimplePersistedJobRetrieval() throws Exception {
  final int nbTasks = 10;
  final String method = ReflectionUtils.getCurrentMethodName();
  final JPPFJob job = BaseTestHelper.createJob(method, false, nbTasks, LifeCycleTask.class, 0L);
  job.getSLA().setCancelUponClientDisconnect(false);
  job.getSLA().getPersistenceSpec().setPersistent(true).setAutoExecuteOnRestart(false).setDeleteOnCompletion(false);
  print(false, false, "submitting job");
  client.submitAsync(job);
  final List<Task<?>> results = job.awaitResults();
  if (h2Server != null) Script.main("-url", DB_URL, "-user", DB_USER, "-password", DB_PWD, "-script", "test1h2dump.log");
  print(false, false, "checking job results");
  checkJobResults(nbTasks, results, false);
  final JMXDriverConnectionWrapper jmx = client.awaitWorkingConnectionPool().awaitWorkingJMXConnection();
  print(false, false, "got jmx connection");
  final JPPFDriverJobPersistence mgr = new JPPFDriverJobPersistence(jmx);
  assertTrue(ConcurrentUtils.awaitCondition(new PersistedJobCompletion(mgr, job.getUuid()), 6000L, 500L, false));
  final List<String> persistedUuids = mgr.listJobs(JobSelector.ALL_JOBS);
  assertNotNull(persistedUuids);
  assertEquals(1, persistedUuids.size());
  print(false, false, "retrieving job 2 from store");
  final JPPFJob job2 = mgr.retrieveJob(job.getUuid());
  compareJobs(job, job2, true);
  print(false, false, "checking job 2 results");
  checkJobResults(nbTasks, job2.getResults().getAllResults(), false);
  assertEquals(JobStatus.COMPLETE, job2.getStatus());
  assertTrue(mgr.deleteJob(job.getUuid()));
  assertTrue(ConcurrentUtils.awaitCondition(new EmptyPersistedUuids(mgr), WAIT_TIME_EMPTY_UUIDS, 250, false));
}
 
Example #2
Source File: CompactLocalH2.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #3
Source File: ToolMain.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("startupLogger")
private static void recreate(File dataDir) throws Exception {
    File backupFile = new File(dataDir, "backup.sql");
    if (backupFile.exists() && !backupFile.delete()) {
        startupLogger.warn("recreate failed: cannot delete existing backup.sql");
    }
    Script.main("-url", "jdbc:h2:" + dataDir.getPath() + File.separator + "data", "-user", "sa",
            "-script", backupFile.getPath());
    File dbFile = new File(dataDir, "data.h2.db");
    File dbBakFile = new File(dataDir, "data.h2.db.bak");
    if (dbBakFile.exists() && !dbBakFile.delete()) {
        startupLogger.warn("recreate failed, cannot delete existing file: {}",
                dbBakFile.getPath());
    }
    if (!dbFile.renameTo(dbBakFile)) {
        startupLogger.warn("recreate failed, cannot rename {} to {}", dbFile.getPath(),
                dbBakFile.getPath());
        return;
    }
    RunScript.main("-url", "jdbc:h2:" + dataDir.getPath() + File.separator + "data", "-script",
            backupFile.getPath());
    startupLogger.info("recreate succeeded");

    // clean up
    if (!dbBakFile.delete()) {
        startupLogger.info("failed to clean-up, cannot delete file: {}", dbBakFile.getPath());
    }
    if (!backupFile.delete()) {
        startupLogger.info("failed to clean-up, cannot delete file: {}", backupFile.getPath());
    }
}