KickJava   Java API By Example, From Geeks To Geeks.

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


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/RoleInsert.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 RoleInsert
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_ROLE_ID) + 1, 1) FROM WM_ROLE ")
41                                                          .append("INSERT INTO WM_ROLE (WM_ROLE_ID, NAME) VALUES (@ID, ?) ")
42                                                          .append("SELECT * FROM WM_ROLE WHERE WM_ROLE_ID = @ID")
43                                                          .toString(); */

44
45
46   public static final String JavaDoc SQL = null;
47
48
49     protected static Class JavaDoc[] queryClasses = {
50       SelectIDWMRole.class,
51       InsertWMRole.class,
52       SelectWMRole.class
53     };
54
55     // Method implementations
56

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

78         queries[2].setQueryParams("WM_ROLE_ID", wmRoleId);
79         queries[2].execute(); // ...and execute it
80
addResult(queries[2].fetchResultSet());
81
82         if (isNotOpen) { aTKDBConnection.commitTransaction(); }
83     }
84     catch (SQLException JavaDoc sqle) {
85       WebmanExceptionHandler.getException(sqle);
86       try {
87         aTKDBConnection.rollbackTransaction();
88       }
89       catch (SQLException JavaDoc sqle2) {
90         WebmanExceptionHandler.getException(sqle2);
91       }
92     }
93     finally {
94         return hasResults();
95     }
96   }
97
98     public void initQuery (Connection JavaDoc connection)
99     {
100         super.initQuery(connection,
101                         true,
102                         ORDER,
103                         TYPES,
104                         RELEVANTS,
105                         SQL);
106     }
107
108 }
109
Popular Tags