001: package de.webman.content.db.queries;
002:
003: import java.sql.*;
004: import com.teamkonzept.db.*;
005: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
006: import com.teamkonzept.webman.mainint.db.queries.content.SelectMaxContent;
007: import com.teamkonzept.webman.mainint.db.queries.content.InsertContentXML;
008: import com.teamkonzept.webman.mainint.db.queries.content.SelectContent;
009:
010: import de.webman.content.db.ContentConstants;
011:
012: /**
013: * Inserts a new content into the database.
014: * <TABLE>
015: * <TR>
016: * <TD><B>Order</B></TD>
017: * <TD><B>Name</B></TD>
018: * <TD><B>Type</B></TD>
019: * </TR>
020: * <TR>
021: * <TD COLSPAN="3"><I>Parameters<I/></TD>
022: * </TR>
023: * <TR>
024: * <TD><TT>1</TT></TD>
025: * <TD><TT>de.webman.content.db.ContentConstants.XML_TEXT</TT></TD>
026: * <TD><TT>java.lang.String</TT></TD>
027: * </TR>
028: * <TR>
029: * <TD COLSPAN="3"><I>Results<I/></TD>
030: * </TR>
031: * <TR>
032: * <TD><TT>1</TT></TD>
033: * <TD><TT>de.webman.content.db.ContentConstants.CONTENT_ID</TT></TD>
034: * <TD><TT>java.lang.Integer</TT></TD>
035: * </TR>
036: * </TABLE>
037: *
038: * @author <A HREF="mailto:unl@webman.de">Ulrich Nicolas Lissé</A>,
039: * © 2001 Webman AG.
040: * @version $Revision: 1.5 $
041: */
042: public class XMLContentInsert extends TKExtendedPrepQuery {
043:
044: public final static boolean IS_PREPARED = true;
045: public final static String[] PARAM_ORDER = { ContentConstants.XML_TEXT };
046: public final static Object[][] PARAM_TYPES = { {
047: ContentConstants.XML_TEXT, new Integer(Types.CLOB) } };
048: public final static boolean[] SET_RELEVANTS = { true };
049:
050: protected static Class[] queryClasses = { SelectMaxContent.class, // [0]
051: InsertContentXML.class, // [1]
052: SelectContent.class // [2]
053: };
054:
055: public boolean execute() {
056: try {
057:
058: init(queryClasses); // init query objects
059:
060: // BEGIN TRANSACTION
061: boolean isNotOpen = aTKDBConnection.isAutoCommit();
062: if (isNotOpen) {
063: TKDBManager.beginTransaction(); // begin transaction
064: }
065:
066: Integer contentId = null;
067: int id = 1;
068:
069: // [0]
070: queries[0].execute();
071: ResultSet rs = queries[0].fetchResultSet();
072: if (rs != null && rs.next()) {
073: id = rs.getInt(1) + 1;
074: }
075: contentId = new Integer(id);
076: // [1]
077: queries[1].setQueryParams(ContentConstants.CONTENT_ID,
078: contentId);
079: queries[1].setQueryParams(ContentConstants.XML_TEXT,
080: queryParams.get(ContentConstants.XML_TEXT));
081: queries[1].execute();
082: // [2]
083: queries[2].setQueryParams(ContentConstants.CONTENT_ID,
084: contentId);
085: queries[2].execute();
086: addResult(queries[2].fetchResultSet());
087:
088: // COMMIT TRANSACTION
089: if (isNotOpen) {
090: aTKDBConnection.commitTransaction(); // commit all changes
091: }
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, IS_PREPARED, PARAM_ORDER, PARAM_TYPES,
101: SET_RELEVANTS, sqlString);
102: }
103: }
|