01: /*
02: * $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 $
03: *
04: */
05: package com.teamkonzept.webman.mainint.db.queries;
06:
07: import java.sql.*;
08:
09: 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: public final static boolean isPrepared = true;
22:
23: public final static String[] order = { "TEMPLATE_NAME" };
24:
25: public final static Object[][] types = { { "TEMPLATE_NAME",
26: new Integer(Types.VARCHAR) } };
27:
28: public final static boolean[] setRelevants = { true };
29:
30: /* public final static String sqlString =
31: "DECLARE @ID INT " +
32:
33: "BEGIN TRANSACTION " +
34:
35: "SELECT " +
36: " @ID=ISNULL(MAX(TEMPLATE_ID)+1, 1) " +
37: "FROM " +
38: " TEMPLATE " +
39:
40: "INSERT INTO " +
41: "TEMPLATE " +
42: " (TEMPLATE_ID, TEMPLATE_NAME) " +
43: "VALUES(@ID, ?) " +
44:
45: "COMMIT TRANSACTION " +
46:
47: "SELECT " +
48: " * " +
49: "FROM " +
50: " TEMPLATE " +
51: "WHERE " +
52: " TEMPLATE_ID = @ID "; */
53:
54: protected static Class[] queryClasses = { SelectMaxTemplate.class,
55: InsertTemplate.class, SelectTemplate.class };
56:
57: public boolean execute() {
58: try {
59: init(queryClasses);
60:
61: boolean isNotOpen = aTKDBConnection.isAutoCommit();
62: if (isNotOpen) {
63: TKDBManager.beginTransaction();
64: }
65:
66: queries[0].execute(); // SELECT MAX(TEMPLATE_ID) FROM TEMPLATE
67: ResultSet rs = queries[0].fetchResultSet();
68: int max = 1;
69: if (rs != null && rs.next()) {
70: max = rs.getInt(1) + 1;
71: }
72:
73: queries[1].setQueryParams("TEMPLATE_ID", new Integer(max));
74: queries[1].setQueryParams("TEMPLATE_NAME", queryParams
75: .get("TEMPLATE_NAME"));
76: queries[1].execute(); // INSERT INTO TEMPLATE (TEMPLATE_ID, TEMPLATE_NAME) VALUES (max, ?)
77:
78: queries[2].setQueryParams("TEMPLATE_ID", new Integer(max));
79: queries[2].execute(); // SELECT * FROM TEMPLATE WHERE TEMPLATE_ID = max;
80: addResult(queries[2].fetchResultSet());
81:
82: if (isNotOpen) {
83: TKDBManager.commitTransaction();
84: }
85: } catch (Throwable t) {
86: TKDBManager.safeRollbackTransaction(t);
87: }
88: return hasResults();
89: }
90:
91: public void initQuery(Connection con) {
92: super.initQuery(con, isPrepared, order, types, setRelevants,
93: null);
94: }
95: }
|