1 32 33 package com.knowgate.crm; 34 35 import java.sql.SQLException ; 36 import java.sql.PreparedStatement ; 37 import java.sql.ResultSet ; 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 50 public class Note extends DBPersist { 51 52 public Note() { 53 super(DB.k_contact_notes, "Note"); 54 } 55 56 58 65 public boolean store(JDCConnection oConn) throws SQLException { 66 java.sql.Timestamp dtNow = new java.sql.Timestamp (DBBind.getTime()); 67 PreparedStatement oStmt; 68 ResultSet oRSet; 69 Object oMax; 70 Integer 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 (1); 80 else 81 iMax = new Integer (Integer.parseInt(oMax.toString())+1); 82 } 83 else 84 iMax = new Integer (1); 85 oRSet.close(); 86 oStmt.close(); 87 88 put(DB.pg_note, iMax.intValue()); 89 } 91 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 } 105 112 public boolean delete(JDCConnection oConn) throws SQLException { 113 boolean bRetVal = super.delete(oConn); 114 115 PreparedStatement 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 126 public static final short ClassId = 93; 127 } | Popular Tags |