001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/webman/mainint/db/queries/oracle/Attic/TKDBPropGroupNew.java,v 1.5 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.properties.*;
011: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
012:
013: /*
014: * TKDBPropNew
015: * input "PROPGROUP_NAME"
016: * output neuer DS
017: * erzeugt neuen Eintrag in PROPERTIES
018: */
019: public class TKDBPropGroupNew extends TKExtendedPrepQuery {
020:
021: public final static boolean isPrepared = true;
022:
023: public final static String[] paramOrder = { "PROPGROUP_NAME" };
024:
025: public final static Object[][] paramTypes = { { "PROPGROUP_NAME",
026: new Integer(Types.VARCHAR) } };
027:
028: public final static boolean[] setRelevants = { true };
029:
030: /* public final static String sqlString =
031:
032: "DECLARE @PID int " +
033:
034: "BEGIN TRANSACTION " +
035:
036: "SELECT " +
037: " @PID=ISNULL(MAX(PROPERTY_GROUP_ID)+1, 0) " +
038: "FROM " +
039: " PROPERTY_GROUP " +
040:
041: "INSERT INTO " +
042: "PROPERTY_GROUP " +
043: " (PROPERTY_GROUP_ID, NAME) " +
044: "VALUES (@PID, ?) " +
045:
046: "COMMIT TRANSACTION "; */
047:
048: protected static Class[] queryClasses = {
049: SelectMaxPropertyGroup.class, // [0]
050: InsertPropertyGroup.class // [1]
051: };
052:
053: public boolean execute() {
054: try {
055:
056: init(queryClasses); // init query objects
057:
058: // BEGIN TRANSACTION
059: boolean isNotOpen = aTKDBConnection.isAutoCommit();
060: if (isNotOpen) {
061: TKDBManager.beginTransaction(); // begin transaction
062: }
063:
064: Object propGroupId = null;
065: // OLD: SELECT @PID=ISNULL(MAX(PROPERTY_GROUP_ID)+1, 0) FROM PROPERTY_GROUP
066: // NEW: SELECT DBStringFactory.nvl(MAX(PROPERTY_GROUP_ID)+1, 0) FROM PROPERTY_GROUP
067: // CLASS: SelectMaxPropertyGroup.class
068: // [0]
069: queries[0].execute();
070: ResultSet rs = queries[0].fetchResultSet();
071: if (rs != null && rs.next()) {
072: propGroupId = rs.getObject(1);
073: }
074:
075: // OLD: INSERT INTO PROPERTY_GROUP (PROPERTY_GROUP_ID, NAME) VALUES (@PID, ?)
076: // NEW: INSERT INTO PROPERTY_GROUP (PROPERTY_GROUP_ID, NAME) VALUES (?, ?)
077: // PARAMS: PROPGROUP_ID, PROPGROUP_NAME
078: // CLASS: InsertPropertyGroup.class
079: // [1]
080: queries[1].setQueryParams("PROPGROUP_ID", propGroupId);
081: queries[1].setQueryParams("PROPGROUP_NAME", queryParams
082: .get("PROPGROUP_NAME"));
083: queries[1].execute();
084:
085: // COMMIT TRANSACTION
086: if (isNotOpen) {
087: aTKDBConnection.commitTransaction(); // commit all changes
088: }
089:
090: } catch (Throwable t) {
091: TKDBManager.safeRollbackTransaction(t);
092: }
093: return hasResults();
094: }
095:
096: public void initQuery(Connection con) {
097: super.initQuery(con, isPrepared, paramOrder, paramTypes,
098: setRelevants, sqlString);
099: }
100: }
|