KickJava   Java API By Example, From Geeks To Geeks.

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


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

24     public static final String JavaDoc[] ORDER =
25     {
26         "NAME",
27         "SHORTCUT"
28     };
29
30     public static final Object JavaDoc[][] TYPES =
31     {
32         {"NAME", new Integer JavaDoc(Types.VARCHAR)},
33         {"SHORTCUT", new Integer JavaDoc(Types.VARCHAR)}
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("SELECT @ID = ISNULL(MAX(WM_CONTEXT_ID) + 1, 1) FROM WM_CONTEXT ")
43                                                          .append("INSERT INTO WM_CONTEXT (WM_CONTEXT_ID, NAME, SHORTCUT) VALUES (@ID, ?, ?) ")
44                                                          .append("SELECT * FROM WM_CONTEXT WHERE WM_CONTEXT_ID = @ID")
45                                                          .toString(); */

46
47   public static final String JavaDoc SQL = null;
48
49     protected static Class JavaDoc[] queryClasses = {
50       SelectIDWMContext.class, // [0]
51
InsertWMContext.class, // [1]
52
SelectWMContext.class // [2]
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
66         queries[0].execute(); // execute first query
67
ResultSet JavaDoc rs = queries[0].fetchResultSet();
68         Integer JavaDoc wmContextId = null;
69         if (rs != null && rs.next()) {
70             int max = 1;
71            max = rs.getInt(1) + 1; // get max if any and increase by 1
72
wmContextId = new Integer JavaDoc(max);
73         }
74
75         queries[1].setQueryParams("WM_CONTEXT_ID", wmContextId);
76         queries[1].execute(); // ...and execute it
77

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