KickJava   Java API By Example, From Geeks To Geeks.

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


1 package de.webman.acl.db.queries;
2
3 import java.sql.*;
4 import com.teamkonzept.db.*;
5 import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
6 import com.teamkonzept.webman.mainint.db.queries.accesscontrol.*;
7
8 /**
9  * $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/db/queries/PropertyInsert.java,v 1.2 2001/09/19 11:51:38 markus Exp $
10  *
11  * @version 0.10
12  * @since 0.10
13  * @author © 2000 Team-Konzept
14  */

15 public class PropertyInsert
16     extends TKExtendedPrepQuery
17 {
18
19     // Constants
20

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

45
46
47     protected static Class JavaDoc[] queryClasses = {
48         SelectPropertyMax.class, // [0]
49
InsertProperty.class, // [1]
50
SelectProperty.class // [2]
51
};
52     
53     // Method implementations
54

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

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