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/ProfileInsert.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 ProfileInsert extends TKExtendedPrepQuery {
19:
20: // Constants
21:
22: public static final String[] ORDER = { "WM_PROFILE_ID",
23: "WM_USER_ID" };
24:
25: public static final Object[][] TYPES = {
26: { "WM_PROFILE_ID", new Integer(Types.INTEGER) },
27: { "WM_USER_ID", new Integer(Types.INTEGER) } };
28:
29: public static final boolean[] RELEVANTS = { true };
30:
31: /* public static final String SQL = (new StringBuffer()).append("DECLARE @ID INT ")
32: .append("DECLARE @PRIO INT ")
33: .append("SELECT @ID = ? ")
34: .append("SELECT @PRIO = ISNULL(MAX(PRIORITY) + 1, 1) FROM WM_PROFILE WHERE WM_PROFILE_ID = @ID ")
35: .append("INSERT INTO WM_PROFILE (WM_USER_ID, WM_PROFILE_ID, PRIORITY) VALUES (?, @ID, @PRIO)")
36: .toString(); */
37:
38: public static final String SQL = null;
39:
40: protected static Class[] queryClasses = { SelectIDWMProfile.class,
41: InsertWMProfile.class };
42:
43: // Method implementations
44:
45: public boolean execute() {
46: try {
47: init(queryClasses);
48:
49: boolean isNotOpen = aTKDBConnection.isAutoCommit();
50: if (isNotOpen) {
51: aTKDBConnection.beginTransaction();
52: }
53: queries[0].setQueryParams("WM_PROFILE_ID", queryParams
54: .get("WM_PROFILE_ID"));
55: queries[0].execute(); // execute first query
56: ResultSet rs = queries[0].fetchResultSet();
57: Integer priority = null;
58: if (rs != null && rs.next()) {
59: int max = 1;
60: max = rs.getInt(1) + 1; // get max if any and increase by 1
61: priority = new Integer(max);
62: }
63:
64: queries[1].setQueryParams("PRIORITY", priority);
65: queries[1].setQueryParams("WM_PROFILE_ID", queryParams
66: .get("WM_PROFILE_ID"));
67: queries[1].setQueryParams("WM_USER_ID", queryParams
68: .get("WM_USER_ID"));
69: queries[1].execute(); // ...and execute it
70:
71: if (isNotOpen) {
72: aTKDBConnection.commitTransaction();
73: }
74:
75: } catch (SQLException sqle) {
76: WebmanExceptionHandler.getException(sqle);
77: try {
78: aTKDBConnection.rollbackTransaction();
79: } catch (SQLException sqle2) {
80: WebmanExceptionHandler.getException(sqle2);
81: }
82: } finally {
83: return hasResults();
84: }
85: }
86:
87: public void initQuery(Connection connection) {
88: super .initQuery(connection, true, ORDER, TYPES, RELEVANTS, SQL);
89: }
90:
91: }
|