CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondCore/ORA/src/IDatabaseSchema.h

Go to the documentation of this file.
00001 #ifndef INCLUDE_ORA_IDATABASESCHEMA_H
00002 #define INCLUDE_ORA_IDATABASESCHEMA_H
00003 
00004 //
00005 #include <string> 
00006 #include <map> 
00007 #include <set> 
00008 #include <vector>
00009 
00010 namespace coral {
00011   class ISchema;
00012   class ITable;
00013 }
00014 
00015 namespace ora {
00016 
00017   std::string poolSchemaVersion();
00018 
00019   void setTableAccessPermission( coral::ITable& table, const std::string& principal, bool forWrite );
00020 
00021   class IDatabaseTable {
00022     public:
00023     explicit IDatabaseTable( coral::ISchema& schema ); 
00024     virtual ~IDatabaseTable(){}
00025 
00026     virtual std::string name() = 0;
00027     virtual bool exists() = 0;
00028     virtual void create( ) = 0;
00029     virtual void drop() = 0;
00030     virtual void setAccessPermission( const std::string& principal, bool forWrite );
00031     coral::ISchema& schema();
00032   private:
00033     coral::ISchema& m_schema;
00034     
00035   };
00036 
00037   class IMainTable: public IDatabaseTable {
00038     public:
00039     static std::string versionParameterName();
00040     static std::string userSchemaVersionParameterName();
00041     public:
00042     explicit IMainTable( coral::ISchema& schema ); 
00043     virtual ~IMainTable(){}
00044     virtual void setParameter( const std::string& paramName, const std::string& paramValue ) = 0;
00045     virtual bool getParameters( std::map<std::string,std::string>& destination ) = 0;
00046     virtual std::string schemaVersion() = 0;
00047   };
00048 
00049   class ISequenceTable : public IDatabaseTable{
00050     public:
00051     explicit ISequenceTable( coral::ISchema& schema ); 
00052     virtual ~ISequenceTable(){
00053     }
00054 
00055     virtual bool add( const std::string& sequenceName ) = 0;
00056     virtual bool getLastId( const std::string& sequenceName, int& lastId ) = 0;
00057     virtual void sinchronize( const std::string& sequenceName, int lastValue ) = 0;
00058     virtual void erase( const std::string& sequenceName ) = 0;
00059   };
00060 
00061   struct MappingRawElement {
00062       static std::string emptyScope();
00063       MappingRawElement();
00064       MappingRawElement(const MappingRawElement& rhs);
00065       MappingRawElement& operator==(const MappingRawElement& rhs);
00066       std::string scopeName;
00067       std::string variableName;
00068       std::string variableType;
00069       std::string elementType;
00070       std::string tableName;
00071       std::vector<std::string> columns;
00072   };
00073 
00074   struct MappingRawData {
00075       MappingRawData();
00076       explicit MappingRawData( const std::string& version );
00077       MappingRawElement& addElement( int elementId );
00078       std::string version;
00079       std::map< int, MappingRawElement> elements;
00080   };
00081 
00082 
00083   struct ContainerHeaderData {
00084       ContainerHeaderData();
00085       ContainerHeaderData( int contId,
00086                            const std::string& classN,
00087                            unsigned int numberObj );
00088       ContainerHeaderData( const ContainerHeaderData& rhs );
00089       ContainerHeaderData& operator=( const ContainerHeaderData& rhs );
00090       int id;
00091       std::string className;
00092       unsigned int numberOfObjects;
00093   };
00094   
00095   class IContainerHeaderTable: public IDatabaseTable  {
00096     public:
00097     explicit IContainerHeaderTable( coral::ISchema& schema ); 
00098     virtual ~IContainerHeaderTable(){
00099     }
00100     virtual bool getContainerData( std::map<std::string, ContainerHeaderData>& destination ) = 0;
00101     virtual void addContainer( int id, const std::string& containerName, const std::string& className ) = 0;
00102     virtual void removeContainer( int id ) = 0;
00103     virtual bool lockContainer( int id, ContainerHeaderData& destination ) = 0;
00104     virtual void incrementNumberOfObjects( int id  ) = 0;
00105     virtual void decrementNumberOfObjects( int id  ) = 0;
00106     virtual void updateNumberOfObjects( const std::map<int,unsigned int>& numberOfObjectsForContainerIds ) = 0;
00107   };
00108 
00109   class IMappingSchema {
00110     public:
00111     virtual ~IMappingSchema(){
00112     }
00113     virtual bool getVersionList( std::set<std::string>& destination ) = 0;
00114     virtual bool getMapping( const std::string& version, MappingRawData& destination ) = 0;
00115     virtual void storeMapping( const MappingRawData& data ) = 0;
00116     virtual void removeMapping( const std::string& version ) = 0;
00117     virtual bool getContainerTableMap( std::map<std::string, int>& destination ) = 0;
00118     virtual bool getMappingVersionListForContainer( int containerId, std::set<std::string>& destination, bool onlyDependency=false ) = 0;
00119     virtual bool getDependentClassesInContainerMapping( int containerId, std::set<std::string>& destination ) = 0;
00120     virtual bool getClassVersionListForMappingVersion( const std::string& mappingVersion, std::set<std::string>& destination ) = 0;
00121     virtual bool getClassVersionListForContainer( int containerId, std::map<std::string,std::string>& versionMap ) = 0;
00122     virtual bool getMappingVersionListForTable( const std::string& tableName, std::set<std::string>& destination ) = 0;
00123     virtual bool selectMappingVersion( const std::string& classId, int containerId, std::string& destination ) = 0;
00124     virtual bool containerForMappingVersion( const std::string& mappingVersion, int& destination ) = 0;
00125     virtual void insertClassVersion( const std::string& className, const std::string& classVersion, const std::string& classId,
00126                                      int dependencyIndex, int containerId, const std::string& mappingVersion )= 0;
00127     virtual void setMappingVersion( const std::string& classId, int containerId, const std::string& mappingVersion ) = 0;
00128   };
00129 
00130   class INamingServiceTable: public IDatabaseTable  {
00131     public:
00132     explicit INamingServiceTable( coral::ISchema& schema ); 
00133     virtual ~INamingServiceTable(){
00134     }
00135     virtual void setObjectName( const std::string& name, int contId, int itemId ) = 0;
00136     virtual bool eraseObjectName( const std::string& name ) = 0;
00137     virtual bool eraseAllNames() = 0;
00138     virtual bool getObjectByName( const std::string& name, std::pair<int,int>& destination ) = 0;
00139     virtual bool getNamesForObject( int contId, int itemId, std::vector<std::string>& destination ) = 0;
00140     virtual bool getNamesForContainer( int contId, std::vector<std::string>& destination ) = 0;
00141     virtual bool getAllNames( std::vector<std::string>& destination ) = 0;
00142   };
00143 
00144   class IDatabaseSchema {
00145     public:
00146 
00147     static IDatabaseSchema* createSchemaHandle( coral::ISchema& schema );
00148 
00149     public:
00150     IDatabaseSchema( coral::ISchema& schema );
00151     virtual ~IDatabaseSchema(){
00152     }
00153 
00154     virtual bool exists() = 0;
00155     virtual void create( const std::string& userSchemaVersion ) = 0;
00156     virtual void drop() = 0;
00157     virtual void setAccessPermission( const std::string& userName, bool forWrite ) = 0;
00158 
00159     virtual IMainTable& mainTable() = 0;
00160     virtual ISequenceTable& sequenceTable() = 0;
00161     virtual IDatabaseTable& mappingVersionTable() = 0;
00162     virtual IDatabaseTable& mappingElementTable() = 0;
00163     virtual IContainerHeaderTable& containerHeaderTable() = 0;
00164     virtual IDatabaseTable& classVersionTable() = 0;
00165     virtual IMappingSchema& mappingSchema() = 0;
00166     virtual INamingServiceTable& namingServiceTable() = 0;
00167     virtual bool testDropPermission() = 0;
00168     coral::ISchema& storageSchema();
00169     
00170     private:
00171     coral::ISchema& m_schema;
00172   };
00173   
00174 }
00175 
00176 #endif
00177   
00178     
00179