KickJava   Java API By Example, From Geeks To Geeks.

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


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/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
19     extends TKExtendedPrepQuery
20 {
21
22     // Constants
23

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

47
48   public static final String JavaDoc SQL = null;
49
50
51     protected static Class JavaDoc[] queryClasses = {SelectIDWMProfile.class, InsertWMProfile.class };
52
53     // Method implementations
54

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

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