X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src2%2FcreaImageIOSQLiteTreeHandler.h;h=6948675d43d05fe154702695df4fab97a2558e7f;hb=381f766db11094bd9b96f9e948527cbec24f680a;hp=a1a4f623bccd5ea830c4ffc63617a4eeb83681ff;hpb=bae4df8a3e1ea669400c3a6c44ef4aa8d90fa1ed;p=creaImageIO.git diff --git a/src2/creaImageIOSQLiteTreeHandler.h b/src2/creaImageIOSQLiteTreeHandler.h index a1a4f62..6948675 100644 --- a/src2/creaImageIOSQLiteTreeHandler.h +++ b/src2/creaImageIOSQLiteTreeHandler.h @@ -8,91 +8,132 @@ class CppSQLite3DB; namespace creaImageIO { - + + /** + * \ingroup Model + */ //======================================================================= - /// Concrete TreeHandler which manages a tree stored in a sqlite database + /// 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 + //==================================================================== + // QUERY METHODS /// Is the 'source' readable ? virtual bool IsReadable() { return true; } /// Is the 'source' writable ? virtual bool IsWritable() { return true; } - ///==================================================================== + //==================================================================== - ///==================================================================== - /// INITIALIZATION / FINALIZATION - ///==================================================================== + //==================================================================== + // INITIALIZATION / FINALIZATION + //==================================================================== - ///==================================================================== + //==================================================================== /// Opens an existing 'source' - /// Default mode is read only - /// If IsWritable and writable==true then opens in read/write mode + // 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 + // 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(); - ///==================================================================== + /// Begins a transaction + virtual void BeginTransaction(); + ///Commits results and ends transaction + virtual void EndTransaction(); + //==================================================================== - ///==================================================================== + //==================================================================== // 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. + // 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); - ///==================================================================== + //==================================================================== - ///==================================================================== + //==================================================================== + /// Returns the attribute requested. Useful for synchronization. + virtual void GetAttribute(std::string levelDescriptor, + std::string searchParam, + std::string searchVal, + std::string key, + std::string& result); + //==================================================================== + + + //==================================================================== /// 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. + // 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 + // WITHOUT altering the source, e.g. the database virtual void UnLoad(tree::Node* n); ///==================================================================== - - - ///==================================================================== - /// WRITE METHODS : WORK ONLY IN WRITE MODE + + //==================================================================== + /// Returns the top level node id for the given search param and search value + virtual void GetTopLevelNodeId(const std::string& searchParam, + const std::string& searchValue, + std::string& parent_id); ///==================================================================== + + //==================================================================== + // 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 + // 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 + // Removes the node and its descendants virtual bool Remove(tree::Node*); + // Sets an attribute of a Node + virtual bool SetAttribute(tree::Node*, + const std::string& key, + const std::string& value); + // Sets an attribute + virtual void SetAttribute(const std::string& levelDescriptor, + const std::string& key, + const std::string& value, + const std::string& searchParam, + const std::string& searchVal); + //Deletes the tuple that matches the parameters given + virtual void DeleteTuple(std::string levelDescriptor, std::string key, std::string value); + //Deletes the entries that match the parameters given + virtual void RemoveEntries(const std::string i_table, + const std::string i_attribute, + const std::string i_operand, + const std::string i_val); + //==================================================================== @@ -109,17 +150,73 @@ namespace creaImageIO /// 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); + void SQLAppendAttributesDefinition(int level, std::string& s); //====================================================================== //====================================================================== + + /// Returns the parent to which the branch defined by the attributes + // provided must be grafted tree::Node* DBGetParent( const AttributeMapType& attr); //====================================================================== //====================================================================== + + /// Loads the children of Node parent + // Can recurse to numberoflevels levels + // \return The total number of Node loaded (may be at different levels) int DBLoadChildren( tree::Node* parent, int numberoflevels = 1); //====================================================================== + //====================================================================== + + /// Appends to string s the SQL command to set the attributes values + // of node n + void SQLAppendAttributesValues(tree::Node* n, std::string& s); + //====================================================================== + + //====================================================================== + + /// Graft the branch defined by the attributes to the parent + void DBGraftToParent( tree::Node* parent, const AttributeMapType& attr); + //====================================================================== + //====================================================================== + + /// Sets an attribute of a Node and updates the database + bool DBSetAttribute(tree::Node*, + const std::string& key, + const std::string& value); + //====================================================================== + //====================================================================== + /// Sets an attribute and updates the database + void DBSetAttribute(const std::string& levelDescriptor, + const std::string& key, + const std::string& value, + const std::string& searchParam, + const std::string& searchVal); + //====================================================================== + //====================================================================== + + /// Inserts the Node in the database + void DBInsert(tree::Node* n); + //====================================================================== + + + //====================================================================== + + /// Deletes the tuple that matches the value specified in the given key and that belongs to the given level + void DBDelete(std::string levelDescriptor, std::string key, std::string value); + //====================================================================== + + //====================================================================== + + /// Recursively Removes the nodes whose parent is given as a parameter + void DBRecursiveRemoveNode(tree::Node* node); + /// Recursively Removes the nodes found in the given level with the given parent id + void DBRecursiveRemoveNode(int level, std::string parentId); + + //====================================================================== + /* /// int DBQueryNumberOfChildren(tree::Node* n); @@ -150,9 +247,9 @@ namespace creaImageIO // UpdateSummary& summary); - // - void DBRecursiveRemoveNode(tree::Node* node); + */ + /* void BuildSQLFieldsValues(tree::Node* n, std::string& str); @@ -170,6 +267,7 @@ namespace creaImageIO bool mWritable; void SetWritable(bool w) { mWritable; } bool GetWritable() const { return mWritable; } + bool mIsAdding; /* struct TypeId