// JobRepository.h #ifndef JobRepository_H #define JobRepository_H // David Adamsmurthy // July 2004 // // Interface for database holding Job objects // User is provided means to insert and extract job 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: // JobRepository* 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 "dial_job/JobId.h" #include "dial_job/JobIdList.h" #include "dial_job/Job.h" namespace dial { class JobRepository { public: // typedefs typedef dset::GenericRepository::size_type size_type; typedef dset::CatalogError::Status Status; typedef JobIdList IdList; typedef std::map RepMap; typedef std::map ManageMap; private: // data // Transient database. RepMap m_dss; ManageMap m_mgs; dset::GenericRepository* m_prep; mutable Status m_error; bool m_manage; // Web page. mutable Text m_wp; private: // Hidden function. // No copying allowed. JobRepository(const JobRepository&); // No assignment allowed. JobRepository& operator=(const JobRepository&); 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 JobRepository& 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 job repository as the default by // 1. creating an empty SQLRESULT job repository jr.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. JobRepository(); // Constructor from a generic repository. explicit JobRepository(dset::GenericRepository* rep); // Constructor from connection string. explicit JobRepository(std::string name); // Destructor. ~JobRepository(); // 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 the number of entries since a given time. size_type size_since(time_t time) const; // Return if the repository has a given ID either in transient // or persistent store. bool has(JobId id) const; // Return the list of ID's in the repository. // Argument is the maximum number to return. IdList get_ids(size_t maxent =100000) const; // Return the list of ID's added since a given time. // Argument is the maximum number to return. IdList get_ids_since(time_t time, size_t maxent =100000) const; // Return the job associated with an ID. // If readnull is set, then an attempt is made to fetch the // job from persistent store if the transient value is null. const Job* extract(JobId id, bool readnull =false); // Return a copy of a job. // The caller has management of the returned copy. Job* copy(JobId jid) const; // Return the time the job was inserted in the repository. time_t time(JobId jid) const; // Put a job in the repository. // The ID is returned. // ID is invalid if the write fails. // The repository manages (deletes) the job if manage is true. JobId insert(const Job* pds, bool manage =false); // Remove a job from repository. // Returns 0 on success. int remove(JobId id); // Verify all entries bool verify() const; // Output stream. std::ostream& ostr(std::ostream& str) const; // Web page summary. // urls is a map of base URL's indexed by name // entry specifies the content of the page with the following options: // maxent=100 to set the max number of entries // jid=123-456 to display the corresponding job // prep is a pointer to the repository where subjobs may be found // The page is referenced with the path baseurl?entry const Text& web_page(const Job::UrlMap& urls, std::string entry, JobRepository* prep); }; } // end namespace dset // Output stream. std::ostream& operator<<(std::ostream& lhs, const dial::JobRepository& rhs); #endif