KickJava   Java API By Example, From Geeks To Geeks.

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


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.CallableStatement JavaDoc;
37 import java.sql.Statement JavaDoc;
38 import java.sql.PreparedStatement JavaDoc;
39 import java.sql.ResultSet JavaDoc;
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 /**
49  * <p>Sales Oportunity</p>
50  * @author Sergio Montoro Ten
51  * @version 1.0
52  */

53 public class Oportunity extends DBPersist {
54
55   public Oportunity() {
56     super(DB.k_oportunities, "Oportunity");
57   }
58
59   // ----------------------------------------------------------
60

61   /**
62    * <p>Store Oportunity</p>
63    * Fields gu_oportunity, dt_modified, tx_contact and tx_company are automatically filled if not given
64    * @param oConn Database Connection
65    * @return
66    * @throws SQLException
67    */

68   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
69     PreparedStatement JavaDoc oStmt;
70     ResultSet JavaDoc 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 JavaDoc dtNow = new java.sql.Timestamp JavaDoc(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   } // store
120

121   // ----------------------------------------------------------
122

123   public boolean delete(JDCConnection oConn) throws SQLException JavaDoc {
124     return Oportunity.delete(oConn, getString(DB.gu_oportunity));
125   }
126
127   // **********************************************************
128
// Static Methods
129

130   /**
131    * Delete Oportunity
132    * Call k_sp_del_oportunity stored procedure
133    * @param oConn Database Connection
134    * @param sOportunityGUID GUID of Oportunity to be deleted.
135    * @throws SQLException
136    */

137   public static boolean delete(JDCConnection oConn, String JavaDoc sOportunityGUID) throws SQLException JavaDoc {
138     CallableStatement JavaDoc oCall;
139     Statement JavaDoc 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   // **********************************************************
172
// Constantes Publicas
173

174   public static final short ClassId = 92;
175 }
Popular Tags