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/EventInsert.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 EventInsert 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_EVENT_ID) + 1, 1) FROM WM_EVENT ")
31: .append("INSERT INTO WM_EVENT (WM_EVENT_ID, NAME) VALUES (@ID, ?) ")
32: .append("SELECT * FROM WM_EVENT WHERE WM_EVENT_ID = @ID")
33: .toString(); */
34:
35: public static final String SQL = null;
36:
37: protected static Class[] queryClasses = { SelectIDWMEvent.class,
38: InsertWMEvent.class, SelectWMEvent.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:
51: queries[0].execute(); // execute first query
52: ResultSet rs = queries[0].fetchResultSet();
53: Integer wmEventId = null;
54: if (rs != null && rs.next()) {
55: int max = 1;
56: max = rs.getInt(1) + 1; // get max if any and increase by 1
57: wmEventId = new Integer(max);
58: }
59:
60: queries[1].setQueryParams("WM_EVENT_ID", wmEventId);
61: queries[1].setQueryParams("NAME", queryParams.get("NAME"));
62: queries[1].execute(); // ...and execute it
63:
64: queries[2].setQueryParams("WM_EVENT_ID", wmEventId);
65: queries[2].execute();
66: addResult(queries[2].fetchResultSet()); // store result for later use
67:
68: if (isNotOpen) {
69: aTKDBConnection.commitTransaction();
70: }
71:
72: } catch (SQLException sqle) {
73: WebmanExceptionHandler.getException(sqle);
74: try {
75: aTKDBConnection.rollbackTransaction();
76: } catch (SQLException sqle2) {
77: WebmanExceptionHandler.getException(sqle2);
78: }
79: } finally {
80: return hasResults();
81: }
82: }
83:
84: public void initQuery(Connection connection) {
85: super .initQuery(connection, true, ORDER, TYPES, RELEVANTS, SQL);
86: }
87:
88: }
|