001: /*
002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
003: C/Oña, 107 1º2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.projtrack;
034:
035: import com.knowgate.debug.DebugFile;
036: import com.knowgate.jdc.JDCConnection;
037: import com.knowgate.dataobjs.DB;
038: import com.knowgate.dataobjs.DBBind;
039: import com.knowgate.dataobjs.DBPersist;
040: import com.knowgate.dataobjs.DBSubset;
041:
042: import com.knowgate.misc.Gadgets;
043:
044: import java.sql.Connection;
045: import java.sql.SQLException;
046: import java.sql.CallableStatement;
047: import java.sql.PreparedStatement;
048: import java.sql.Statement;
049: import java.sql.ResultSet;
050:
051: public class Duty extends DBPersist {
052:
053: /**
054: * Create empty Duty
055: */
056: public Duty() {
057: super (DB.k_duties, "Duty");
058: }
059:
060: // ----------------------------------------------------------
061:
062: /**
063: * Load Duty from database
064: */
065: public Duty(JDCConnection oConn, String sIdDuty)
066: throws SQLException {
067: super (DB.k_duties, "Duty");
068:
069: Object aDuty[] = { sIdDuty };
070:
071: load(oConn, aDuty);
072: }
073:
074: // ----------------------------------------------------------
075:
076: /**
077: * <p>Delete Duty</p>
078: * Calls k_sp_del_duty stored procedure.
079: * @param oConn Database Connection
080: * @throws SQLException
081: */
082: public boolean delete(JDCConnection oConn) throws SQLException {
083: return Duty.delete(oConn, getString(DB.gu_duty));
084: }
085:
086: // ----------------------------------------------------------
087:
088: /**
089: * <p>Store Duty</p>
090: * If gu_duty is null a new GUID is automatically assigned.<br>
091: * dt_modified field is set to current date.
092: * @param oConn Database Connection
093: * @throws SQLException
094: */
095: public boolean store(JDCConnection oConn) throws SQLException {
096: java.sql.Timestamp dtNow = new java.sql.Timestamp(DBBind
097: .getTime());
098:
099: if (!AllVals.containsKey(DB.gu_duty))
100: put(DB.gu_duty, Gadgets.generateUUID());
101:
102: // Forzar la fecha de modificación del registro
103: replace(DB.dt_modified, dtNow);
104:
105: return super .store(oConn);
106: }
107:
108: // **********************************************************
109: // Static Methods
110:
111: /**
112: * <p>Delete Duty</p>
113: * Calls k_sp_del_duty stored procedure.
114: * @param oConn Database Connection
115: * @param sDutyGUID GUID of Duty to be deleted
116: * @throws SQLException
117: */
118: public static boolean delete(JDCConnection oConn, String sDutyGUID)
119: throws SQLException {
120: boolean bRetVal;
121:
122: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_POSTGRESQL) {
123: if (DebugFile.trace)
124: DebugFile
125: .writeln("Connection.executeQuery(SELECT k_sp_del_duty ('"
126: + sDutyGUID + "'))");
127: Statement oStmt = oConn.createStatement();
128: ResultSet oRSet = oStmt
129: .executeQuery("SELECT k_sp_del_duty ('" + sDutyGUID
130: + "')");
131: oRSet.close();
132: oStmt.close();
133: bRetVal = true;
134: } else {
135: if (DebugFile.trace)
136: DebugFile
137: .writeln("Connection.prepareCall({ call k_sp_del_duty ('"
138: + sDutyGUID + "')})");
139: CallableStatement oCall = oConn
140: .prepareCall("{call k_sp_del_duty ('" + sDutyGUID
141: + "')}");
142: bRetVal = oCall.execute();
143: oCall.close();
144: }
145:
146: return bRetVal;
147: } // delete()
148:
149: // **********************************************************
150: // Constantes Publicas
151:
152: public static final short ClassId = 81;
153: }
|