diff --git a/Database/APR/RelationalCollection/src/DBLock.cpp b/Database/APR/RelationalCollection/src/DBLock.cpp index 6668fd35b10b622b67552f872a60416cce360d76..d81d12c6bb3f3a1657acc4d4528dd2cd1e7dd0fa 100644 --- a/Database/APR/RelationalCollection/src/DBLock.cpp +++ b/Database/APR/RelationalCollection/src/DBLock.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "DBLock.h" @@ -63,7 +63,7 @@ using namespace pool::RelationalCollection; -DBLock::DBLock( coral::ISessionProxy& session, std::string collName ) +DBLock::DBLock( coral::ISessionProxy& session, const std::string& collName ) : m_session( session ), m_name( collName ), m_locked( false ), diff --git a/Database/APR/RelationalCollection/src/DBLock.h b/Database/APR/RelationalCollection/src/DBLock.h index f564be87a122273e7e4d74d4c491158db991260a..1923fd0d97cba89ba623d95ff7df786ac6bb7c2e 100644 --- a/Database/APR/RelationalCollection/src/DBLock.h +++ b/Database/APR/RelationalCollection/src/DBLock.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef RELATIONALCOLLECTION_DBLOCK_H @@ -14,7 +14,7 @@ namespace pool { class DBLock { public: - DBLock( coral::ISessionProxy& session, std::string collName ); + DBLock( coral::ISessionProxy& session, const std::string& collName ); ~DBLock(); /// set a global lock to serialize collection operations (creation etc) diff --git a/Database/APR/RelationalCollection/src/RelationalCollection.cpp b/Database/APR/RelationalCollection/src/RelationalCollection.cpp index d5a59cab5eff772170919eb3b190a6b7afb35743..ecc1eeec38d30aa3844a42ccd0730928f3a4ee74 100644 --- a/Database/APR/RelationalCollection/src/RelationalCollection.cpp +++ b/Database/APR/RelationalCollection/src/RelationalCollection.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "RelationalCollection.h" @@ -403,10 +403,9 @@ drop_impl( const std::string& _fragmentName, } // If collection fragment has parent fragments, update parent fragment rows in collection headers table. - for ( std::vector< std::string >::const_iterator iName = parentFragmentNames.begin(); - iName != parentFragmentNames.end(); iName++ ) + for (const std::string& name : parentFragmentNames ) { - m_whereDataForCollectionNameInHeadersTable->begin()->data<std::string>() = *iName; + m_whereDataForCollectionNameInHeadersTable->begin()->data<std::string>() = name; std::string setClause = RelationalCollectionNames::childCollectionNameVariableInCollectionHeadersTable() + " = " + "\'\'" + " , " + RelationalCollectionNames::foreignKeyNameVariableInCollectionHeadersTable() + " = " + "\'\'"; nominalSchema.tableHandle( RelationalCollectionNames::nameOfCollectionHeadersTable() ).dataEditor().updateRows( setClause, @@ -1548,7 +1547,7 @@ createLinkIdToTokenKeyMaps( const std::string& fragmentName ) void pool::RelationalCollection::RelationalCollection::createIndex( const std::string& indexName, - const std::vector< std::string > columnNames, + const std::vector< std::string >& columnNames, bool isUnique ) { coral::ISchema& nominalSchema = m_session->nominalSchema(); @@ -1605,7 +1604,7 @@ pool::RelationalCollection::RelationalCollection::createIndex( const std::string delete query; bool indexFound = false; for( std::map< std::string, std::vector< std::string >* >::const_iterator iData = - collectionColumnNamesForIndexName.begin(); iData != collectionColumnNamesForIndexName.end(); iData++ ) + collectionColumnNamesForIndexName.begin(); iData != collectionColumnNamesForIndexName.end(); ++iData ) { std::string existingIndexName = iData->first; std::vector< std::string >* existingColumnNames = iData->second; @@ -1748,7 +1747,7 @@ setUniqueConstraint( const std::string& constraintName, const std::vector< std:: for( std::map< std::string, std::vector< std::string >* >::const_iterator iData = collectionColumnNamesForUniqueConstraintName.begin(); iData != collectionColumnNamesForUniqueConstraintName.end(); - iData++ ) + ++iData ) { std::string existingUniqueConstraintName = iData->first; std::vector< std::string >* existingColumnNames = iData->second; @@ -1885,7 +1884,7 @@ pool::RelationalCollection::RelationalCollection::retrieveIndexDescriptions( con for( std::map< std::string, std::vector< std::string >* >::const_iterator iIndex = collectionColumnNamesForIndexName.begin(); iIndex != collectionColumnNamesForIndexName.end(); - iIndex++ ) + ++iIndex ) { std::string indexName = iIndex->first; @@ -1965,7 +1964,7 @@ pool::RelationalCollection::RelationalCollection::retrieveUniqueConstraintDescri // Add unique constraints to collection description. for( std::map< std::string, std::vector< std::string >* >::const_iterator iConstraint = collectionColumnNamesForUniqueConstraintName.begin(); iConstraint != - collectionColumnNamesForUniqueConstraintName.end(); iConstraint++ ) + collectionColumnNamesForUniqueConstraintName.end(); ++iConstraint ) { // MN: FIX guess - check functionality! // m_description.setUniqueConstraint( iConstraint->first, *iConstraint->second ); diff --git a/Database/APR/RelationalCollection/src/RelationalCollection.h b/Database/APR/RelationalCollection/src/RelationalCollection.h index 4ad428f7457090eee4bc19dbeca7bf8d501e0958..128d5990018203597cb58a51bf9e860a1273b7d7 100755 --- a/Database/APR/RelationalCollection/src/RelationalCollection.h +++ b/Database/APR/RelationalCollection/src/RelationalCollection.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef RELATIONALCOLLECTION_RELATIONALCOLLECTION_H @@ -268,7 +268,7 @@ namespace pool { * @param isUnique Flag to indicates whether combination of indexed column values must be unique. */ void createIndex( const std::string& indexName, - const std::vector< std::string > columnNames, + const std::vector< std::string >& columnNames, bool isUnique ); /** diff --git a/Database/APR/RelationalCollection/src/RelationalCollectionDataEditor.cpp b/Database/APR/RelationalCollection/src/RelationalCollectionDataEditor.cpp index e008a9be58746334871702fd72e1fbf880752988..7ebe75a7f8b05a34d1396fcb0af7716f0ecbb0dd 100755 --- a/Database/APR/RelationalCollection/src/RelationalCollectionDataEditor.cpp +++ b/Database/APR/RelationalCollection/src/RelationalCollectionDataEditor.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "RelationalCollectionDataEditor.h" @@ -712,7 +712,7 @@ deleteRows( const std::string& whereClause, coral::AttributeList* attributeBindD // Loop over all collection fragments. for ( std::map< std::string, std::string >::const_iterator iName = m_dataTableNameForCollectionFragmentName.begin(); - iName != m_dataTableNameForCollectionFragmentName.end(); iName++ ) + iName != m_dataTableNameForCollectionFragmentName.end(); ++iName ) { // Get names of collection fragment, data table and links table. std::string fragmentName = iName->first; diff --git a/Database/APR/RelationalCollection/src/RelationalCollectionExpressionParser.cpp b/Database/APR/RelationalCollection/src/RelationalCollectionExpressionParser.cpp index c2a568256c7f1c0044afe0e7f275b69f71ad4cfd..e6bbee27d41d5dcca9553c6830c459264822df19 100755 --- a/Database/APR/RelationalCollection/src/RelationalCollectionExpressionParser.cpp +++ b/Database/APR/RelationalCollection/src/RelationalCollectionExpressionParser.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "RelationalCollectionExpressionParser.h" @@ -138,7 +138,7 @@ pool::RelationalCollection::RelationalCollectionExpressionParser::parse( std::vector< std::string > newWhereClauseFragments; unsigned pos = 0; for( std::vector< std::string >::const_iterator iWord = whereClauseFragments.begin(); - iWord != whereClauseFragments.end(); iWord++, pos++ ) + iWord != whereClauseFragments.end(); ++iWord, ++pos ) { // cout << "Parsing: cond: " << *iWord << endl; bool isAttribute(false), isToken(false); @@ -160,10 +160,10 @@ pool::RelationalCollection::RelationalCollectionExpressionParser::parse( if( isAttribute || isToken ) { fragmentName = description.collectionFragmentName( *iWord ); columnName = it->second; - for( std::vector< std::string >::const_iterator iName = collectionFragmentNames.begin(); - iName != collectionFragmentNames.end(); iName++ ) + for (const std::string& name : collectionFragmentNames ) { - if( *iName == fragmentName ) { + if( name == fragmentName ) { + // cppcheck-suppress invalidContainerLoop; ok: we break after this collectionFragmentNames.push_back( fragmentName ); break; } @@ -190,16 +190,16 @@ pool::RelationalCollection::RelationalCollectionExpressionParser::parse( } // Check if where clause fragment is part of a Token column condition. - if( nextWord.find( "." ) == 0 ) { + if( !nextWord.empty() && nextWord[0] == '.' ) { // Is Token column condition. Increment iterator and position and get Token column name. - iWord++; pos++; + ++iWord; ++pos; // Find name of Token column used for condition. std::string columnName; if( whereClauseFragments.size() > pos+1 ) { // Column name found. Increment iterator and position. columnName = whereClauseFragments[pos+1]; - iWord++; pos++; + ++iWord; ++pos; bool isOIDColumn = ( columnName == RelationalCollectionNames::oid_1_variableInCollectionDataTable() || @@ -273,15 +273,15 @@ pool::RelationalCollection::RelationalCollectionExpressionParser::parse( comparator.find_first_not_of( " >(" ) == comparator.npos ) ) { // Comparison operator found. Increment iterator and position. - iWord++; - pos++; + ++iWord; + ++pos; // Look for the Token value in the next where clause fragment to the right. if ( whereClauseFragments.size() > pos+1 ) { // Token value found. Increment iterator and position. valueAsString = whereClauseFragments[pos+1]; - iWord++; - pos++; + ++iWord; + ++pos; } else { std::string errorMsg = "Badly formed Token condition. No value found for Token '" + *iWord + "'."; @@ -331,7 +331,7 @@ pool::RelationalCollection::RelationalCollectionExpressionParser::parse( unsigned oid2ColumnValue = 0; std::map< std::string, unsigned >* linkIdForTokenKey = ( mapOfLinkIdForTokenKeyMaps.find( fragmentName ) )->second; - if ( valueAsString.find( ":" ) == 0 ) + if ( !valueAsString.empty() && valueAsString[0] == ':' ) { // Get bind variable for Token. std::string bindVariable = valueAsString.substr( 1 ); @@ -439,10 +439,9 @@ pool::RelationalCollection::RelationalCollectionExpressionParser::parse( } // Add all new where clause fragments to the output string sequentially. - for ( std::vector< std::string >::const_iterator iFragment = newWhereClauseFragments.begin(); - iFragment != newWhereClauseFragments.end(); iFragment++ ) + for (const std::string& fragment : newWhereClauseFragments ) { - parsingOutput << *iFragment; + parsingOutput << fragment; } coral::MessageStream log( "pool::RelationalCollectionExpressionParser::parse()" ); diff --git a/Database/APR/RelationalCollection/src/RelationalCollectionQuery.cpp b/Database/APR/RelationalCollection/src/RelationalCollectionQuery.cpp index 0ae0c8d8d49b17c01b83b30cfa25bbb5b9377d64..083145ac89f4e944c01ce47401d874827a89d485 100755 --- a/Database/APR/RelationalCollection/src/RelationalCollectionQuery.cpp +++ b/Database/APR/RelationalCollection/src/RelationalCollectionQuery.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "RelationalCollectionQuery.h" @@ -261,9 +261,8 @@ pool::RelationalCollection::RelationalCollectionQuery::prepareQuery( ) if( m_readPrimaryKey ) addPrimaryKeyToSelect(); // Add names of links tables used for Token column conditions to query table list. - for( vector< string >::const_iterator iName = m_linksTableNames.begin(); - iName != m_linksTableNames.end(); iName++ ) { - m_query->addToTableList( *iName ); + for (const std::string& name : m_linksTableNames) { + m_query->addToTableList( name ); } // Add data table associated with collection fragment to query table list. @@ -372,9 +371,8 @@ pool::RelationalCollection::RelationalCollectionQuery::addToTokenOutputList( con "RelationalCollection" ); } - if( m_selectedTokenColumnNames.find(columnName) == m_selectedTokenColumnNames.end() ) { + if (m_selectedTokenColumnNames.insert(columnName).second) { // cout << "Adding token column to query output list:" << columnName << endl; - m_selectedTokenColumnNames.insert( columnName ); m_outputTokenList->extend( columnName ); addToCollectionFragmentList( m_description.collectionFragmentName( columnName ) ); } diff --git a/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.cpp b/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.cpp index 89ee375875d4a47a568eea83f7e9d6456e5dd0e3..dc32d1a93ff08773c3ce73a8201bf25c7a3fbfd6 100755 --- a/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.cpp +++ b/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "RelationalCollectionSchemaEditor.h" @@ -434,7 +434,7 @@ dropColumn( const std::string& columnName ) for( std::map< int, std::string >::iterator iData = m_collectionColumnNameForTableColumnPosition.begin(); - iData != m_collectionColumnNameForTableColumnPosition.end(); iData++ ) + iData != m_collectionColumnNameForTableColumnPosition.end(); ++iData ) { if( iData->second == columnName ) { m_collectionColumnNameForTableColumnPosition.erase( iData ); @@ -529,7 +529,7 @@ pool::RelationalCollection::RelationalCollectionSchemaEditor::renameColumn( cons m_collectionRowBuffer.setAttributeList( attributeList ); } for ( std::map< int, std::string >::iterator iData = m_collectionColumnNameForTableColumnPosition.begin(); - iData != m_collectionColumnNameForTableColumnPosition.end(); iData++ ) + iData != m_collectionColumnNameForTableColumnPosition.end(); ++iData ) { int pos = iData->first; if ( iData->second == oldName ) @@ -764,7 +764,7 @@ pool::RelationalCollection::RelationalCollectionSchemaEditor::dropIndex( const s void pool::RelationalCollection::RelationalCollectionSchemaEditor:: -setUniqueConstraint( std::string constraintName, const std::string& columnName ) +setUniqueConstraint( const std::string& constraintName, const std::string& columnName ) { setUniqueConstraint( constraintName, std::vector<std::string>( 1, columnName ) ); } @@ -772,15 +772,15 @@ setUniqueConstraint( std::string constraintName, const std::string& columnName ) void pool::RelationalCollection::RelationalCollectionSchemaEditor:: -setUniqueConstraint( std::string constraintName, const std::vector< std::string >& columnNames ) +setUniqueConstraint( const std::string& constraintNameIn, const std::vector< std::string >& columnNames ) { coral::ISchema& nominalSchema = m_session->nominalSchema(); // Set unique constraint in collection description object. - m_description->setUniqueConstraint( constraintName, columnNames ); + m_description->setUniqueConstraint( constraintNameIn, columnNames ); // Get newly generated name for unique constraint. - constraintName = m_description->uniqueConstraint( columnNames ).name(); + std::string constraintName = m_description->uniqueConstraint( columnNames ).name(); // Get data table column names for columns used by this unique constraint. std::vector< std::string > tableColumnNames; @@ -1076,12 +1076,9 @@ addCollectionFragment( const std::string& fragmentName, const pool::ICollectionFragment& fragment = m_description->collectionFragment( fragmentName ); coral::AttributeList* dataTableRowBuffer = new coral::AttributeList; int tokPos = 0; - for( std::vector< pool::CollectionColumn* >::const_iterator - iColumn = fragment.tokenColumns().begin(); - iColumn != fragment.tokenColumns().end(); - iColumn++ ) + for (pool::CollectionColumn* column : fragment.tokenColumns()) { - std::string collectionColumnName = (*iColumn)->name(); + std::string collectionColumnName = column->name(); std::string variableName = RelationalCollectionNames::variableDataVariableInCollectionDataTable( tokPos ); std::string tableColumnPrefix = dataTableName + "." + variableName + "_"; //std::cout << " >>>> Adding Token Column prefix: " << collectionColumnName @@ -1100,10 +1097,10 @@ addCollectionFragment( const std::string& fragmentName, tokPos++; } int attrPos = 0; - for ( std::vector< pool::CollectionColumn* >::const_iterator iColumn = fragment.attributeColumns().begin(); iColumn != fragment.attributeColumns().end(); iColumn++ ) + for (pool::CollectionColumn* column : fragment.attributeColumns()) { - std::string collectionColumnName = (*iColumn)->name(); - std::string columnType = (*iColumn)->type(); + std::string collectionColumnName = column->name(); + std::string columnType = column->type(); std::string tableColumnName = dataTableName + "." + RelationalCollectionNames::variableDataVariableInCollectionDataTable( attrPos ); m_tableAttributeColumnNameForCollectionAttributeColumnName.insert( std::make_pair( collectionColumnName, tableColumnName ) ); @@ -1231,7 +1228,7 @@ dropCollectionFragment( const std::string& fragmentName ) m_tableTokenColumnPrefixForCollectionTokenColumnName.erase( collectionColumnName ); m_tableColumnNameForCollectionColumnName.erase( collectionColumnName ); for ( std::map< int, std::string >::iterator iData = m_collectionColumnNameForTableColumnPosition.begin(); - iData != m_collectionColumnNameForTableColumnPosition.end(); iData++ ) + iData != m_collectionColumnNameForTableColumnPosition.end(); ++iData ) { if ( iData->second == collectionColumnName ) { m_collectionColumnNameForTableColumnPosition.erase( iData->first ); @@ -1248,7 +1245,7 @@ dropCollectionFragment( const std::string& fragmentName ) m_tableAttributeColumnNameForCollectionAttributeColumnName.erase( collectionColumnName ); m_tableColumnNameForCollectionColumnName.erase( collectionColumnName ); for ( std::map< int, std::string >::iterator iData = m_collectionColumnNameForTableColumnPosition.begin(); - iData != m_collectionColumnNameForTableColumnPosition.end(); iData++ ) + iData != m_collectionColumnNameForTableColumnPosition.end(); ++iData ) { if ( iData->second == collectionColumnName ) { m_collectionColumnNameForTableColumnPosition.erase( iData->first ); diff --git a/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.h b/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.h index 80bc1e0125e0affc26d0da2a08a58b56779d6313..6af41c931117c6657a105865373487d10309c742 100755 --- a/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.h +++ b/Database/APR/RelationalCollection/src/RelationalCollectionSchemaEditor.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef RELATIONALCOLLECTION_RELATIONALCOLLECTIONSCHEMAEDITOR_H @@ -242,7 +242,7 @@ namespace pool { * * @param columnName Name of column for which constraint is applied. */ - void setUniqueConstraint( std::string constraintName, const std::string& columnName ); + void setUniqueConstraint( const std::string& constraintName, const std::string& columnName ); /** * Sets a unique constraint on one or more columns of the collection. Automatically generates a @@ -250,7 +250,7 @@ namespace pool { * * @param columnNames Names of columns for which constraint is applied. */ - void setUniqueConstraint( std::string constraintName, const std::vector<std::string>& columnNames ); + void setUniqueConstraint( const std::string& constraintName, const std::vector<std::string>& columnNames ); /** * Unsets an existing unique constraint on a single column of the collection, diff --git a/Database/APR/RelationalCollection/tests/WriteRead/TestDriver.cpp b/Database/APR/RelationalCollection/tests/WriteRead/TestDriver.cpp index 329a8b8d8b58fbea7e9862e052a0f021f05fa399..cc62e2f831333f5086430dc0885b3bbaa2b182f3 100644 --- a/Database/APR/RelationalCollection/tests/WriteRead/TestDriver.cpp +++ b/Database/APR/RelationalCollection/tests/WriteRead/TestDriver.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "TestDriver.h" @@ -91,7 +91,7 @@ TestDriver::write() token.oid().first = i%4; token.oid().second = 100000*tok_n + i; if( iToken.tokenName() == "Ref" ) - token.oid().second += 1<<31U; + token.oid().second += 1u<<31U; token.setData( &*iToken ); cout << "Storing token:" << iToken->toString() << endl; tok_n++; ++iToken;