KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > db > queries > EventInsert


1 package de.webman.acl.db.queries;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.Types JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.sql.ResultSet JavaDoc;
7 import com.teamkonzept.db.*;
8 import com.teamkonzept.webman.mainint.db.queries.accesscontrol.*;
9 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
19     extends TKExtendedPrepQuery
20 {
21
22     // Constants
23

24     public static final String JavaDoc[] ORDER =
25     {
26         "NAME"
27     };
28
29     public static final Object JavaDoc[][] TYPES =
30     {
31         {"NAME", new Integer JavaDoc(Types.VARCHAR)}
32     };
33
34     public static final boolean[] RELEVANTS =
35     {
36         true
37     };
38
39 /* public static final String SQL = (new StringBuffer()).append("DECLARE @ID INT ")
40                                                          .append("SELECT @ID = ISNULL(MAX(WM_EVENT_ID) + 1, 1) FROM WM_EVENT ")
41                                                          .append("INSERT INTO WM_EVENT (WM_EVENT_ID, NAME) VALUES (@ID, ?) ")
42                                                          .append("SELECT * FROM WM_EVENT WHERE WM_EVENT_ID = @ID")
43                                                          .toString(); */

44
45   public static final String JavaDoc SQL = null;
46
47     protected static Class JavaDoc[] queryClasses = { SelectIDWMEvent.class, InsertWMEvent.class, SelectWMEvent.class };
48
49     // Method implementations
50

51   public boolean execute() {
52     try {
53         init(queryClasses);
54
55         boolean isNotOpen = aTKDBConnection.isAutoCommit();
56         if (isNotOpen) {
57           aTKDBConnection.beginTransaction();
58         }
59
60         queries[0].execute(); // execute first query
61
ResultSet JavaDoc rs = queries[0].fetchResultSet();
62         Integer JavaDoc wmEventId = null;
63         if (rs != null && rs.next()) {
64           int max = 1;
65            max = rs.getInt(1) + 1; // get max if any and increase by 1
66
wmEventId = new Integer JavaDoc(max);
67         }
68
69         queries[1].setQueryParams("WM_EVENT_ID", wmEventId);
70         queries[1].setQueryParams("NAME", queryParams.get("NAME"));
71         queries[1].execute(); // ...and execute it
72

73         queries[2].setQueryParams("WM_EVENT_ID", wmEventId);
74         queries[2].execute();
75         addResult(queries[2].fetchResultSet()); // store result for later use
76

77         if (isNotOpen) {
78           aTKDBConnection.commitTransaction();
79         }
80
81     }
82     catch (SQLException JavaDoc sqle) {
83       WebmanExceptionHandler.getException(sqle);
84       try {
85         aTKDBConnection.rollbackTransaction();
86       }
87       catch (SQLException JavaDoc sqle2) {
88         WebmanExceptionHandler.getException(sqle2);
89       }
90     }
91     finally {
92         return hasResults();
93     }
94   }
95
96     public void initQuery (Connection JavaDoc connection)
97     {
98         super.initQuery(connection,
99                         true,
100                         ORDER,
101                         TYPES,
102                         RELEVANTS,
103                         SQL);
104     }
105
106 }
107
Popular Tags