// SqlGenericRepository.h #ifndef SqlGenericRepository_H #define SqlGenericRepository_H // Vinay Sambamurthy // June 2004 // // Interface for access to a GenericRepository which uses an // underlying SqlTable. // // Any of the names registered for SqlTable creation may be used // to construct a generic repository of this type. // The table has one of the three following schema: // 1. uid, sxml // 2. idhi, idlo, sxml // 3. vidh, vidl, sxml // // This repository may or may not manage (delete) the underlying SQL // table. // // The table is required to hold an entry with id "0-0" and name // same as the type, e.g. "DatasetRepository". // // If this name is followed by a space and a connection string, // then the creator for this repository will construct a cache // repository with this class as the cache and the connection as // the primary. #include "dataset_catalog/GenericRepository.h" #include "dataset_sql/SqlTable.h" #include #include #include namespace dset { class SqlGenericRepository : public GenericRepository { public: // typedefs typedef std::vector NameList; private: // data SqlTable* m_ptable; bool m_valid; bool m_manage; public: // Constructors and destructor // Constructor. // Repository manages the table. SqlGenericRepository(SqlTable* table); // Constructor. // Repository does not manage the table. SqlGenericRepository(SqlTable& table); // Destructor. ~SqlGenericRepository(); public: // const functions // Is this a valid repository? bool is_valid() const; // Return the type of repository. // Returns an empty string on error. std::string repository_type() const; // Return the primary connection string if this table // is flagged to serve as a cache. // Returns blank if not. std::string cache_connection() const; // Return the error code. int error() const; // Return a string describing an error. std::string error_string(int ecode) const; // Is the element in the repository? // Returns true if element is present. bool has(std::string id) const; // Retrieve an element from repository. // Returns an empty string if element is invalid. std::string get(std::string id) const; // Return a list of elements. int mget(const IdList& ids, ElementList& eles) const; // Retrieve the time the entry was made. time_t time(std::string sid) const; // Return the number of entries in the repository. size_type size() const; // Return the number of entries made since a given time (inclusive). size_type size_since(time_t time) const; // Get all the IDs in the repository. // Argument is the maximum # ID's to return. IdList get_ids(size_type maxent =100) const; // Get all the IDs entered since the given time. // Second argument is the maximum # ID's to return. IdList get_ids_since(time_t time, size_type maxent =100) const; public: // non-const functions // Insert a new element into repository. // Returns 0 on success. int insert(std::string id, std::string element) const; // Delete an element from repository. // Returns 0 on success. int remove(std::string id) const; }; } // end namespace dset #endif