KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HashMap JavaDoc;
36
37 import java.sql.Connection JavaDoc;
38 import java.sql.SQLException JavaDoc;
39 import java.sql.CallableStatement JavaDoc;
40 import java.sql.Statement JavaDoc;
41 import java.sql.PreparedStatement JavaDoc;
42 import java.sql.ResultSet JavaDoc;
43
44 import com.knowgate.debug.DebugFile;
45 import com.knowgate.misc.Gadgets;
46 import com.knowgate.jdc.JDCConnection;
47 import com.knowgate.dataobjs.DB;
48 import com.knowgate.dataobjs.DBBind;
49 import com.knowgate.dataobjs.DBSubset;
50 import com.knowgate.dataobjs.DBPersist;
51 import com.knowgate.hipergate.Address;
52 import com.knowgate.hipergate.DBLanguages;
53
54 /**
55  * <p>Company</p>
56  * <p>Copyright: Copyright (c) KnowGate 2003</p>
57  * @author Sergio Montoro Ten
58  * @version 3.0
59  */

60
61 public class Company extends DBPersist {
62
63   /**
64    * Create Empty Company.
65   */

66   public Company() {
67     super(DB.k_companies, "Company");
68   }
69
70   /**
71    * Create Company and set gu_company field.
72    * Does not load other fields from database.
73    * @param sCompanyId Company GUID
74    */

75   public Company(String JavaDoc sCompanyId) {
76     super(DB.k_companies, "Company");
77
78     put (DB.gu_company, sCompanyId);
79   }
80
81   // ----------------------------------------------------------
82

83   /**
84    * Create Company and load fields from database.
85    * @param oConn JDCConnection
86    * @param sCompanyId Company GUID
87    * @throws SQLException
88    */

89   public Company(JDCConnection oConn, String JavaDoc sCompanyId)
90     throws SQLException JavaDoc {
91     super(DB.k_companies, "Company");
92     load (oConn, sCompanyId);
93   }
94
95   // ----------------------------------------------------------
96

97   /**
98    * <P>Add a bank account to this Company</P>
99    * If company is already associated to the given bank account then a foreign key violation SQLException is thrown
100    * @param oConn Database Connection
101    * @throws SQLException
102    * @since 3.0
103    */

104   public boolean addBankAccount(JDCConnection oConn, String JavaDoc sFullBankAccount)
105     throws SQLException JavaDoc {
106     PreparedStatement JavaDoc oStmt = null;
107     boolean bRetVal;
108
109     try {
110       oStmt = oConn.prepareStatement("INSERT INTO " + DB.k_x_company_bank + " (" + DB.gu_company + "," + DB.nu_bank_acc + "," + DB.gu_workarea + ") VALUES (?,?,?)");
111       oStmt.setString(1, getStringNull(DB.gu_company, null));
112       oStmt.setString(2, sFullBankAccount);
113       oStmt.setString(3, getStringNull(DB.gu_workarea, null));
114       int iAffected = oStmt.executeUpdate();
115       oStmt.close();
116       oStmt = null;
117       bRetVal = (iAffected > 0);
118     } catch (SQLException JavaDoc sqle) {
119       bRetVal = false;
120       try { if (oStmt!=null) oStmt.close(); } catch (Exception JavaDoc ignore) {}
121     }
122     return bRetVal;
123   } // addBankAccount
124

125   // ----------------------------------------------------------
126

127   /**
128    * Get all bank accounts associated with Company
129    * @param oConn JDCConnection
130    * @return DBSubset nu_bank_acc,dt_created,bo_active,tp_account,nm_bank,tx_addr,nm_cardholder,nu_card,tp_card,tx_expire,nu_pin,nu_cvv2,im_credit_limit,de_bank_acc
131    * @throws SQLException
132    * @throws IllegalStateException if gu_company or gu_workarea are not set
133    * @since 3.0
134    */

135   public DBSubset getAllBankAccounts(JDCConnection oConn)
136     throws SQLException JavaDoc,IllegalStateException JavaDoc {
137     if (isNull(DB.gu_company))
138       throw new IllegalStateException JavaDoc("Company.getAllBankAccounts() gu_company property is not set");
139     if (isNull(DB.gu_workarea))
140       throw new IllegalStateException JavaDoc("Company.getAllBankAccounts() gu_workarea property is not set");
141
142     DBSubset oAccs = new DBSubset (DB.k_bank_accounts,
143                                    DB.nu_bank_acc+","+DB.dt_created+","+DB.bo_active+","+DB.tp_account+","+DB.nm_bank+","+DB.tx_addr+","+DB.nm_cardholder+","+DB.nu_card+","+DB.tp_card+","+DB.tx_expire+","+DB.nu_pin+","+DB.nu_cvv2+","+DB.im_credit_limit+","+DB.de_bank_acc,
144                                    DB.gu_workarea+"=? AND "+DB.nu_bank_acc+" IN (SELECT "+DB.nu_bank_acc+" FROM "+DB.k_x_company_bank+" WHERE "+DB.gu_workarea+"=? AND "+DB.gu_company+"=?)",10);
145
146     oAccs.load(oConn, new Object JavaDoc[]{get(DB.gu_workarea),get(DB.gu_workarea),get(DB.gu_company)});
147     return oAccs;
148   } // getAllBankAccounts
149

150   // ----------------------------------------------------------
151

152   /**
153    * Get active bank accounts for this Company
154    * @param oConn JDCConnection
155    * @return DBSubset nu_bank_acc,dt_created,tp_account,nm_bank,tx_addr,nm_cardholder,nu_card,tp_card,tx_expire,nu_pin,nu_cvv2,im_credit_limit,de_bank_acc
156    * @throws SQLException
157    * @throws IllegalStateException if gu_company or gu_workarea are not set
158    * @since 3.0
159    */

160   public DBSubset getActiveBankAccounts(JDCConnection oConn)
161     throws SQLException JavaDoc,IllegalStateException JavaDoc {
162     if (isNull(DB.gu_company))
163       throw new IllegalStateException JavaDoc("Company.getActiveBankAccounts() gu_company property is not set");
164     if (isNull(DB.gu_workarea))
165       throw new IllegalStateException JavaDoc("Company.getActiveBankAccounts() gu_workarea property is not set");
166
167     DBSubset oAccs = new DBSubset (DB.k_bank_accounts,
168                                    DB.nu_bank_acc+","+DB.dt_created+","+DB.tp_account+","+DB.nm_bank+","+DB.tx_addr+","+DB.nm_cardholder+","+DB.nu_card+","+DB.tp_card+","+DB.tx_expire+","+DB.nu_pin+","+DB.nu_cvv2+","+DB.im_credit_limit+","+DB.de_bank_acc,
169                                    DB.gu_workarea+"=? AND "+DB.bo_active+"<>0 AND "+DB.nu_bank_acc+" IN (SELECT "+DB.nu_bank_acc+" FROM "+DB.k_x_company_bank+" WHERE "+DB.gu_workarea+"=? AND "+DB.gu_company+"=?)",10);
170
171     oAccs.load(oConn, new Object JavaDoc[]{get(DB.gu_workarea),get(DB.gu_workarea),get(DB.gu_company)});
172     return oAccs;
173   } // getActiveBankAccounts
174

175   // ----------------------------------------------------------
176

177   /**
178    * Get unactive bank accounts for this Company
179    * @param oConn JDCConnection
180    * @return DBSubset nu_bank_acc,dt_created,tp_account,nm_bank,tx_addr,nm_cardholder,nu_card,tp_card,tx_expire,nu_pin,nu_cvv2,im_credit_limit,de_bank_acc
181    * @throws SQLException
182    * @throws IllegalStateException if gu_company or gu_workarea are not set
183    * @since 3.0
184    */

185   public DBSubset getUnactiveBankAccounts(JDCConnection oConn)
186     throws SQLException JavaDoc,IllegalStateException JavaDoc {
187     if (isNull(DB.gu_company))
188       throw new IllegalStateException JavaDoc("Company.getUnactiveBankAccounts() gu_company property is not set");
189     if (isNull(DB.gu_workarea))
190       throw new IllegalStateException JavaDoc("Company.getUnactiveBankAccounts() gu_workarea property is not set");
191
192     DBSubset oAccs = new DBSubset (DB.k_bank_accounts,
193                                    DB.nu_bank_acc+","+DB.dt_created+","+DB.tp_account+","+DB.nm_bank+","+DB.tx_addr+","+DB.nm_cardholder+","+DB.nu_card+","+DB.tp_card+","+DB.tx_expire+","+DB.nu_pin+","+DB.nu_cvv2+","+DB.im_credit_limit+","+DB.de_bank_acc,
194                                    DB.gu_workarea+"=? AND "+DB.bo_active+"=0 AND "+DB.nu_bank_acc+" IN (SELECT "+DB.nu_bank_acc+" FROM "+DB.k_x_company_bank+" WHERE "+DB.gu_workarea+"=? AND "+DB.gu_company+"=?)",10);
195
196     oAccs.load(oConn, new Object JavaDoc[]{get(DB.gu_workarea),get(DB.gu_workarea),get(DB.gu_company)});
197     return oAccs;
198   } // getUnactiveBankAccounts
199

200   // ----------------------------------------------------------
201

202   /**
203    * Store Company
204    * Automatically generates gu_company GUID and dt_modified DATE if not explicitly set.
205    * @param oConn Database Connection
206    * @throws SQLException
207    */

208   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
209     java.sql.Timestamp JavaDoc dtNow = new java.sql.Timestamp JavaDoc(DBBind.getTime());
210
211     if (!AllVals.containsKey(DB.gu_company))
212       put(DB.gu_company, Gadgets.generateUUID());
213
214     replace(DB.dt_modified, dtNow);
215
216     return super.store(oConn);
217   } // store
218

219   // ----------------------------------------------------------
220

221   /**
222    * Delete Company
223    * @param oConn Database Connection
224    * @throws SQLException
225    */

226   public boolean delete(JDCConnection oConn) throws SQLException JavaDoc {
227     return Company.delete(oConn, getString(DB.gu_company));
228   }
229
230   // ----------------------------------------------------------
231

232   /**
233    * <p>Find out whether or not a company exists at database</p>
234    * Look up company by GUID or by legal name and work area.
235    * @param oConn database connection
236    * @return <b>true</b> if a company with such GUID or legal name+work area is found.
237    * @throws SQLException
238    */

239
240   public boolean exists(JDCConnection oConn) throws SQLException JavaDoc {
241     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT NULL FROM "+DB.k_companies+" WHERE "+DB.gu_company+"=? OR ("+DB.nm_legal+"=? AND "+DB.gu_workarea+"=?)",
242                                                      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
243     oStmt.setString(1, getStringNull(DB.gu_company,null));
244     oStmt.setString(2, getStringNull(DB.nm_legal,null));
245     oStmt.setString(3, getStringNull(DB.gu_workarea,null));
246     ResultSet JavaDoc oRSet = oStmt.executeQuery();
247     boolean bExists = oRSet.next();
248     oRSet.close();
249     oStmt.close();
250     return bExists;
251   } // exists
252

253   // ----------------------------------------------------------
254

255   /**
256    * <P>Add an Address to this Company</P>
257    * If contact is already associated to the given address a foreign key violation
258    * SQLExceception is raised.
259    * @param oConn Database Connection
260    * @throws SQLException
261    */

262   public boolean addAddress(JDCConnection oConn, String JavaDoc sAddrGUID) throws SQLException JavaDoc {
263     PreparedStatement JavaDoc oStmt = null;
264     boolean bRetVal;
265
266     try {
267       oStmt = oConn.prepareStatement("INSERT INTO " + DB.k_x_company_addr + " (" + DB.gu_company + "," + DB.gu_address + ") VALUES (?,?)");
268       oStmt.setString(1, getStringNull(DB.gu_company, null));
269       oStmt.setString(2, sAddrGUID);
270       int iAffected = oStmt.executeUpdate();
271       oStmt.close();
272       oStmt = null;
273       bRetVal = (iAffected > 0);
274     } catch (SQLException JavaDoc sqle) {
275       bRetVal = false;
276       try { if (oStmt!=null) oStmt.close(); } catch (Exception JavaDoc ignore) {}
277     }
278     return bRetVal;
279   } // addAddress
280

281   // ----------------------------------------------------------
282

283   /**
284    * Get address by location type
285    * @param oConn JDCConnection
286    * @param sTpLocation String Value for column tp_location from k_addresses table
287    * @return Address or <b>null</b> is no address with such location type was found
288    * @throws SQLException
289    * @throws IllegalStateException if gu_company property is not set
290    * @since 3.0
291    */

292   public Address getAddress(JDCConnection oConn, String JavaDoc sTpLocation)
293     throws SQLException JavaDoc,IllegalStateException JavaDoc {
294
295     Address oRetAdr;
296
297     if (isNull(DB.gu_company))
298       throw new IllegalStateException JavaDoc("Company.getAddress([Connection],"+sTpLocation+") gu_company property is not set");
299
300     if (DebugFile.trace) {
301       DebugFile.writeln("Begin Company.getAddress([Connection],"+sTpLocation+")" );
302       DebugFile.incIdent();
303     }
304
305     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT x." + DB.gu_address +
306                                                      " FROM " + DB.k_x_company_addr + " x," +
307                                                      DB.k_addresses + " a WHERE " +
308                                                      "x." + DB.gu_address + "=a." + DB.gu_address +
309                                                      " AND x." + DB.gu_company+"=?" +
310                                                      " AND a." + DB.tp_location+"=?",
311                                                      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
312     oStmt.setString(1, getString(DB.gu_company));
313     oStmt.setString(2, sTpLocation);
314     ResultSet JavaDoc oRSet = oStmt.executeQuery();
315     if (oRSet.next())
316       oRetAdr = new Address(oConn, oRSet.getString(1));
317     else
318       oRetAdr = null;
319     oRSet.close();
320     oStmt.close();
321
322     if (DebugFile.trace) {
323       DebugFile.decIdent();
324       DebugFile.writeln("End Company.getAddress()");
325     }
326     return oRetAdr;
327   } // getAddress
328

329   // ----------------------------------------------------------
330

331   /**
332    * <p>Get Company Addresses</p>
333    * @param oConn Database Connection
334    * @return A DBSubset with all columns from k_addresses for Company
335    * @throws SQLException
336    * @throws IllegalStateException if gu_company property is not set
337    */

338   public DBSubset getAddresses(JDCConnection oConn)
339       throws SQLException JavaDoc,IllegalStateException JavaDoc {
340
341     if (isNull(DB.gu_company))
342       throw new IllegalStateException JavaDoc("Company.getAddresses() gu_company property is not set");
343
344     if (DebugFile.trace) {
345       DebugFile.writeln("Begin Company.getAddresses([Connection])" );
346       DebugFile.incIdent();
347     }
348
349     Address oAddr = new Address();
350
351     DBSubset oAddrs = new DBSubset (DB.k_addresses,
352                                     oAddr.getTable(oConn).getColumnsStr(),
353                                     DB.gu_address + " IN (SELECT " + DB.gu_address + " FROM " + DB.k_x_company_addr + " WHERE " + DB.gu_company + "=?)", 10);
354     int iAddrs = oAddrs.load(oConn, new Object JavaDoc[]{getString(DB.gu_company)});
355
356     oAddr = null;
357
358     if (DebugFile.trace) {
359       DebugFile.decIdent();
360       DebugFile.writeln("End Company.getAddresses() : " + String.valueOf(iAddrs));
361     }
362
363     return oAddrs;
364   } // getAddresses
365

366   // ----------------------------------------------------------
367

368   // **********************************************************
369
// Static Methods
370

371   /**
372    * <p>Delete Company.</p>
373    * Delete all associated contacts and call k_sp_del_company stored procedure.<br>
374    * If k_orders table exists, then Orders for this Company are deleted.<br>
375    * If k_projects table exists, then Projects for this Company are deleted.<br>
376    * @param oConn Database Connection
377    * @param sCompanyGUID Company GUID
378    * @throws SQLException
379    */

380   public static boolean delete(JDCConnection oConn, String JavaDoc sCompanyGUID) throws SQLException JavaDoc {
381     boolean bRetVal;
382     Statement JavaDoc oStmt;
383
384     if (DebugFile.trace) {
385       DebugFile.writeln("Begin Company.delete([Connection], " + sCompanyGUID + ")");
386       DebugFile.incIdent();
387     }
388
389     /* Desasociar los e-mails */
390      if (DBBind.exists(oConn, DB.k_inet_addrs, "U")) {
391        oStmt = oConn.createStatement();
392
393        if (DebugFile.trace)
394          DebugFile.writeln("UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_company + "=NULL WHERE " + DB.gu_company + "='" + sCompanyGUID + "'");
395
396        oStmt.executeUpdate("UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_company + "=NULL WHERE " + DB.gu_company + "='" + sCompanyGUID + "'");
397
398        oStmt.close();
399      }
400
401     if (DBBind.exists(oConn, DB.k_projects, "U")) {
402       DBSubset oProjs = new DBSubset(DB.k_projects, DB.gu_project, DB.gu_company + "='" + sCompanyGUID + "'", 10);
403
404       int iProjs = oProjs.load(oConn);
405
406       for (int p=0; p<iProjs; p++)
407         com.knowgate.projtrack.Project.delete (oConn, oProjs.getString(0,p));
408     }
409
410     if (DBBind.exists(oConn, DB.k_orders, "U")) {
411       DBSubset oOrders = new DBSubset(DB.k_orders, DB.gu_order, DB.gu_company + "='" + sCompanyGUID + "'", 1000);
412
413       int iOrders = oOrders.load(oConn);
414
415       for (int o=0; o<iOrders; o++)
416         com.knowgate.hipergate.Order.delete (oConn, oOrders.getString(0,o));
417     } // fi (exists(DB.k_orders))
418

419     DBSubset oContacts = new DBSubset(DB.k_contacts, DB.gu_contact, DB.gu_company + "='" + sCompanyGUID + "'", 1000);
420     int iContacts = oContacts.load(oConn);
421
422     for (int c=0; c<iContacts; c++)
423       Contact.delete(oConn, oContacts.getString(0,c));
424
425     oContacts = null;
426
427     if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
428       oStmt = oConn.createStatement();
429       if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(SELECT k_sp_del_company ('" + sCompanyGUID + "')");
430       oStmt.executeQuery("SELECT k_sp_del_company ('" + sCompanyGUID + "')");
431       oStmt.close();
432       bRetVal = true;
433     }
434     else {
435
436       if (DebugFile.trace)
437         DebugFile.writeln ("Conenction.prepareCall({call k_sp_del_company ('" + sCompanyGUID + "')}");
438
439       CallableStatement JavaDoc oCall = oConn.prepareCall("{call k_sp_del_company ('" + sCompanyGUID + "')}");
440       bRetVal = oCall.execute();
441       oCall.close();
442     }
443
444     if (DebugFile.trace) {
445       DebugFile.decIdent();
446       DebugFile.writeln("End Company.delete() : " + String.valueOf(bRetVal));
447     }
448
449     return bRetVal;
450   } // delete
451

452   /**
453    * <p>Add a Company Sector lookup value</a>
454    * @param oConn Connection
455    * @param sGuWorkArea String GUID of WorkArea
456    * @param sDeTitle String Sector Internal Identifier
457    * @param oTranslations HashMap with one entry for each language
458    * @return boolean <b>true</b> if new sector was added, <b>false</b> if it already existed
459    * @throws SQLException
460    * @since 3.0
461    */

462   public static boolean addLookupSector (Connection JavaDoc oConn, String JavaDoc sGuWorkArea, String JavaDoc sIdSector, HashMap JavaDoc oTranslations)
463     throws SQLException JavaDoc {
464     return DBLanguages.addLookup(oConn, DB.k_companies_lookup, sGuWorkArea, DB.id_sector, sIdSector, oTranslations);
465   }
466
467   /**
468    * <p>Add a Company Type lookup value</a>
469    * @param oConn Connection
470    * @param sGuWorkArea String GUID of WorkArea
471    * @param sDeTitle String Company Type Internal Identifier
472    * @param oTranslations HashMap with one entry for each language
473    * @return boolean <b>true</b> if new sector was added, <b>false</b> if it already existed
474    * @throws SQLException
475    * @since 3.0
476    */

477   public static boolean addLookupCompanyType (Connection JavaDoc oConn, String JavaDoc sGuWorkArea, String JavaDoc sIdType, HashMap JavaDoc oTranslations)
478     throws SQLException JavaDoc {
479     return DBLanguages.addLookup(oConn, DB.k_companies_lookup, sGuWorkArea, DB.tp_company, sIdType, oTranslations);
480   }
481
482   /**
483    * <p>Get company GUID given its legal name</p>
484    * @param oConn Connection
485    * @param sLegalName String Legal name of sought Company
486    * @param sWorkArea String GUID of WorkArea where to search
487    * @return String Company GUID or <b>null</b> if no company with such legal name was found at given work area
488    * @throws SQLException
489    * @since 3.0
490    */

491   public static String JavaDoc getIdFromName(Connection JavaDoc oConn, String JavaDoc sLegalName, String JavaDoc sWorkArea)
492     throws SQLException JavaDoc {
493     String JavaDoc sRetVal;
494     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT "+DB.gu_company+" FROM "+DB.k_companies+" WHERE "+DB.nm_legal+"=? AND "+DB.gu_workarea+"=?",
495                                                      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
496     oStmt.setString(1, sLegalName);
497     oStmt.setString(2, sWorkArea);
498     ResultSet JavaDoc oRSet = oStmt.executeQuery();
499     if (oRSet.next())
500       sRetVal = oRSet.getString(1);
501     else
502       sRetVal = null;
503     oRSet.close();
504     oStmt.close();
505     return sRetVal;
506   } // getIdFromName
507

508   /**
509    * <p>Get company GUID given its external reference</p>
510    * @param oConn Connection
511    * @param sLegalName String External reference of sought Company
512    * @param sWorkArea String GUID of WorkArea where to search
513    * @return String Company GUID or <b>null</b> if no company with such reference was found at given work area
514    * @throws SQLException
515    * @since 3.0
516    */

517   public static String JavaDoc getIdFromRef(Connection JavaDoc oConn, String JavaDoc sReference, String JavaDoc sWorkArea)
518     throws SQLException JavaDoc {
519     String JavaDoc sRetVal;
520     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT "+DB.gu_company+" FROM "+DB.k_companies+" WHERE "+DB.id_ref+"=? AND "+DB.gu_workarea+"=?",
521                                                      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
522     oStmt.setString(1, sReference);
523     oStmt.setString(2, sWorkArea);
524     ResultSet JavaDoc oRSet = oStmt.executeQuery();
525     if (oRSet.next())
526       sRetVal = oRSet.getString(1);
527     else
528       sRetVal = null;
529     oRSet.close();
530     oStmt.close();
531     return sRetVal;
532   } // getIdFromRef
533

534   /**
535    * <p>Get company GUID given its legal number</p>
536    * @param oConn Connection
537    * @param sLegalName String Legal Number of sought Company
538    * @param sWorkArea String GUID of WorkArea where to search
539    * @return String Company GUID or <b>null</b> if no company with such legal number was found at given work area
540    * @throws SQLException
541    * @since 3.0
542    */

543   public static String JavaDoc getIdFromLegalNum(Connection JavaDoc oConn, String JavaDoc sLegalId, String JavaDoc sWorkArea)
544     throws SQLException JavaDoc {
545     String JavaDoc sRetVal;
546     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("SELECT "+DB.gu_company+" FROM "+DB.k_companies+" WHERE "+DB.id_legal+"=? AND "+DB.gu_workarea+"=?",
547                                                      ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
548     oStmt.setString(1, sLegalId);
549     oStmt.setString(2, sWorkArea);
550     ResultSet JavaDoc oRSet = oStmt.executeQuery();
551     if (oRSet.next())
552       sRetVal = oRSet.getString(1);
553     else
554       sRetVal = null;
555     oRSet.close();
556     oStmt.close();
557     return sRetVal;
558   } // getIdFromLegalNum
559

560   // **********************************************************
561
// Public Constants
562

563   public static final short ClassId = 91;
564 }
565
Popular Tags