1 32 33 package com.knowgate.crm; 34 35 import java.sql.SQLException ; 36 import java.sql.CallableStatement ; 37 import java.sql.Statement ; 38 import java.sql.PreparedStatement ; 39 import java.sql.ResultSet ; 40 41 import com.knowgate.debug.DebugFile; 42 import com.knowgate.misc.Gadgets; 43 import com.knowgate.jdc.JDCConnection; 44 import com.knowgate.dataobjs.DB; 45 import com.knowgate.dataobjs.DBBind; 46 import com.knowgate.dataobjs.DBPersist; 47 48 53 public class Oportunity extends DBPersist { 54 55 public Oportunity() { 56 super(DB.k_oportunities, "Oportunity"); 57 } 58 59 61 68 public boolean store(JDCConnection oConn) throws SQLException { 69 PreparedStatement oStmt; 70 ResultSet oRSet; 71 boolean bRetVal; 72 73 if (DebugFile.trace) { 74 DebugFile.writeln("Begin Oportunity.store([Connection])"); 75 DebugFile.incIdent(); 76 } 77 78 java.sql.Timestamp dtNow = new java.sql.Timestamp (DBBind.getTime()); 79 80 if (!AllVals.containsKey(DB.gu_oportunity)) 81 put(DB.gu_oportunity, Gadgets.generateUUID()); 82 83 replace(DB.dt_modified, dtNow); 84 85 if (!AllVals.containsKey(DB.tx_contact)) { 86 if (DebugFile.trace) 87 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.tx_surname + "," + DB.tx_name + " FROM " + DB.k_contacts + " WHERE " + DB.gu_contact + "='" + getStringNull(DB.gu_contact, "null") + "')"); 88 89 oStmt = oConn.prepareStatement("SELECT " + DB.tx_surname + "," + DB.tx_name + " FROM " + DB.k_contacts + " WHERE " + DB.gu_contact + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 90 oStmt.setObject (1, get(DB.gu_contact), java.sql.Types.CHAR); 91 oRSet = oStmt.executeQuery(); 92 if (oRSet.next()) 93 put (DB.tx_contact, oRSet.getString(1) + ", " + oRSet.getString(2)); 94 oRSet.close(); 95 oStmt.close(); 96 } 97 98 if (!AllVals.containsKey(DB.tx_company)) { 99 if (DebugFile.trace) 100 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.nm_legal + " FROM " + DB.k_companies + " WHERE " + DB.gu_company + "='" + getStringNull(DB.gu_company, "null") + "')"); 101 102 oStmt = oConn.prepareStatement("SELECT " + DB.nm_legal + " FROM " + DB.k_companies + " WHERE " + DB.gu_company + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 103 oStmt.setObject (1, get(DB.gu_company), java.sql.Types.CHAR); 104 oRSet = oStmt.executeQuery(); 105 if (oRSet.next()) 106 put (DB.tx_company, oRSet.getString(1)); 107 oRSet.close(); 108 oStmt.close(); 109 } 110 111 bRetVal = super.store(oConn); 112 113 if (DebugFile.trace) { 114 DebugFile.decIdent(); 115 DebugFile.writeln("End Oportunity.store() : " + String.valueOf(bRetVal)); 116 } 117 118 return bRetVal; 119 } 121 123 public boolean delete(JDCConnection oConn) throws SQLException { 124 return Oportunity.delete(oConn, getString(DB.gu_oportunity)); 125 } 126 127 130 137 public static boolean delete(JDCConnection oConn, String sOportunityGUID) throws SQLException { 138 CallableStatement oCall; 139 Statement oStmt; 140 boolean bRetVal; 141 142 if (DebugFile.trace) { 143 DebugFile.writeln("Begin Oportunity.delete([Connection], " + sOportunityGUID + ")"); 144 DebugFile.incIdent(); 145 146 } 147 148 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) { 149 oStmt = oConn.createStatement(); 150 151 if (DebugFile.trace) DebugFile.writeln("Statement.execute(SELECT k_sp_del_oportunity ('" + sOportunityGUID + "'))"); 152 153 bRetVal = oStmt.execute("SELECT k_sp_del_oportunity ('" + sOportunityGUID + "')"); 154 oStmt.close(); 155 } 156 else { 157 if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_del_oportunity('" + sOportunityGUID + "')})"); 158 159 oCall = oConn.prepareCall("{ call k_sp_del_oportunity ('" + sOportunityGUID + "')}"); 160 bRetVal = oCall.execute(); 161 oCall.close(); 162 } 163 if (DebugFile.trace) { 164 DebugFile.decIdent(); 165 DebugFile.writeln("End Oportunity.delete() : " + String.valueOf(bRetVal)); 166 } 167 168 return bRetVal; 169 } 170 171 174 public static final short ClassId = 92; 175 } | Popular Tags |