01: /*
02: * Copyright (c) 2006 Your Corporation. All Rights Reserved.
03: */
04:
05: package com.tacitknowledge.util.migration.jdbc;
06:
07: import java.sql.SQLException;
08:
09: import org.apache.log4j.Logger;
10: import com.tacitknowledge.util.migration.MigrationException;
11:
12: public class AutopatchSupport {
13: private static final Logger log = Logger
14: .getLogger(AutopatchSupport.class);
15: private JdbcMigrationLauncher launcher;
16:
17: public AutopatchSupport(String systemName)
18: throws MigrationException {
19: this (MigrationLauncherFactoryLoader.createFactory(), systemName);
20: }
21:
22: public AutopatchSupport(
23: JdbcMigrationLauncherFactory launcherFactory,
24: String systemName) throws MigrationException {
25: this (launcherFactory.createMigrationLauncher(systemName));
26: }
27:
28: public AutopatchSupport(JdbcMigrationLauncher launcher) {
29: this .launcher = launcher;
30: }
31:
32: public PatchTable makePatchTable() throws SQLException {
33: JdbcMigrationContext jdbcMigrationContext = launcher
34: .getJdbcMigrationContext();
35: return new PatchTable(jdbcMigrationContext,
36: jdbcMigrationContext.getConnection());
37: }
38:
39: public void setPatchLevel(int patchLevel) throws SQLException {
40: PatchTable patchTable = makePatchTable();
41: patchTable.lockPatchTable();
42: patchTable.updatePatchLevel(patchLevel);
43: log.info("Set the patch level to " + patchLevel);
44: patchTable.unlockPatchTable();
45: }
46:
47: public int getPatchLevel() throws SQLException {
48: PatchTable patchTable = makePatchTable();
49: return patchTable.getPatchLevel();
50: }
51:
52: public int getHighestPatchLevel() throws MigrationException {
53: return launcher.getNextPatchLevel() - 1;
54: }
55:
56: }
|