KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > projtrack > Duty


1 /*
2   Copyright (C) 2003 Know Gate S.L. All rights reserved.
3                       C/Oña, 107 1º2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.projtrack;
34
35 import com.knowgate.debug.DebugFile;
36 import com.knowgate.jdc.JDCConnection;
37 import com.knowgate.dataobjs.DB;
38 import com.knowgate.dataobjs.DBBind;
39 import com.knowgate.dataobjs.DBPersist;
40 import com.knowgate.dataobjs.DBSubset;
41
42 import com.knowgate.misc.Gadgets;
43
44 import java.sql.Connection JavaDoc;
45 import java.sql.SQLException JavaDoc;
46 import java.sql.CallableStatement JavaDoc;
47 import java.sql.PreparedStatement JavaDoc;
48 import java.sql.Statement JavaDoc;
49 import java.sql.ResultSet JavaDoc;
50
51 public class Duty extends DBPersist {
52
53   /**
54    * Create empty Duty
55    */

56   public Duty() {
57     super(DB.k_duties, "Duty");
58   }
59
60   // ----------------------------------------------------------
61

62   /**
63    * Load Duty from database
64    */

65   public Duty(JDCConnection oConn, String JavaDoc sIdDuty) throws SQLException JavaDoc {
66     super(DB.k_duties,"Duty");
67
68     Object JavaDoc aDuty[] = { sIdDuty };
69
70     load (oConn,aDuty);
71   }
72
73   // ----------------------------------------------------------
74

75   /**
76    * <p>Delete Duty</p>
77    * Calls k_sp_del_duty stored procedure.
78    * @param oConn Database Connection
79    * @throws SQLException
80    */

81   public boolean delete(JDCConnection oConn) throws SQLException JavaDoc {
82     return Duty.delete(oConn, getString(DB.gu_duty));
83   }
84
85   // ----------------------------------------------------------
86

87   /**
88    * <p>Store Duty</p>
89    * If gu_duty is null a new GUID is automatically assigned.<br>
90    * dt_modified field is set to current date.
91    * @param oConn Database Connection
92    * @throws SQLException
93    */

94   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
95     java.sql.Timestamp JavaDoc dtNow = new java.sql.Timestamp JavaDoc(DBBind.getTime());
96
97     if (!AllVals.containsKey(DB.gu_duty))
98       put(DB.gu_duty, Gadgets.generateUUID());
99
100     // Forzar la fecha de modificación del registro
101
replace(DB.dt_modified, dtNow);
102
103     return super.store(oConn);
104   }
105
106   // **********************************************************
107
// Static Methods
108

109   /**
110    * <p>Delete Duty</p>
111    * Calls k_sp_del_duty stored procedure.
112    * @param oConn Database Connection
113    * @param sDutyGUID GUID of Duty to be deleted
114    * @throws SQLException
115    */

116   public static boolean delete(JDCConnection oConn, String JavaDoc sDutyGUID) throws SQLException JavaDoc {
117     boolean bRetVal;
118
119     if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
120       if (DebugFile.trace) DebugFile.writeln("Connection.executeQuery(SELECT k_sp_del_duty ('" + sDutyGUID + "'))");
121       Statement JavaDoc oStmt = oConn.createStatement();
122       ResultSet JavaDoc oRSet = oStmt.executeQuery("SELECT k_sp_del_duty ('" + sDutyGUID + "')");
123       oRSet.close();
124       oStmt.close();
125       bRetVal = true;
126     }
127     else {
128       if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_del_duty ('" + sDutyGUID + "')})");
129       CallableStatement JavaDoc oCall = oConn.prepareCall("{call k_sp_del_duty ('" + sDutyGUID + "')}");
130       bRetVal = oCall.execute();
131       oCall.close();
132     }
133
134     return bRetVal;
135   } // delete()
136

137   // **********************************************************
138
// Constantes Publicas
139

140   public static final short ClassId = 81;
141 }
Popular Tags