CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CondCore/ORA/src/PoolDatabaseSchema.h

Go to the documentation of this file.
00001 #ifndef INCLUDE_ORA_POOLDATABASESCHEMA_H
00002 #define INCLUDE_ORA_POOLDATABASESCHEMA_H
00003 
00004 #include "IDatabaseSchema.h"
00005 // externals
00006 #include "CoralBase/AttributeList.h"
00007 
00008 namespace ora {
00009 
00010     struct PoolDbCacheData {
00011       PoolDbCacheData();
00012         
00013       PoolDbCacheData( int id, const std::string& name, const std::string& className,
00014                        const std::string& mappingVersion, unsigned int nobjWritten );
00015 
00016       ~PoolDbCacheData();
00017 
00018       PoolDbCacheData( const PoolDbCacheData& rhs );
00019 
00020       PoolDbCacheData& operator=( const PoolDbCacheData& rhs );
00021 
00022       int m_id;
00023       std::string m_name;
00024       std::string m_className;
00025       std::string m_mappingVersion;
00026       unsigned int m_nobjWr;
00027   };
00028   
00029   class PoolDbCache {
00030     public:
00031     PoolDbCache();
00032     ~PoolDbCache();
00033     void add( int id, const PoolDbCacheData& data );
00034     const std::string& nameById( int id );
00035     int idByName( const std::string& name );
00036     PoolDbCacheData& find( int id );
00037     void remove( int id );
00038     std::map<std::string,PoolDbCacheData* >& sequences();
00039     void clear();
00040     
00041     private:
00042     PoolDbCacheData m_databaseData;
00043     PoolDbCacheData m_mappingData;
00044     std::map<int,PoolDbCacheData > m_idMap;
00045     std::map<std::string,PoolDbCacheData* > m_sequences;
00046   };
00047 
00048   class PoolMainTable: public IMainTable {
00049     public:
00050     static std::string version();
00051     static std::string tableName();
00052     public:
00053     explicit PoolMainTable( coral::ISchema& dbSchema );
00054     virtual ~PoolMainTable();
00055     void setParameter( const std::string& paramName, const std::string& paramValue );
00056     bool getParameters( std::map<std::string,std::string>& destination );
00057     std::string schemaVersion();
00058     public:
00059     std::string name();
00060     bool exists();
00061     void create();
00062     void drop();
00063   };
00064 
00065   
00066   class PoolSequenceTable : public ISequenceTable{
00067     public:
00068     static std::string tableName();
00069     static std::string sequenceNameColumn();
00070     static std::string sequenceValueColumn();    
00071     public:
00072     explicit PoolSequenceTable( coral::ISchema& dbSchema );
00073     virtual ~PoolSequenceTable();
00074     void init( PoolDbCache& dbCache );
00075     bool add( const std::string& sequenceName );
00076     bool getLastId( const std::string& sequenceName, int& lastId );
00077     void sinchronize( const std::string& sequenceName, int lastValue );
00078     void erase( const std::string& sequenceName );
00079     public:
00080     std::string name();
00081     bool exists();
00082     void create();
00083     void drop();    
00084     private:
00085     PoolDbCache* m_dbCache;
00086   };
00087 
00088   class PoolMappingVersionTable: public IDatabaseTable {
00089     public:
00090     static std::string tableName();
00091     static std::string mappingVersionColumn();
00092     static std::string containerNameColumn();
00093     public:
00094     explicit PoolMappingVersionTable( coral::ISchema& dbSchema  );
00095     virtual ~PoolMappingVersionTable();
00096     public:
00097     std::string name();
00098     bool exists();
00099     void create();
00100     void drop();
00101   };
00102   
00103   class PoolMappingElementTable: public IDatabaseTable {
00104     public:
00105     static std::string tableName();
00106     static std::string mappingVersionColumn();
00107     static std::string elementIdColumn();
00108     static std::string elementTypeColumn();
00109     static std::string scopeNameColumn();
00110     static std::string variableNameColumn();
00111     static std::string variableParIndexColumn();
00112     static std::string variableTypeColumn();
00113     static std::string tableNameColumn();
00114     static std::string columnNameColumn();
00115     public:
00116     explicit PoolMappingElementTable( coral::ISchema& dbSchema  );
00117     virtual ~PoolMappingElementTable();
00118     public:
00119     std::string name();
00120     bool exists();
00121     void create();
00122     void drop();
00123   };
00124   
00125   class PoolContainerHeaderTable: public IContainerHeaderTable {
00126     public:
00127     static std::string tableName();
00128     static std::string containerIdColumn();
00129     static std::string containerNameColumn();
00130     static std::string containerTypeColumn();
00131     static std::string tableNameColumn();
00132     static std::string classNameColumn();
00133     static std::string baseMappingVersionColumn();
00134     static std::string numberOfWrittenObjectsColumn();
00135     static std::string numberOfDeletedObjectsColumn();
00136     static std::string homogeneousContainerType();
00137     public:
00138     explicit PoolContainerHeaderTable( coral::ISchema& dbSchema );
00139     virtual ~PoolContainerHeaderTable();
00140     void init( PoolDbCache& dbCache );
00141     bool getContainerData( std::map<std::string, ContainerHeaderData>& destination );
00142     void addContainer( int id, const std::string& containerName, const std::string& className );
00143     void removeContainer( int id );
00144     bool lockContainer( int id, ContainerHeaderData& destination );
00145     void incrementNumberOfObjects( int id  );
00146     void decrementNumberOfObjects( int id  );
00147     void updateNumberOfObjects( const std::map<int,unsigned int>& numberOfObjectsForContainerIds );
00148     public:
00149     std::string name();
00150     bool exists();
00151     void create();
00152     void drop();
00153     private:
00154     PoolDbCache* m_dbCache;
00155   };
00156 
00157   class PoolClassVersionTable: public IDatabaseTable {
00158     public:
00159     static std::string tableName();
00160     static std::string classVersionColumn();
00161     static std::string containerNameColumn();
00162     static std::string mappingVersionColumn();
00163     public:
00164     explicit PoolClassVersionTable( coral::ISchema& dbSchema  );
00165     virtual ~PoolClassVersionTable();
00166     public:
00167     std::string name();
00168     bool exists();
00169     void create();
00170     void drop();
00171   };
00172 
00173   class PoolMappingSchema: public IMappingSchema {
00174     public:
00175     static std::string emptyScope();
00176     public:
00177     explicit PoolMappingSchema( coral::ISchema& dbSchema );
00178     virtual ~PoolMappingSchema();
00179     void init( PoolDbCache& dbCache );
00180     public:
00181     bool getVersionList( std::set<std::string>& destination );
00182     bool getMapping( const std::string& version, MappingRawData& destination );
00183     void storeMapping( const MappingRawData& mapping );
00184     void removeMapping( const std::string& version );
00185     bool getContainerTableMap( std::map<std::string, int>& destination );
00186     bool getMappingVersionListForContainer( int containerId, std::set<std::string>& destination, bool onlyDependency=false );
00187     bool getMappingVersionListForTable( const std::string& tableName, std::set<std::string>& destination );
00188     bool getDependentClassesInContainerMapping( int containerId, std::set<std::string>& destination );
00189     bool getClassVersionListForMappingVersion( const std::string& mappingVersion, std::set<std::string>& destination );
00190     bool getClassVersionListForContainer( int containerId, std::map<std::string,std::string>& versionMap );
00191     bool selectMappingVersion( const std::string& classId, int containerId, std::string& destination );
00192     bool containerForMappingVersion( const std::string& mappingVersion, int& destination );
00193     void insertClassVersion( const std::string& className, const std::string& classVersion, const std::string& classId,
00194                              int dependencyIndex, int containerId, const std::string& mappingVersion );
00195     void setMappingVersion( const std::string& classId, int containerId, const std::string& mappingVersion );
00196     private:
00197     coral::ISchema& m_schema;
00198     PoolDbCache* m_dbCache;
00199   };
00200 
00201   class CondMetadataTable : public INamingServiceTable {
00202     public:
00203     static std::string& tableName();
00204     static std::string& objectNameColumn();
00205     static std::string& tokenColumn();
00206     static std::string& timetypeColumn();
00207    public: 
00208     CondMetadataTable( coral::ISchema& dbSchema, PoolDbCache& dbCache );
00209     virtual ~CondMetadataTable();
00210     void setObjectName( const std::string& name, int contId, int itemId );
00211     bool eraseObjectName( const std::string& name );
00212     bool eraseAllNames();
00213     bool getObjectByName( const std::string& name, std::pair<int,int>& destination );
00214     bool getNamesForObject( int contId, int itemId, std::vector<std::string>& destination );
00215     bool getNamesForContainer( int contId, std::vector<std::string>& destination );
00216     bool getAllNames( std::vector<std::string>& destination );
00217    public:
00218     std::string name();
00219     bool exists();
00220     void create();
00221     void drop();    
00222   private:
00223     PoolDbCache& m_dbCache;
00224   };
00225   
00226   class PoolDatabaseSchema: public IDatabaseSchema {
00227     public:
00228     static bool existsMainTable( coral::ISchema& dbSchema );
00229     public:
00230     explicit PoolDatabaseSchema( coral::ISchema& dbSchema );
00231     virtual ~PoolDatabaseSchema();
00232 
00233     bool exists();
00234     void create( const std::string& userSchemaVersion );
00235     void drop();
00236     void setAccessPermission( const std::string& principal, bool forWrite );
00237 
00238     IMainTable& mainTable();
00239     ISequenceTable& sequenceTable();
00240     IDatabaseTable& mappingVersionTable();
00241     IDatabaseTable& mappingElementTable();
00242     IContainerHeaderTable& containerHeaderTable();
00243     IDatabaseTable& classVersionTable();
00244     IMappingSchema& mappingSchema();
00245     INamingServiceTable& namingServiceTable();
00246     bool testDropPermission(){
00247       return false;
00248     }
00249 
00250     private:
00251     coral::ISchema& m_schema;
00252     PoolDbCache m_dbCache;
00253     PoolMainTable m_mainTable;
00254     PoolSequenceTable m_sequenceTable;
00255     PoolMappingVersionTable m_mappingVersionTable;
00256     PoolMappingElementTable m_mappingElementTable;
00257     PoolContainerHeaderTable m_containerHeaderTable;
00258     PoolClassVersionTable m_classVersionTable;
00259     PoolMappingSchema m_mappingSchema;
00260     CondMetadataTable m_metadataTable;
00261   };  
00262   
00263 }
00264 
00265 #endif
00266   
00267