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/ContextInsert.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 ContextInsert extends TKExtendedPrepQuery {
19:
20: // Constants
21:
22: public static final String[] ORDER = { "NAME", "SHORTCUT" };
23:
24: public static final Object[][] TYPES = {
25: { "NAME", new Integer(Types.VARCHAR) },
26: { "SHORTCUT", new Integer(Types.VARCHAR) } };
27:
28: public static final boolean[] RELEVANTS = { true };
29:
30: /* public static final String SQL = (new StringBuffer()).append("DECLARE @ID INT ")
31: .append("SELECT @ID = ISNULL(MAX(WM_CONTEXT_ID) + 1, 1) FROM WM_CONTEXT ")
32: .append("INSERT INTO WM_CONTEXT (WM_CONTEXT_ID, NAME, SHORTCUT) VALUES (@ID, ?, ?) ")
33: .append("SELECT * FROM WM_CONTEXT WHERE WM_CONTEXT_ID = @ID")
34: .toString(); */
35:
36: public static final String SQL = null;
37:
38: protected static Class[] queryClasses = { SelectIDWMContext.class, // [0]
39: InsertWMContext.class, // [1]
40: SelectWMContext.class // [2]
41: };
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:
54: queries[0].execute(); // execute first query
55: ResultSet rs = queries[0].fetchResultSet();
56: Integer wmContextId = null;
57: if (rs != null && rs.next()) {
58: int max = 1;
59: max = rs.getInt(1) + 1; // get max if any and increase by 1
60: wmContextId = new Integer(max);
61: }
62:
63: queries[1].setQueryParams("WM_CONTEXT_ID", wmContextId);
64: queries[1].execute(); // ...and execute it
65:
66: queries[2].setQueryParams("WM_CONTEXT_ID", wmContextId);
67: queries[2].setQueryParams("NAME", queryParams.get("NAME"));
68: queries[2].setQueryParams("SHORTCUT", queryParams
69: .get("SHORTCUT"));
70: queries[2].execute();
71: addResult(queries[2].fetchResultSet()); // store result for later use
72: if (isNotOpen) {
73: aTKDBConnection.commitTransaction();
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: }
|