001: package com.teamkonzept.webman.mainint.db.queries;
002:
003: import com.teamkonzept.db.*;
004: import java.sql.*;
005: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
006: import com.teamkonzept.webman.mainint.db.queries.content.SelectMaxContentVersion;
007: import com.teamkonzept.webman.mainint.db.queries.content.SelectMaxContentVersionWhere;
008: import com.teamkonzept.webman.mainint.db.queries.content.InsertContentVersion;
009: import com.teamkonzept.webman.mainint.db.queries.content.SelectContentVersionContentInstance;
010:
011: public class TKDBContentNewVersion extends TKExtendedPrepQuery {
012:
013: public final static boolean ISPREPARED = true;
014:
015: public final static String[] PARAMORDER = { "INSTANCE_ID",
016: "STATUS_ID", "VERS_INFO", "VERS_AUTHOR" };
017:
018: public final static Object[][] TYPES = {
019: { "VERS_INFO", new Integer(Types.VARCHAR) },
020: { "VERS_AUTHOR", new Integer(Types.VARCHAR) }, };
021:
022: public final static boolean[] SETRELEVANTS = { false };
023:
024: protected static Class[] queryClasses = {
025: SelectMaxContentVersion.class, // [0]
026: SelectMaxContentVersionWhere.class, // [1]
027: InsertContentVersion.class, // [2]
028: SelectContentVersionContentInstance.class // [3]
029: };
030:
031: public boolean execute() {
032: try {
033: init(queryClasses); // init query objects
034:
035: // SELECT @INST_ID = ?
036: Integer instIdObj = (Integer) queryParams
037: .get("INSTANCE_ID");
038:
039: boolean isNotOpen = aTKDBConnection.isAutoCommit();
040: if (isNotOpen) {
041: TKDBManager.beginTransaction();
042: }
043:
044: int vers_id = 1;
045: // SELECT @VERS_ID=ISNULL(MAX(VERSION_ID)+1, 1) FROM CONTENT_VERSION
046: queries[0].execute();
047: ResultSet rs = queries[0].fetchResultSet();
048: if (rs != null && rs.next()) {
049: vers_id = rs.getInt(1) + 1;
050: }
051:
052: //int cont_id = 0;
053: Object contIdObj = null;
054: // SELECT @CONT_ID= ( SELECT MAX (CONTENT_ID) FROM CONTENT_VERSION WHERE INSTANCE_ID = @INST_ID )
055: // PARAMS: INSTANCE_ID
056: queries[1].setQueryParams("INSTANCE_ID", instIdObj);
057: queries[1].execute();
058: rs = queries[1].fetchResultSet();
059: if (rs != null && rs.next()) {
060: contIdObj = rs.getObject(1);
061: }
062:
063: // INSERT INTO CONTENT_VERSION (VERSION_ID, INSTANCE_ID, CONTENT_ID, STATUS_ID, VERSION_DATE, INFO, AUTHOR)
064: // VALUES (@VERS_ID, @INST_ID, @CONT_ID, ?, {fn NOW()}, ?, ?)
065: // PARAMS: VERSION_ID, INSTANCE_ID, CONTENT_ID, STATUS_ID, DATE (DATE), VERS_INFO (VARCHAR), VERS_AUTHOR (VARCHAR)
066: queries[2].setQueryParams("VERSION_ID",
067: new Integer(vers_id));
068: queries[2].setQueryParams("INSTANCE_ID", instIdObj);
069: queries[2].setQueryParams("CONTENT_ID", contIdObj);
070: queries[2].setQueryParams("STATUS_ID", queryParams
071: .get("STATUS_ID"));
072: queries[2].setQueryParams("DATE", new java.sql.Timestamp(
073: System.currentTimeMillis()));
074: queries[2].setQueryParams("VERS_INFO", queryParams
075: .get("VERS_INFO"));
076: queries[2].setQueryParams("VERS_AUTHOR", queryParams
077: .get("VERS_AUTHOR"));
078: queries[2].execute();
079:
080: if (isNotOpen) {
081: aTKDBConnection.commitTransaction(); // commit all changes
082: }
083:
084: // SELECT CV.*, CI.NAME FROM CONTENT_VERSION CV, CONTENT_INSTANCE CI
085: // WHERE CV.VERSION_ID = @VERS_ID AND CI.INSTANCE_ID = @INST_ID
086: // PARAMS: VERSION_ID, INSTANCE_ID
087: queries[3].setQueryParams("VERSION_ID",
088: new Integer(vers_id));
089: queries[3].setQueryParams("INSTANCE_ID", instIdObj);
090: queries[3].execute();
091: addResult(queries[3].fetchResultSet());
092:
093: } catch (Throwable t) {
094: TKDBManager.safeRollbackTransaction(t);
095: }
096: return hasResults();
097: }
098:
099: public void initQuery(Connection con) {
100: super.initQuery(con, ISPREPARED, PARAMORDER, TYPES,
101: SETRELEVANTS, null);
102: }
103: }
|