KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > crm > Note


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.crm;
34
35 import java.sql.SQLException JavaDoc;
36 import java.sql.PreparedStatement JavaDoc;
37 import java.sql.ResultSet JavaDoc;
38
39 import com.knowgate.jdc.JDCConnection;
40 import com.knowgate.dataobjs.DB;
41 import com.knowgate.dataobjs.DBBind;
42 import com.knowgate.dataobjs.DBPersist;
43
44 /**
45  * <p>Contact Note</p>
46  * <p>Copyright: Copyright (c) KnowGate 2003</p>
47  * @author Sergio Montoro Ten
48  * @version 2.1
49  */

50 public class Note extends DBPersist {
51
52   public Note() {
53     super(DB.k_contact_notes, "Note");
54   }
55
56   // ----------------------------------------------------------
57

58   /**
59    * Store Note
60    * A new pg_note is automatically generated if not explicitly set.<br>
61    * k_contact.nu_notes fields is incrmented by 1
62    * @param oConn Database Connection
63    * @throws SQLException
64    */

65   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
66     java.sql.Timestamp JavaDoc dtNow = new java.sql.Timestamp JavaDoc(DBBind.getTime());
67     PreparedStatement JavaDoc oStmt;
68     ResultSet JavaDoc oRSet;
69     Object JavaDoc oMax;
70     Integer JavaDoc iMax;
71
72     if (!AllVals.containsKey(DB.pg_note)) {
73       oStmt = oConn.prepareStatement("SELECT MAX(pg_note) FROM " + DB.k_contact_notes + " WHERE " + DB.gu_contact + "=?");
74       oStmt.setString(1, getString(DB.gu_contact));
75       oRSet = oStmt.executeQuery();
76       if (oRSet.next()) {
77         oMax = oRSet.getObject(1);
78         if (oRSet.wasNull())
79           iMax = new Integer JavaDoc(1);
80         else
81           iMax = new Integer JavaDoc(Integer.parseInt(oMax.toString())+1);
82       }
83       else
84         iMax = new Integer JavaDoc(1);
85       oRSet.close();
86       oStmt.close();
87
88       put(DB.pg_note, iMax.intValue());
89     } // fi(DB.pg_note)
90

91     // Poner por defecto la fecha de modificación del registro
92
if (!AllVals.containsKey(DB.dt_modified))
93       put(DB.dt_modified, dtNow);
94
95     boolean bRetVal = super.store(oConn);
96
97     oStmt = oConn.prepareStatement("UPDATE " + DB.k_contacts + " SET " + DB.nu_notes + "=" + DB.nu_notes + "+1 WHERE gu_contact=?");
98     oStmt.setString(1, getString(DB.gu_contact));
99     oStmt.executeUpdate();
100     oStmt.close();
101
102     return bRetVal;
103   } // store
104

105   /**
106    * Delete Note
107    * k_contact.nu_notes fields is decremented by 1
108    * @param oConn Database Connection
109    * @return
110    * @throws SQLException
111    */

112   public boolean delete(JDCConnection oConn) throws SQLException JavaDoc {
113     boolean bRetVal = super.delete(oConn);
114
115     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("UPDATE " + DB.k_contacts + " SET " + DB.nu_notes + "=" + DB.nu_notes + "-1 WHERE gu_contact=?");
116     oStmt.setString(1, getString(DB.gu_contact));
117     oStmt.executeUpdate();
118     oStmt.close();
119
120     return bRetVal;
121   }
122
123   // **********************************************************
124
// Public Constants
125

126   public static final short ClassId = 93;
127 }
Popular Tags