// DatasetRepository.h #ifndef DatasetRepository_H #define DatasetRepository_H // David Adamsmurthy // July 2004 // // Interface for database holding Dataset objects // User is provided means to insert and extract dataset objects. // This class provides a transient repository and has // the read and write methods to provide persistence. // // This class hold a CatalogError status that is reset when any method // is called. // // The normal usage is as a singleton: // DatasetRepository* pdr = default_instance(); // An object of this type is created as the default. // // This class also manages the GenericRepository that it uses // if the manage flag is set. #include "dataset_catalog/CatalogError.h" #include "dataset_catalog/GenericRepository.h" #include "dataset_id/DatasetId.h" #include "dataset_base/Dataset.h" namespace dset { class DatasetRepository { public: // typedefs typedef GenericRepository::size_type size_type; typedef CatalogError::Status Status; typedef std::map RepMap; typedef std::map ManageMap; private: // data // Transient database. RepMap m_dss; ManageMap m_mgs; GenericRepository* m_prep; mutable Status m_error; bool m_manage; private: // Hidden function. // No copying allowed. DatasetRepository(const DatasetRepository&); // No assignment allowed. DatasetRepository& operator=(const DatasetRepository&); public: // static functions // Return the default concrete instance of this class. // First pass, use set_default_instance or // define an invalid catalog if this fails. static DatasetRepository& default_instance(); // Set the the default instance of this class with a connection // string. Fails with no change if the connection cannot be resolved. // Returns 0 for success. static int set_default_instance(std::string name = ""); // Assign an empty dataset repository as the default by // 1. creating an empty SQLRESULT dataset repository dr.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: // member functions // Default Constructor. DatasetRepository(); // Constructor from a generic repository. explicit DatasetRepository(GenericRepository* rep); // Constructor from connection string. explicit DatasetRepository(std::string name); // Destructor. ~DatasetRepository(); // Is this a valid repository? bool is_valid() const; // Error code. int error() const; // Error message. std::string error_message() const; // Return the number of entries. size_type size() const; // Return if the repository has a given ID either in transient // or persistent store. bool has(DatasetId id) const; // Return the dataset associated with an ID. // If readnull is set, then an attempt is made to fetch the // dataset from persistent store if the transient value is null. const Dataset* extract(DatasetId id, bool readnull =false); // Return the datasets associated with a list of ID's. // A null entry is returned for any dataset that cannot be found. // Returns 0 if all entries are found not null. // Returns nonzero if any entries are not found or are null or for // any other error. int extract(const DatasetIdList& dids, DatasetList& dsts, bool readnull =false); // Put a dataset in the repository. // The ID is returned. // ID is invalid if the write fails. // The repository manages (deletes) the dataset if manage is true. DatasetId insert(const Dataset* pds, bool manage =false); // Remove a dataset from repository. // Returns 0 on success. int remove(DatasetId id); // Verify all entries bool verify() const; // Output stream. std::ostream& ostr(std::ostream& str) const; // Web page. // entry: // blank to show entire repository // did=123-456 to show dataset with ID 123-456 Text web_page(std::string baseurl, std::string entry); }; } // end namespace dset // Output stream. std::ostream& operator<<(std::ostream& lhs, const dset::DatasetRepository& rhs); #endif