CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
ora::MappingToSchema Class Reference

#include <MappingToSchema.h>

Public Member Functions

void alter (const MappingTree &mapping)
 
bool check (const MappingTree &mapping)
 
void create (const MappingTree &mapping)
 
 MappingToSchema (coral::ISchema &schema)
 Constructor. More...
 
 ~MappingToSchema ()
 Destructor. More...
 

Private Member Functions

void createTable (const TableInfo &tableInfo)
 

Private Attributes

coral::ISchema & m_schema
 Reference to the schema in use. More...
 

Detailed Description

Helper class which is used for the creation of the tables which hold the object data, conforming to a given object/relational mapping.

Definition at line 19 of file MappingToSchema.h.

Constructor & Destructor Documentation

ora::MappingToSchema::MappingToSchema ( coral::ISchema &  schema)
explicit

Constructor.

Definition at line 16 of file MappingToSchema.cc.

16  :
17  m_schema( schema ){
18 }
coral::ISchema & m_schema
Reference to the schema in use.
ora::MappingToSchema::~MappingToSchema ( )

Destructor.

Definition at line 20 of file MappingToSchema.cc.

20  {
21 }

Member Function Documentation

void ora::MappingToSchema::alter ( const MappingTree mapping)

Definition at line 78 of file MappingToSchema.cc.

References funct::false, i, asciidump::table, ora::MappingTree::tables(), and ora::throwException().

Referenced by ora::ContainerSchema::evolve().

78  {
79  std::vector<TableInfo> tableList = mapping.tables();
80  for( std::vector<TableInfo>::iterator iT = tableList.begin();
81  iT != tableList.end(); ++iT ){
82  if( m_schema.existsTable( iT->m_tableName ) ){
83  std::set<std::string> allCols;
84  coral::ITable& table = m_schema.tableHandle( iT->m_tableName );
85  // check all of the columns
86  for( std::vector<std::string>::const_iterator iCol = iT->m_idColumns.begin();
87  iCol != iT->m_idColumns.end(); ++iCol ){
88  try {
89  table.description().columnDescription( *iCol );
90  } catch ( const coral::InvalidColumnNameException&){
91  // not recoverable: id columns cannot be added.
92  throwException("ID Column \""+*iCol+"\" has not been found in table \""+iT->m_tableName+"\" as required in the mapping.",
93  "MappingToSchema::alter");
94  }
95  allCols.insert( *iCol );
96  }
97  for( std::map<std::string,std::string>::const_iterator iDataCol = iT->m_dataColumns.begin();
98  iDataCol != iT->m_dataColumns.end(); ++iDataCol ){
99  try {
100  const coral::IColumn& colDescr = table.description().columnDescription( iDataCol->first );
101  // check the type
102  if( colDescr.type() != iDataCol->second ){
103  // not recoverable: column type cannot be changed.
104  throwException("ID Column \""+iDataCol->first+"\" in table \""+iT->m_tableName+"\" is type \""+colDescr.type()+
105  "\" while is required of type \""+iDataCol->second+"\" in the mapping.",
106  "MappingToSchema::alter");
107  }
108 
109  } catch ( const coral::InvalidColumnNameException&){
110  table.schemaEditor().insertColumn( iDataCol->first, iDataCol->second );
111  table.schemaEditor().setNotNullConstraint( iDataCol->first );
112  }
113  allCols.insert( iDataCol->first );
114  }
115  // then check the unused columns for not null constraint
116  int ncols = table.description().numberOfColumns();
117  for( int i=0;i<ncols;i++ ){
118  const coral::IColumn& colDescr = table.description().columnDescription( i );
119  std::set<std::string>::const_iterator iC = allCols.find( colDescr.name() );
120  if( iC == allCols.end() ){
121  table.schemaEditor().setNotNullConstraint( colDescr.name(), false );
122  }
123  }
124  } else {
125  createTable( *iT );
126  }
127  }
128 }
list table
Definition: asciidump.py:386
int i
Definition: DBlmapReader.cc:9
coral::ISchema & m_schema
Reference to the schema in use.
void createTable(const TableInfo &tableInfo)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
bool ora::MappingToSchema::check ( const MappingTree mapping)

Definition at line 130 of file MappingToSchema.cc.

References convertSQLiteXML::ok, and ora::MappingTree::tables().

130  {
131  bool ok = true;
132  std::vector<TableInfo> tableList = mapping.tables();
133  for( std::vector<TableInfo>::iterator iT = tableList.begin();
134  iT != tableList.end(); ++iT ){
135  if( m_schema.existsTable( iT->m_tableName ) ){
136  ok = false;
137  }
138  }
139  return ok;
140 }
coral::ISchema & m_schema
Reference to the schema in use.
void ora::MappingToSchema::create ( const MappingTree mapping)

Definition at line 69 of file MappingToSchema.cc.

References ora::MappingTree::tables().

Referenced by ora::ContainerSchema::create().

69  {
70  std::vector<TableInfo> tableList = mapping.tables();
71  for( std::vector<TableInfo>::iterator iT = tableList.begin();
72  iT != tableList.end(); ++iT ){
73  createTable( *iT );
74  }
75 
76 }
void createTable(const TableInfo &tableInfo)
void ora::MappingToSchema::createTable ( const TableInfo tableInfo)
private

Definition at line 23 of file MappingToSchema.cc.

References idDealer::description, ora::MappingRules::fkNameForIdentity(), i, ora::TableInfo::m_dataColumns, ora::TableInfo::m_dependency, ora::TableInfo::m_idColumns, ora::TableInfo::m_nullableColumns, ora::TableInfo::m_parentTableName, ora::TableInfo::m_refColumns, ora::TableInfo::m_tableName, and AlCaHLTBitMon_QueryRunRegistry::string.

23  {
24  coral::TableDescription description("ORA");
25  description.setName(tableInfo.m_tableName);
26  std::vector<std::string> columnsForIndex;
27  std::vector<std::string> columnsForFk;
28  size_t i=0;
29  size_t cols = tableInfo.m_idColumns.size();
30  for( std::vector<std::string>::const_iterator iCol = tableInfo.m_idColumns.begin();
31  iCol != tableInfo.m_idColumns.end(); ++iCol ){
32  description.insertColumn( *iCol, coral::AttributeSpecification::typeNameForId( typeid(int) ) );
33  description.setNotNullConstraint( *iCol );
34  if( !tableInfo.m_dependency ) {
35  columnsForIndex.push_back( *iCol );
36  if( i< cols-1 ) columnsForFk.push_back( *iCol );
37  } else {
38  if( i>0 ) columnsForIndex.push_back( *iCol );
39  if( i>0 && i< cols-1 ) columnsForFk.push_back( *iCol );
40  }
41  ++i;
42  }
43  for( std::map<std::string,std::string>::const_iterator iDataCol = tableInfo.m_dataColumns.begin();
44  iDataCol != tableInfo.m_dataColumns.end(); ++iDataCol ){
45  description.insertColumn( iDataCol->first, iDataCol->second );
46  // workaround (temporary?) for Blob. The metadata column has to be relaxed in the NOT NULL constraint (previous versions are not filling this column)
47  std::set<std::string>::const_iterator iNullable = tableInfo.m_nullableColumns.find( iDataCol->first );
48  if( iNullable == tableInfo.m_nullableColumns.end()){
49  description.setNotNullConstraint( iDataCol->first );
50  }
51  }
52  description.setPrimaryKey( columnsForIndex );
53  if( !tableInfo.m_parentTableName.empty() ){
54  std::string fkName = MappingRules::fkNameForIdentity( tableInfo.m_tableName );
55 
56  if( !tableInfo.m_dependency ) {
57  description.createForeignKey( fkName, columnsForFk, tableInfo.m_parentTableName, tableInfo.m_refColumns );
58  } else {
59  std::vector<std::string> refCols;
60  for(size_t i=1;i<tableInfo.m_refColumns.size();i++) refCols.push_back( tableInfo.m_refColumns[i] );
61  if( !refCols.empty() ) description.createForeignKey( fkName, columnsForFk, tableInfo.m_parentTableName, refCols );
62  }
63  }
64  m_schema.createTable( description );
65  //.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
66 
67 }
int i
Definition: DBlmapReader.cc:9
coral::ISchema & m_schema
Reference to the schema in use.
tuple description
Definition: idDealer.py:66
static std::string fkNameForIdentity(const std::string &tableName, int index=0)

Member Data Documentation

coral::ISchema& ora::MappingToSchema::m_schema
private

Reference to the schema in use.

Definition at line 39 of file MappingToSchema.h.