1 32 33 package com.knowgate.crm; 34 35 import java.sql.SQLException ; 36 import java.sql.Statement ; 37 import java.sql.ResultSet ; 38 39 import com.knowgate.debug.DebugFile; 40 import com.knowgate.jdc.JDCConnection; 41 import com.knowgate.dataobjs.DB; 42 import com.knowgate.dataobjs.DBBind; 43 import com.knowgate.dataobjs.DBPersist; 44 import com.knowgate.hipergate.Product; 45 46 52 53 public class Attachment extends DBPersist { 54 55 public Attachment() { 56 super(DB.k_contact_attachs, "Attachment"); 57 } 58 59 61 74 public boolean store(JDCConnection oConn) throws SQLException { 75 Statement oStmt; 76 ResultSet oRSet; 77 java.sql.Timestamp dtNow = new java.sql.Timestamp (DBBind.getTime()); 78 boolean bRetVal; 79 80 if (DebugFile.trace) { 81 DebugFile.writeln("Begin Attachment.store([Connection])"); 82 DebugFile.incIdent(); 83 } 84 85 replace(DB.dt_modified, dtNow); 86 87 if (!AllVals.containsKey(DB.pg_product)) { 88 89 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 90 91 if (DebugFile.trace) 92 DebugFile.writeln("Statement.executeQuery(SELECT " + DBBind.Functions.ISNULL + "(MAX(" + DB.pg_product + "),0)+1 FROM " + DB.k_contact_attachs + " WHERE " + DB.gu_contact + "='" + getStringNull(DB.gu_contact,"null") + "')"); 93 94 oRSet = oStmt.executeQuery("SELECT " + DBBind.Functions.ISNULL + "(MAX(" + DB.pg_product + "),0)+1 FROM " + DB.k_contact_attachs + " WHERE " + DB.gu_contact + "='" + getString(DB.gu_contact) + "'"); 95 oRSet.next(); 96 put (DB.pg_product, oRSet.getObject(1)); 97 oRSet.close(); 98 oStmt.close(); 99 } 100 101 bRetVal = super.store(oConn); 102 103 oStmt = oConn.createStatement(); 104 105 if (DebugFile.trace) 106 DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_contacts + " SET " + DB.nu_attachs + "=" + DB.nu_attachs + "+1 WHERE gu_contact='" + getStringNull(DB.gu_contact,"null") + "')"); 107 108 oStmt.executeUpdate("UPDATE " + DB.k_contacts + " SET " + DB.nu_attachs + "=" + DB.nu_attachs + "+1 WHERE gu_contact='" + getString(DB.gu_contact) + "'"); 109 oStmt.close(); 110 111 if (DebugFile.trace) { 112 DebugFile.decIdent(); 113 DebugFile.writeln("End Attachment.store() : " + String.valueOf(getInt(DB.pg_product))); 114 } 115 116 return bRetVal; 117 } 119 121 128 public boolean delete(JDCConnection oConn) throws SQLException { 129 Statement oStmt; 130 boolean bRetVal; 131 132 Product oProd = new Product(oConn, getString(DB.gu_product)); 133 bRetVal = oProd.delete(oConn); 134 135 if (bRetVal) bRetVal = super.delete(oConn); 136 137 oStmt = oConn.createStatement(); 138 oStmt.executeUpdate("UPDATE " + DB.k_contacts + " SET " + DB.nu_attachs + "=" + DB.nu_attachs + "-1 WHERE gu_contact='" + getString(DB.gu_contact) + "'"); 139 oStmt.close(); 140 141 return bRetVal; 142 } 143 144 147 public static final short ClassId = 94; 148 } 149 | Popular Tags |