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"
17 static std::string s_version(
"1.1.0");
22 static std::string s_name(
"ORA_DB");
27 static std::string s_column(
"PARAMETER_NAME");
32 static std::string s_column(
"PARAMETER_VALUE");
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 );
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() ) {
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 ) );
81 return schema().existsTable( tableName() );
85 if(
schema().existsTable( tableName() )){
86 throwException(
"ORA database main table already exists in this schema.",
87 "OraMainTable::create");
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() ) );
100 coral::ITable&
table =
schema().createTable( descr );
102 coral::AttributeList dataToInsert;
103 dataToInsert.extend<std::string>( parameterNameColumn());
104 dataToInsert.extend<std::string>( parameterValueColumn());
106 dataToInsert[ parameterValueColumn() ].data<std::string>() =
version();
107 table.dataEditor().insertRow( dataToInsert );
111 schema().dropIfExistsTable( tableName() );
115 static std::string s_name(
"ORA_SEQUENCE");
120 static std::string s_column(
"NAME");
125 static std::string s_column(
"VALUE");
131 m_tableName( tableName() ){
137 m_tableName( tname ){
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;
152 iAttribute->data<
int >() = -1;
153 schema().tableHandle(
name() ).dataEditor().insertRow( insertData );
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 >();
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() );
186 coral::AttributeList::iterator iAttribute = updateData.begin();
187 iAttribute->data< std::string >() = sequenceName;
189 iAttribute->data<
int >() = lastValue;
190 schema().tableHandle(
name() ).dataEditor().updateRows( setClause,whereClause,updateData );
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 );
211 throwException(
"ORA database sequence table already exists in this schema.",
212 "OraSequenceTable::create");
216 description.setName(
name() );
218 description.insertColumn( sequenceNameColumn(), coral::AttributeSpecification::typeNameForType<std::string>() );
219 description.setNotNullConstraint( sequenceNameColumn() );
221 description.insertColumn( sequenceValueColumn(),coral::AttributeSpecification::typeNameForType<int>() );
222 description.setNotNullConstraint( sequenceValueColumn() );
224 description.setPrimaryKey( std::vector< std::string >( 1, sequenceNameColumn() ) );
225 schema().createTable( description );
233 static std::string s_table(
"ORA_MAPPING_VERSION");
238 static std::string s_col(
"MAPPING_VERSION");
254 return schema().existsTable( tableName() );
258 if(
schema().existsTable( tableName() )){
259 throwException(
"ORA database mapping version table already exists in this schema.",
260 "OraMappingVersionTable::create");
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 );
273 schema().dropIfExistsTable( tableName() );
278 static std::string s_table(
"ORA_MAPPING_ELEMENT");
283 static std::string s_col(
"MAPPING_VERSION");
288 static std::string s_col(
"ELEMENT_ID");
293 static std::string s_col(
"ELEMENT_TYPE");
298 static std::string s_col(
"VARIABLE_SCOPE");
303 static std::string s_col(
"VARIABLE_NAME");
308 static std::string s_col(
"VARIABLE_PAR_INDEX");
313 static std::string s_col(
"VARIABLE_TYPE");
319 static std::string s_col(
"TABLE_NAME");
324 static std::string s_col(
"COLUMN_NAME");
340 return schema().existsTable( tableName() );
344 if(
schema().existsTable( tableName() )){
345 throwException(
"ORA database mapping element table already exists in this schema.",
346 "OraMappingElementTable::create");
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 );
391 schema().dropIfExistsTable( tableName() );
395 static std::string s_name(
"ORA_CONTAINER");
401 static std::string s_column(
"CONTAINER_ID");
407 static std::string s_column(
"CONTAINER_NAME");
412 static std::string s_column(
"CLASS_NAME");
417 static std::string s_column(
"NUMBER_OF_OBJECTS");
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() ) {
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 ) )) ;
453 const std::string& containerName,
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 );
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);
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);
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() ) {
508 const coral::AttributeList& row = cursor.currentRow();
510 dest.
className = row[ classNameColumn()].data< std::string >();
511 dest.
numberOfObjects = row[ numberOfObjectsColumn()].data<
unsigned int >();
517 std::stringstream setClause;
518 setClause << numberOfObjectsColumn() <<
" = " <<numberOfObjectsColumn() <<
" + 1";
519 return updateContainer( containerId, setClause.str() );
523 std::stringstream setClause;
524 setClause << numberOfObjectsColumn() <<
" = " <<numberOfObjectsColumn() <<
" - 1";
525 return updateContainer( containerId, setClause.str() );
529 if( numberOfObjectsForContainerIds.size() ){
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() );
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()));
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();
557 return schema().existsTable( tableName() );
561 if(
schema().existsTable( tableName() )){
562 throwException(
"ORA database container header table already exists in this schema.",
563 "OraContainerHeaderTable::create");
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 );
586 schema().dropIfExistsTable( tableName() );
590 static std::string s_table(
"ORA_CLASS_VERSION");
595 static std::string s_col(
"CLASS_NAME");
600 static std::string s_col(
"CLASS_VERSION");
605 static std::string s_col(
"CLASS_ID");
610 static std::string s_col(
"DEPENDENCY_INDEX");
615 static std::string s_col(
"CONTAINER_ID");
621 static std::string s_col(
"MAPPING_VERSION");
638 return schema().existsTable( tableName() );
642 if(
schema().existsTable( tableName() )){
643 throwException(
"ORA database class version table already exists in this schema.",
644 "OraClassVersionTable::create");
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 );
681 schema().dropIfExistsTable( tableName() );
685 m_schema( dbSchema ){
695 coral::ICursor& cursor =
query->execute();
696 while ( cursor.next() ) {
698 const coral::AttributeList& currentRow = cursor.currentRow();
700 dest.insert( mappingVersion );
709 std::auto_ptr<coral::IQuery>
query(mappingTable.newQuery());
710 coral::AttributeList outputBuffer;
718 query->defineOutput( outputBuffer );
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 );
736 coral::ICursor& cursor =
query->execute();
737 while ( cursor.next() ) {
739 const coral::AttributeList& currentRow = cursor.currentRow();
755 coral::AttributeList rowBuffer;
758 mappingVersionTable.dataEditor().insertRow( rowBuffer );
762 coral::AttributeList dataBuffer;
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++ ){
785 mappingElementTable.dataEditor().insertRow( dataBuffer );
792 coral::AttributeList whereData;
794 whereData.begin()->data<std::string>() = version;
804 std::auto_ptr<coral::IQuery>
query(m_schema.newQuery());
807 query->setDistinct();
810 std::ostringstream condition;
812 coral::AttributeList condData;
813 query->setCondition(condition.str(),condData);
814 coral::ICursor& cursor =
query->execute();
815 while ( cursor.next() ) {
817 const coral::AttributeList& currentRow = cursor.currentRow();
820 dest.insert(std::make_pair(tableName,containerId));
851 std::set<std::string>& destination ){
854 query->setDistinct();
856 std::ostringstream condition;
859 coral::AttributeList condData;
862 query->setCondition(condition.str(),condData);
863 coral::ICursor& cursor =
query->execute();
864 while ( cursor.next() ) {
866 const coral::AttributeList& currentRow = cursor.currentRow();
868 destination.insert( className );
874 std::set<std::string>& destination ){
878 query->setDistinct();
880 std::ostringstream condition;
882 coral::AttributeList condData;
885 query->setCondition(condition.str(),condData);
886 coral::ICursor& cursor =
query->execute();
887 while ( cursor.next() ) {
889 const coral::AttributeList& currentRow = cursor.currentRow();
891 destination.insert( classVersion );
897 std::set<std::string>&
dest,
898 bool onlyDependency ){
901 query->setDistinct();
903 std::ostringstream condition;
905 coral::AttributeList condData;
907 if( onlyDependency ){
911 query->setCondition(condition.str(),condData);
912 coral::ICursor& cursor =
query->execute();
913 while ( cursor.next() ) {
915 const coral::AttributeList& currentRow = cursor.currentRow();
917 dest.insert( mappingVersion );
923 std::map<std::string,std::string>& versionMap ){
926 query->setDistinct();
929 std::ostringstream condition;
931 coral::AttributeList condData;
934 query->setCondition(condition.str(),condData);
935 coral::ICursor& cursor =
query->execute();
936 while ( cursor.next() ) {
938 const coral::AttributeList& currentRow = cursor.currentRow();
941 versionMap.insert( std::make_pair(classVersion,mappingVersion ) );
947 std::set<std::string>& destination )
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() ) {
963 const coral::AttributeList& currentRow = cursor.currentRow();
965 destination.insert( mappingVersion );
972 std::string& destination ){
977 std::ostringstream condition;
980 coral::AttributeList condData;
983 coral::AttributeList::iterator iAttribute = condData.begin();
984 iAttribute->data< std::string >() = classId;
986 iAttribute->data<
int >() = containerId;
987 query->setCondition( condition.str(), condData );
988 coral::ICursor& cursor =
query->execute();
989 while ( cursor.next() ) {
991 const coral::AttributeList& currentRow = cursor.currentRow();
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() ) {
1012 const coral::AttributeList& currentRow = cursor.currentRow();
1019 const std::string& classVersion,
1020 const std::string& classId,
1021 int dependencyIndex,
1023 const std::string& mappingVersion ){
1032 coral::AttributeList::iterator iInAttr = inputData.begin();
1033 iInAttr->data< std::string >() = mappingVersion;
1035 iInAttr->data< std::string >() = className;
1037 iInAttr->data< std::string >() = classVersion;
1039 iInAttr->data< std::string >() = classId;
1041 iInAttr->data<
int >() = dependencyIndex;
1043 iInAttr->data<
int >() = containerId;
1044 classVersionTable.dataEditor().insertRow( inputData );
1049 const std::string& mappingVersion ){
1055 coral::AttributeList::iterator iInAttr = inputData.begin();
1056 iInAttr->data< std::string >() = mappingVersion;
1058 iInAttr->data< std::string >() = classId;
1060 iInAttr->data<
int >() = containerId;
1064 classVersionTable.dataEditor().updateRows( setClause,whereClause, inputData );
1073 static std::string s_table(
"ORA_NAMING_SERVICE" );
1078 static std::string s_column(
"OBJECT_NAME");
1083 static std::string s_column(
"CONTAINER_ID");
1088 static std::string s_column(
"ITEM_ID");
1104 return schema().existsTable( tableName() );
1108 if(
schema().existsTable( tableName() )){
1109 throwException(
"ORA naming service table already exists in this schema.",
1110 "OraNameTable::create");
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() ) );
1126 schema().createTable( descr );
1130 schema().dropIfExistsTable( tableName() );
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 );
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;
1156 std::string condition(
"");
1157 coral::AttributeList whereData;
1158 return schema().tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
1162 std::pair<int,int>& destination ){
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() ) {
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;
1193 std::vector<std::string>& destination ){
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;
1211 iAttribute->data<
int >() = itemId;
1212 query->setCondition( condition.str(), condData );
1213 coral::ICursor& cursor =
query->execute();
1214 while ( cursor.next() ) {
1216 const coral::AttributeList& row = cursor.currentRow();
1217 std::string
name = row[ objectNameColumn() ].data< std::string >();
1218 destination.push_back( name );
1224 std::vector<std::string>& destination ){
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() ) {
1242 const coral::AttributeList& row = cursor.currentRow();
1243 std::string
name = row[ objectNameColumn() ].data< std::string >();
1244 destination.push_back( name );
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() ) {
1260 const coral::AttributeList& row = cursor.currentRow();
1261 std::string
name = row[ objectNameColumn() ].data< std::string >();
1262 destination.push_back( name );
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 ){
1284 if(!m_mainTable.exists()){
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");
1303 m_mainTable.create();
1305 m_sequenceTable.create();
1306 m_mappingVersionTable.create();
1307 m_mappingElementTable.create();
1308 m_containerHeaderTable.create();
1309 m_classVersionTable.create();
1310 m_namingServiceTable.create();
1314 m_namingServiceTable.drop();
1315 m_classVersionTable.drop();
1316 m_containerHeaderTable.drop();
1317 m_mappingElementTable.drop();
1318 m_mappingVersionTable.drop();
1319 m_sequenceTable.drop();
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 );
1339 return m_sequenceTable;
1343 return m_mappingVersionTable;
1347 return m_mappingElementTable;
1351 return m_containerHeaderTable;
1355 return m_classVersionTable;
1359 return m_mappingSchema;
1363 return m_namingServiceTable;
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");
1377 coral::TableDescription descr(
"OraDb" );
1378 descr.setName( tableName );
1379 descr.insertColumn(
"DUMMY",
1380 coral::AttributeSpecification::typeNameForType<int>() );
1381 m_schema.createTable( descr );
1387 if(ret ) m_schema.dropIfExistsTable( tableName );
static std::string versionParameterName()
static std::string classIdColumn()
void sinchronize(const std::string &sequenceName, int lastValue)
bool testDropPermission()
static std::string userSchemaVersionParameterName()
void setMappingVersion(const std::string &classId, int containerId, const std::string &mappingVersion)
OraDatabaseSchema(coral::ISchema &dbSchema)
MappingRawElement & addElement(int elementId)
virtual ~OraNamingServiceTable()
void setParameter(const std::string ¶mName, const std::string ¶mValue)
bool getMapping(const std::string &version, MappingRawData &destination)
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
virtual ~OraClassVersionTable()
virtual ~OraMappingElementTable()
static std::string mappingVersionColumn()
bool getLastId(const std::string &sequenceName, int &lastId)
OraSequenceTable(coral::ISchema &dbSchema)
IDatabaseTable & classVersionTable()
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()
static std::string & tableName()
OraMappingElementTable(coral::ISchema &dbSchema)
IContainerHeaderTable & containerHeaderTable()
static std::string classNameColumn()
OraClassVersionTable(coral::ISchema &dbSchema)
static std::string tableNameColumn()
std::string schemaVersion()
virtual ~OraMappingSchema()
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()
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)
virtual ~OraSequenceTable()
static std::string tableName()
static std::string variableTypeColumn()
static std::string parameterNameColumn()
virtual ~OraMappingVersionTable()
static bool existsMainTable(coral::ISchema &dbSchema)
static std::string classVersionColumn()
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()
bool getMappingVersionListForContainer(int containerId, std::set< std::string > &destination, bool onlyDependency=false)
static std::string dependencyIndexColumn()
bool getMappingVersionListForTable(const std::string &tableName, std::set< std::string > &destination)
std::vector< std::vector< double > > tmp
static std::string & objectNameColumn()
void create(const std::string &userSchemaVersion)
bool containerForMappingVersion(const std::string &mappingVersion, int &destination)
virtual ~OraDatabaseSchema()
static std::string scopeNameColumn()
OraMappingSchema(coral::ISchema &dbSchema)
static std::string columnNameColumn()
void throwException(const std::string &message, const std::string &methodName)
bool add(const std::string &sequenceName)
IDatabaseTable & mappingVersionTable()
void setObjectName(const std::string &name, int contId, int itemId)
static std::string elementIdColumn()
bool selectMappingVersion(const std::string &classId, int containerId, std::string &destination)
void storeMapping(const MappingRawData &mapping)
static std::string & containerIdColumn()
static std::string version()
std::string className(const T &t)
bool getDependentClassesInContainerMapping(int containerId, std::set< std::string > &destination)
static std::string & itemIdColumn()
static std::string parameterValueColumn()
OraMainTable(coral::ISchema &dbSchema)
static std::string containerIdColumn()