// DatasetReplicaCatalog.h #ifndef dset__DatasetReplicaCatalog_H #define dset__DatasetReplicaCatalog_H // David Adams // November 2004 // // A dataset replica catalog hold sth mapping between virtual and // non-virtual (logical, physica, staged) datasets. This class provides // a C++ interface to such a catalog. // // This class is build on GenericReplicaCatalog. #include #include "dataset_id/DatasetId.h" #include "dataset_id/DatasetIdList.h" #include "dataset_catalog/GenericReplicaCatalog.h" namespace dset { class DatasetReplicaCatalog { public: // typedefs typedef int Status; typedef std::string Connection; typedef DatasetId Id; typedef DatasetIdList IdList; typedef IdList::size_type size_type; private: // data GenericReplicaCatalog* m_pcat; private: // No copying allowd. DatasetReplicaCatalog(const DatasetReplicaCatalog&); // No assignment allowed. DatasetReplicaCatalog& operator=(const DatasetReplicaCatalog&); public: // static methods // Return the default concrete instance of this class. // First pass, use set_default_instance or // define an invalid catalog if this fails. static DatasetReplicaCatalog& default_instance(); // Set the default instance of this class. // Returns 0 for success. static int set_default_instance(DatasetReplicaCatalog* pdrc); // Set the default instance of this class. // Returns 0 for success. static int set_default_instance(Connection conn = ""); // Assign an empty DSC as the default by // 1. creating an empty SQLRESULT DRC drc.dat, // 2. appending a clause to resolver.dat and // 3. setting the latter as the connection configuration file. // This should only be used for testing. // The connection resolver is shared by all catalogs. // Returns 0 for success. static int create_default_instance(); public: // methods // Default constructor. DatasetReplicaCatalog(); // Constructor from a table. explicit DatasetReplicaCatalog(GenericReplicaCatalog* pcat); // Constructor from a catalog description. explicit DatasetReplicaCatalog(Connection conn); // Destructor. ~DatasetReplicaCatalog(); public: // const methods // Is this a valid catalog? bool is_valid() const; // Number of logical datasets size_type logical_size() const; // Number of replicas. size_type replica_size() const; // Is a logical dataset present? bool has_logical(Id lid) const; // Is a replica dataset present? bool has_replica(Id rid) const; // Is a logical-replica mapping present? bool has(Id lid, Id rid) const; // Return the list of logical ID's. IdList logicals() const; // Return the list of replica ID's. IdList replicas() const; // Return the list of replica ID's associated with a logical ID. IdList replicas(Id lid) const; // Return the logical ID associated with a replica ID. // Returns invalid if there is not exactly one match. Id logical(Id rid) const; public: // non-const methods // Insert a logical ID. // Second argument is a list of associated replica ID's. // Error if the logical ID or any of the replica ID's are // already present or the catalog cannot be updated. // Returns 0 for success. // The default implementations for the first two make use of // the last. Status insert(Id lid, const IdList& rids); // Update a logical ID. // Second argument is a list of replica ID's to be appended to // those associated with the logical ID. // Error if the logical ID is not already present, any of the // replica ID's are already present or the catalog cannot // be updated. // Returns 0 for success. Status update(Id lid, const IdList& rids); // Remove a replica from the catalog. // The logical ID is *not* removed from the table. // Error if the specified mapping is not be present. // Returns 0 for success. Status remove_replica(Id lid, Id rid); // Remove a logical ID (i.e. all its mappings) from the catalog. // Error if the logical ID is not present or catalog cannot be // updated. // Returns 0 for success. Status remove_logical(Id lid); }; } // end dset namespace // Output stream. std::ostream& operator<<(std::ostream& lhs, const dset::DatasetReplicaCatalog& rhs); #endif