01: package de.webman.acl.db.queries;
02:
03: import java.sql.Connection;
04: import java.sql.Types;
05: import java.sql.SQLException;
06: import java.sql.ResultSet;
07: import com.teamkonzept.db.*;
08: import com.teamkonzept.webman.mainint.db.queries.accesscontrol.*;
09: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
10:
11: /**
12: * $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/db/queries/RoleInsert.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 RoleInsert 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 = (new StringBuffer()).append("DECLARE @ID INT ")
30: .append("SELECT @ID = ISNULL(MAX(WM_ROLE_ID) + 1, 1) FROM WM_ROLE ")
31: .append("INSERT INTO WM_ROLE (WM_ROLE_ID, NAME) VALUES (@ID, ?) ")
32: .append("SELECT * FROM WM_ROLE WHERE WM_ROLE_ID = @ID")
33: .toString(); */
34:
35: public static final String SQL = null;
36:
37: protected static Class[] queryClasses = { SelectIDWMRole.class,
38: InsertWMRole.class, SelectWMRole.class };
39:
40: // Method implementations
41:
42: public boolean execute() {
43: try {
44: init(queryClasses);
45:
46: boolean isNotOpen = aTKDBConnection.isAutoCommit();
47: if (isNotOpen) {
48: aTKDBConnection.beginTransaction();
49: }
50: queries[0].execute(); // execute first query
51: ResultSet rs = queries[0].fetchResultSet();
52: Integer wmRoleId = null;
53: if (rs != null && rs.next()) {
54: int max = 1;
55: max = rs.getInt(1) + 1; // get max if any and increase by 1
56: wmRoleId = new Integer(max);
57: }
58:
59: queries[1].setQueryParams("WM_ROLE_ID", wmRoleId);
60: queries[1].setQueryParams("NAME", queryParams.get("NAME"));
61: queries[1].execute(); // ...and execute it
62:
63: queries[2].setQueryParams("WM_ROLE_ID", wmRoleId);
64: queries[2].execute(); // ...and execute it
65: addResult(queries[2].fetchResultSet());
66:
67: if (isNotOpen) {
68: aTKDBConnection.commitTransaction();
69: }
70: } catch (SQLException sqle) {
71: WebmanExceptionHandler.getException(sqle);
72: try {
73: aTKDBConnection.rollbackTransaction();
74: } catch (SQLException sqle2) {
75: WebmanExceptionHandler.getException(sqle2);
76: }
77: } finally {
78: return hasResults();
79: }
80: }
81:
82: public void initQuery(Connection connection) {
83: super .initQuery(connection, true, ORDER, TYPES, RELEVANTS, SQL);
84: }
85:
86: }
|