CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OraDatabaseSchema.cc
Go to the documentation of this file.
2 #include "OraDatabaseSchema.h"
3 //
4 #include <memory>
5 // externals
6 #include "RelationalAccess/ISchema.h"
7 #include "RelationalAccess/ITable.h"
8 #include "RelationalAccess/IQuery.h"
9 #include "RelationalAccess/ICursor.h"
10 #include "RelationalAccess/TableDescription.h"
11 #include "RelationalAccess/ITablePrivilegeManager.h"
12 #include "RelationalAccess/ITableDataEditor.h"
13 #include "RelationalAccess/IBulkOperation.h"
14 #include "CoralBase/Attribute.h"
15 
17  static const std::string s_version("1.1.0");
18  return s_version;
19 }
20 
22  static const std::string s_name("ORA_DB");
23  return s_name;
24 }
25 
27  static const std::string s_column("PARAMETER_NAME");
28  return s_column;
29 }
30 
32  static const std::string s_column("PARAMETER_VALUE");
33  return s_column;
34 }
35 
36 ora::OraMainTable::OraMainTable( coral::ISchema& dbSchema ):
37  IMainTable( dbSchema ){
38 }
39 
41 }
42 
44  const std::string& paramValue ){
45  if( !paramName.empty() && !paramValue.empty() ){
46  coral::ITable& table = schema().tableHandle( tableName() );
47  coral::AttributeList dataToInsert;
48  dataToInsert.extend<std::string>( parameterNameColumn());
49  dataToInsert.extend<std::string>( parameterValueColumn());
50  dataToInsert[ parameterNameColumn() ].data<std::string>() = paramName;
51  dataToInsert[ parameterValueColumn() ].data<std::string>() = paramValue;
52  table.dataEditor().insertRow( dataToInsert );
53  }
54 }
55 
56 bool ora::OraMainTable::getParameters( std::map<std::string,std::string>& dest ){
57  bool ret = false;
58  coral::ITable& mainTable = schema().tableHandle( tableName() );
59  std::auto_ptr<coral::IQuery> query(mainTable.newQuery());
60  coral::ICursor& cursor = query->execute();
61  while ( cursor.next() ) {
62  ret = true;
63  const coral::AttributeList& row = cursor.currentRow();
64  std::string paramName = row[ parameterNameColumn()].data< std::string >();
65  std::string paramValue = row[ parameterValueColumn()].data< std::string >();
66  dest.insert( std::make_pair( paramName, paramValue ) );
67  }
68  return ret;
69 }
70 
72  // could be replaced by a call to getParameters in case of needs to distinguish between ora db schema versions...
73  return version();
74 }
75 
77  return tableName();
78 }
79 
81  return schema().existsTable( tableName() );
82 }
83 
85  if( schema().existsTable( tableName() )){
86  throwException( "ORA database main table already exists in this schema.",
87  "OraMainTable::create");
88  }
89 
90  coral::TableDescription descr( "OraDb" );
91  descr.setName( tableName() );
92  descr.insertColumn( parameterNameColumn(),
93  coral::AttributeSpecification::typeNameForType<std::string>() );
94  descr.insertColumn( parameterValueColumn(),
95  coral::AttributeSpecification::typeNameForType<std::string>() );
96  descr.setNotNullConstraint( parameterNameColumn() );
97  descr.setNotNullConstraint( parameterValueColumn() );
98  descr.setPrimaryKey( std::vector<std::string>( 1, parameterNameColumn() ) );
99 
100  coral::ITable& table = schema().createTable( descr );
101 
102  coral::AttributeList dataToInsert;
103  dataToInsert.extend<std::string>( parameterNameColumn());
104  dataToInsert.extend<std::string>( parameterValueColumn());
105  dataToInsert[ parameterNameColumn() ].data<std::string>() = IMainTable::versionParameterName();
106  dataToInsert[ parameterValueColumn() ].data<std::string>() = version();
107  table.dataEditor().insertRow( dataToInsert );
108 }
109 
111  schema().dropIfExistsTable( tableName() );
112 }
113 
115  static const std::string s_name("ORA_SEQUENCE");
116  return s_name;
117 }
118 
120  static const std::string s_column("NAME");
121  return s_column;
122 }
123 
125  static const std::string s_column("VALUE");
126  return s_column;
127 }
128 
130  ISequenceTable( schema),
131  m_tableName( tableName() ){
132 }
133 
135  coral::ISchema& schema ):
136  ISequenceTable( schema),
137  m_tableName( tname ){
138 }
139 
141 }
142 
143 bool
145  // Create the entry in the table
146  coral::AttributeList insertData;
147  insertData.extend<std::string>(sequenceNameColumn());
148  insertData.extend<int>(sequenceValueColumn());
149  coral::AttributeList::iterator iAttribute = insertData.begin();
150  iAttribute->data< std::string >() = sequenceName;
151  ++iAttribute;
152  iAttribute->data< int >() = -1;
153  schema().tableHandle( name() ).dataEditor().insertRow( insertData );
154  return true;
155 }
156 
157 bool
159  int& lastId ) {
160  std::auto_ptr< coral::IQuery > query( schema().tableHandle( name() ).newQuery() );
161  query->limitReturnedRows( 1, 0 );
162  query->addToOutputList( sequenceValueColumn() );
163  query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() );
164  query->setForUpdate();
165  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
166  coral::AttributeList rowData;
167  rowData.extend<std::string>(sequenceNameColumn());
168  rowData.begin()->data< std::string >() = sequenceName;
169  query->setCondition( whereClause, rowData );
170  coral::ICursor& cursor = query->execute();
171  if ( cursor.next() ) {
172  lastId = cursor.currentRow().begin()->data<int >();
173  return true;
174  }
175  return false;
176 }
177 
179  int lastValue ){
180  coral::AttributeList updateData;
181  updateData.extend<std::string>(sequenceNameColumn());
182  updateData.extend<int>(sequenceValueColumn());
183  std::string setClause( sequenceValueColumn() + " = :" + sequenceValueColumn() );
184  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
185  // Increment the oid in the database as well
186  coral::AttributeList::iterator iAttribute = updateData.begin();
187  iAttribute->data< std::string >() = sequenceName;
188  ++iAttribute;
189  iAttribute->data< int >() = lastValue;
190  schema().tableHandle( name() ).dataEditor().updateRows( setClause,whereClause,updateData );
191 }
192 
194  coral::AttributeList whereData;
195  whereData.extend<std::string>(sequenceNameColumn());
196  whereData[ sequenceNameColumn() ].data<std::string>() = sequenceName;
197  std::string whereClause( sequenceNameColumn() + " = :" + sequenceNameColumn() );
198  schema().tableHandle( name() ).dataEditor().deleteRows( whereClause, whereData );
199 }
200 
202  return m_tableName;
203 }
204 
206  return schema().existsTable( name() );
207 }
208 
210  if( schema().existsTable( name() )){
211  throwException( "ORA database sequence table already exists in this schema.",
212  "OraSequenceTable::create");
213  }
214 
215  coral::TableDescription description( "OraDb" );
216  description.setName( name() );
217 
218  description.insertColumn( sequenceNameColumn(), coral::AttributeSpecification::typeNameForType<std::string>() );
219  description.setNotNullConstraint( sequenceNameColumn() );
220 
221  description.insertColumn( sequenceValueColumn(),coral::AttributeSpecification::typeNameForType<int>() );
222  description.setNotNullConstraint( sequenceValueColumn() );
223 
224  description.setPrimaryKey( std::vector< std::string >( 1, sequenceNameColumn() ) );
225  schema().createTable( description );
226 }
227 
229  schema().dropIfExistsTable( name() );
230 }
231 
233  static const std::string s_table("ORA_MAPPING_VERSION");
234  return s_table;
235 }
236 
238  static const std::string s_col("MAPPING_VERSION");
239  return s_col;
240 }
241 
243  IDatabaseTable( dbSchema ){
244 }
245 
247 }
248 
250  return tableName();
251 }
252 
254  return schema().existsTable( tableName() );
255 }
256 
258  if( schema().existsTable( tableName() )){
259  throwException( "ORA database mapping version table already exists in this schema.",
260  "OraMappingVersionTable::create");
261  }
262  // version table
263  coral::TableDescription description0( "OraDb" );
264  description0.setName( tableName() );
265  description0.insertColumn( mappingVersionColumn(),
266  coral::AttributeSpecification::typeNameForType<std::string>(), 1000, false);
267  description0.setNotNullConstraint( mappingVersionColumn() );
268  description0.setPrimaryKey( mappingVersionColumn() );
269  schema().createTable( description0 );
270 }
271 
273  schema().dropIfExistsTable( tableName() );
274 }
275 
276 
278  static const std::string s_table("ORA_MAPPING_ELEMENT");
279  return s_table;
280 }
281 
283  static const std::string s_col("MAPPING_VERSION");
284  return s_col;
285 }
286 
288  static const std::string s_col("ELEMENT_ID");
289  return s_col;
290 }
291 
293  static const std::string s_col("ELEMENT_TYPE");
294  return s_col;
295 }
296 
298  static const std::string s_col("VARIABLE_SCOPE");
299  return s_col;
300 }
301 
303  static const std::string s_col("VARIABLE_NAME");
304  return s_col;
305 }
306 
308  static const std::string s_col("VARIABLE_PAR_INDEX");
309  return s_col;
310 }
311 
313  static const std::string s_col("VARIABLE_TYPE");
314  return s_col;
315 
316 }
317 
319  static const std::string s_col("TABLE_NAME");
320  return s_col;
321 }
322 
324  static const std::string s_col("COLUMN_NAME");
325  return s_col;
326 }
327 
329  IDatabaseTable( dbSchema ){
330 }
331 
333 }
334 
336  return tableName();
337 }
338 
340  return schema().existsTable( tableName() );
341 }
342 
344  if( schema().existsTable( tableName() )){
345  throwException( "ORA database mapping element table already exists in this schema.",
346  "OraMappingElementTable::create");
347  }
348 
349  // mapping elements table
350  coral::TableDescription description2( "OraDb" );
351  description2.setName( tableName() );
352  description2.insertColumn( mappingVersionColumn(),
353  coral::AttributeSpecification::typeNameForType<std::string>(), 1000, false );
354  description2.setNotNullConstraint( mappingVersionColumn() );
355  description2.insertColumn( elementIdColumn(),
356  coral::AttributeSpecification::typeNameForType<int>() );
357  description2.setNotNullConstraint( elementIdColumn() );
358  description2.insertColumn( elementTypeColumn(),
359  coral::AttributeSpecification::typeNameForType<std::string>() );
360  description2.setNotNullConstraint( elementTypeColumn() );
361  description2.insertColumn( scopeNameColumn(),
362  coral::AttributeSpecification::typeNameForType<std::string>() );
363  description2.setNotNullConstraint( scopeNameColumn() );
364  description2.insertColumn( variableNameColumn(),
365  coral::AttributeSpecification::typeNameForType<std::string>() );
366  description2.setNotNullConstraint( variableNameColumn() );
367  description2.insertColumn( variableParIndexColumn(),
368  coral::AttributeSpecification::typeNameForType<unsigned int>() );
369  description2.setNotNullConstraint( variableParIndexColumn() );
370  description2.insertColumn( variableTypeColumn(),
371  coral::AttributeSpecification::typeNameForType<std::string>() );
372  description2.setNotNullConstraint( variableTypeColumn() );
373  description2.insertColumn( tableNameColumn(),
374  coral::AttributeSpecification::typeNameForType<std::string>() );
375  description2.setNotNullConstraint( tableNameColumn() );
376  description2.insertColumn( columnNameColumn(),
377  coral::AttributeSpecification::typeNameForType<std::string>() );
378  description2.setNotNullConstraint( columnNameColumn() );
379  std::vector<std::string> cols2;
380  cols2.push_back( elementIdColumn() );
381  cols2.push_back( variableParIndexColumn() );
382  description2.setPrimaryKey( cols2 );
383  std::string fkName20 = mappingVersionColumn()+"_FK_1";
384  description2.createForeignKey( fkName20, mappingVersionColumn(),
386  schema().createTable( description2 );
387 
388 }
389 
391  schema().dropIfExistsTable( tableName() );
392 }
393 
395  static const std::string s_name("ORA_CONTAINER");
396  return s_name;
397 }
398 
399 
401  static const std::string s_column("CONTAINER_ID");
402  return s_column;
403 }
404 
405 
407  static const std::string s_column("CONTAINER_NAME");
408  return s_column;
409 }
410 
412  static const std::string s_column("CLASS_NAME");
413  return s_column;
414 }
415 
417  static const std::string s_column("NUMBER_OF_OBJECTS");
418  return s_column;
419 }
420 
422  IContainerHeaderTable(dbSchema){
423 }
424 
426 }
427 
430  bool ret = false;
431  coral::ITable& containerTable = schema().tableHandle( tableName() );
432  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
433  coral::AttributeList outputBuffer;
434  outputBuffer.extend<int>( containerIdColumn() );
435  outputBuffer.extend<std::string>( containerNameColumn() );
436  outputBuffer.extend<std::string>( classNameColumn() );
437  outputBuffer.extend<unsigned int>( numberOfObjectsColumn() );
438  query->defineOutput( outputBuffer );
439  coral::ICursor& cursor = query->execute();
440  while ( cursor.next() ) {
441  ret = true;
442  const coral::AttributeList& row = cursor.currentRow();
443  int containerId = row[ containerIdColumn() ].data< int >();
444  std::string containerName = row[ containerNameColumn()].data< std::string >();
445  std::string className = row[ classNameColumn()].data< std::string >();
446  unsigned int numberOfObjects = row[ numberOfObjectsColumn()].data< unsigned int >();
447  dest.insert( std::make_pair( containerName, ContainerHeaderData( containerId, className, numberOfObjects ) )) ;
448  }
449  return ret;
450 }
451 
453  const std::string& containerName,
454  const std::string& className ){
455  coral::AttributeList dataToInsert;
456  unsigned int numberOfObjects = 0;
457  dataToInsert.extend<int>( containerIdColumn());
458  dataToInsert.extend<std::string>( containerNameColumn());
459  dataToInsert.extend<std::string>( classNameColumn());
460  dataToInsert.extend<unsigned int>( numberOfObjectsColumn());
461  dataToInsert[ containerIdColumn() ].data<int>() = containerId;
462  dataToInsert[ containerNameColumn() ].data<std::string>() = containerName;
463  dataToInsert[ classNameColumn() ].data<std::string>() = className;
464  dataToInsert[ numberOfObjectsColumn() ].data<unsigned int>() = numberOfObjects;
465  coral::ITable& containerTable = schema().tableHandle( tableName() );
466  containerTable.dataEditor().insertRow( dataToInsert );
467 }
468 
470  std::stringstream whereClause;
471  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
472  coral::AttributeList whereData;
473  whereData.extend< int >( containerIdColumn() );
474  whereData.begin()->data< int >() = id;
475  coral::ITable& containerTable = schema().tableHandle( tableName() );
476  containerTable.dataEditor().deleteRows(whereClause.str(),whereData);
477 }
478 
480  const std::string& setClause ){
481  std::stringstream whereClause;
482  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
483  coral::AttributeList updateData;
484  updateData.extend<int>( containerIdColumn() );
485  updateData.begin()->data<int>() = containerId;
486  coral::ITable& containerTable = schema().tableHandle( tableName() );
487  containerTable.dataEditor().updateRows(setClause,whereClause.str(),updateData);
488 }
489 
491  bool ret = false;
492  coral::ITable& containerTable = schema().tableHandle( tableName() );
493  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
494  query->addToOutputList( classNameColumn() );
495  query->defineOutputType( classNameColumn() , coral::AttributeSpecification::typeNameForType<std::string>() );
496  query->addToOutputList( numberOfObjectsColumn() );
497  query->defineOutputType( numberOfObjectsColumn() , coral::AttributeSpecification::typeNameForType<unsigned int>() );
498  std::stringstream whereClause;
499  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
500  coral::AttributeList whereData;
501  whereData.extend<int>( containerIdColumn() );
502  whereData.begin()->data<int>() = id;
503  query->setCondition( whereClause.str(), whereData );
504  query->setForUpdate();
505  coral::ICursor& cursor = query->execute();
506  if( cursor.next() ) {
507  ret = true;
508  const coral::AttributeList& row = cursor.currentRow();
509  dest.id = id;
510  dest.className = row[ classNameColumn()].data< std::string >();
511  dest.numberOfObjects = row[ numberOfObjectsColumn()].data< unsigned int >();
512  }
513  return ret;
514 }
515 
517  std::stringstream setClause;
518  setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " + 1";
519  return updateContainer( containerId, setClause.str() );
520 }
521 
523  std::stringstream setClause;
524  setClause << numberOfObjectsColumn() << " = " <<numberOfObjectsColumn() << " - 1";
525  return updateContainer( containerId, setClause.str() );
526 }
527 
528 void ora::OraContainerHeaderTable::updateNumberOfObjects( const std::map<int,unsigned int>& numberOfObjectsForContainerIds ){
529  if( numberOfObjectsForContainerIds.size() ){
530 
531  std::stringstream whereClause;
532  whereClause << containerIdColumn() << "= :" <<containerIdColumn();
533  std::stringstream setClause;
534  setClause << numberOfObjectsColumn() << " = :" <<numberOfObjectsColumn();
535  coral::AttributeList updateData;
536  updateData.extend<unsigned int>( numberOfObjectsColumn() );
537  updateData.extend<int>( containerIdColumn() );
538 
539  coral::ITable& containerTable = schema().tableHandle( tableName() );
540  std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size()));
541 
542  for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin();
543  iCont != numberOfObjectsForContainerIds.end(); ++iCont ){
544  updateData[containerIdColumn()].data<int>() = iCont->first;
545  updateData[numberOfObjectsColumn()].data<unsigned int>() = iCont->second;
546  bulkUpdate->processNextIteration();
547  }
548  bulkUpdate->flush();
549  }
550 }
551 
553  return tableName();
554 }
555 
557  return schema().existsTable( tableName() );
558 }
559 
561  if( schema().existsTable( tableName() )){
562  throwException( "ORA database container header table already exists in this schema.",
563  "OraContainerHeaderTable::create");
564  }
565 
566  coral::TableDescription descr( "OraDb" );
567  descr.setName( tableName() );
568  descr.insertColumn( containerIdColumn(),
569  coral::AttributeSpecification::typeNameForType<int>() );
570  descr.insertColumn( containerNameColumn(),
571  coral::AttributeSpecification::typeNameForType<std::string>() );
572  descr.insertColumn( classNameColumn(),
573  coral::AttributeSpecification::typeNameForType<std::string>() );
574  descr.insertColumn( numberOfObjectsColumn(),
575  coral::AttributeSpecification::typeNameForType<unsigned int>() );
576  descr.setNotNullConstraint( containerIdColumn() );
577  descr.setNotNullConstraint( containerNameColumn() );
578  descr.setNotNullConstraint( classNameColumn() );
579  descr.setNotNullConstraint( numberOfObjectsColumn() );
580  descr.setPrimaryKey( std::vector<std::string>( 1, containerIdColumn() ) );
581  descr.setUniqueConstraint( containerNameColumn() );
582  schema().createTable( descr );
583 }
584 
586  schema().dropIfExistsTable( tableName() );
587 }
588 
590  static const std::string s_table("ORA_CLASS_VERSION");
591  return s_table;
592 }
593 
595  static const std::string s_col("CLASS_NAME");
596  return s_col;
597 }
598 
600  static const std::string s_col("CLASS_VERSION");
601  return s_col;
602 }
603 
605  static const std::string s_col("CLASS_ID");
606  return s_col;
607 }
608 
610  static const std::string s_col("DEPENDENCY_INDEX");
611  return s_col;
612 }
613 
615  static const std::string s_col("CONTAINER_ID");
616  return s_col;
617 
618 }
619 
621  static const std::string s_col("MAPPING_VERSION");
622  return s_col;
623 }
624 
625 
627  IDatabaseTable( dbSchema ){
628 }
629 
631 }
632 
634  return tableName();
635 }
636 
638  return schema().existsTable( tableName() );
639 }
640 
642  if( schema().existsTable( tableName() )){
643  throwException( "ORA database class version table already exists in this schema.",
644  "OraClassVersionTable::create");
645  }
646  // class version table
647  coral::TableDescription description1( "OraDb" );
648  description1.setName( tableName() );
649  description1.insertColumn( classNameColumn(),
650  coral::AttributeSpecification::typeNameForType<std::string>(), 1000, false);
651  description1.setNotNullConstraint( classNameColumn() );
652  description1.insertColumn( classVersionColumn(),
653  coral::AttributeSpecification::typeNameForType<std::string>(), 1000, false);
654  description1.setNotNullConstraint( classVersionColumn() );
655  description1.insertColumn( classIdColumn(),
656  coral::AttributeSpecification::typeNameForType<std::string>(), 1000, false);
657  description1.setNotNullConstraint( classIdColumn() );
658  description1.insertColumn( dependencyIndexColumn(),
659  coral::AttributeSpecification::typeNameForType<int>() );
660  description1.setNotNullConstraint( dependencyIndexColumn() );
661  description1.insertColumn( containerIdColumn(),
662  coral::AttributeSpecification::typeNameForType<int>() );
663  description1.setNotNullConstraint( containerIdColumn() );
664  description1.insertColumn( mappingVersionColumn(),
665  coral::AttributeSpecification::typeNameForType<std::string>(), 1000, false);
666  description1.setNotNullConstraint( mappingVersionColumn() );
667  std::vector<std::string> cols1;
668  cols1.push_back( classIdColumn() );
669  cols1.push_back( containerIdColumn() );
670  description1.setPrimaryKey( cols1 );
671  std::string fk10Name = mappingVersionColumn()+"_FK10";
672  description1.createForeignKey( fk10Name, mappingVersionColumn(),
674  std::string fk11Name = containerIdColumn()+"_FK11";
675  description1.createForeignKey( fk11Name, containerIdColumn(),
677  schema().createTable( description1 );
678 }
679 
681  schema().dropIfExistsTable( tableName() );
682 }
683 
684 ora::OraMappingSchema::OraMappingSchema( coral::ISchema& dbSchema ):
685  m_schema( dbSchema ){
686 }
687 
689 }
690 
691 bool ora::OraMappingSchema::getVersionList( std::set<std::string>& dest ){
692  bool ret = false;
693  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraMappingVersionTable::tableName() ).newQuery() );
695  coral::ICursor& cursor = query->execute();
696  while ( cursor.next() ) {
697  ret = true;
698  const coral::AttributeList& currentRow = cursor.currentRow();
699  std::string mappingVersion = currentRow[ OraMappingVersionTable::mappingVersionColumn()].data<std::string>();
700  dest.insert( mappingVersion );
701  }
702  return ret;
703 }
704 
707  bool ret = false;
708  coral::ITable& mappingTable = m_schema.tableHandle( OraMappingElementTable::tableName() );
709  std::auto_ptr<coral::IQuery> query(mappingTable.newQuery());
710  coral::AttributeList outputBuffer;
711  outputBuffer.extend<int>( OraMappingElementTable::elementIdColumn() );
712  outputBuffer.extend<std::string>( OraMappingElementTable::elementTypeColumn() );
713  outputBuffer.extend<std::string>( OraMappingElementTable::scopeNameColumn() );
716  outputBuffer.extend<std::string>( OraMappingElementTable::tableNameColumn() );
717  outputBuffer.extend<std::string>( OraMappingElementTable::columnNameColumn() );
718  query->defineOutput( outputBuffer );
719  query->addToOutputList( OraMappingElementTable::elementIdColumn() );
720  query->addToOutputList( OraMappingElementTable::elementTypeColumn() );
721  query->addToOutputList( OraMappingElementTable::scopeNameColumn() );
724  query->addToOutputList( OraMappingElementTable::tableNameColumn() );
725  query->addToOutputList( OraMappingElementTable::columnNameColumn() );
726  std::ostringstream condition;
728  coral::AttributeList condData;
730  coral::AttributeList::iterator iAttribute = condData.begin();
731  iAttribute->data< std::string >() = version;
732  query->setCondition( condition.str(), condData );
733  query->addToOrderList( OraMappingElementTable::scopeNameColumn() );
736  coral::ICursor& cursor = query->execute();
737  while ( cursor.next() ) {
738  ret = true;
739  const coral::AttributeList& currentRow = cursor.currentRow();
740  int elementId = currentRow[ OraMappingElementTable::elementIdColumn() ].data<int>();
741  MappingRawElement& elem = dest.addElement( elementId );
743  elem.scopeName = currentRow[ OraMappingElementTable::scopeNameColumn() ].data<std::string>();
744  elem.variableName = currentRow[ OraMappingElementTable::variableNameColumn() ].data<std::string>();
745  elem.variableType = currentRow[ OraMappingElementTable::variableTypeColumn() ].data<std::string>();
746  elem.tableName = currentRow[ OraMappingElementTable::tableNameColumn() ].data<std::string>();
747  elem.columns.push_back( currentRow[ OraMappingElementTable::columnNameColumn() ].data<std::string>() );
748  }
749  return ret;
750 }
751 
753  // first update the version table
754  coral::ITable& mappingVersionTable = m_schema.tableHandle( OraMappingVersionTable::tableName() );
755  coral::AttributeList rowBuffer;
757  rowBuffer[ OraMappingVersionTable::mappingVersionColumn() ].data<std::string>()= mapping.version;
758  mappingVersionTable.dataEditor().insertRow( rowBuffer );
759 
760  // then update the element tables
761  coral::ITable& mappingElementTable = m_schema.tableHandle( OraMappingElementTable::tableName() );
762  coral::AttributeList dataBuffer;
764  dataBuffer.extend< int >( OraMappingElementTable::elementIdColumn() );
765  dataBuffer.extend< std::string >( OraMappingElementTable::elementTypeColumn() );
766  dataBuffer.extend< std::string >( OraMappingElementTable::scopeNameColumn() );
768  dataBuffer.extend< unsigned int >( OraMappingElementTable::variableParIndexColumn() );
770  dataBuffer.extend< std::string >( OraMappingElementTable::tableNameColumn() );
771  dataBuffer.extend< std::string >( OraMappingElementTable::columnNameColumn() );
772  dataBuffer[ OraMappingElementTable::mappingVersionColumn() ].data<std::string>()= mapping.version;
773 
774  for( std::map < int, MappingRawElement >::const_iterator iElem = mapping.elements.begin();
775  iElem != mapping.elements.end(); iElem++ ){
776  for( size_t iParamIndex = 0; iParamIndex < iElem->second.columns.size(); iParamIndex++ ){
777  dataBuffer[ OraMappingElementTable::elementIdColumn() ].data<int>() = iElem->first;
778  dataBuffer[ OraMappingElementTable::elementTypeColumn()].data<std::string>()= iElem->second.elementType;
779  dataBuffer[ OraMappingElementTable::scopeNameColumn() ].data<std::string>()= iElem->second.scopeName;
780  dataBuffer[ OraMappingElementTable::variableNameColumn() ].data<std::string>()= iElem->second.variableName;
781  dataBuffer[ OraMappingElementTable::variableParIndexColumn() ].data<unsigned int>() = iParamIndex;
782  dataBuffer[ OraMappingElementTable::variableTypeColumn() ].data<std::string>()= iElem->second.variableType;
783  dataBuffer[ OraMappingElementTable::tableNameColumn() ].data<std::string>()= iElem->second.tableName;
784  dataBuffer[ OraMappingElementTable::columnNameColumn() ].data<std::string>()= iElem->second.columns[iParamIndex];
785  mappingElementTable.dataEditor().insertRow( dataBuffer );
786  }
787  }
788 }
789 
791  // Remove all rows in the tables with the version.
792  coral::AttributeList whereData;
794  whereData.begin()->data<std::string>() = version;
795 
797  m_schema.tableHandle( OraClassVersionTable::tableName() ).dataEditor().deleteRows( condition, whereData );
798  m_schema.tableHandle( OraMappingElementTable::tableName() ).dataEditor().deleteRows( condition, whereData );
799  m_schema.tableHandle( OraMappingVersionTable::tableName() ).dataEditor().deleteRows( condition, whereData );
800 }
801 
802 bool ora::OraMappingSchema::getContainerTableMap( std::map<std::string, int>& dest ){
803  bool ret = false;
804  std::auto_ptr<coral::IQuery> query(m_schema.newQuery());
805  query->addToTableList( OraMappingElementTable::tableName(),"T0");
806  query->addToTableList( OraClassVersionTable::tableName(), "T1");
807  query->setDistinct();
808  query->addToOutputList( "T0."+ OraMappingElementTable::tableNameColumn() );
809  query->addToOutputList( "T1."+ OraClassVersionTable::containerIdColumn());
810  std::ostringstream condition;
812  coral::AttributeList condData;
813  query->setCondition(condition.str(),condData);
814  coral::ICursor& cursor = query->execute();
815  while ( cursor.next() ) {
816  ret = true;
817  const coral::AttributeList& currentRow = cursor.currentRow();
819  int containerId = currentRow[ "T1."+ OraClassVersionTable::containerIdColumn()].data<int>();
820  dest.insert(std::make_pair(tableName,containerId));
821  }
822  return ret;
823 }
824 
851  std::set<std::string>& destination ){
852  bool ret = false;
853  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraClassVersionTable::tableName() ).newQuery() );
854  query->setDistinct();
855  query->addToOutputList( OraClassVersionTable::classNameColumn() );
856  std::ostringstream condition;
858  condition << " AND "<< OraClassVersionTable::dependencyIndexColumn()<<" > 0";
859  coral::AttributeList condData;
860  condData.extend< int >( OraClassVersionTable::containerIdColumn() );
861  condData[ OraClassVersionTable::containerIdColumn() ].data< int >() = containerId;
862  query->setCondition(condition.str(),condData);
863  coral::ICursor& cursor = query->execute();
864  while ( cursor.next() ) {
865  ret = true;
866  const coral::AttributeList& currentRow = cursor.currentRow();
868  destination.insert( className );
869  }
870  return ret;
871 }
872 
874  std::set<std::string>& destination ){
875 
876  bool ret = false;
877  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraClassVersionTable::tableName() ).newQuery() );
878  query->setDistinct();
879  query->addToOutputList( OraClassVersionTable::classVersionColumn() );
880  std::ostringstream condition;
882  coral::AttributeList condData;
884  condData[ OraClassVersionTable::mappingVersionColumn() ].data< std::string >() = mappingVersion;
885  query->setCondition(condition.str(),condData);
886  coral::ICursor& cursor = query->execute();
887  while ( cursor.next() ) {
888  ret = true;
889  const coral::AttributeList& currentRow = cursor.currentRow();
890  std::string classVersion = currentRow[ OraClassVersionTable::classVersionColumn() ].data<std::string>();
891  destination.insert( classVersion );
892  }
893  return ret;
894 }
895 
897  std::set<std::string>& dest,
898  bool onlyDependency ){
899  bool ret = false;
900  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraClassVersionTable::tableName() ).newQuery() );
901  query->setDistinct();
903  std::ostringstream condition;
905  coral::AttributeList condData;
906  condData.extend< int >( OraClassVersionTable::containerIdColumn() );
907  if( onlyDependency ){
908  condition << " AND "<<OraClassVersionTable::dependencyIndexColumn()<<" > 0";
909  }
910  condData[ OraClassVersionTable::containerIdColumn() ].data< int >() = containerId;
911  query->setCondition(condition.str(),condData);
912  coral::ICursor& cursor = query->execute();
913  while ( cursor.next() ) {
914  ret = true;
915  const coral::AttributeList& currentRow = cursor.currentRow();
916  std::string mappingVersion = currentRow[ OraClassVersionTable::mappingVersionColumn() ].data<std::string>();
917  dest.insert( mappingVersion );
918  }
919  return ret;
920 }
921 
923  std::map<std::string,std::string>& versionMap ){
924  bool ret = false;
925  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraClassVersionTable::tableName() ).newQuery() );
926  query->setDistinct();
927  query->addToOutputList( OraClassVersionTable::classVersionColumn() );
929  std::ostringstream condition;
931  coral::AttributeList condData;
932  condData.extend< int >( OraClassVersionTable::containerIdColumn() );
933  condData[ OraClassVersionTable::containerIdColumn() ].data< int >() = containerId;
934  query->setCondition(condition.str(),condData);
935  coral::ICursor& cursor = query->execute();
936  while ( cursor.next() ) {
937  ret = true;
938  const coral::AttributeList& currentRow = cursor.currentRow();
939  std::string classVersion = currentRow[ OraClassVersionTable::classVersionColumn() ].data<std::string>();
940  std::string mappingVersion = currentRow[ OraClassVersionTable::mappingVersionColumn() ].data<std::string>();
941  versionMap.insert( std::make_pair(classVersion,mappingVersion ) );
942  }
943  return ret;
944 }
945 
947  std::set<std::string>& destination )
948 {
949  bool ret = false;
950  destination.clear();
951  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraMappingElementTable::tableName() ).newQuery() );
952  query->setDistinct();
954  std::ostringstream condition;
956  coral::AttributeList condData;
958  condData.begin()->data<std::string>() = tableName;
959  query->setCondition(condition.str(),condData);
960  coral::ICursor& cursor = query->execute();
961  while ( cursor.next() ) {
962  ret = true;
963  const coral::AttributeList& currentRow = cursor.currentRow();
964  std::string mappingVersion = currentRow[ OraMappingElementTable::mappingVersionColumn()].data<std::string>();
965  destination.insert( mappingVersion );
966  }
967  return ret;
968 }
969 
971  int containerId,
973  bool ret = false;
974  destination.clear();
975  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraClassVersionTable::tableName() ).newQuery() );
977  std::ostringstream condition;
978  condition << OraClassVersionTable::classIdColumn() << " =:" << OraClassVersionTable::classIdColumn() << " AND ";
980  coral::AttributeList condData;
981  condData.extend<std::string>( OraClassVersionTable::classIdColumn() );
982  condData.extend<int>( OraClassVersionTable::containerIdColumn() );
983  coral::AttributeList::iterator iAttribute = condData.begin();
984  iAttribute->data< std::string >() = classId;
985  ++iAttribute;
986  iAttribute->data< int >() = containerId;
987  query->setCondition( condition.str(), condData );
988  coral::ICursor& cursor = query->execute();
989  while ( cursor.next() ) {
990  ret = true;
991  const coral::AttributeList& currentRow = cursor.currentRow();
992  destination = currentRow[OraClassVersionTable::mappingVersionColumn()].data<std::string>();
993  }
994  return ret;
995 }
996 
998  int& destination ){
999  bool ret = false;
1000  std::auto_ptr<coral::IQuery> query( m_schema.tableHandle( OraClassVersionTable::tableName() ).newQuery() );
1001  query->addToOutputList( OraClassVersionTable::containerIdColumn() );
1002  std::ostringstream condition;
1004  coral::AttributeList condData;
1006  coral::AttributeList::iterator iAttribute = condData.begin();
1007  iAttribute->data< std::string >() = mappingVersion;
1008  query->setCondition( condition.str(), condData );
1009  coral::ICursor& cursor = query->execute();
1010  while ( cursor.next() ) {
1011  ret = true;
1012  const coral::AttributeList& currentRow = cursor.currentRow();
1013  destination = currentRow[ OraClassVersionTable::containerIdColumn() ].data<int>();
1014  }
1015  return ret;
1016 }
1017 
1019  const std::string& classVersion,
1020  const std::string& classId,
1021  int dependencyIndex,
1022  int containerId,
1023  const std::string& mappingVersion ){
1024  coral::ITable& classVersionTable = m_schema.tableHandle( OraClassVersionTable::tableName() );
1025  coral::AttributeList inputData;
1027  inputData.extend<std::string>( OraClassVersionTable::classNameColumn());
1029  inputData.extend<std::string>( OraClassVersionTable::classIdColumn());
1030  inputData.extend<int>( OraClassVersionTable::dependencyIndexColumn());
1031  inputData.extend<int>( OraClassVersionTable::containerIdColumn());
1032  coral::AttributeList::iterator iInAttr = inputData.begin();
1033  iInAttr->data< std::string >() = mappingVersion;
1034  ++iInAttr;
1035  iInAttr->data< std::string >() = className;
1036  ++iInAttr;
1037  iInAttr->data< std::string >() = classVersion;
1038  ++iInAttr;
1039  iInAttr->data< std::string >() = classId;
1040  ++iInAttr;
1041  iInAttr->data< int >() = dependencyIndex;
1042  ++iInAttr;
1043  iInAttr->data< int >() = containerId;
1044  classVersionTable.dataEditor().insertRow( inputData );
1045 }
1046 
1048  int containerId,
1049  const std::string& mappingVersion ){
1050  coral::ITable& classVersionTable = m_schema.tableHandle( OraClassVersionTable::tableName() );
1051  coral::AttributeList inputData;
1053  inputData.extend<std::string>( OraClassVersionTable::classIdColumn());
1054  inputData.extend<int>( OraClassVersionTable::containerIdColumn());
1055  coral::AttributeList::iterator iInAttr = inputData.begin();
1056  iInAttr->data< std::string >() = mappingVersion;
1057  ++iInAttr;
1058  iInAttr->data< std::string >() = classId;
1059  ++iInAttr;
1060  iInAttr->data< int >() = containerId;
1064  classVersionTable.dataEditor().updateRows( setClause,whereClause, inputData );
1065 }
1066 
1067 bool ora::OraDatabaseSchema::existsMainTable( coral::ISchema& dbSchema ){
1068  OraMainTable tmp( dbSchema );
1069  return tmp.exists();
1070 }
1071 
1073  static const std::string s_table("ORA_NAMING_SERVICE" );
1074  return s_table;
1075 }
1076 
1078  static const std::string s_column("OBJECT_NAME");
1079  return s_column;
1080 }
1081 
1083  static const std::string s_column("CONTAINER_ID");
1084  return s_column;
1085 }
1086 
1088  static const std::string s_column("ITEM_ID");
1089  return s_column;
1090 }
1091 
1093  INamingServiceTable( dbSchema ){
1094 }
1095 
1097 }
1098 
1100  return tableName();
1101 }
1102 
1104  return schema().existsTable( tableName() );
1105 }
1106 
1108  if( schema().existsTable( tableName() )){
1109  throwException( "ORA naming service table already exists in this schema.",
1110  "OraNameTable::create");
1111  }
1112 
1113  coral::TableDescription descr( "OraDb" );
1114  descr.setName( tableName() );
1115  descr.insertColumn( objectNameColumn(),
1116  coral::AttributeSpecification::typeNameForType<std::string>() );
1117  descr.insertColumn( containerIdColumn(),
1118  coral::AttributeSpecification::typeNameForType<int>() );
1119  descr.insertColumn( itemIdColumn(),
1120  coral::AttributeSpecification::typeNameForType<int>() );
1121  descr.setNotNullConstraint( objectNameColumn() );
1122  descr.setNotNullConstraint( containerIdColumn() );
1123  descr.setNotNullConstraint( itemIdColumn() );
1124  descr.setPrimaryKey( std::vector<std::string>( 1, objectNameColumn() ) );
1125 
1126  schema().createTable( descr );
1127 }
1128 
1130  schema().dropIfExistsTable( tableName() );
1131 }
1132 
1134  int contId,
1135  int itemId ){
1136  coral::AttributeList dataToInsert;
1137  dataToInsert.extend<std::string>( objectNameColumn() );
1138  dataToInsert.extend<int>( containerIdColumn());
1139  dataToInsert.extend<int>( itemIdColumn());
1140  dataToInsert[ objectNameColumn() ].data<std::string>() = name;
1141  dataToInsert[ containerIdColumn() ].data<int>() = contId;
1142  dataToInsert[ itemIdColumn() ].data<int>() = itemId;
1143  coral::ITable& containerTable = schema().tableHandle( tableName() );
1144  containerTable.dataEditor().insertRow( dataToInsert );
1145 }
1146 
1148  coral::AttributeList whereData;
1149  whereData.extend<std::string>( objectNameColumn() );
1150  whereData.begin()->data<std::string>() = name;
1151  std::string condition = objectNameColumn() + " = :" + objectNameColumn();
1152  return schema().tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
1153 }
1154 
1156  std::string condition("");
1157  coral::AttributeList whereData;
1158  return schema().tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
1159 }
1160 
1162  std::pair<int,int>& destination ){
1163  bool ret = false;
1164  coral::ITable& containerTable = schema().tableHandle( tableName() );
1165  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
1166  coral::AttributeList outputBuffer;
1167  outputBuffer.extend<int>( containerIdColumn() );
1168  outputBuffer.extend<int>( itemIdColumn() );
1169  query->defineOutput( outputBuffer );
1170  query->addToOutputList( containerIdColumn() );
1171  query->addToOutputList( itemIdColumn() );
1172  std::ostringstream condition;
1173  condition << objectNameColumn()<<"= :"<< objectNameColumn();
1174  coral::AttributeList condData;
1175  condData.extend<std::string>( objectNameColumn() );
1176  coral::AttributeList::iterator iAttribute = condData.begin();
1177  iAttribute->data< std::string >() = name;
1178  query->setCondition( condition.str(), condData );
1179  coral::ICursor& cursor = query->execute();
1180  while ( cursor.next() ) {
1181  ret = true;
1182  const coral::AttributeList& row = cursor.currentRow();
1183  int containerId = row[ containerIdColumn() ].data< int >();
1184  int itemId = row[ itemIdColumn() ].data< int >();
1185  destination.first = containerId;
1186  destination.second = itemId;
1187  }
1188  return ret;
1189 }
1190 
1192  int itemId,
1193  std::vector<std::string>& destination ){
1194  bool ret = false;
1195  coral::ITable& containerTable = schema().tableHandle( tableName() );
1196  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
1197  coral::AttributeList outputBuffer;
1198  outputBuffer.extend<std::string>( objectNameColumn() );
1199  query->defineOutput( outputBuffer );
1200  query->addToOutputList( objectNameColumn() );
1201  std::ostringstream condition;
1202  condition << containerIdColumn()<<"= :"<< containerIdColumn();
1203  condition << " AND ";
1204  condition << itemIdColumn()<<"= :"<< itemIdColumn();
1205  coral::AttributeList condData;
1206  condData.extend<int>( containerIdColumn() );
1207  condData.extend<int>( itemIdColumn() );
1208  coral::AttributeList::iterator iAttribute = condData.begin();
1209  iAttribute->data< int >() = contId;
1210  ++iAttribute;
1211  iAttribute->data< int >() = itemId;
1212  query->setCondition( condition.str(), condData );
1213  coral::ICursor& cursor = query->execute();
1214  while ( cursor.next() ) {
1215  ret = true;
1216  const coral::AttributeList& row = cursor.currentRow();
1217  std::string name = row[ objectNameColumn() ].data< std::string >();
1218  destination.push_back( name );
1219  }
1220  return ret;
1221 }
1222 
1224  std::vector<std::string>& destination ){
1225  bool ret = false;
1226  coral::ITable& containerTable = schema().tableHandle( tableName() );
1227  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
1228  coral::AttributeList outputBuffer;
1229  outputBuffer.extend<std::string>( objectNameColumn() );
1230  query->defineOutput( outputBuffer );
1231  query->addToOutputList( objectNameColumn() );
1232  std::ostringstream condition;
1233  condition << containerIdColumn()<<"= :"<< containerIdColumn();
1234  coral::AttributeList condData;
1235  condData.extend<int>( containerIdColumn() );
1236  coral::AttributeList::iterator iAttribute = condData.begin();
1237  iAttribute->data< int >() = contId;
1238  query->setCondition( condition.str(), condData );
1239  coral::ICursor& cursor = query->execute();
1240  while ( cursor.next() ) {
1241  ret = true;
1242  const coral::AttributeList& row = cursor.currentRow();
1243  std::string name = row[ objectNameColumn() ].data< std::string >();
1244  destination.push_back( name );
1245  }
1246  return ret;
1247 }
1248 
1249 bool ora::OraNamingServiceTable::getAllNames( std::vector<std::string>& destination ){
1250  bool ret = false;
1251  coral::ITable& containerTable = schema().tableHandle( tableName() );
1252  std::auto_ptr<coral::IQuery> query( containerTable.newQuery());
1253  coral::AttributeList outputBuffer;
1254  outputBuffer.extend<std::string>( objectNameColumn() );
1255  query->defineOutput( outputBuffer );
1256  query->addToOutputList( objectNameColumn() );
1257  coral::ICursor& cursor = query->execute();
1258  while ( cursor.next() ) {
1259  ret = true;
1260  const coral::AttributeList& row = cursor.currentRow();
1261  std::string name = row[ objectNameColumn() ].data< std::string >();
1262  destination.push_back( name );
1263  }
1264  return ret;
1265 }
1266 
1267 ora::OraDatabaseSchema::OraDatabaseSchema( coral::ISchema& dbSchema ):
1268  IDatabaseSchema( dbSchema ),
1269  m_schema( dbSchema ),
1270  m_mainTable( dbSchema ),
1271  m_sequenceTable( dbSchema ),
1272  m_mappingVersionTable( dbSchema ),
1273  m_mappingElementTable( dbSchema ),
1274  m_containerHeaderTable( dbSchema ),
1275  m_classVersionTable( dbSchema ),
1276  m_mappingSchema( dbSchema ),
1277  m_namingServiceTable( dbSchema ){
1278 }
1279 
1281 }
1282 
1284  if(!m_mainTable.exists()){
1285  return false;
1286  }
1287  if(!m_namingServiceTable.exists())
1288  throwException( "ORA database is corrupted. Naming Service table is missing", "OraDatabaseSchema::exists");
1289  if(!m_sequenceTable.exists())
1290  throwException( "ORA database is corrupted. Sequence table is missing.","OraDatabaseSchema::exists");
1291  if(!m_mappingVersionTable.exists())
1292  throwException( "ORA database is corrupted. Mapping Version table is missing.","OraDatabaseSchema::exists");
1293  if(!m_mappingElementTable.exists())
1294  throwException( "ORA database is corrupted. Mapping Element table is missing.","OraDatabaseSchema::exists");
1295  if(!m_containerHeaderTable.exists())
1296  throwException( "ORA database is corrupted. Container Header table is missing.","OraDatabaseSchema::exists");
1297  if(!m_classVersionTable.exists())
1298  throwException( "ORA database is corrupted. Class Version table is missing.","OraDatabaseSchema::exists");
1299  return true;
1300 }
1301 
1302 void ora::OraDatabaseSchema::create( const std::string& userSchemaVersion ){
1303  m_mainTable.create();
1304  m_mainTable.setParameter( IMainTable::userSchemaVersionParameterName(), userSchemaVersion );
1305  m_sequenceTable.create();
1306  m_mappingVersionTable.create();
1307  m_mappingElementTable.create();
1308  m_containerHeaderTable.create();
1309  m_classVersionTable.create();
1310  m_namingServiceTable.create();
1311 }
1312 
1314  m_namingServiceTable.drop();
1315  m_classVersionTable.drop();
1316  m_containerHeaderTable.drop();
1317  m_mappingElementTable.drop();
1318  m_mappingVersionTable.drop();
1319  m_sequenceTable.drop();
1320  m_mainTable.drop();
1321 }
1322 
1324  bool forWrite ){
1325  m_mainTable.setAccessPermission( principal, forWrite );
1326  m_sequenceTable.setAccessPermission( principal, forWrite );
1327  m_mappingVersionTable.setAccessPermission( principal, forWrite );
1328  m_mappingElementTable.setAccessPermission( principal, forWrite );
1329  m_containerHeaderTable.setAccessPermission( principal, forWrite );
1330  m_classVersionTable.setAccessPermission( principal, forWrite );
1331  m_namingServiceTable.setAccessPermission( principal, forWrite );
1332 }
1333 
1335  return m_mainTable;
1336 }
1337 
1339  return m_sequenceTable;
1340 }
1341 
1343  return m_mappingVersionTable;
1344 }
1345 
1347  return m_mappingElementTable;
1348 }
1349 
1351  return m_containerHeaderTable;
1352 }
1353 
1355  return m_classVersionTable;
1356 }
1357 
1359  return m_mappingSchema;
1360 }
1361 
1363  return m_namingServiceTable;
1364 }
1365 
1367  // horrible work-around to avoid the attempt to DROP a db with no permission:
1368  // due to Oracle implicit COMMIT after any DDL attempt (successful or not...), the previous DELETE on containers are commited
1369  // as a result the ora db is left corrupted
1370  bool ret = false;
1371  std::string tableName("ORA_TEST_DROP");
1372  if( m_schema.existsTable( tableName )){
1373  throwException( "ORA_TEST_DROP table already exists in this schema.",
1374  "OraNameTable::testDropPermission");
1375  }
1376  try{
1377  coral::TableDescription descr( "OraDb" );
1378  descr.setName( tableName );
1379  descr.insertColumn( "DUMMY",
1380  coral::AttributeSpecification::typeNameForType<int>() );
1381  m_schema.createTable( descr );
1382  ret = true;
1383  ::sleep(1);
1384  }catch ( const coral::Exception& ){
1385  ret = false;
1386  }
1387  if(ret ) m_schema.dropIfExistsTable( tableName );
1388  return ret;
1389 }
1390 
static std::string versionParameterName()
void updateContainer(int id, const std::string &setClause)
static std::string classIdColumn()
void sinchronize(const std::string &sequenceName, int lastValue)
tuple ret
prodAgent to be discontinued
static std::string userSchemaVersionParameterName()
void setMappingVersion(const std::string &classId, int containerId, const std::string &mappingVersion)
OraDatabaseSchema(coral::ISchema &dbSchema)
MappingRawElement & addElement(int elementId)
void setParameter(const std::string &paramName, const std::string &paramValue)
static std::string objectNameColumn()
bool getMapping(const std::string &version, MappingRawData &destination)
tuple schema
Definition: dataDML.py:2334
static char const * tname
Definition: GTSchema.h:13
static std::string sequenceNameColumn()
bool getContainerTableMap(std::map< std::string, int > &destination)
void insertClassVersion(const std::string &className, const std::string &classVersion, const std::string &classId, int dependencyIndex, int containerId, const std::string &mappingVersion)
static std::string variableNameColumn()
void removeMapping(const std::string &version)
IDatabaseTable & mappingElementTable()
static std::string mappingVersionColumn()
std::map< int, MappingRawElement > elements
bool lockContainer(int id, ContainerHeaderData &destination)
static std::string mappingVersionColumn()
bool getLastId(const std::string &sequenceName, int &lastId)
OraSequenceTable(coral::ISchema &dbSchema)
IDatabaseTable & classVersionTable()
static std::string containerNameColumn()
static std::string classNameColumn()
static std::string tableName()
bool getNamesForObject(int contId, int itemId, std::vector< std::string > &destination)
static std::string tableName()
bool getClassVersionListForContainer(int containerId, std::map< std::string, std::string > &versionMap)
IMappingSchema & mappingSchema()
OraMappingElementTable(coral::ISchema &dbSchema)
static std::string tableName()
IContainerHeaderTable & containerHeaderTable()
static std::string classNameColumn()
OraClassVersionTable(coral::ISchema &dbSchema)
static std::string tableNameColumn()
static std::string containerIdColumn()
std::string schemaVersion()
bool getContainerData(std::map< std::string, ContainerHeaderData > &destination)
bool getNamesForContainer(int contId, std::vector< std::string > &destination)
bool getParameters(std::map< std::string, std::string > &destination)
static std::string elementTypeColumn()
bool getClassVersionListForMappingVersion(const std::string &mappingVersion, std::set< std::string > &destination)
bool getVersionList(std::set< std::string > &destination)
OraMappingVersionTable(coral::ISchema &dbSchema)
static std::string tableName()
static std::string variableParIndexColumn()
static std::string tableName()
static std::string numberOfObjectsColumn()
INamingServiceTable & namingServiceTable()
static std::string sequenceValueColumn()
static std::string tableName()
ISequenceTable & sequenceTable()
void erase(const std::string &sequenceName)
void setAccessPermission(const std::string &principal, bool forWrite)
static std::string itemIdColumn()
static std::string tableName()
tuple description
Definition: idDealer.py:66
static std::string variableTypeColumn()
static std::string parameterNameColumn()
static bool existsMainTable(coral::ISchema &dbSchema)
static std::string classVersionColumn()
OraContainerHeaderTable(coral::ISchema &dbSchema)
OraNamingServiceTable(coral::ISchema &dbSchema)
bool getAllNames(std::vector< std::string > &destination)
bool eraseObjectName(const std::string &name)
bool getObjectByName(const std::string &name, std::pair< int, int > &destination)
static std::string mappingVersionColumn()
static std::string containerIdColumn()
bool getMappingVersionListForContainer(int containerId, std::set< std::string > &destination, bool onlyDependency=false)
static std::string dependencyIndexColumn()
void updateNumberOfObjects(const std::map< int, unsigned int > &numberOfObjectsForContainerIds)
bool getMappingVersionListForTable(const std::string &tableName, std::set< std::string > &destination)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void create(const std::string &userSchemaVersion)
bool containerForMappingVersion(const std::string &mappingVersion, int &destination)
static std::string scopeNameColumn()
tuple query
Definition: o2o.py:269
OraMappingSchema(coral::ISchema &dbSchema)
static std::string columnNameColumn()
bool add(const std::string &sequenceName)
IDatabaseTable & mappingVersionTable()
void setObjectName(const std::string &name, int contId, int itemId)
static std::string elementIdColumn()
void addContainer(int id, const std::string &containerName, const std::string &className)
bool selectMappingVersion(const std::string &classId, int containerId, std::string &destination)
void storeMapping(const MappingRawData &mapping)
static std::string version()
std::string className(const T &t)
Definition: ClassName.h:30
bool getDependentClassesInContainerMapping(int containerId, std::set< std::string > &destination)
tuple inputData
Definition: idDealer.py:72
static std::string parameterValueColumn()
OraMainTable(coral::ISchema &dbSchema)
static std::string containerIdColumn()