01: package de.webman.content.workflow.db.queries;
02:
03: import java.sql.*;
04:
05: import com.teamkonzept.db.*;
06: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
07: import de.webman.content.workflow.db.queries.SelectMaxVersionStatus;
08: import de.webman.content.workflow.db.queries.InsertVersionStatus;
09: import de.webman.content.workflow.db.queries.SelectVersionStatus;
10:
11: /*
12: *
13: * erzeugt neuen Eintrag in VERSION_STATUS
14: *
15: * @author
16: * @version
17: */
18: public class InsertStatus extends TKExtendedPrepQuery {
19:
20: public final static boolean ISPREPARED = true;
21: public final static String[] ORDER = { "STATUS",
22: "STATUS_ATTRIBUTES" };
23: public final static Object[][] TYPES = null;
24: public final static boolean[] SETRELEVANTS = { true };
25:
26: protected static Class[] queryClasses = {
27: SelectMaxVersionStatus.class, InsertVersionStatus.class,
28: SelectVersionStatus.class };
29:
30: public boolean execute() {
31: try {
32: init(queryClasses);
33:
34: boolean isNotOpen = aTKDBConnection.isAutoCommit();
35: if (isNotOpen) {
36: TKDBManager.beginTransaction();
37: }
38:
39: // SELECT MAX(STATUS_ID) FROM VERSION_STATUS
40: queries[0].execute();
41: int status_id = 1;
42: ResultSet rs = queries[0].fetchResultSet();
43: if (rs != null && rs.next()) {
44: status_id = rs.getInt(1) + 1;
45: }
46: Integer statusId = new Integer(status_id);
47:
48: // INSERT INTO VERSION_STATUS (STATUS_ID, STATUS, STATUS_ATTRIBUTES) VALUES (?, ?, ?)
49: queries[1].setQueryParams("STATUS_ID", statusId);
50: queries[1].setQueryParams("STATUS", queryParams
51: .get("STATUS"));
52: queries[1].setQueryParams("STATUS_ATTRIBUTES", queryParams
53: .get("STATUS_ATTRIBUTES"));
54: queries[1].execute();
55:
56: // SELECT * FROM VERSION_STATUS WHERE STATUS_ID = ?
57: queries[2].setQueryParams("STATUS_ID", statusId);
58: queries[2].execute();
59: addResult(queries[2].fetchResultSet());
60:
61: if (isNotOpen) {
62: TKDBManager.commitTransaction();
63: }
64:
65: } catch (Throwable t) {
66: TKDBManager.safeRollbackTransaction(t);
67: }
68: return hasResults();
69: }
70:
71: public void initQuery(Connection con) {
72: super.initQuery(con, ISPREPARED, ORDER, TYPES, SETRELEVANTS,
73: null);
74: }
75: }
|