001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/webman/mainint/db/queries/oracle/Attic/TKDBDocContentUpdate.java,v 1.6 2001/06/11 09:14:12 alex Exp $
003: *
004: */
005: package com.teamkonzept.webman.mainint.db.queries.oracle;
006:
007: import java.sql.*;
008:
009: import com.teamkonzept.db.*;
010: import com.teamkonzept.webman.mainint.db.queries.content.*;
011: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
012: import com.teamkonzept.lib.TKNull;
013:
014: /*
015: * TKDBDocContentUpdate
016: * Schreibt einen DS fuer einen Document_Content
017: *
018: * Input: Kompl. DS
019: * Output: none
020: */
021: public class TKDBDocContentUpdate extends TKExtendedPrepQuery {
022:
023: public final static boolean isPrepared = true;
024:
025: public final static String[] paramOrder = { "SELECTION_TYPE",
026: "SELECTION_DATA", "SITE_NODE_ID", "SITE_NODE_DOC_IDX",
027: "PRESENTATION_COMPONENT_IDX", "CONTENT_NODE_ID",
028: "SITE_NODE_ID", "SITE_NODE_DOC_IDX",
029: "PRESENTATION_COMPONENT_IDX" };
030:
031: public final static Object[][] types = {
032: { "SELECTION_TYPE", new Integer(Types.VARCHAR) },
033: { "SELECTION_DATA", new Integer(Types.LONGVARCHAR) } };
034:
035: public final static boolean[] setRelevants = { false };
036:
037: /* public final static String sqlString =
038:
039: "DECLARE @ST VARCHAR(80) " +
040: "DECLARE @SID INT " +
041: "DECLARE @OLDSID INT " +
042:
043: "SELECT @ST = ? " +
044: "SELECT @SID = NULL " +
045: "SELECT @OLDSID = NULL " +
046:
047: "BEGIN TRANSACTION " +
048:
049: "IF ( @ST IS NOT NULL ) " +
050: "BEGIN " +
051: "SELECT " +
052: " @SID = ISNULL(MAX(SELECTION_ID) + 1,0) " +
053: "FROM " +
054: " CONTENT_SELECTION " +
055:
056: "INSERT INTO "+
057: " CONTENT_SELECTION " +
058: " (SELECTION_ID, SELECTION_TYPE, SELECTION_DATA) " +
059: "VALUES " +
060: " (@SID, @ST, ?) " +
061: "END " +
062:
063: "SELECT " +
064: " @OLDSID = SELECTION_ID " +
065: "FROM " +
066: " DOCUMENT_CONTENT " +
067: "WHERE " +
068: " SITE_NODE_ID = ? " +
069: "AND " +
070: " SITE_NODE_DOC_IDX = ? " +
071: "AND " +
072: " PRESENTATION_COMPONENT_IDX = ? " +
073:
074: "UPDATE " +
075: " DOCUMENT_CONTENT " +
076: "SET " +
077: " CONTENT_NODE_ID = ?, " +
078: " SELECTION_ID = @SID " +
079: "WHERE " +
080: " SITE_NODE_ID = ? " +
081: "AND " +
082: " SITE_NODE_DOC_IDX = ? " +
083: "AND " +
084: " PRESENTATION_COMPONENT_IDX = ? " +
085:
086: "IF (@OLDSID IS NOT NULL) " +
087: "BEGIN " +
088: "DELETE FROM " +
089: " CONTENT_SELECTION " +
090: "WHERE " +
091: " SELECTION_ID = @OLDSID " +
092: "END " +
093:
094: "COMMIT TRANSACTION "; */
095:
096: protected static Class[] queryClasses = {
097: SelectMaxContentSelection.class,
098: InsertContentSelection.class, SelectDocumentContent.class,
099: UpdateDocumentContent.class,
100: DeleteFromContentSelection.class };
101:
102: public boolean execute() {
103: try {
104: init(queryClasses); // init query objects
105:
106: Object st = queryParams.get("SELECTION_TYPE");
107:
108: // BEGIN TRANSACTION
109: boolean isNotOpen = aTKDBConnection.isAutoCommit();
110: if (isNotOpen) {
111: TKDBManager.beginTransaction(); // begin transaction
112: }
113: int sid = 0;
114: Integer selectionId = null;
115:
116: // IF ( @ST IS NOT NULL )
117: if (st != null && !(st instanceof TKNull)) {
118: //if (!(st == null || st instanceof TKNull)) {
119: // SELECT @SID = ISNULL(MAX(SELECTION_ID) + 1,0) FROM CONTENT_SELECTION
120: queries[0].execute();
121: ResultSet rs = queries[0].fetchResultSet();
122: if (rs != null && rs.next()) {
123: sid = rs.getInt(1) + 1;
124: }
125: selectionId = new Integer(sid);
126:
127: // INSERT INTO CONTENT_SELECTION (SELECTION_ID, SELECTION_TYPE, SELECTION_DATA) VALUES (@SID, @ST, ?)
128: queries[1].setQueryParams("SELECTION_ID", selectionId);
129: queries[1].setQueryParams("SELECTION_TYPE", st);
130: queries[1].setQueryParams("SELECTION_DATA", queryParams
131: .get("SELECTION_DATA"));
132: queries[1].execute();
133:
134: }
135: // END
136:
137: // SELECT @OLDSID = SELECTION_ID FROM DOCUMENT_CONTENT WHERE SITE_NODE_ID = ? AND SITE_NODE_DOC_IDX = ? AND PRESENTATION_COMPONENT_IDX = ?
138: Object oldSelectionId = null;
139: queries[2].setQueryParams("SITE_NODE_ID", queryParams
140: .get("SITE_NODE_ID"));
141: queries[2].setQueryParams("SITE_NODE_DOC_IDX", queryParams
142: .get("SITE_NODE_DOC_IDX"));
143: queries[2].setQueryParams("PRESENTATION_COMPONENT_IDX",
144: queryParams.get("PRESENTATION_COMPONENT_IDX"));
145: queries[2].execute(); // execute first query
146: ResultSet rs = queries[2].fetchResultSet();
147: if (rs != null && rs.next()) {
148: oldSelectionId = rs.getObject(1);
149: }
150:
151: // UPDATE DOCUMENT_CONTENT SET CONTENT_NODE_ID = ?, SELECTION_ID = @SID WHERE SITE_NODE_ID = ? AND SITE_NODE_DOC_IDX = ? AND PRESENTATION_COMPONENT_IDX = ?
152: queries[3].setQueryParams("CONTENT_NODE_ID", queryParams
153: .get("CONTENT_NODE_ID"));
154: queries[3].setQueryParams("SELECTION_ID", selectionId);
155: queries[3].setQueryParams("SITE_NODE_ID", queryParams
156: .get("SITE_NODE_ID"));
157: queries[3].setQueryParams("SITE_NODE_DOC_IDX", queryParams
158: .get("SITE_NODE_DOC_IDX"));
159: queries[3].setQueryParams("PRESENTATION_COMPONENT_IDX",
160: queryParams.get("PRESENTATION_COMPONENT_IDX"));
161: queries[3].execute(); // ...and execute it
162:
163: // IF (@OLDSID IS NOT NULL)
164: // DELETE FROM CONTENT_SELECTION WHERE SELECTION_ID = @OLDSID
165: // END
166: if (oldSelectionId != null
167: && !(oldSelectionId instanceof TKNull)) {
168: queries[4].setQueryParams("SELECTION_ID",
169: oldSelectionId);
170: queries[4].execute();
171: }
172:
173: // COMMIT TRANSACTION
174: if (isNotOpen) {
175: aTKDBConnection.commitTransaction(); // commit all changes
176: }
177:
178: } catch (Throwable t) {
179: TKDBManager.safeRollbackTransaction(t);
180: }
181: return hasResults();
182: }
183:
184: public void initQuery(Connection con) {
185: super.initQuery(con, isPrepared, paramOrder, types,
186: setRelevants, sqlString);
187: }
188: }
|