00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _ANCLIST_H_
00031 #define _ANCLIST_H_
00032
00033
00034
00035
00036 #include <map>
00037 #include <memory>
00038 #include <set>
00039
00040
00041
00042
00043 #include "associate.h"
00044 #include "contract.h"
00045 #include "osbid.h"
00046
00047
00048 namespace OSB_DB {
00049 class Session;
00050 }
00051
00052
00053
00054 namespace OSB_LIB {
00055
00056
00057
00058 struct AnCFilter;
00059
00060
00061
00062
00063
00064
00068 class AssociateList {
00069 public:
00077 typedef std::auto_ptr<Associate> AssociateAutoPtr;
00078
00080
00081
00086 typedef std::map<Id<Associate>, Associate*> List;
00088 typedef List::iterator Iterator;
00090 typedef List::const_iterator ConstIterator;
00092 typedef List::size_type SizeType;
00094 typedef List::key_type KeyType;
00096
00098 AssociateList() {};
00099
00106 AssociateList(const AssociateList& rhs);
00107
00109 AssociateList& operator=(const AssociateList& rhs);
00110
00112 ~AssociateList();
00113
00122
00123 Iterator begin() { return list_.begin(); }
00125 Iterator end() { return list_.end(); }
00127 Iterator find(const KeyType& k) { return list_.find(k); }
00129 ConstIterator begin() const { return list_.begin(); }
00131 ConstIterator end() const { return list_.end(); }
00133 ConstIterator find(const KeyType& k) const
00134 { return list_.find(k); }
00136 SizeType size() const { return list_.size(); }
00138 void swap(AssociateList& rhs);
00140
00155 Associate* insert(const Associate& assoc);
00156
00174 Associate* insert(AssociateAutoPtr ap);
00175
00184 void erase(Iterator pos);
00185
00194 void erase(const KeyType& k);
00195
00202 void clear();
00203
00205 const List& list() const { return list_; }
00206
00214 Associate* findAssociate(const Id<Associate>& asId);
00215
00223 const Associate* findAssociate(const Id<Associate>& asId) const;
00224
00232 const Associate& getAssociate(const Id<Associate>& asId) const;
00233
00242 Associate& getAssociate(const Id<Associate>& asId);
00243
00244 private:
00246 List list_;
00247 };
00248
00249
00250
00254 class AnCList {
00256 friend class Associate;
00257 private:
00259 typedef std::set<Associate::Oid> AssociateIds;
00260
00261 public:
00263 class AssocReadFailed : public OsbException {
00264 public:
00266 AssocReadFailed(
00267 ErrorNo errNo,
00268 const Associate::Oid& asId
00269 );
00270 };
00271
00273 class ContractReadFailed : public OsbException {
00274 public:
00276 ContractReadFailed(
00277 ErrorNo errNo,
00278 const Contract::Oid& coId
00279 );
00280 };
00281
00283 class PpReadFailed : public OsbException {
00284 public:
00286 PpReadFailed(
00287 ErrorNo errNo,
00288 const Id<PersProduct>& ppId
00289 );
00290 };
00291
00292 public:
00294 typedef std::map< Id<Contract>, Contract> ContractMap;
00296 typedef std::map< Id<PersProduct>, Id<Contract> > PersProductMap;
00297
00298 public:
00300 AnCList() {}
00302 AnCList(const AnCList& rhs);
00304 AnCList& operator=(const AnCList& rhs);
00306 ~AnCList();
00307
00308 public:
00310 const AssociateList& associateList() const
00311 {
00312 return aList_;
00313 }
00314
00316 const ContractMap& contractMap() const
00317 {
00318 return cMap_;
00319 }
00320
00322
00323
00332 long search(
00333 const OSB_DB::Session& session,
00334 AnCFilter& filter
00335 );
00337
00339
00340
00347 Associate* associate(const Associate::Oid& asId);
00348
00357 Associate& getAssociate(const Associate::Oid& asId);
00358
00380 Associate* read(
00381 const OSB_DB::Session& session,
00382 const Associate::Oid asId
00383 );
00384
00395 bool create(
00396 OSB_DB::Session& session,
00397 Associate& assoc
00398 );
00399
00415 bool replace(
00416 const Associate& assoc
00417 );
00418
00431 bool remove(
00432 OSB_DB::Session& session,
00433 const Associate::Oid asId
00434 );
00436
00438
00439
00446 const Contract* findContract(const Contract::Oid& coId) const;
00447
00456 Contract* contract(const Contract::Oid& coId);
00457
00465 const Contract& getContract(const Contract::Oid& coId) const;
00466
00474 Contract& getContract(const Contract::Oid& coId);
00475
00491 Contract* read(
00492 const OSB_DB::Session& session,
00493 const Contract::Oid coId
00494 );
00495
00504 bool create(
00505 OSB_DB::Session& session,
00506 const Associate::Oid& owner,
00507 Contract& contract
00508 );
00509
00516 void remove(
00517 OSB_DB::Session& session,
00518 const Contract::Oid coId
00519 );
00520
00532 bool replace(
00533 const Contract& contract
00534 );
00536
00538
00539
00546 PersProduct* persProduct(
00547 const Id<PersProduct>& ppId
00548 );
00549
00571 PersProduct* read(
00572 const OSB_DB::Session& session,
00573 const Id<PersProduct> ppId
00574 );
00576
00582 void refresh(const OSB_DB::Session& session);
00583
00584 private:
00597 void read(
00598 const OSB_DB::Session& session,
00599 const AssociateIds& idList
00600 );
00601
00605 void swap(AnCList& rhs);
00606
00616 void insert(
00617 const Contract& co
00618 );
00619
00630 void erase(
00631 const Contract::Oid coId
00632 );
00633
00651 bool delAssoc(
00652 const OSB_DB::Session& session,
00653 const Associate::Oid asId
00654 );
00655
00656 private:
00658 AssociateList aList_;
00660 ContractMap cMap_;
00662 PersProductMap ppMap_;
00663 };
00664
00666 struct AnCFilter {
00668 Associate::Oid asId_;
00670 std::string asName_;
00672 Contract::Oid coId_;
00673
00675 size_t maxRows_;
00677 bool moreRows_;
00678
00684 AnCFilter();
00685 };
00686 }
00687
00688
00689
00690 namespace OSB_LIB {
00691 }
00692 #endif // #ifndef _ANCLIST_H_