// GenericRepository.h #ifndef GenericRepository_H #define GenericRepository_H // Vinay Sambamurthy // June 2004 // Modified by David Adams - November 2004 // // Abstract interface for a generic repository // // Provides a static method to create a generic repository from a // connection string. The connection is resolved before creation. // Subclasses are expected to register functions to make this creation // possible. #include "dataset_sql/SqlResult.h" #include #include #include #include namespace dset { class GenericRepository { public: // typedefs // List of IDs typedef std::vector IdList; typedef IdList::size_type size_type; typedef std::vector ElementList; // Function to create a generic repository. // Inputs are the repository type and the connection string. typedef GenericRepository* (*Create) (std::string type, std::string conn); public: // static member functions // Register a creator. static int register_creator(std::string name, Create pfun); // Create a generic repository. // Arguments are the same as those for the creator function. // Connection string is of the form NAME:... or ...@NAME:... . // The connection is resolved before creating repository. // The creator registered with name NAME is used. static GenericRepository* create(std::string type, std::string conn =""); public: // non-static member functions // Constructor. GenericRepository(); // Destructor. virtual ~GenericRepository(); public: // non-static member functions // Is this a valid repository? // Default returns true iff error() returns 0. virtual bool is_valid() const; // Return the error code. virtual int error() const =0; // Return a string describing an error. // error. virtual std::string error_string(int ecode) const =0; // Return the type of repository. virtual std::string repository_type() const =0; // Return the cache connection string. // Blank if this repository is not configured as a cache. // Default implementation returns blank. virtual std::string cache_connection() const; // Is the element in the repository? // Returns true if element is present. virtual bool has(std::string sid) const =0; // Retrieve an element from repository. virtual std::string get(std::string sid) const =0; // Retrieve a collection of elements from repository. // Elements are appended to the input list. // If successful, the number of appended is equal to the size of // the input list. // Implementation here simply calls get(sid). // Returns 0 for success. virtual int mget(const IdList& sids, ElementList& eles) const; // Retrieve the time the entry was made. // Return 0 if entry does not exist or information is not available. virtual time_t time(std::string sid) const =0; // Return the number of entries in the repository. virtual size_type size() const =0; // Return the number of entries made since a given time (inclusive). virtual size_type size_since(time_t time) const =0; // Get all the IDs in the repository. // Argument is the maximum # ID's to return. virtual IdList get_ids(size_type maxent =100) const =0; // Get all the IDs entered since the given time. // Second argument is the maximum # ID's to return. virtual IdList get_ids_since(time_t time, size_type maxent =100) const =0; // Return if the current credential authorizes removal of id // or insertion if id is blank. // For now, authorization is granted to any nonblank credential owner. bool authorized(std::string id ="") const; public: // non-static member functions // Insert a new element into repository. virtual int insert(std::string id, std::string element) const =0; // Delete an element from repository. virtual int remove(std::string id) const =0; }; } // end namespace dset #endif