001: package de.webman.content.db.queries;
002:
003: import java.sql.Connection;
004: import java.sql.Types;
005: import java.sql.SQLException;
006: import com.teamkonzept.db.TKDBManager;
007: import com.teamkonzept.db.TKExtendedPrepQuery;
008: import com.teamkonzept.webman.mainint.db.queries.content.SelectContent;
009: import de.webman.content.db.ContentConstants;
010:
011: /**
012: * Updates an existing content in the database.
013: * <TABLE>
014: * <TR>
015: * <TD><B>Order</B></TD>
016: * <TD><B>Name</B></TD>
017: * <TD><B>Type</B></TD>
018: * </TR>
019: * <TR>
020: * <TD COLSPAN="3"><I>Parameters<I/></TD>
021: * </TR>
022: * <TR>
023: * <TD><TT>1</TT></TD>
024: * <TD><TT>de.webman.content.db.ContentConstants.XML_TEXT</TT></TD>
025: * <TD><TT>java.lang.String</TT></TD>
026: * </TR>
027: * <TR>
028: * <TD><TT>2</TT></TD>
029: * <TD><TT>de.webman.content.db.ContentConstants.CONTENT_ID</TT></TD>
030: * <TD><TT>java.lang.Integer</TT></TD>
031: * </TR>
032: * <TR>
033: * <TD COLSPAN="3"><I>Results<I/></TD>
034: * </TR>
035: * <TR>
036: * <TD><TT>1</TT></TD>
037: * <TD><TT>de.webman.content.db.ContentConstants.CONTENT_ID</TT></TD>
038: * <TD><TT>java.lang.Integer</TT></TD>
039: * </TR>
040: * </TABLE>
041: *
042: * @author <A HREF="mailto:unl@webman.de">Ulrich Nicolas Lissé</A>,
043: * © 2001 Webman AG.
044: * @version $Revision: 1.2 $
045: */
046: public class XMLContentUpdate extends TKExtendedPrepQuery {
047: // $Id: XMLContentUpdate.java,v 1.2 2001/12/27 14:37:07 alex Exp $
048:
049: // Constants.
050:
051: /**
052: * The preparation state.
053: */
054: private final static boolean IS_PREPARED = true;
055:
056: /**
057: * The parameter order.
058: */
059: private final static String[] PARAMETER_ORDER = {
060: ContentConstants.XML_TEXT, ContentConstants.CONTENT_ID };
061:
062: /**
063: * The parameter types.
064: */
065: private final static Object[][] PARAMETER_TYPES = {
066: { ContentConstants.XML_TEXT, new Integer(Types.CLOB) },
067: { ContentConstants.CONTENT_ID, new Integer(Types.INTEGER) } };
068:
069: /**
070: * The relevance state.
071: */
072: private final static boolean[] SET_RELEVANTS = { true };
073:
074: /**
075: * The sub-queries.
076: */
077: private static Class[] QUERY_CLASSES = { UpdateContent.class,
078: SelectContent.class };
079:
080: // Implementation of 'com.teamkonzept.db.TKQuery'
081:
082: /**
083: * Executes the query.
084: *
085: * @return <CODE>true</CODE>, if the query has been executed
086: * successfully, otherwise <CODE>false</CODE>.
087: * @exception java.sql.SQLException if any error occurred
088: * during query execution.
089: */
090: public final boolean execute() throws SQLException {
091: try {
092: // Initialize queries.
093: init(QUERY_CLASSES);
094:
095: // Get transaction state.
096: boolean transactional = aTKDBConnection.isAutoCommit();
097:
098: if (transactional) {
099: // Begin transaction.
100: TKDBManager.beginTransaction();
101: }
102:
103: // Perform update.
104: this .queries[0].setQueryParams(ContentConstants.XML_TEXT,
105: queryParams.get(ContentConstants.XML_TEXT));
106: this .queries[0].setQueryParams(ContentConstants.CONTENT_ID,
107: queryParams.get(ContentConstants.CONTENT_ID));
108: this .queries[0].execute();
109:
110: // Perform select.
111: this .queries[1].setQueryParams(ContentConstants.CONTENT_ID,
112: queryParams.get(ContentConstants.CONTENT_ID));
113: this .queries[1].execute();
114:
115: // Add result.
116: addResult(this .queries[1].fetchResultSet());
117:
118: if (transactional) {
119: // Commit transaction.
120: TKDBManager.commitTransaction();
121: }
122: } catch (Throwable t) {
123: TKDBManager.safeRollbackTransaction(t);
124: }
125:
126: // Deliver result state.
127: return hasResults();
128: }
129:
130: /**
131: * Initializes the query with the given connection.
132: *
133: * @param connection the connection.
134: */
135: public void initQuery(Connection connection) {
136: super.initQuery(connection, IS_PREPARED, PARAMETER_ORDER,
137: PARAMETER_TYPES, SET_RELEVANTS, this.sqlString);
138: }
139:
140: }
|