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/UserInsert.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 UserInsert extends TKExtendedPrepQuery {
19:
20: // Constants
21:
22: public static final String[] ORDER = { "NAME", "LOGIN", "TYPE" };
23:
24: public static final Object[][] TYPES = {
25: { "NAME", new Integer(Types.VARCHAR) },
26: { "LOGIN", new Integer(Types.VARCHAR) },
27: { "TYPE", new Integer(Types.CHAR) } };
28:
29: public static final boolean[] RELEVANTS = { true };
30:
31: /* public static final String SQL = (new StringBuffer()).append("DECLARE @ID INT ")
32: .append("SELECT @ID = ISNULL(MAX(WM_USER_ID) + 1, 1) FROM WM_USER ")
33: .append("INSERT INTO WM_USER (WM_USER_ID, NAME, LOGIN, TYPE) VALUES (@ID, ?, ?, ?) ")
34: .append("SELECT * FROM WM_USER WHERE WM_USER_ID = @ID")
35: .toString(); */
36:
37: protected static Class[] queryClasses = { SelectIDWMUser.class,
38: InsertWMUser.class, SelectWMUser.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(); // start transaction
49: }
50: queries[0].execute(); // execute first query
51: ResultSet rs = queries[0].fetchResultSet();
52: Integer wmUserId = 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: wmUserId = new Integer(max);
57: }
58:
59: queries[1].setQueryParams("WM_USER_ID", wmUserId);
60: queries[1].setQueryParams("NAME", queryParams.get("NAME"));
61: queries[1]
62: .setQueryParams("LOGIN", queryParams.get("LOGIN"));
63: queries[1].setQueryParams("TYPE", queryParams.get("TYPE"));
64: queries[1].execute(); // ...and execute it
65:
66: queries[2].setQueryParams("WM_USER_ID", wmUserId);
67: queries[2].execute(); // ...and execute it
68: addResult(queries[2].fetchResultSet());
69:
70: if (isNotOpen) {
71: aTKDBConnection.commitTransaction();
72: }
73:
74: } catch (SQLException sqle) {
75: WebmanExceptionHandler.getException(sqle);
76: try {
77: aTKDBConnection.rollbackTransaction();
78: } catch (SQLException sqle2) {
79: WebmanExceptionHandler.getException(sqle2);
80: }
81: } finally {
82: return hasResults();
83: }
84: }
85:
86: public void initQuery(Connection connection) {
87: super
88: .initQuery(connection, true, ORDER, TYPES, RELEVANTS,
89: null);
90: }
91:
92: }
|