KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > webman > mainint > db > queries > TKDBTmplNew


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/webman/mainint/db/queries/Attic/TKDBTmplNew.java,v 1.6 2001/08/15 13:18:55 markus Exp $
3  *
4  */

5 package com.teamkonzept.webman.mainint.db.queries;
6
7 import java.sql.*;
8
9 import com.teamkonzept.db.*;
10 import com.teamkonzept.webman.mainint.db.queries.template.*;
11 import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
12
13 /*
14  * TKDBTmplNew
15  * input "TEMPLATE_NAME"
16  * output neuer DS
17  * erzeugt neuen Eintrag in TEMPLATE
18  */

19 public class TKDBTmplNew extends TKExtendedPrepQuery
20 {
21
22     public final static boolean isPrepared = true;
23
24     public final static String JavaDoc[] order = { "TEMPLATE_NAME" };
25
26     public final static Object JavaDoc[][] types =
27     { {"TEMPLATE_NAME", new Integer JavaDoc(Types.VARCHAR)} };
28
29     public final static boolean[] setRelevants = { true };
30
31 /* public final static String sqlString =
32         "DECLARE @ID INT " +
33
34         "BEGIN TRANSACTION " +
35
36         "SELECT " +
37         " @ID=ISNULL(MAX(TEMPLATE_ID)+1, 1) " +
38         "FROM " +
39         " TEMPLATE " +
40
41         "INSERT INTO " +
42         "TEMPLATE " +
43         " (TEMPLATE_ID, TEMPLATE_NAME) " +
44         "VALUES(@ID, ?) " +
45
46         "COMMIT TRANSACTION " +
47
48         "SELECT " +
49         " * " +
50         "FROM " +
51         " TEMPLATE " +
52         "WHERE " +
53         " TEMPLATE_ID = @ID "; */

54
55     protected static Class JavaDoc[] queryClasses = {
56     SelectMaxTemplate.class,
57     InsertTemplate.class,
58     SelectTemplate.class
59     };
60
61     public boolean execute()
62     {
63     try
64     {
65         init(queryClasses);
66
67         boolean isNotOpen = aTKDBConnection.isAutoCommit();
68         if (isNotOpen)
69         {
70         TKDBManager.beginTransaction();
71         }
72
73         queries[0].execute(); // SELECT MAX(TEMPLATE_ID) FROM TEMPLATE
74
ResultSet rs = queries[0].fetchResultSet();
75         int max = 1;
76         if (rs != null && rs.next())
77         {
78         max = rs.getInt(1) + 1;
79         }
80
81         queries[1].setQueryParams("TEMPLATE_ID", new Integer JavaDoc(max));
82         queries[1].setQueryParams("TEMPLATE_NAME",
83                       queryParams.get("TEMPLATE_NAME"));
84         queries[1].execute(); // INSERT INTO TEMPLATE (TEMPLATE_ID, TEMPLATE_NAME) VALUES (max, ?)
85

86         queries[2].setQueryParams("TEMPLATE_ID", new Integer JavaDoc(max));
87         queries[2].execute(); // SELECT * FROM TEMPLATE WHERE TEMPLATE_ID = max;
88
addResult(queries[2].fetchResultSet());
89
90         if (isNotOpen)
91         {
92         TKDBManager.commitTransaction();
93         }
94     }
95     catch(Throwable JavaDoc t)
96     {
97         TKDBManager.safeRollbackTransaction(t);
98     }
99     return hasResults();
100     }
101
102
103     public void initQuery(Connection con)
104     {
105     super.initQuery(con, isPrepared, order, types, setRelevants, null);
106     }
107 }
108
Popular Tags