KickJava   Java API By Example, From Geeks To Geeks.

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


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.Statement JavaDoc;
37 import java.sql.PreparedStatement JavaDoc;
38 import java.sql.CallableStatement JavaDoc;
39 import java.sql.ResultSet JavaDoc;
40
41 import com.knowgate.debug.DebugFile;
42 import com.knowgate.jdc.JDCConnection;
43 import com.knowgate.dataobjs.DB;
44 import com.knowgate.dataobjs.DBPersist;
45 import com.knowgate.acl.ACLUser;
46
47 /**
48  * <p>Sales Man</p>
49  * <p>Copyright: Copyright (c) KnowGate 2003</p>
50  * @author Sergio Montoro Ten
51  * @version 2.2
52  */

53 public class SalesMan extends DBPersist {
54
55   private ACLUser oUser;
56
57   public SalesMan() {
58     super(DB.k_sales_men, "SalesMan");
59     oUser=null;
60   }
61
62   /**
63    * Get user for this sales man
64    * @return ACLUser
65    */

66   public ACLUser getUser() {
67     return oUser;
68   }
69
70   /**
71    * Load sales man and initialize internal user instance
72    * @param oConn JDCConnection
73    * @param PKVals Object[]
74    * @return boolean
75    * @throws SQLException
76    */

77   public boolean load(JDCConnection oConn, Object JavaDoc[] PKVals) throws SQLException JavaDoc {
78     boolean bRetVal = super.load(oConn, PKVals);
79     if (bRetVal)
80       oUser = new ACLUser(oConn, getString(DB.gu_sales_man));
81     return bRetVal;
82   }
83
84   /**
85    * <p>Store sales man</p>
86    * This method initializes internal user inctance if it was not previously set
87    * @param oConn JDCConnection
88    * @return boolean
89    * @throws SQLException
90    */

91   public boolean store (JDCConnection oConn) throws SQLException JavaDoc {
92     boolean bRetVal = super.store(oConn);
93     if (oUser==null)
94       oUser = new ACLUser(oConn, getString(DB.gu_sales_man));
95     return bRetVal;
96   }
97
98   /**
99    * Delete sales man.
100    * @throws SQLException
101    */

102   public boolean delete(JDCConnection oConn) throws SQLException JavaDoc {
103     return SalesMan.delete(oConn, getString(DB.gu_sales_man));
104   }
105
106   /**
107    * <p>Delete sales man</p>
108    * This method calls k_sp_del_sales_man stored procedure
109    * @param oConn JDCConnection
110    * @param sSalesManGUID String GUID of sales man to be deleted
111    * @return boolean
112    * @throws SQLException
113    */

114   public static boolean delete(JDCConnection oConn, String JavaDoc sSalesManGUID) throws SQLException JavaDoc {
115     CallableStatement JavaDoc oCall;
116     Statement JavaDoc oStmt;
117     if (DebugFile.trace) {
118       DebugFile.writeln("Begin SalesMan.delete([Connection], " + sSalesManGUID + ")");
119       DebugFile.incIdent();
120       DebugFile.writeln("Connection.prepareCall({ call k_sp_del_sales_man('" + sSalesManGUID + "')}");
121     }
122     switch (oConn.getDataBaseProduct()) {
123       case JDCConnection.DBMS_POSTGRESQL:
124         oStmt = oConn.createStatement();
125         oStmt.executeQuery("SELECT k_sp_del_sales_man('" + sSalesManGUID + "')").close();
126         oStmt.close();
127         oStmt=null;
128         break;
129       default:
130         oCall = oConn.prepareCall("{ call k_sp_del_sales_man('" + sSalesManGUID + "')}");
131         oCall.execute();
132         oCall.close();
133         oCall = null;
134     }
135     if (DebugFile.trace) {
136       DebugFile.decIdent();
137       DebugFile.writeln("End SalesMan.delete()");
138     }
139
140     return true;
141   } // delete
142

143   /**
144    * Get whether a user exists as a sales man or not
145    * @param oConn JDCConnection
146    * @param sSalesManGUID String sales man GUID
147    * @return boolean <b>true</b> if a record with gu_sales_man=sSalesManGUID
148    * exists at table k_sales_men, <b>false</b> otherwise
149    * @throws SQLException
150    */

151   public static boolean exists(JDCConnection oConn, String JavaDoc sSalesManGUID) throws SQLException JavaDoc {
152     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT NULL FROM "+DB.k_sales_men+" WHERE "+DB.gu_sales_man+"=?",
153                                                      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
154     oStmt.setString(1, sSalesManGUID);
155     ResultSet JavaDoc oRSet = oStmt.executeQuery();
156     boolean bExists = oRSet.next();
157     oRSet.close();
158     oStmt.close();
159     return bExists;
160   }
161
162   // **********************************************************
163
// Public Constants
164

165   public static final short ClassId = 97;
166 }
167
Popular Tags