#ifndef __creaImageIOSQLiteTreeHandler_h_INCLUDED__ #define __creaImageIOSQLiteTreeHandler_h_INCLUDED__ #include class CppSQLite3DB; namespace creaImageIO { /** * \ingroup Model */ //======================================================================= /// Concrete TreeHandler which manages a tree stored in a sqlite database class SQLiteTreeHandler : virtual public TreeHandler { public: ///==================================================================== /// Ctor with database file name SQLiteTreeHandler(const std::string& filename); /// Dtor virtual ~SQLiteTreeHandler(); ///==================================================================== ///==================================================================== /// Returns the sqlite db file name const std::string& GetFileName() const { return mFileName; } ///==================================================================== ///==================================================================== /// QUERY METHODS /// Is the 'source' readable ? virtual bool IsReadable() { return true; } /// Is the 'source' writable ? virtual bool IsWritable() { return true; } ///==================================================================== ///==================================================================== /// INITIALIZATION / FINALIZATION ///==================================================================== ///==================================================================== /// Opens an existing 'source' /// Default mode is read only /// If IsWritable and writable==true then opens in read/write mode virtual bool Open(bool writable = false); /// Closes the 'source' virtual bool Close(); /// Creates a new 'source' /// Default mode is read only /// If IsWritable and writable==true then opens in read/write mode virtual bool Create(bool writable = false); /// Destroys the 'source' virtual bool Destroy(); ///==================================================================== ///==================================================================== // READ METHODS ///==================================================================== ///==================================================================== /// Returns the number of children of the Node *WITHOUT LOADING THEM* /// REM : The Tree itself is a Node and asking for its number of /// children returns the number of children of level 1. virtual unsigned int GetNumberOfChildren(tree::Node* n); ///==================================================================== ///==================================================================== /// Recursively loads the children of node 'parent' until maxlevel /// is reached. /// If parent == NULL or parent == tree then starts with the 'children' of /// the tree itself. /// Returns the total number of children loaded. virtual int LoadChildren(tree::Node* parent, int maxlevel); ///==================================================================== ///==================================================================== /// Unloads the Node and its descendants /// WITHOUT altering the source, e.g. the database virtual void UnLoad(tree::Node* n); ///==================================================================== ///==================================================================== /// WRITE METHODS : WORK ONLY IN WRITE MODE ///==================================================================== /// Adds a branch in the tree with the attributes provided /// returns the Level in the tree where the branch was connected /// (-1 for error, 0 for top level, etc. ) /// Of course the branch is loaded on exit virtual int AddBranch( const AttributeMapType& attr ); /// Removes the node and its descendants virtual bool Remove(tree::Node*); //==================================================================== protected: //====================================================================== /// Open the database bool DBOpen(); /// Import the Tree::Description from database (verifies the structure) bool DBImportTreeDescription(); //====================================================================== //====================================================================== // Creation /// Creates a new database on disk and the tables bool DBCreate(); /// Appends to string s the SQL command to create the attributes of a given level void AppendAttributesSQLDefinition(int level, std::string& s); //====================================================================== //====================================================================== tree::Node* DBGetParent( const AttributeMapType& attr); //====================================================================== //====================================================================== int DBLoadChildren( tree::Node* parent, int numberoflevels = 1); //====================================================================== /* /// int DBQueryNumberOfChildren(tree::Node* n); // Insertion bool DBInsert(tree::Node* alien_node) ; //, UpdateSummary& summary); // std::string DBGetNodeId(tree::Node* node, const std::string& parent_id); tree::Node* GetNodeFromTypeId(int level, const std::string& id); // tree::Node* DBGetOrCreateNode(tree::Node* alien_node, tree::Node* internal_parent, std::string parentid, std::string& created_id); // UpdateSummary& summary); tree::Node* DBGetOrCreateParent(tree::Node* alien_node, std::string& parent_id); // UpdateSummary& summary); void DBRecursiveGetOrCreateNode(tree::Node* alien_node, tree::Node* parent, const std::string& parent_id); // UpdateSummary& summary); // void DBRecursiveRemoveNode(tree::Node* node); void BuildSQLFieldsValues(tree::Node* n, std::string& str); tree::Node* GetChildrenLike(tree::Node* internal_parent, tree::Node* alien_node); */ private: /// The DB CppSQLite3DB* mDB; /// The physical location associated to the DicomDatabase (directory, db file...) std::string mFileName; /// Is the DB writable ? bool mWritable; void SetWritable(bool w) { mWritable; } bool GetWritable() const { return mWritable; } /* struct TypeId { int type; std::string id; bool operator< (const TypeId& o) const { return ((type TypeIdToNodeMapType; TypeIdToNodeMapType mTypeIdToNodeMap; */ }; // EO class SQLiteTreeHandler //======================================================================= } // EO namespace creaImageIO // EOF #endif