001: /*
002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
003: C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.crm;
034:
035: import java.sql.SQLException;
036: import java.sql.Statement;
037: import java.sql.PreparedStatement;
038: import java.sql.CallableStatement;
039: import java.sql.ResultSet;
040:
041: import com.knowgate.debug.DebugFile;
042: import com.knowgate.jdc.JDCConnection;
043: import com.knowgate.dataobjs.DB;
044: import com.knowgate.dataobjs.DBPersist;
045: import com.knowgate.acl.ACLUser;
046:
047: /**
048: * <p>Sales Man</p>
049: * <p>Copyright: Copyright (c) KnowGate 2003</p>
050: * @author Sergio Montoro Ten
051: * @version 2.2
052: */
053: public class SalesMan extends DBPersist {
054:
055: private ACLUser oUser;
056:
057: public SalesMan() {
058: super (DB.k_sales_men, "SalesMan");
059: oUser = null;
060: }
061:
062: /**
063: * Get user for this sales man
064: * @return ACLUser
065: */
066: public ACLUser getUser() {
067: return oUser;
068: }
069:
070: /**
071: * Load sales man and initialize internal user instance
072: * @param oConn JDCConnection
073: * @param PKVals Object[]
074: * @return boolean
075: * @throws SQLException
076: */
077: public boolean load(JDCConnection oConn, Object[] PKVals)
078: throws SQLException {
079: boolean bRetVal = super .load(oConn, PKVals);
080: if (bRetVal)
081: oUser = new ACLUser(oConn, getString(DB.gu_sales_man));
082: return bRetVal;
083: }
084:
085: /**
086: * <p>Store sales man</p>
087: * This method initializes internal user inctance if it was not previously set
088: * @param oConn JDCConnection
089: * @return boolean
090: * @throws SQLException
091: */
092: public boolean store(JDCConnection oConn) throws SQLException {
093: boolean bRetVal = super .store(oConn);
094: if (oUser == null)
095: oUser = new ACLUser(oConn, getString(DB.gu_sales_man));
096: return bRetVal;
097: }
098:
099: /**
100: * Delete sales man.
101: * @throws SQLException
102: */
103: public boolean delete(JDCConnection oConn) throws SQLException {
104: return SalesMan.delete(oConn, getString(DB.gu_sales_man));
105: }
106:
107: /**
108: * <p>Delete sales man</p>
109: * This method calls k_sp_del_sales_man stored procedure
110: * @param oConn JDCConnection
111: * @param sSalesManGUID String GUID of sales man to be deleted
112: * @return boolean
113: * @throws SQLException
114: */
115: public static boolean delete(JDCConnection oConn,
116: String sSalesManGUID) throws SQLException {
117: CallableStatement oCall;
118: Statement oStmt;
119: if (DebugFile.trace) {
120: DebugFile.writeln("Begin SalesMan.delete([Connection], "
121: + sSalesManGUID + ")");
122: DebugFile.incIdent();
123: DebugFile
124: .writeln("Connection.prepareCall({ call k_sp_del_sales_man('"
125: + sSalesManGUID + "')}");
126: }
127: switch (oConn.getDataBaseProduct()) {
128: case JDCConnection.DBMS_POSTGRESQL:
129: oStmt = oConn.createStatement();
130: oStmt.executeQuery(
131: "SELECT k_sp_del_sales_man('" + sSalesManGUID
132: + "')").close();
133: oStmt.close();
134: oStmt = null;
135: break;
136: default:
137: oCall = oConn.prepareCall("{ call k_sp_del_sales_man('"
138: + sSalesManGUID + "')}");
139: oCall.execute();
140: oCall.close();
141: oCall = null;
142: }
143: if (DebugFile.trace) {
144: DebugFile.decIdent();
145: DebugFile.writeln("End SalesMan.delete()");
146: }
147:
148: return true;
149: } // delete
150:
151: /**
152: * Get whether a user exists as a sales man or not
153: * @param oConn JDCConnection
154: * @param sSalesManGUID String sales man GUID
155: * @return boolean <b>true</b> if a record with gu_sales_man=sSalesManGUID
156: * exists at table k_sales_men, <b>false</b> otherwise
157: * @throws SQLException
158: */
159: public static boolean exists(JDCConnection oConn,
160: String sSalesManGUID) throws SQLException {
161: PreparedStatement oStmt = oConn
162: .prepareStatement("SELECT NULL FROM " + DB.k_sales_men
163: + " WHERE " + DB.gu_sales_man + "=?",
164: ResultSet.TYPE_FORWARD_ONLY,
165: ResultSet.CONCUR_READ_ONLY);
166: oStmt.setString(1, sSalesManGUID);
167: ResultSet oRSet = oStmt.executeQuery();
168: boolean bExists = oRSet.next();
169: oRSet.close();
170: oStmt.close();
171: return bExists;
172: }
173:
174: // **********************************************************
175: // Public Constants
176:
177: public static final short ClassId = 97;
178: }
|