01: /*
02: * SingleVerbCommand.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.sql.commands;
13:
14: import java.sql.SQLException;
15: import workbench.log.LogMgr;
16: import workbench.resource.ResourceMgr;
17: import workbench.sql.SqlCommand;
18: import workbench.sql.StatementRunnerResult;
19:
20: /**
21: *
22: * @author support@sql-workbench.net
23: */
24: public class SingleVerbCommand extends SqlCommand {
25: public static final SqlCommand COMMIT = new SingleVerbCommand(
26: "COMMIT");
27: public static final SqlCommand ROLLBACK = new SingleVerbCommand(
28: "ROLLBACK");
29:
30: private String verb;
31:
32: public SingleVerbCommand(String aVerb) {
33: this .verb = aVerb;
34: this .isUpdatingCommand = "COMMIT".equalsIgnoreCase(this .verb);
35: }
36:
37: public StatementRunnerResult execute(String aSql)
38: throws SQLException {
39: StatementRunnerResult result = new StatementRunnerResult(aSql);
40: try {
41: if (currentConnection.useJdbcCommit()) {
42: if ("COMMIT".equals(this .verb)) {
43: currentConnection.getSqlConnection().commit();
44: } else if ("ROLLBACK".equals(this .verb)) {
45: currentConnection.getSqlConnection().rollback();
46: }
47: } else {
48: this .currentStatement = currentConnection
49: .createStatement();
50: this .currentStatement.execute(verb);
51: }
52:
53: result.addMessage(this .verb + " "
54: + ResourceMgr.getString("MsgKnownStatementOK"));
55: result.setSuccess();
56: processMoreResults(aSql, result, false);
57: } catch (Exception e) {
58: addErrorInfo(result, aSql, e);
59: LogMgr.logSqlError("SingleVerbCommand.execute()", aSql, e);
60: } finally {
61: done();
62: }
63:
64: return result;
65: }
66:
67: public String getVerb() {
68: return verb;
69: }
70:
71: }
|