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.crm;
034:
035: import java.sql.SQLException;
036: import java.sql.PreparedStatement;
037: import java.sql.ResultSet;
038:
039: import com.knowgate.jdc.JDCConnection;
040: import com.knowgate.dataobjs.DB;
041: import com.knowgate.dataobjs.DBBind;
042: import com.knowgate.dataobjs.DBPersist;
043:
044: /**
045: * <p>Contact Note</p>
046: * <p>Copyright: Copyright (c) KnowGate 2003</p>
047: * @author Sergio Montoro Ten
048: * @version 2.1
049: */
050: public class Note extends DBPersist {
051:
052: public Note() {
053: super (DB.k_contact_notes, "Note");
054: }
055:
056: // ----------------------------------------------------------
057:
058: /**
059: * Store Note
060: * A new pg_note is automatically generated if not explicitly set.<br>
061: * k_contact.nu_notes fields is incrmented by 1
062: * @param oConn Database Connection
063: * @throws SQLException
064: */
065: public boolean store(JDCConnection oConn) throws SQLException {
066: java.sql.Timestamp dtNow = new java.sql.Timestamp(DBBind
067: .getTime());
068: PreparedStatement oStmt;
069: ResultSet oRSet;
070: Object oMax;
071: Integer iMax;
072:
073: if (!AllVals.containsKey(DB.pg_note)) {
074: oStmt = oConn.prepareStatement("SELECT MAX(pg_note) FROM "
075: + DB.k_contact_notes + " WHERE " + DB.gu_contact
076: + "=?");
077: oStmt.setString(1, getString(DB.gu_contact));
078: oRSet = oStmt.executeQuery();
079: if (oRSet.next()) {
080: oMax = oRSet.getObject(1);
081: if (oRSet.wasNull())
082: iMax = new Integer(1);
083: else
084: iMax = new Integer(Integer
085: .parseInt(oMax.toString()) + 1);
086: } else
087: iMax = new Integer(1);
088: oRSet.close();
089: oStmt.close();
090:
091: put(DB.pg_note, iMax.intValue());
092: } // fi(DB.pg_note)
093:
094: // Poner por defecto la fecha de modificación del registro
095: if (!AllVals.containsKey(DB.dt_modified))
096: put(DB.dt_modified, dtNow);
097:
098: boolean bRetVal = super .store(oConn);
099:
100: oStmt = oConn.prepareStatement("UPDATE " + DB.k_contacts
101: + " SET " + DB.nu_notes + "=" + DB.nu_notes
102: + "+1 WHERE gu_contact=?");
103: oStmt.setString(1, getString(DB.gu_contact));
104: oStmt.executeUpdate();
105: oStmt.close();
106:
107: return bRetVal;
108: } // store
109:
110: /**
111: * Delete Note
112: * k_contact.nu_notes fields is decremented by 1
113: * @param oConn Database Connection
114: * @return
115: * @throws SQLException
116: */
117: public boolean delete(JDCConnection oConn) throws SQLException {
118: boolean bRetVal = super .delete(oConn);
119:
120: PreparedStatement oStmt = oConn.prepareStatement("UPDATE "
121: + DB.k_contacts + " SET " + DB.nu_notes + "="
122: + DB.nu_notes + "-1 WHERE gu_contact=?");
123: oStmt.setString(1, getString(DB.gu_contact));
124: oStmt.executeUpdate();
125: oStmt.close();
126:
127: return bRetVal;
128: }
129:
130: // **********************************************************
131: // Public Constants
132:
133: public static final short ClassId = 93;
134: }
|