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(
"V1.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");
45 coral::ITable& mainTable = m_schema.tableHandle( tableName() );
46 std::auto_ptr<coral::IQuery>
query(mainTable.newQuery());
47 coral::ICursor& cursor =
query->execute();
48 while ( cursor.next() ) {
50 const coral::AttributeList& row = cursor.currentRow();
51 std::string paramName = row[ parameterNameColumn()].data< std::string >();
52 std::string paramValue = row[ parameterValueColumn()].data< std::string >();
53 dest.insert( std::make_pair( paramName, paramValue ) );
64 return m_schema.existsTable( tableName() );
68 if( m_schema.existsTable( tableName() )){
69 throwException(
"ORA database main table already exists in this schema.",
70 "OraMainTable::create");
73 coral::TableDescription descr(
"OraDb" );
74 descr.setName( tableName() );
75 descr.insertColumn( parameterNameColumn(),
76 coral::AttributeSpecification::typeNameForType<std::string>() );
77 descr.insertColumn( parameterValueColumn(),
78 coral::AttributeSpecification::typeNameForType<std::string>() );
79 descr.setNotNullConstraint( parameterNameColumn() );
80 descr.setNotNullConstraint( parameterValueColumn() );
81 descr.setPrimaryKey( std::vector<std::string>( 1, parameterNameColumn() ) );
83 coral::ITable&
table = m_schema.createTable( descr );
84 table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
86 coral::AttributeList dataToInsert;
87 dataToInsert.extend<std::string>( parameterNameColumn());
88 dataToInsert.extend<std::string>( parameterValueColumn());
90 dataToInsert[ parameterValueColumn() ].data<std::string>() =
version();
91 table.dataEditor().insertRow( dataToInsert );
95 m_schema.dropIfExistsTable( tableName() );
99 static std::string s_name(
"ORA_SEQUENCE");
104 static std::string s_column(
"NAME");
109 static std::string s_column(
"VALUE");
123 coral::AttributeList insertData;
124 insertData.extend<std::string>(sequenceNameColumn());
125 insertData.extend<
int>(sequenceValueColumn());
126 coral::AttributeList::iterator iAttribute = insertData.begin();
127 iAttribute->data< std::string >() = sequenceName;
129 iAttribute->data<
int >() = 0;
130 m_schema.tableHandle( tableName() ).dataEditor().insertRow( insertData );
137 std::auto_ptr< coral::IQuery >
query( m_schema.tableHandle( tableName() ).newQuery() );
138 query->limitReturnedRows( 1, 0 );
139 query->addToOutputList( sequenceValueColumn() );
140 query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() );
141 query->setForUpdate();
142 std::string whereClause( sequenceNameColumn() +
" = :" + sequenceNameColumn() );
143 coral::AttributeList rowData;
144 rowData.extend<std::string>(sequenceNameColumn());
145 rowData.begin()->data< std::string >() = sequenceName;
146 query->setCondition( whereClause, rowData );
147 coral::ICursor& cursor =
query->execute();
148 if ( cursor.next() ) {
149 lastId = cursor.currentRow().begin()->data<
int >();
157 coral::AttributeList updateData;
158 updateData.extend<std::string>(sequenceNameColumn());
159 updateData.extend<
int>(sequenceValueColumn());
160 std::string setClause( sequenceValueColumn() +
" = :" + sequenceValueColumn() );
161 std::string whereClause( sequenceNameColumn() +
" = :" + sequenceNameColumn() );
163 coral::AttributeList::iterator iAttribute = updateData.begin();
164 iAttribute->data< std::string >() = sequenceName;
166 iAttribute->data<
int >() = lastValue;
167 m_schema.tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData );
171 coral::AttributeList whereData;
172 whereData.extend<std::string>(sequenceNameColumn());
173 whereData[ sequenceNameColumn() ].data<std::string>() = name;
174 std::string whereClause( sequenceNameColumn() +
" = :" + sequenceNameColumn() );
175 m_schema.tableHandle( tableName() ).dataEditor().deleteRows( whereClause, whereData );
179 return m_schema.existsTable( tableName() );
183 if( m_schema.existsTable( tableName() )){
184 throwException(
"ORA database sequence table already exists in this schema.",
185 "OraSequenceTable::create");
189 description.setName( tableName() );
191 description.insertColumn( sequenceNameColumn(), coral::AttributeSpecification::typeNameForType<std::string>() );
192 description.setNotNullConstraint( sequenceNameColumn() );
194 description.insertColumn( sequenceValueColumn(),coral::AttributeSpecification::typeNameForType<int>() );
195 description.setNotNullConstraint( sequenceValueColumn() );
197 description.setPrimaryKey( std::vector< std::string >( 1, sequenceNameColumn() ) );
198 m_schema.createTable( description ).privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
202 m_schema.dropIfExistsTable( tableName() );
206 static std::string s_table(
"ORA_MAPPING_VERSION");
211 static std::string s_col(
"MAPPING_VERSION");
216 m_schema( dbSchema ){
223 return m_schema.existsTable( tableName() );
227 if( m_schema.existsTable( tableName() )){
228 throwException(
"ORA database mapping version table already exists in this schema.",
229 "OraMappingVersionTable::create");
232 coral::TableDescription description0(
"OraDb" );
233 description0.setName( tableName() );
234 description0.insertColumn( mappingVersionColumn(),
235 coral::AttributeSpecification::typeNameForType<std::string>(), 1000,
false);
236 description0.setNotNullConstraint( mappingVersionColumn() );
237 description0.setPrimaryKey( mappingVersionColumn() );
238 m_schema.createTable( description0 ).privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
242 m_schema.dropIfExistsTable( tableName() );
247 static std::string s_table(
"ORA_MAPPING_ELEMENT");
252 static std::string s_col(
"MAPPING_VERSION");
257 static std::string s_col(
"ELEMENT_ID");
262 static std::string s_col(
"ELEMENT_TYPE");
267 static std::string s_col(
"VARIABLE_SCOPE");
272 static std::string s_col(
"VARIABLE_NAME");
277 static std::string s_col(
"VARIABLE_PAR_INDEX");
282 static std::string s_col(
"VARIABLE_TYPE");
288 static std::string s_col(
"TABLE_NAME");
293 static std::string s_col(
"COLUMN_NAME");
298 m_schema( dbSchema ){
305 return m_schema.existsTable( tableName() );
309 if( m_schema.existsTable( tableName() )){
310 throwException(
"ORA database mapping element table already exists in this schema.",
311 "OraMappingElementTable::create");
315 coral::TableDescription description2(
"OraDb" );
316 description2.setName( tableName() );
317 description2.insertColumn( mappingVersionColumn(),
318 coral::AttributeSpecification::typeNameForType<std::string>(), 1000,
false );
319 description2.setNotNullConstraint( mappingVersionColumn() );
320 description2.insertColumn( elementIdColumn(),
321 coral::AttributeSpecification::typeNameForType<int>() );
322 description2.setNotNullConstraint( elementIdColumn() );
323 description2.insertColumn( elementTypeColumn(),
324 coral::AttributeSpecification::typeNameForType<std::string>() );
325 description2.setNotNullConstraint( elementTypeColumn() );
326 description2.insertColumn( scopeNameColumn(),
327 coral::AttributeSpecification::typeNameForType<std::string>() );
328 description2.setNotNullConstraint( scopeNameColumn() );
329 description2.insertColumn( variableNameColumn(),
330 coral::AttributeSpecification::typeNameForType<std::string>() );
331 description2.setNotNullConstraint( variableNameColumn() );
332 description2.insertColumn( variableParIndexColumn(),
333 coral::AttributeSpecification::typeNameForType<unsigned int>() );
334 description2.setNotNullConstraint( variableParIndexColumn() );
335 description2.insertColumn( variableTypeColumn(),
336 coral::AttributeSpecification::typeNameForType<std::string>() );
337 description2.setNotNullConstraint( variableTypeColumn() );
338 description2.insertColumn( tableNameColumn(),
339 coral::AttributeSpecification::typeNameForType<std::string>() );
340 description2.setNotNullConstraint( tableNameColumn() );
341 description2.insertColumn( columnNameColumn(),
342 coral::AttributeSpecification::typeNameForType<std::string>() );
343 description2.setNotNullConstraint( columnNameColumn() );
344 std::vector<std::string> cols2;
345 cols2.push_back( elementIdColumn() );
346 cols2.push_back( variableParIndexColumn() );
347 description2.setPrimaryKey( cols2 );
348 std::string fkName20 = mappingVersionColumn()+
"_FK_1";
349 description2.createForeignKey( fkName20, mappingVersionColumn(),
351 m_schema.createTable( description2 ).privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
355 m_schema.dropIfExistsTable( tableName() );
359 static std::string s_name(
"ORA_CONTAINER");
365 static std::string s_column(
"CONTAINER_ID");
371 static std::string s_column(
"CONTAINER_NAME");
376 static std::string s_column(
"CLASS_NAME");
381 static std::string s_column(
"NUMBER_OF_OBJECTS");
395 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
396 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
397 coral::AttributeList outputBuffer;
398 outputBuffer.extend<
int>( containerIdColumn() );
399 outputBuffer.extend<std::string>( containerNameColumn() );
400 outputBuffer.extend<std::string>( classNameColumn() );
401 outputBuffer.extend<
unsigned int>( numberOfObjectsColumn() );
402 query->defineOutput( outputBuffer );
403 coral::ICursor& cursor =
query->execute();
404 while ( cursor.next() ) {
406 const coral::AttributeList& row = cursor.currentRow();
407 int containerId = row[ containerIdColumn() ].data<
int >();
408 std::string containerName = row[ containerNameColumn()].data< std::string >();
409 std::string
className = row[ classNameColumn()].data< std::string >();
410 unsigned int numberOfObjects = row[ numberOfObjectsColumn()].data<
unsigned int >();
411 dest.insert( std::make_pair( containerName,
ContainerHeaderData( containerId, className, numberOfObjects ) )) ;
417 const std::string& containerName,
419 coral::AttributeList dataToInsert;
420 unsigned int numberOfObjects = 0;
421 dataToInsert.extend<
int>( containerIdColumn());
422 dataToInsert.extend<std::string>( containerNameColumn());
423 dataToInsert.extend<std::string>( classNameColumn());
424 dataToInsert.extend<
unsigned int>( numberOfObjectsColumn());
425 dataToInsert[ containerIdColumn() ].data<
int>() = containerId;
426 dataToInsert[ containerNameColumn() ].data<std::string>() = containerName;
427 dataToInsert[ classNameColumn() ].data<std::string>() = className;
428 dataToInsert[ numberOfObjectsColumn() ].data<
unsigned int>() = numberOfObjects;
429 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
430 containerTable.dataEditor().insertRow( dataToInsert );
434 std::stringstream whereClause;
435 whereClause << containerIdColumn() <<
"= :" <<containerIdColumn();
436 coral::AttributeList whereData;
437 whereData.extend<
int >( containerIdColumn() );
438 whereData.begin()->data<
int >() =
id;
439 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
440 containerTable.dataEditor().deleteRows(whereClause.str(),whereData);
444 const std::string& setClause ){
445 std::stringstream whereClause;
446 whereClause << containerIdColumn() <<
"= :" <<containerIdColumn();
447 coral::AttributeList updateData;
448 updateData.extend<
int>( containerIdColumn() );
449 updateData.begin()->data<
int>() = containerId;
450 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
451 containerTable.dataEditor().updateRows(setClause,whereClause.str(),updateData);
455 std::stringstream setClause;
456 setClause << numberOfObjectsColumn() <<
" = " <<numberOfObjectsColumn() <<
" + 1";
457 return updateContainer( containerId, setClause.str() );
461 std::stringstream setClause;
462 setClause << numberOfObjectsColumn() <<
" = " <<numberOfObjectsColumn() <<
" - 1";
463 return updateContainer( containerId, setClause.str() );
467 if( numberOfObjectsForContainerIds.size() ){
469 std::stringstream whereClause;
470 whereClause << containerIdColumn() <<
"= :" <<containerIdColumn();
471 std::stringstream setClause;
472 setClause << numberOfObjectsColumn() <<
" = :" <<numberOfObjectsColumn();
473 coral::AttributeList updateData;
474 updateData.extend<
unsigned int>( numberOfObjectsColumn() );
475 updateData.extend<
int>( containerIdColumn() );
477 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
478 std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size()));
480 for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin();
481 iCont != numberOfObjectsForContainerIds.end(); ++iCont ){
482 updateData[containerIdColumn()].data<
int>() = iCont->first;
483 updateData[numberOfObjectsColumn()].data<
unsigned int>() = iCont->second;
484 bulkUpdate->processNextIteration();
491 return m_schema.existsTable( tableName() );
495 if( m_schema.existsTable( tableName() )){
496 throwException(
"ORA database container header table already exists in this schema.",
497 "OraContainerHeaderTable::create");
500 coral::TableDescription descr(
"OraDb" );
501 descr.setName( tableName() );
502 descr.insertColumn( containerIdColumn(),
503 coral::AttributeSpecification::typeNameForType<int>() );
504 descr.insertColumn( containerNameColumn(),
505 coral::AttributeSpecification::typeNameForType<std::string>() );
506 descr.insertColumn( classNameColumn(),
507 coral::AttributeSpecification::typeNameForType<std::string>() );
508 descr.insertColumn( numberOfObjectsColumn(),
509 coral::AttributeSpecification::typeNameForType<unsigned int>() );
510 descr.setNotNullConstraint( containerIdColumn() );
511 descr.setNotNullConstraint( containerNameColumn() );
512 descr.setNotNullConstraint( classNameColumn() );
513 descr.setNotNullConstraint( numberOfObjectsColumn() );
514 descr.setPrimaryKey( std::vector<std::string>( 1, containerIdColumn() ) );
515 descr.setUniqueConstraint( containerNameColumn() );
516 coral::ITable&
table = m_schema.createTable( descr );
517 table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
521 m_schema.dropIfExistsTable( tableName() );
525 static std::string s_table(
"ORA_CLASS_VERSION");
530 static std::string s_col(
"CLASS_NAME");
535 static std::string s_col(
"CLASS_VERSION");
540 static std::string s_col(
"CLASS_ID");
545 static std::string s_col(
"DEPENDENCY_INDEX");
550 static std::string s_col(
"CONTAINER_ID");
556 static std::string s_col(
"MAPPING_VERSION");
562 m_schema( dbSchema ){
569 return m_schema.existsTable( tableName() );
573 if( m_schema.existsTable( tableName() )){
574 throwException(
"ORA database class version table already exists in this schema.",
575 "OraClassVersionTable::create");
578 coral::TableDescription description1(
"OraDb" );
579 description1.setName( tableName() );
580 description1.insertColumn( classNameColumn(),
581 coral::AttributeSpecification::typeNameForType<std::string>(), 1000,
false);
582 description1.setNotNullConstraint( classNameColumn() );
583 description1.insertColumn( classVersionColumn(),
584 coral::AttributeSpecification::typeNameForType<std::string>(), 1000,
false);
585 description1.setNotNullConstraint( classVersionColumn() );
586 description1.insertColumn( classIdColumn(),
587 coral::AttributeSpecification::typeNameForType<std::string>(), 1000,
false);
588 description1.setNotNullConstraint( classIdColumn() );
589 description1.insertColumn( dependencyIndexColumn(),
590 coral::AttributeSpecification::typeNameForType<int>() );
591 description1.setNotNullConstraint( dependencyIndexColumn() );
592 description1.insertColumn( containerIdColumn(),
593 coral::AttributeSpecification::typeNameForType<int>() );
594 description1.setNotNullConstraint( containerIdColumn() );
595 description1.insertColumn( mappingVersionColumn(),
596 coral::AttributeSpecification::typeNameForType<std::string>(), 1000,
false);
597 description1.setNotNullConstraint( mappingVersionColumn() );
598 std::vector<std::string> cols1;
599 cols1.push_back( classIdColumn() );
600 cols1.push_back( containerIdColumn() );
601 description1.setPrimaryKey( cols1 );
602 std::string fk10Name = mappingVersionColumn()+
"_FK10";
603 description1.createForeignKey( fk10Name, mappingVersionColumn(),
605 std::string fk11Name = containerIdColumn()+
"_FK11";
606 description1.createForeignKey( fk11Name, containerIdColumn(),
608 m_schema.createTable( description1 ).privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
612 m_schema.dropIfExistsTable( tableName() );
616 m_schema( dbSchema ){
626 coral::ICursor& cursor =
query->execute();
627 while ( cursor.next() ) {
629 const coral::AttributeList& currentRow = cursor.currentRow();
631 dest.insert( mappingVersion );
640 std::auto_ptr<coral::IQuery>
query(mappingTable.newQuery());
641 coral::AttributeList outputBuffer;
649 query->defineOutput( outputBuffer );
657 std::ostringstream condition;
659 coral::AttributeList condData;
661 coral::AttributeList::iterator iAttribute = condData.begin();
662 iAttribute->data< std::string >() = version;
663 query->setCondition( condition.str(), condData );
667 coral::ICursor& cursor =
query->execute();
668 while ( cursor.next() ) {
670 const coral::AttributeList& currentRow = cursor.currentRow();
686 coral::AttributeList rowBuffer;
689 mappingVersionTable.dataEditor().insertRow( rowBuffer );
693 coral::AttributeList dataBuffer;
705 for( std::map < int, MappingRawElement >::const_iterator iElem = mapping.
elements.begin();
706 iElem != mapping.
elements.end(); iElem++ ){
707 for(
size_t iParamIndex = 0; iParamIndex < iElem->second.columns.size(); iParamIndex++ ){
716 mappingElementTable.dataEditor().insertRow( dataBuffer );
723 coral::AttributeList whereData;
725 whereData.begin()->data<std::string>() = version;
735 std::auto_ptr<coral::IQuery>
query(m_schema.newQuery());
738 query->setDistinct();
741 std::ostringstream condition;
743 coral::AttributeList condData;
744 query->setCondition(condition.str(),condData);
745 coral::ICursor& cursor =
query->execute();
746 while ( cursor.next() ) {
748 const coral::AttributeList& currentRow = cursor.currentRow();
751 dest.insert(std::make_pair(tableName,containerId));
782 std::set<std::string>& destination ){
785 query->setDistinct();
787 std::ostringstream condition;
790 coral::AttributeList condData;
793 query->setCondition(condition.str(),condData);
794 coral::ICursor& cursor =
query->execute();
795 while ( cursor.next() ) {
797 const coral::AttributeList& currentRow = cursor.currentRow();
799 destination.insert( className );
805 std::set<std::string>& destination ){
809 query->setDistinct();
811 std::ostringstream condition;
813 coral::AttributeList condData;
816 query->setCondition(condition.str(),condData);
817 coral::ICursor& cursor =
query->execute();
818 while ( cursor.next() ) {
820 const coral::AttributeList& currentRow = cursor.currentRow();
822 destination.insert( classVersion );
828 std::set<std::string>&
dest,
829 bool onlyDependency ){
832 query->setDistinct();
834 std::ostringstream condition;
836 coral::AttributeList condData;
838 if( onlyDependency ){
842 query->setCondition(condition.str(),condData);
843 coral::ICursor& cursor =
query->execute();
844 while ( cursor.next() ) {
846 const coral::AttributeList& currentRow = cursor.currentRow();
848 dest.insert( mappingVersion );
854 std::map<std::string,std::string>& versionMap ){
857 query->setDistinct();
860 std::ostringstream condition;
862 coral::AttributeList condData;
865 query->setCondition(condition.str(),condData);
866 coral::ICursor& cursor =
query->execute();
867 while ( cursor.next() ) {
869 const coral::AttributeList& currentRow = cursor.currentRow();
872 versionMap.insert( std::make_pair(classVersion,mappingVersion ) );
878 std::set<std::string>& destination )
883 query->setDistinct();
885 std::ostringstream condition;
887 coral::AttributeList condData;
889 condData.begin()->data<std::string>() = tableName;
890 query->setCondition(condition.str(),condData);
891 coral::ICursor& cursor =
query->execute();
892 while ( cursor.next() ) {
894 const coral::AttributeList& currentRow = cursor.currentRow();
896 destination.insert( mappingVersion );
903 std::string& destination ){
908 std::ostringstream condition;
911 coral::AttributeList condData;
914 coral::AttributeList::iterator iAttribute = condData.begin();
915 iAttribute->data< std::string >() = classId;
917 iAttribute->data<
int >() = containerId;
918 query->setCondition( condition.str(), condData );
919 coral::ICursor& cursor =
query->execute();
920 while ( cursor.next() ) {
922 const coral::AttributeList& currentRow = cursor.currentRow();
933 std::ostringstream condition;
935 coral::AttributeList condData;
937 coral::AttributeList::iterator iAttribute = condData.begin();
938 iAttribute->data< std::string >() = mappingVersion;
939 query->setCondition( condition.str(), condData );
940 coral::ICursor& cursor =
query->execute();
941 while ( cursor.next() ) {
943 const coral::AttributeList& currentRow = cursor.currentRow();
950 const std::string& classVersion,
951 const std::string& classId,
954 const std::string& mappingVersion ){
963 coral::AttributeList::iterator iInAttr = inputData.begin();
964 iInAttr->data< std::string >() = mappingVersion;
966 iInAttr->data< std::string >() = className;
968 iInAttr->data< std::string >() = classVersion;
970 iInAttr->data< std::string >() = classId;
972 iInAttr->data<
int >() = dependencyIndex;
974 iInAttr->data<
int >() = containerId;
975 classVersionTable.dataEditor().insertRow( inputData );
980 const std::string& mappingVersion ){
986 coral::AttributeList::iterator iInAttr = inputData.begin();
987 iInAttr->data< std::string >() = mappingVersion;
989 iInAttr->data< std::string >() = classId;
991 iInAttr->data<
int >() = containerId;
995 classVersionTable.dataEditor().updateRows( setClause,whereClause, inputData );
1004 static std::string s_table(
"ORA_NAMING_SERVICE" );
1009 static std::string s_column(
"OBJECT_NAME");
1014 static std::string s_column(
"CONTAINER_ID");
1019 static std::string s_column(
"ITEM_ID");
1030 return m_schema.existsTable( tableName() );
1034 if( m_schema.existsTable( tableName() )){
1035 throwException(
"ORA naming service table already exists in this schema.",
1036 "OraNameTable::create");
1039 coral::TableDescription descr(
"OraDb" );
1040 descr.setName( tableName() );
1041 descr.insertColumn( objectNameColumn(),
1042 coral::AttributeSpecification::typeNameForType<std::string>() );
1043 descr.insertColumn( containerIdColumn(),
1044 coral::AttributeSpecification::typeNameForType<int>() );
1045 descr.insertColumn( itemIdColumn(),
1046 coral::AttributeSpecification::typeNameForType<int>() );
1047 descr.setNotNullConstraint( objectNameColumn() );
1048 descr.setNotNullConstraint( containerIdColumn() );
1049 descr.setNotNullConstraint( itemIdColumn() );
1050 descr.setPrimaryKey( std::vector<std::string>( 1, objectNameColumn() ) );
1052 coral::ITable&
table = m_schema.createTable( descr );
1053 table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select );
1057 m_schema.dropIfExistsTable( tableName() );
1063 coral::AttributeList dataToInsert;
1064 dataToInsert.extend<std::string>( objectNameColumn() );
1065 dataToInsert.extend<
int>( containerIdColumn());
1066 dataToInsert.extend<
int>( itemIdColumn());
1067 dataToInsert[ objectNameColumn() ].data<std::string>() = name;
1068 dataToInsert[ containerIdColumn() ].data<
int>() = contId;
1069 dataToInsert[ itemIdColumn() ].data<
int>() = itemId;
1070 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1071 containerTable.dataEditor().insertRow( dataToInsert );
1075 coral::AttributeList whereData;
1076 whereData.extend<std::string>( objectNameColumn() );
1077 whereData.begin()->data<std::string>() = name;
1078 std::string condition = objectNameColumn() +
" = :" + objectNameColumn();
1079 return m_schema.tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
1083 std::string condition(
"");
1084 coral::AttributeList whereData;
1085 return m_schema.tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
1089 std::pair<int,int>& destination ){
1091 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1092 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1093 coral::AttributeList outputBuffer;
1094 outputBuffer.extend<
int>( containerIdColumn() );
1095 outputBuffer.extend<
int>( itemIdColumn() );
1096 query->defineOutput( outputBuffer );
1097 query->addToOutputList( containerIdColumn() );
1098 query->addToOutputList( itemIdColumn() );
1099 std::ostringstream condition;
1100 condition << objectNameColumn()<<
"= :"<< objectNameColumn();
1101 coral::AttributeList condData;
1102 condData.extend<std::string>( objectNameColumn() );
1103 coral::AttributeList::iterator iAttribute = condData.begin();
1104 iAttribute->data< std::string >() = name;
1105 query->setCondition( condition.str(), condData );
1106 coral::ICursor& cursor =
query->execute();
1107 while ( cursor.next() ) {
1109 const coral::AttributeList& row = cursor.currentRow();
1110 int containerId = row[ containerIdColumn() ].data<
int >();
1111 int itemId = row[ itemIdColumn() ].data<
int >();
1112 destination.first = containerId;
1113 destination.second = itemId;
1120 std::vector<std::string>& destination ){
1122 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1123 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1124 coral::AttributeList outputBuffer;
1125 outputBuffer.extend<std::string>( objectNameColumn() );
1126 query->defineOutput( outputBuffer );
1127 query->addToOutputList( objectNameColumn() );
1128 std::ostringstream condition;
1129 condition << containerIdColumn()<<
"= :"<< containerIdColumn();
1130 condition <<
" AND ";
1131 condition << itemIdColumn()<<
"= :"<< itemIdColumn();
1132 coral::AttributeList condData;
1133 condData.extend<
int>( containerIdColumn() );
1134 condData.extend<
int>( itemIdColumn() );
1135 coral::AttributeList::iterator iAttribute = condData.begin();
1136 iAttribute->data<
int >() = contId;
1138 iAttribute->data<
int >() = itemId;
1139 query->setCondition( condition.str(), condData );
1140 coral::ICursor& cursor =
query->execute();
1141 while ( cursor.next() ) {
1143 const coral::AttributeList& row = cursor.currentRow();
1144 std::string
name = row[ objectNameColumn() ].data< std::string >();
1145 destination.push_back( name );
1151 std::vector<std::string>& destination ){
1153 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1154 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1155 coral::AttributeList outputBuffer;
1156 outputBuffer.extend<std::string>( objectNameColumn() );
1157 query->defineOutput( outputBuffer );
1158 query->addToOutputList( objectNameColumn() );
1159 std::ostringstream condition;
1160 condition << containerIdColumn()<<
"= :"<< containerIdColumn();
1161 coral::AttributeList condData;
1162 condData.extend<
int>( containerIdColumn() );
1163 coral::AttributeList::iterator iAttribute = condData.begin();
1164 iAttribute->data<
int >() = contId;
1165 query->setCondition( condition.str(), condData );
1166 coral::ICursor& cursor =
query->execute();
1167 while ( cursor.next() ) {
1169 const coral::AttributeList& row = cursor.currentRow();
1170 std::string
name = row[ objectNameColumn() ].data< std::string >();
1171 destination.push_back( name );
1178 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1179 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1180 coral::AttributeList outputBuffer;
1181 outputBuffer.extend<std::string>( objectNameColumn() );
1182 query->defineOutput( outputBuffer );
1183 query->addToOutputList( objectNameColumn() );
1184 coral::ICursor& cursor =
query->execute();
1185 while ( cursor.next() ) {
1187 const coral::AttributeList& row = cursor.currentRow();
1188 std::string
name = row[ objectNameColumn() ].data< std::string >();
1189 destination.push_back( name );
1196 m_schema( dbSchema ),
1197 m_mainTable( dbSchema ),
1198 m_sequenceTable( dbSchema ),
1199 m_mappingVersionTable( dbSchema ),
1200 m_mappingElementTable( dbSchema ),
1201 m_containerHeaderTable( dbSchema ),
1202 m_classVersionTable( dbSchema ),
1203 m_mappingSchema( dbSchema ),
1204 m_namingServiceTable( dbSchema ){
1211 if(!m_mainTable.exists()){
1214 if(!m_sequenceTable.exists() ||
1215 !m_mappingVersionTable.exists() ||
1216 !m_mappingElementTable.exists() ||
1217 !m_containerHeaderTable.exists() ||
1218 !m_classVersionTable.exists() ||
1219 !m_namingServiceTable.exists()){
1221 "OraDatabaseSchema::exists");
1227 m_mainTable.create();
1228 m_sequenceTable.create();
1229 m_mappingVersionTable.create();
1230 m_mappingElementTable.create();
1231 m_containerHeaderTable.create();
1232 m_classVersionTable.create();
1233 m_namingServiceTable.create();
1237 m_namingServiceTable.drop();
1238 m_classVersionTable.drop();
1239 m_containerHeaderTable.drop();
1240 m_mappingElementTable.drop();
1241 m_mappingVersionTable.drop();
1242 m_sequenceTable.drop();
1251 return m_sequenceTable;
1255 return m_mappingVersionTable;
1259 return m_mappingElementTable;
1263 return m_containerHeaderTable;
1267 return m_classVersionTable;
1271 return m_mappingSchema;
1275 return m_namingServiceTable;
static std::string versionParameterName()
static std::string classIdColumn()
void sinchronize(const std::string &sequenceName, int lastValue)
void setMappingVersion(const std::string &classId, int containerId, const std::string &mappingVersion)
OraDatabaseSchema(coral::ISchema &dbSchema)
MappingRawElement & addElement(int elementId)
virtual ~OraNamingServiceTable()
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)
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()
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()