001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/webman/mainint/db/queries/Attic/TKDBPropNew.java,v 1.4 2001/08/15 13:16:49 markus Exp $
003: *
004: */
005: package com.teamkonzept.webman.mainint.db.queries;
006:
007: import java.sql.*;
008:
009: import com.teamkonzept.db.*;
010: import com.teamkonzept.webman.mainint.db.queries.properties.*;
011: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
012:
013: /*
014: * TKDBPropNew
015: * input "PROP_NAME"
016: * output neuer DS
017: * erzeugt neuen Eintrag in PROPERTIES
018: */
019: public class TKDBPropNew extends TKExtendedPrepQuery {
020:
021: public final static boolean isPrepared = true;
022:
023: public final static String[] paramOrder = { "PROP_NAME",
024: "PROP_VALUE" };
025:
026: public final static Object[][] paramTypes = {
027: { "PROP_NAME", new Integer(Types.VARCHAR) },
028: { "PROP_VALUE", new Integer(Types.LONGVARCHAR) } };
029:
030: public final static boolean[] setRelevants = { true };
031:
032: /* public final static String sqlString =
033:
034: "DECLARE @PID int " +
035:
036: "BEGIN TRANSACTION " +
037:
038: "SELECT " +
039: " @PID=ISNULL(MAX(PROPERTY_ID)+1, 0) " +
040: "FROM " +
041: " PROPERTY " +
042:
043: "INSERT INTO " +
044: "PROPERTY " +
045: " (PROPERTY_ID, NAME, VALUE) " +
046: "VALUES (@PID, ?, ?) " +
047:
048: "COMMIT TRANSACTION " +
049:
050: "SELECT @PID as PROP_ID "; */
051: protected static Class[] queryClasses = { SelectMaxProperty.class, // [0]
052: InsertProperty.class, // [1]
053: SelectPropId.class // [2]
054: };
055:
056: public boolean execute() {
057: try {
058:
059: init(queryClasses); // init query objects
060:
061: // BEGIN TRANSACTION
062: boolean isNotOpen = aTKDBConnection.isAutoCommit();
063: if (isNotOpen) {
064: TKDBManager.beginTransaction(); // begin transaction
065: }
066:
067: Object propId = null;
068: // OLD: SELECT @PID=ISNULL(MAX(PROPERTY_ID)+1, 0) FROM PROPERTY
069: // NEW: SELECT DBStringFactory.nvl(MAX(PROPERTY_ID)+1, 0) FROM PROPERTY
070: // CLASS: SelectMaxProperty.class
071: // [0]
072: queries[0].execute();
073: ResultSet rs = queries[0].fetchResultSet();
074: if (rs != null && rs.next()) {
075: propId = rs.getObject(1);
076: }
077:
078: // OLD: INSERT INTO PROPERTY (PROPERTY_ID, NAME, VALUE) VALUES (@PID, ?, ?)
079: // NEW: INSERT INTO PROPERTY (PROPERTY_ID, NAME, VALUE) VALUES (?, ?, ?)
080: // PARAMS: PROP_ID, PROP_NAME, PROP_VALUE
081: // CLASS: InsertProperty.class
082: // [1]
083: queries[1].setQueryParams("PROP_ID", propId);
084: queries[1].setQueryParams("PROP_NAME", queryParams
085: .get("PROP_NAME"));
086: queries[1].setQueryParams("PROP_VALUE", queryParams
087: .get("PROP_VALUE"));
088: queries[1].execute();
089:
090: // OLD: SELECT @PID as PROP_ID
091: // NEW: SELECT ? AS PROP_ID
092: // PARAMS: PROP_ID
093: // CLASS: SelectPropId.class
094: // [2]
095: queries[2].setQueryParams("PROP_ID", propId);
096: queries[2].execute();
097: addResult(queries[2].fetchResultSet());
098:
099: // COMMIT TRANSACTION
100: if (isNotOpen) {
101: aTKDBConnection.commitTransaction(); // commit all changes
102: }
103:
104: } catch (Throwable t) {
105: TKDBManager.safeRollbackTransaction(t);
106: }
107: return hasResults();
108: }
109:
110: public void initQuery(Connection con) {
111: super.initQuery(con, isPrepared, paramOrder, paramTypes,
112: setRelevants, sqlString);
113: }
114: }
|