9 #include "RelationalAccess/ISchema.h"
10 #include "RelationalAccess/ITable.h"
11 #include "RelationalAccess/IQuery.h"
12 #include "RelationalAccess/ICursor.h"
13 #include "RelationalAccess/TableDescription.h"
14 #include "RelationalAccess/ITablePrivilegeManager.h"
15 #include "RelationalAccess/ITableDataEditor.h"
16 #include "RelationalAccess/IBulkOperation.h"
17 #include "CoralBase/Attribute.h"
23 static std::string s_name(
"POOL_RSS_DB");
43 return m_schema.existsTable( tableName() );
47 if( m_schema.existsTable( tableName() )){
48 throwException(
"POOL database main table already exists in this schema.",
49 "PoolMainTable::create");
51 throwException(
"POOL database cannot be created.",
"PoolMainTable::create");
55 m_schema.dropIfExistsTable( tableName() );
59 static std::string s_name(
"POOL_RSS_SEQ");
64 static std::string s_column(
"NAME");
69 static std::string s_column(
"VALUE");
88 coral::AttributeList insertData;
89 insertData.extend<std::string>(sequenceNameColumn());
90 insertData.extend<
int>(sequenceValueColumn());
91 coral::AttributeList::iterator iAttribute = insertData.begin();
92 iAttribute->data< std::string >() = sequenceName;
94 iAttribute->data<
int >() = 0;
95 m_schema.tableHandle( tableName() ).dataEditor().insertRow( insertData );
103 throwException(
"Sequence Table handle has not been initialized.",
"PoolSequenceTable::getLastId");
107 std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
108 std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
109 if( iS != seq.end()){
110 if( iS->second->m_nobjWr == 0 )
return false;
111 lastId = iS->second->m_nobjWr-1;
116 std::auto_ptr< coral::IQuery >
query( m_schema.tableHandle( tableName() ).newQuery() );
117 query->limitReturnedRows( 1, 0 );
118 query->addToOutputList( sequenceValueColumn() );
119 query->defineOutputType( sequenceValueColumn(), coral::AttributeSpecification::typeNameForType<int>() );
120 query->setForUpdate();
121 std::string whereClause( sequenceNameColumn() +
" = :" + sequenceNameColumn() );
122 coral::AttributeList rowData;
123 rowData.extend<std::string>(sequenceNameColumn());
124 rowData.begin()->data< std::string >() = sequenceName;
125 query->setCondition( whereClause, rowData );
126 coral::ICursor& cursor =
query->execute();
127 if ( cursor.next() ) {
128 lastId = cursor.currentRow().begin()->data<
int >();
137 throwException(
"Sequence Table handle has not been initialized.",
"PoolSequenceTable::sinchronize");
140 std::map<std::string,PoolDbCacheData*>& seq = m_dbCache->sequences();
141 std::map<std::string,PoolDbCacheData*>::iterator iS = seq.find( sequenceName );
142 if( iS != seq.end()){
143 iS->second->m_nobjWr = lastValue+1;
147 coral::AttributeList updateData;
148 updateData.extend<std::string>(sequenceNameColumn());
149 updateData.extend<
int>(sequenceValueColumn());
150 std::string setClause( sequenceValueColumn() +
" = :" + sequenceValueColumn() );
151 std::string whereClause( sequenceNameColumn() +
" = :" + sequenceNameColumn() );
153 coral::AttributeList::iterator iAttribute = updateData.begin();
154 iAttribute->data< std::string >() = sequenceName;
156 iAttribute->data<
int >() = lastValue;
157 m_schema.tableHandle( tableName() ).dataEditor().updateRows( setClause,whereClause,updateData );
161 coral::AttributeList whereData;
162 whereData.extend<std::string>(sequenceNameColumn());
163 whereData[ sequenceNameColumn() ].data<std::string>() = sequenceName;
164 std::string whereClause( sequenceNameColumn() +
" = :" + sequenceNameColumn() );
165 m_schema.tableHandle( tableName() ).dataEditor().deleteRows( whereClause, whereData );
170 throwException(
"Sequence Table handle has not been initialized.",
"PoolSequenceTable::exists");
173 return m_schema.existsTable( tableName() );
177 if( m_schema.existsTable( tableName() )){
178 throwException(
"POOL database sequence table already exists in this schema.",
179 "PoolSequenceTable::create");
181 throwException(
"POOL database cannot be created.",
"PoolSequenceTable::create");
185 m_schema.dropIfExistsTable( tableName() );
189 static std::string s_table(
"POOL_OR_MAPPING_VERSIONS");
194 static std::string s_col(
"MAPPING_VERSION");
199 static std::string s_col(
"CONTAINER_ID");
204 m_schema( dbSchema ){
211 return m_schema.existsTable( tableName() );
215 if( m_schema.existsTable( tableName() )){
216 throwException(
"POOL database mapping version table already exists in this schema.",
217 "PoolMappingVersionTable::create");
219 throwException(
"POOL database cannot be created.",
"PoolMappingVersionTable::create");
223 m_schema.dropIfExistsTable( tableName() );
228 static std::string s_table(
"POOL_OR_MAPPING_ELEMENTS");
233 static std::string s_col(
"MAPPING_VERSION");
238 static std::string s_col(
"ELEMENT_ID");
243 static std::string s_col(
"ELEMENT_TYPE");
248 static std::string s_col(
"VARIABLE_SCOPE");
253 static std::string s_col(
"VARIABLE_NAME");
258 static std::string s_col(
"VARIABLE_PAR_INDEX");
263 static std::string s_col(
"VARIABLE_TYPE");
268 static std::string s_col(
"TABLE_NAME");
273 static std::string s_col(
"COLUMN_NAME");
278 m_schema( dbSchema ){
285 return m_schema.existsTable( tableName() );
289 if( m_schema.existsTable( tableName() )){
290 throwException(
"POOL database mapping element table already exists in this schema.",
291 "PoolMappingElementTable::create");
293 throwException(
"POOL database cannot be created.",
"PoolMappingElementTable::create");
297 m_schema.dropIfExistsTable( tableName() );
304 m_mappingVersion(
"" ),
309 const std::string&
name,
311 const std::string& mappingVersion,
312 unsigned int nobjWr ):
315 m_className( className ),
316 m_mappingVersion( mappingVersion ),
325 m_name( rhs.m_name ),
326 m_className( rhs.m_className ),
327 m_mappingVersion( rhs.m_mappingVersion ),
328 m_nobjWr( rhs.m_nobjWr ){
353 std::map<int,PoolDbCacheData >::iterator iData = m_idMap.insert( std::make_pair(
id, data )).first;
355 if( iS == m_sequences.end() ){
356 throwException(
"ContainerId Sequence is empty",
"PoolDbCache::add");
358 if(
id > (
int)iS->second->m_nobjWr ){
359 iS->second->m_nobjWr = id;
371 for(std::map<int,PoolDbCacheData >::const_iterator iData = m_idMap.begin();
372 iData != m_idMap.end(); iData++ ){
373 if( iData->second.m_name == name ){
382 std::map<int,PoolDbCacheData >::iterator iC = m_idMap.find(
id );
383 if( iC == m_idMap.end() ){
384 throwException(
"Container has not been found in the cache.",
"PoolDbCache::find");
390 std::string
name =
find(
id ).m_name;
407 static std::string s_name(
"POOL_RSS_CONTAINERS");
413 static std::string s_column(
"CONTAINER_ID");
419 static std::string s_column(
"CONTAINER_NAME");
424 static std::string s_column(
"CONTAINER_TYPE");
429 static std::string s_column(
"TABLE_NAME");
434 static std::string s_column(
"CLASS_NAME");
439 static std::string s_column(
"MAPPING_VERSION");
444 static std::string s_column(
"NUMBER_OF_WRITTEN_OBJECTS");
449 static std::string s_column(
"NUMBER_OF_DELETED_OBJECTS");
454 static std::string s_type(
"Homogeneous");
467 m_dbCache = &dbCache;
473 throwException(
"Container Table handle has not been initialized.",
"PoolContainerHeaderTable::getContainerData");
477 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
478 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
479 coral::AttributeList outputBuffer;
480 outputBuffer.extend<
int>( containerIdColumn() );
481 outputBuffer.extend<std::string>( containerNameColumn() );
482 outputBuffer.extend<std::string>( classNameColumn() );
483 outputBuffer.extend<std::string>( baseMappingVersionColumn() );
484 outputBuffer.extend<
unsigned int>( numberOfWrittenObjectsColumn() );
485 outputBuffer.extend<
unsigned int>( numberOfDeletedObjectsColumn() );
486 query->defineOutput( outputBuffer );
487 query->addToOutputList( containerIdColumn() );
488 query->addToOutputList( containerNameColumn() );
489 query->addToOutputList( classNameColumn() );
490 query->addToOutputList( baseMappingVersionColumn() );
491 query->addToOutputList( numberOfWrittenObjectsColumn() );
492 query->addToOutputList( numberOfDeletedObjectsColumn() );
493 std::stringstream condition;
494 condition << containerTypeColumn()<<
" = :"<<containerTypeColumn();
495 coral::AttributeList condData;
496 condData.extend<std::string>( containerTypeColumn() );
497 condData[ containerTypeColumn() ].data<std::string>()=homogeneousContainerType();
498 query->setCondition( condition.str(), condData );
499 coral::ICursor& cursor =
query->execute();
500 while ( cursor.next() ) {
502 const coral::AttributeList& row = cursor.currentRow();
503 int containerId = row[ containerIdColumn() ].data<
int >() - 1;
504 std::string containerName = row[ containerNameColumn()].data< std::string >();
505 std::string
className = row[ classNameColumn()].data< std::string >();
506 std::string baseMappingVersion = row[ baseMappingVersionColumn()].data< std::string >();
507 unsigned int numberOfWrittenObjects = row[ numberOfWrittenObjectsColumn()].data<
unsigned int >();
508 unsigned int numberOfDeletedObjects = row[ numberOfDeletedObjectsColumn()].data<
unsigned int >();
511 numberOfWrittenObjects-numberOfDeletedObjects ) )) ;
512 m_dbCache->add( containerId,
PoolDbCacheData(containerId, containerName, className, baseMappingVersion, numberOfWrittenObjects) );
518 const std::string& containerName,
545 throwException(
"Cannot create new Containers into POOL database.",
"PoolContainerHeaderTable::addContainer");
550 throwException(
"Container Table handle has not been initialized.",
"PoolContainerHeaderTable::removeContainer");
552 m_dbCache->remove(
id );
553 std::stringstream whereClause;
554 whereClause << containerIdColumn() <<
"= :" <<containerIdColumn();
555 coral::AttributeList whereData;
556 whereData.extend<
int >( containerIdColumn() );
557 whereData.begin()->data<
int >() =
id + 1;
558 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
559 containerTable.dataEditor().deleteRows(whereClause.str(),whereData);
563 throwException(
"Operation not supported into POOL database.",
"PoolContainerHeaderTable::incrementNumberOfObjects");
567 throwException(
"Operation not supported into POOL database.",
"PoolContainerHeaderTable::decrementNumberOfObjects");
571 if( numberOfObjectsForContainerIds.size() ){
574 throwException(
"Container Table handle has not been initialized.",
"PoolContainerHeaderTable::updateNumberOfObjects");
577 std::stringstream whereClause;
578 whereClause << containerIdColumn() <<
" = :" <<containerIdColumn();
579 std::stringstream setClause;
580 setClause << numberOfWrittenObjectsColumn()<<
" = :"<<numberOfWrittenObjectsColumn();
581 setClause <<
" , "<< numberOfDeletedObjectsColumn()<<
" = :"<<numberOfDeletedObjectsColumn();
582 coral::AttributeList updateData;
583 updateData.extend<
unsigned int>( numberOfWrittenObjectsColumn() );
584 updateData.extend<
unsigned int>( numberOfDeletedObjectsColumn() );
585 updateData.extend<
int>( containerIdColumn() );
587 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
588 std::auto_ptr<coral::IBulkOperation> bulkUpdate( containerTable.dataEditor().bulkUpdateRows( setClause.str(), whereClause.str(), updateData,(int)numberOfObjectsForContainerIds.size()+1));
590 for( std::map<int,unsigned int>::const_iterator iCont = numberOfObjectsForContainerIds.begin();
591 iCont != numberOfObjectsForContainerIds.end(); ++iCont ){
594 unsigned int nwrt = contData.
m_nobjWr;
595 unsigned int ndel = nwrt-iCont->second;
597 updateData[containerIdColumn()].data<
int>() = iCont->first + 1;
598 updateData[numberOfWrittenObjectsColumn()].data<
unsigned int>() = nwrt;
599 updateData[numberOfDeletedObjectsColumn()].data<
unsigned int>() = ndel;
600 bulkUpdate->processNextIteration();
608 return m_schema.existsTable( tableName() );
612 if( m_schema.existsTable( tableName() )){
613 throwException(
"POOL database container header table already exists in this schema.",
614 "PoolContainerHeaderTable::create");
616 throwException(
"POOL database cannot be created.",
"PoolContainerHeaderTable::create");
620 m_schema.dropIfExistsTable( tableName() );
624 static std::string s_table(
"POOL_OR_CLASS_VERSIONS");
629 static std::string s_col(
"CLASS_VERSION");
634 static std::string s_col(
"CONTAINER_ID");
640 static std::string s_col(
"MAPPING_VERSION");
645 m_schema( dbSchema ){
652 return m_schema.existsTable( tableName() );
656 if( m_schema.existsTable( tableName() )){
657 throwException(
"POOL database class version table already exists in this schema.",
658 "PoolClassVersionTable::create");
660 throwException(
"POOL database cannot be created.",
"PoolClassVersionTable::create");
664 m_schema.dropIfExistsTable( tableName() );
674 size_t ind = variableName.find(
"pool::PVector");
675 if( ind != std::string::npos ){
676 return "ora::PVector"+variableName.substr(13);
683 static std::string s_scope(
" ");
688 m_schema( dbSchema ),
696 m_dbCache = &dbCache;
703 coral::ICursor& cursor =
query->execute();
704 while ( cursor.next() ) {
706 const coral::AttributeList& currentRow = cursor.currentRow();
708 dest.insert( mappingVersion );
716 std::map<std::string, std::vector<MappingRawElement> >::const_iterator iSc = elementsByScope.find( scope );
717 if( iSc != elementsByScope.end() ){
718 for( std::vector<MappingRawElement>::const_iterator iMap = iSc->second.begin();
719 iMap != iSc->second.end(); ++iMap ){
721 elem.
scopeName = extraScope+
"::"+iMap->scopeName;
723 rebuildPoolMapping( scope+
"::"+iMap->variableName, extraScope, elementsByScope, dest, counter );
733 std::auto_ptr<coral::IQuery>
query(mappingTable.newQuery());
734 coral::AttributeList outputBuffer;
741 query->defineOutput( outputBuffer );
748 std::ostringstream condition;
750 coral::AttributeList condData;
752 coral::AttributeList::iterator iAttribute = condData.begin();
753 iAttribute->data< std::string >() = version;
754 query->setCondition( condition.str(), condData );
759 coral::ICursor& cursor =
query->execute();
760 std::set<std::string> topElements;
761 std::map<std::string,MappingRawElement> elementsByVarName;
762 while ( cursor.next() ) {
764 const coral::AttributeList& currentRow = cursor.currentRow();
767 std::string elemId = scope+
"::"+varName;
768 std::map<std::string,MappingRawElement>::iterator iE = elementsByVarName.find( elemId );
769 if( iE == elementsByVarName.end() ) {
770 iE = elementsByVarName.insert( std::make_pair( elemId,
MappingRawElement())).first;
779 if( topElements.find( elemId ) == topElements.end() ){
780 topElements.insert( elemId );
788 std::map<std::string, std::vector<MappingRawElement> > elementsByScope;
789 for( std::map<std::string,MappingRawElement>::iterator iEl = elementsByVarName.begin();
790 iEl != elementsByVarName.end(); ++iEl ){
792 std::vector<std::string> reverseCols;
793 for( std::vector<std::string>::reverse_iterator iR = iEl->second.columns.rbegin();
794 iR != iEl->second.columns.rend(); ++iR ){
795 reverseCols.push_back( *iR );
797 iEl->second.columns = reverseCols;
798 std::string scope = iEl->second.scopeName;
799 if( scope != emptyScope() ){
800 std::map<std::string, std::vector<MappingRawElement> >::iterator iS = elementsByScope.find( scope );
801 if( iS == elementsByScope.end() ){
802 elementsByScope.insert( std::make_pair( scope, std::vector<MappingRawElement>(1,iEl->second ) ));
804 iS->second.push_back( iEl->second );
810 for( std::set<std::string>::const_iterator iEl = topElements.begin();
811 iEl != topElements.end(); ++iEl ){
813 std::map<std::string,MappingRawElement>::iterator iE = elementsByVarName.find( *iEl );
820 firstElement.
scopeName = iE->second.variableName;
824 rebuildPoolMapping( iE->second.variableName, iE->second.variableName, elementsByScope, dest, eid );
832 coral::AttributeList rowBuffer;
835 mappingVersionTable.dataEditor().insertRow( rowBuffer );
839 coral::AttributeList dataBuffer;
851 for( std::map < int, MappingRawElement >::const_iterator iElem = mapping.
elements.begin();
852 iElem != mapping.
elements.end(); iElem++ ){
853 for(
size_t iParamIndex = 0; iParamIndex < iElem->second.columns.size(); iParamIndex++ ){
854 std::stringstream elemIdx;
855 elemIdx << iElem->first;
856 std::string scopeName = iElem->second.scopeName;
866 mappingElementTable.dataEditor().insertRow( dataBuffer );
873 coral::AttributeList whereData;
875 whereData.begin()->data<std::string>() = version;
889 std::set<std::string>&
dest,
890 bool onlyDependency ){
892 std::auto_ptr<coral::IQuery>
query( m_schema.newQuery() );
897 query->setDistinct();
898 std::ostringstream condition;
902 coral::AttributeList condData;
905 if( onlyDependency ){
910 query->setCondition(condition.str(),condData);
911 coral::ICursor& cursor =
query->execute();
912 while ( cursor.next() ) {
914 const coral::AttributeList& currentRow = cursor.currentRow();
916 dest.insert( mappingVersion );
923 std::set<std::string>& ){
929 std::set<std::string>& destination ){
933 std::auto_ptr<coral::IQuery>
query( classVersionTable.newQuery() );
934 query->setDistinct();
936 std::ostringstream condition;
938 coral::AttributeList condData;
941 query->setCondition(condition.str(),condData);
942 coral::ICursor& cursor =
query->execute();
943 while ( cursor.next() ) {
945 const coral::AttributeList& currentRow = cursor.currentRow();
947 destination.insert( classVersion );
953 std::map<std::string,std::string>& versionMap ){
956 std::auto_ptr<coral::IQuery>
query( m_schema.newQuery() );
961 query->setDistinct();
962 std::ostringstream condition;
965 coral::AttributeList condData;
968 query->setCondition(condition.str(),condData);
969 coral::ICursor& cursor =
query->execute();
970 while ( cursor.next() ) {
972 const coral::AttributeList& currentRow = cursor.currentRow();
975 versionMap.insert( std::make_pair(classVersion, mappingVersion ) );
981 std::set<std::string>& ){
988 std::string& destination ){
993 if( !isBaseId.first ){
994 std::auto_ptr<coral::IQuery>
query( m_schema.newQuery() );
998 std::ostringstream condition;
1002 coral::AttributeList condData;
1005 coral::AttributeList::iterator iAttribute = condData.begin();
1008 iAttribute->data<
int >() = containerId + 1;
1009 query->setCondition( condition.str(), condData );
1010 coral::ICursor& cursor =
query->execute();
1011 while ( cursor.next() ) {
1013 const coral::AttributeList& currentRow = cursor.currentRow();
1019 if( containerData.
m_className == isBaseId.second ){
1035 const std::string& classVersion,
1039 const std::string& mappingVersion ){
1041 throwException(
"MappingSchema handle has not been initialized.",
"PoolMappingSchema::insertClassVersion");
1050 std::string containerName = m_dbCache->nameById( containerId );
1051 coral::AttributeList::iterator iInAttr = inputData.begin();
1052 iInAttr->data< std::string >() = mappingVersion;
1054 iInAttr->data< std::string >() = classVersion;
1056 iInAttr->data< std::string >() = containerName;
1057 classVersionTable.dataEditor().insertRow( inputData );
1062 const std::string& mappingVersion ){
1064 throwException(
"MappingSchema handle has not been initialized.",
"PoolMappingSchema::setMappingVersion");
1072 std::string containerName = m_dbCache->nameById( containerId );
1073 coral::AttributeList::iterator iInAttr = inputData.begin();
1074 iInAttr->data< std::string >() = mappingVersion;
1076 iInAttr->data< std::string >() = classVersion;
1078 iInAttr->data< std::string >() = containerName;
1082 classVersionTable.dataEditor().updateRows( setClause,whereClause, inputData );
1086 static std::string s_name(
"METADATA");
1091 static std::string s_column(
"NAME");
1096 static std::string s_column(
"TOKEN");
1101 static std::string s_column(
"TIMETYPE");
1107 m_schema( dbSchema ),
1108 m_dbCache( dbCache ){
1115 int contId,
int itemId ){
1116 coral::AttributeList dataToInsert;
1117 dataToInsert.extend<std::string>( objectNameColumn() );
1118 dataToInsert.extend<std::string>( tokenColumn());
1119 dataToInsert.extend<
int>( timetypeColumn());
1121 std::string token =
cond::writeToken( contData.m_name, contId, itemId, contData.m_className );
1122 dataToInsert[ objectNameColumn() ].data<std::string>() = name;
1123 dataToInsert[ tokenColumn() ].data<std::string>() = token;
1124 dataToInsert[ timetypeColumn() ].data<
int>() = -1;
1125 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1126 containerTable.dataEditor().insertRow( dataToInsert );
1130 coral::AttributeList whereData;
1131 whereData.extend<std::string>( objectNameColumn() );
1132 whereData.begin()->data<std::string>() = name;
1133 std::string condition = objectNameColumn() +
" = :" + objectNameColumn();
1134 return m_schema.tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
1138 std::string condition(
"");
1139 coral::AttributeList whereData;
1140 return m_schema.tableHandle( tableName() ).dataEditor().deleteRows( condition, whereData )>0;
1144 std::pair<int,int>& destination ){
1146 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1147 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1148 coral::AttributeList outputBuffer;
1149 outputBuffer.extend<std::string>( tokenColumn() );
1150 query->defineOutput( outputBuffer );
1151 query->addToOutputList( tokenColumn() );
1152 std::ostringstream condition;
1153 condition << objectNameColumn()<<
"= :"<< objectNameColumn();
1154 coral::AttributeList condData;
1155 condData.extend<std::string>( objectNameColumn() );
1156 coral::AttributeList::iterator iAttribute = condData.begin();
1157 iAttribute->data< std::string >() = name;
1158 query->setCondition( condition.str(), condData );
1159 coral::ICursor& cursor =
query->execute();
1160 while ( cursor.next() ) {
1162 const coral::AttributeList& row = cursor.currentRow();
1163 std::string token = row[ tokenColumn() ].data< std::string >();
1165 destination.first = m_dbCache.idByName( tokData.first );
1166 destination.second = tokData.second;
1173 std::vector<std::string>& destination ){
1175 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1176 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1177 coral::AttributeList outputBuffer;
1178 outputBuffer.extend<std::string>( objectNameColumn() );
1179 query->defineOutput( outputBuffer );
1180 query->addToOutputList( objectNameColumn() );
1181 std::ostringstream condition;
1182 condition << tokenColumn()<<
"= :"<< tokenColumn();
1185 coral::AttributeList condData;
1186 condData.extend<std::string>( tokenColumn() );
1187 coral::AttributeList::iterator iAttribute = condData.begin();
1188 iAttribute->data< std::string >() = token;
1189 query->setCondition( condition.str(), condData );
1190 coral::ICursor& cursor =
query->execute();
1191 while ( cursor.next() ) {
1193 const coral::AttributeList& row = cursor.currentRow();
1194 std::string
name = row[ objectNameColumn() ].data< std::string >();
1195 destination.push_back( name );
1201 std::vector<std::string>& destination ){
1204 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1205 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1206 coral::AttributeList outputBuffer;
1207 outputBuffer.extend<std::string>( objectNameColumn() );
1208 query->defineOutput( outputBuffer );
1209 query->addToOutputList( objectNameColumn() );
1210 std::ostringstream condition;
1211 condition << tokenColumn()<<
" LIKE :"<< tokenColumn();
1214 coral::AttributeList condData;
1215 condData.extend<std::string>( tokenColumn() );
1216 coral::AttributeList::iterator iAttribute = condData.begin();
1217 iAttribute->data< std::string >() = tokenFragment;
1218 query->setCondition( condition.str(), condData );
1219 coral::ICursor& cursor =
query->execute();
1220 while ( cursor.next() ) {
1222 const coral::AttributeList& row = cursor.currentRow();
1223 std::string
name = row[ objectNameColumn() ].data< std::string >();
1224 destination.push_back( name );
1232 coral::ITable& containerTable = m_schema.tableHandle( tableName() );
1233 std::auto_ptr<coral::IQuery>
query( containerTable.newQuery());
1234 coral::AttributeList outputBuffer;
1235 outputBuffer.extend<std::string>( objectNameColumn() );
1236 query->defineOutput( outputBuffer );
1237 query->addToOutputList( objectNameColumn() );
1238 coral::ICursor& cursor =
query->execute();
1239 while ( cursor.next() ) {
1241 const coral::AttributeList& row = cursor.currentRow();
1242 std::string
name = row[ objectNameColumn() ].data< std::string >();
1243 destination.push_back( name );
1249 return m_schema.existsTable( tableName() );
1253 if( m_schema.existsTable( tableName() )){
1255 "CondMetadataTable::create");
1257 throwException(
"Cond Metadata table cannot be created.",
"CondMetadataTable::create");
1261 if( !m_schema.existsTable( tableName() )){
1262 throwException(
"Metadata table does not exists in this schema.",
1263 "CondMetadataTable::drop");
1265 throwException(
"Cond Metadata table cannot be dropped.",
"CondMetadataTable::drop");
1275 m_schema( dbSchema ),
1277 m_mainTable( dbSchema ),
1278 m_sequenceTable( dbSchema ),
1279 m_mappingVersionTable( dbSchema ),
1280 m_mappingElementTable( dbSchema ),
1281 m_containerHeaderTable( dbSchema ),
1282 m_classVersionTable( dbSchema ),
1283 m_mappingSchema( dbSchema ),
1284 m_metadataTable( dbSchema, m_dbCache ){
1294 if(!m_mainTable.exists()){
1298 if(!m_sequenceTable.exists() ||
1299 !m_mappingVersionTable.exists() ||
1300 !m_mappingElementTable.exists() ||
1301 !m_containerHeaderTable.exists() ||
1302 !m_classVersionTable.exists()){
1304 "PoolDatabaseSchema::exists");
1306 if( !m_metadataTable.exists()){
1308 "PoolDatabaseSchema::exists");
1314 throwException(
"POOL database cannot be created.",
"PoolDatabaseSchema::create");
1318 m_classVersionTable.drop();
1319 m_mappingElementTable.drop();
1320 m_sequenceTable.drop();
1321 m_containerHeaderTable.drop();
1322 m_mappingVersionTable.drop();
1331 return m_sequenceTable;
1335 return m_mappingVersionTable;
1339 return m_mappingElementTable;
1343 return m_containerHeaderTable;
1347 return m_classVersionTable;
1351 return m_mappingSchema;
1355 return m_metadataTable;
IDatabaseTable & mappingElementTable()
IMappingSchema & mappingSchema()
static std::string tableName()
MappingRawElement & addElement(int elementId)
static std::string tableNameColumn()
static std::string tableName()
static std::string variableTypeColumn()
PoolDbCacheData m_mappingData
PoolMappingSchema m_mappingSchema
std::map< std::string, PoolDbCacheData * > & sequences()
static std::string dependencyMappingElementType()
Returns the name of the dependent class mapping element type.
std::pair< std::string, int > parseToken(const std::string &objectId)
PoolSequenceTable(coral::ISchema &dbSchema)
std::string mappingTypeFromPool(const std::string &mappingType)
PoolDbCacheData m_databaseData
static std::string tableName()
static std::string columnNameColumn()
PoolMappingSchema(coral::ISchema &dbSchema)
int idByName(const std::string &name)
static std::string mappingVersionColumn()
void init(PoolDbCache &dbCache)
INamingServiceTable & namingServiceTable()
std::map< int, MappingRawElement > elements
void removeMapping(const std::string &version)
std::string writeTokenContainerFragment(const std::string &containerName, const std::string &className)
void sinchronize(const std::string &sequenceName, int lastValue)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
bool getClassVersionListForContainer(int containerId, std::map< std::string, std::string > &versionMap)
void add(int id, const PoolDbCacheData &data)
PoolSequenceTable m_sequenceTable
bool getContainerTableMap(std::map< std::string, int > &destination)
static std::string variableParIndexColumn()
static std::string emptyScope()
static std::string classVersionColumn()
std::string poolSchemaVersion()
IDatabaseTable & mappingVersionTable()
bool selectMappingVersion(const std::string &classId, int containerId, std::string &destination)
PoolMappingElementTable(coral::ISchema &dbSchema)
void setMappingVersion(const std::string &classId, int containerId, const std::string &mappingVersion)
static std::string elementIdColumn()
static std::string sequenceNameForMapping()
virtual ~PoolMappingVersionTable()
bool getMappingVersionListForContainer(int containerId, std::set< std::string > &destination, bool onlyDependency=false)
bool getMapping(const std::string &version, MappingRawData &destination)
bool containerForMappingVersion(const std::string &mappingVersion, int &destination)
static std::string emptyScope()
static bool existsMainTable(coral::ISchema &dbSchema)
static std::string objectMappingElementType()
Returns the name of the object mapping element type.
PoolDbCacheData & find(int id)
bool getParameters(std::map< std::string, std::string > &destination)
PoolClassVersionTable(coral::ISchema &dbSchema)
bool getLastId(const std::string &sequenceName, int &lastId)
static std::string classVersionFromId(const std::string &classId)
static std::pair< bool, std::string > classNameFromBaseId(const std::string &classId)
static std::string sequenceNameColumn()
void rebuildPoolMapping(const std::string &scope, const std::string &extraScope, const std::map< std::string, std::vector< MappingRawElement > > &elementsByScope, ora::MappingRawData &dest, int &counter)
PoolDbCacheData & operator=(const PoolDbCacheData &rhs)
static std::string sequenceValueColumn()
virtual ~PoolMappingSchema()
IContainerHeaderTable & containerHeaderTable()
void init(PoolDbCache &dbCache)
PoolMappingVersionTable(coral::ISchema &dbSchema)
virtual ~PoolSequenceTable()
bool getClassVersionListForMappingVersion(const std::string &mappingVersion, std::set< std::string > &destination)
const std::string & nameById(int id)
PoolDatabaseSchema(coral::ISchema &dbSchema)
static std::string mappingVersionColumn()
PoolMainTable(coral::ISchema &dbSchema)
std::string variableNameFromPool(const std::string &variableName)
static std::string containerNameColumn()
std::vector< std::vector< double > > tmp
std::string m_mappingVersion
static std::string OraArrayMappingElementType()
Returns the name of the ORA array mapping element type.
static std::string scopeNameColumn()
PoolContainerHeaderTable m_containerHeaderTable
void storeMapping(const MappingRawData &mapping)
static std::string variableNameColumn()
bool getMappingVersionListForTable(const std::string &tableName, std::set< std::string > &destination)
static std::string sequenceNameForContainer(const std::string &containerName)
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 sequenceNameForContainerId()
sequence names
void throwException(const std::string &message, const std::string &methodName)
bool getVersionList(std::set< std::string > &destination)
static std::string tableName()
bool add(const std::string &sequenceName)
static std::string mappingVersionColumn()
static std::string containerNameColumn()
virtual ~PoolDatabaseSchema()
IDatabaseTable & classVersionTable()
virtual ~PoolClassVersionTable()
std::string writeToken(const std::string &containerName, int oid0, int oid1, const std::string &className)
virtual ~PoolMappingElementTable()
static std::string classMappingElementType()
Returns the name of the class mapping element type.
ISequenceTable & sequenceTable()
static std::string elementTypeColumn()
std::string className(const T &t)
std::string schemaVersion()
bool getDependentClassesInContainerMapping(int containerId, std::set< std::string > &destination)
void erase(const std::string &sequenceName)
static std::string tableName()