01: package de.webman.acl.db.queries;
02:
03: import java.sql.Connection;
04: import java.sql.SQLException;
05: import java.sql.ResultSet;
06: import java.sql.Types;
07: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
08: import com.teamkonzept.db.*;
09: import com.teamkonzept.webman.mainint.db.queries.accesscontrol.*;
10:
11: /**
12: * $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/db/queries/ActionInsert.java,v 1.2 2001/09/19 11:51:38 markus Exp $
13: *
14: * @version 0.10
15: * @since 0.10
16: * @author © 2000 Team-Konzept
17: */
18: public class ActionInsert extends TKExtendedPrepQuery {
19:
20: // Constants
21:
22: public static final String[] ORDER = { "NAME" };
23:
24: public static final Object[][] TYPES = { { "NAME",
25: new Integer(Types.VARCHAR) } };
26:
27: public static final boolean[] RELEVANTS = { true };
28:
29: public static final String SQL = null;
30:
31: protected static Class[] queryClasses = { SelectIDWMAction.class, // [0]
32: InsertWMAction.class, // [1]
33: SelectWMAction.class // [2]
34: };
35:
36: /* public static final String SQL = (new StringBuffer()).append("DECLARE @ID INT ")
37: .append("SELECT @ID = ISNULL(MAX(WM_ACTION_ID) + 1, 1) FROM WM_ACTION ")
38: .append("INSERT INTO WM_ACTION (WM_ACTION_ID, NAME) VALUES (@ID, ?) ")
39: .append("SELECT * FROM WM_ACTION WHERE WM_ACTION_ID = @ID")
40: .toString(); */
41:
42: // Method implementations
43: public boolean execute() {
44: try {
45: init(queryClasses);
46:
47: boolean isNotOpen = aTKDBConnection.isAutoCommit();
48: if (isNotOpen) {
49: aTKDBConnection.beginTransaction();
50: }
51:
52: queries[0].execute(); // execute first query
53:
54: ResultSet rs = queries[0].fetchResultSet();
55: Integer wmActionId = null;
56: if (rs != null && rs.next()) {
57: int max = 1;
58: max = rs.getInt(1) + 1; // get max if any and increase by 1
59: wmActionId = new Integer(max);
60: }
61:
62: queries[1].setQueryParams("WM_ACTION_ID", wmActionId);
63: queries[1].setQueryParams("NAME", queryParams.get("NAME"));
64: queries[1].execute(); // ...and execute it
65:
66: queries[2].setQueryParams("WM_ACTION_ID", wmActionId);
67: queries[2].execute();
68: addResult(queries[2].fetchResultSet()); // store result for later use
69:
70: if (isNotOpen) {
71: aTKDBConnection.commitTransaction();
72: }
73: } catch (SQLException sqle) {
74: WebmanExceptionHandler.getException(sqle);
75: try {
76: aTKDBConnection.rollbackTransaction();
77: } catch (SQLException sqle2) {
78: WebmanExceptionHandler.getException(sqle2);
79: }
80: } finally {
81: return hasResults();
82: }
83: }
84:
85: public void initQuery(Connection connection) {
86: super .initQuery(connection, true, ORDER, TYPES, RELEVANTS, SQL);
87: }
88:
89: }
|