diff --git a/catalogue/OracleCatalogue.cpp b/catalogue/OracleCatalogue.cpp index 4b1e89acc8ff2a4385eaa4b15bdce3e353b2d5a1..397176c0b0a4373b0d25022842d1add020f4e57b 100644 --- a/catalogue/OracleCatalogue.cpp +++ b/catalogue/OracleCatalogue.cpp @@ -89,41 +89,41 @@ common::dataStructures::ArchiveFile OracleCatalogue::deleteArchiveFile( auto conn = m_connPool.getConn(); auto selectStmt = conn.createStmt(selectSql, rdbms::Stmt::AutocommitMode::OFF); selectStmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId); - std::unique_ptr<rdbms::Rset> selectRset(selectStmt->executeQuery()); + rdbms::Rset selectRset = selectStmt->executeQuery(); std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile; - while(selectRset->next()) { + while(selectRset.next()) { if(nullptr == archiveFile.get()) { archiveFile = cta::make_unique<common::dataStructures::ArchiveFile>(); - archiveFile->archiveFileID = selectRset->columnUint64("ARCHIVE_FILE_ID"); - archiveFile->diskInstance = selectRset->columnString("DISK_INSTANCE_NAME"); - archiveFile->diskFileId = selectRset->columnString("DISK_FILE_ID"); - archiveFile->diskFileInfo.path = selectRset->columnString("DISK_FILE_PATH"); - archiveFile->diskFileInfo.owner = selectRset->columnString("DISK_FILE_USER"); - archiveFile->diskFileInfo.group = selectRset->columnString("DISK_FILE_GROUP"); - archiveFile->diskFileInfo.recoveryBlob = selectRset->columnString("DISK_FILE_RECOVERY_BLOB"); - archiveFile->fileSize = selectRset->columnUint64("SIZE_IN_BYTES"); - archiveFile->checksumType = selectRset->columnString("CHECKSUM_TYPE"); - archiveFile->checksumValue = selectRset->columnString("CHECKSUM_VALUE"); - archiveFile->storageClass = selectRset->columnString("STORAGE_CLASS_NAME"); - archiveFile->creationTime = selectRset->columnUint64("ARCHIVE_FILE_CREATION_TIME"); - archiveFile->reconciliationTime = selectRset->columnUint64("RECONCILIATION_TIME"); + archiveFile->archiveFileID = selectRset.columnUint64("ARCHIVE_FILE_ID"); + archiveFile->diskInstance = selectRset.columnString("DISK_INSTANCE_NAME"); + archiveFile->diskFileId = selectRset.columnString("DISK_FILE_ID"); + archiveFile->diskFileInfo.path = selectRset.columnString("DISK_FILE_PATH"); + archiveFile->diskFileInfo.owner = selectRset.columnString("DISK_FILE_USER"); + archiveFile->diskFileInfo.group = selectRset.columnString("DISK_FILE_GROUP"); + archiveFile->diskFileInfo.recoveryBlob = selectRset.columnString("DISK_FILE_RECOVERY_BLOB"); + archiveFile->fileSize = selectRset.columnUint64("SIZE_IN_BYTES"); + archiveFile->checksumType = selectRset.columnString("CHECKSUM_TYPE"); + archiveFile->checksumValue = selectRset.columnString("CHECKSUM_VALUE"); + archiveFile->storageClass = selectRset.columnString("STORAGE_CLASS_NAME"); + archiveFile->creationTime = selectRset.columnUint64("ARCHIVE_FILE_CREATION_TIME"); + archiveFile->reconciliationTime = selectRset.columnUint64("RECONCILIATION_TIME"); } // If there is a tape file - if(!selectRset->columnIsNull("VID")) { + if(!selectRset.columnIsNull("VID")) { // Add the tape file to the archive file's in-memory structure common::dataStructures::TapeFile tapeFile; - tapeFile.vid = selectRset->columnString("VID"); - tapeFile.fSeq = selectRset->columnUint64("FSEQ"); - tapeFile.blockId = selectRset->columnUint64("BLOCK_ID"); - tapeFile.compressedSize = selectRset->columnUint64("COMPRESSED_SIZE_IN_BYTES"); - tapeFile.copyNb = selectRset->columnUint64("COPY_NB"); - tapeFile.creationTime = selectRset->columnUint64("TAPE_FILE_CREATION_TIME"); + tapeFile.vid = selectRset.columnString("VID"); + tapeFile.fSeq = selectRset.columnUint64("FSEQ"); + tapeFile.blockId = selectRset.columnUint64("BLOCK_ID"); + tapeFile.compressedSize = selectRset.columnUint64("COMPRESSED_SIZE_IN_BYTES"); + tapeFile.copyNb = selectRset.columnUint64("COPY_NB"); + tapeFile.creationTime = selectRset.columnUint64("TAPE_FILE_CREATION_TIME"); tapeFile.checksumType = archiveFile->checksumType; // Duplicated for convenience tapeFile.checksumValue = archiveFile->checksumValue; // Duplicated for convenience - archiveFile->tapeFiles[selectRset->columnUint64("COPY_NB")] = tapeFile; + archiveFile->tapeFiles[selectRset.columnUint64("COPY_NB")] = tapeFile; } } @@ -180,11 +180,11 @@ uint64_t OracleCatalogue::getNextArchiveFileId(rdbms::PooledConn &conn) { "DUAL"; auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - if (!rset->next()) { + if (!rset.next()) { throw exception::Exception(std::string("Result set is unexpectedly empty")); } - return rset->columnUint64("ARCHIVE_FILE_ID"); + return rset.columnUint64("ARCHIVE_FILE_ID"); } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -234,46 +234,46 @@ common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(rdbms::PooledC auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":VID", vid); auto rset = stmt->executeQuery(); - if (!rset->next()) { + if (!rset.next()) { throw exception::Exception(std::string("The tape with VID " + vid + " does not exist")); } common::dataStructures::Tape tape; - tape.vid = rset->columnString("VID"); - tape.logicalLibraryName = rset->columnString("LOGICAL_LIBRARY_NAME"); - tape.tapePoolName = rset->columnString("TAPE_POOL_NAME"); - tape.encryptionKey = rset->columnOptionalString("ENCRYPTION_KEY"); - tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); - tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); - tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnBool("IS_DISABLED"); - tape.full = rset->columnBool("IS_FULL"); - tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); + tape.vid = rset.columnString("VID"); + tape.logicalLibraryName = rset.columnString("LOGICAL_LIBRARY_NAME"); + tape.tapePoolName = rset.columnString("TAPE_POOL_NAME"); + tape.encryptionKey = rset.columnOptionalString("ENCRYPTION_KEY"); + tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES"); + tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES"); + tape.lastFSeq = rset.columnUint64("LAST_FSEQ"); + tape.disabled = rset.columnBool("IS_DISABLED"); + tape.full = rset.columnBool("IS_FULL"); + tape.lbp = rset.columnOptionalBool("LBP_IS_ON"); - tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); - tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); - tape.lastWriteLog = getTapeLogFromRset(*rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); + tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME"); + tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); + tape.lastWriteLog = getTapeLogFromRset(rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); - tape.comment = rset->columnString("USER_COMMENT"); + tape.comment = rset.columnString("USER_COMMENT"); common::dataStructures::UserIdentity creatorUI; - creatorUI.name = rset->columnString("CREATION_LOG_USER_NAME"); + creatorUI.name = rset.columnString("CREATION_LOG_USER_NAME"); common::dataStructures::EntryLog creationLog; - creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); + creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); tape.creationLog = creationLog; common::dataStructures::UserIdentity updaterUI; - updaterUI.name = rset->columnString("LAST_UPDATE_USER_NAME"); + updaterUI.name = rset.columnString("LAST_UPDATE_USER_NAME"); common::dataStructures::EntryLog updateLog; - updateLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - updateLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - updateLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + updateLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + updateLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + updateLog.time = rset.columnUint64("LAST_UPDATE_TIME"); tape.lastModificationLog = updateLog; diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 0f9ede28ed82b9a2193bcf09a979f005c39463e1..ea8639b07d0e92f61a4ce10b4d3d99d9bcae1590 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -125,7 +125,7 @@ bool RdbmsCatalogue::adminUserExists(rdbms::PooledConn &conn, const std::string auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":ADMIN_USER_NAME", adminUsername); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -178,17 +178,17 @@ std::list<common::dataStructures::AdminUser> RdbmsCatalogue::getAdminUsers() con auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::AdminUser admin; - admin.name = rset->columnString("ADMIN_USER_NAME"); - admin.comment = rset->columnString("USER_COMMENT"); - admin.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - admin.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - admin.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - admin.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - admin.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - admin.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + admin.name = rset.columnString("ADMIN_USER_NAME"); + admin.comment = rset.columnString("USER_COMMENT"); + admin.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + admin.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + admin.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + admin.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + admin.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + admin.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); admins.push_back(admin); } @@ -309,7 +309,7 @@ bool RdbmsCatalogue::adminHostExists(rdbms::PooledConn &conn, const std::string auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":ADMIN_HOST_NAME", adminHost); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -362,17 +362,17 @@ std::list<common::dataStructures::AdminHost> RdbmsCatalogue::getAdminHosts() con auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::AdminHost host; - host.name = rset->columnString("ADMIN_HOST_NAME"); - host.comment = rset->columnString("USER_COMMENT"); - host.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - host.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - host.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - host.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - host.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - host.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + host.name = rset.columnString("ADMIN_HOST_NAME"); + host.comment = rset.columnString("USER_COMMENT"); + host.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + host.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + host.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + host.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + host.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + host.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); hosts.push_back(host); } @@ -502,7 +502,7 @@ bool RdbmsCatalogue::storageClassExists(rdbms::PooledConn &conn, const std::stri stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":STORAGE_CLASS_NAME", storageClassName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -566,19 +566,19 @@ std::list<common::dataStructures::StorageClass> auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::StorageClass storageClass; - storageClass.diskInstance = rset->columnString("DISK_INSTANCE_NAME"); - storageClass.name = rset->columnString("STORAGE_CLASS_NAME"); - storageClass.nbCopies = rset->columnUint64("NB_COPIES"); - storageClass.comment = rset->columnString("USER_COMMENT"); - storageClass.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - storageClass.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - storageClass.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - storageClass.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - storageClass.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - storageClass.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + storageClass.diskInstance = rset.columnString("DISK_INSTANCE_NAME"); + storageClass.name = rset.columnString("STORAGE_CLASS_NAME"); + storageClass.nbCopies = rset.columnUint64("NB_COPIES"); + storageClass.comment = rset.columnString("USER_COMMENT"); + storageClass.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + storageClass.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + storageClass.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + storageClass.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + storageClass.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + storageClass.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); storageClasses.push_back(storageClass); } @@ -760,7 +760,7 @@ bool RdbmsCatalogue::tapePoolExists(rdbms::PooledConn &conn, const std::string & auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":TAPE_POOL_NAME", tapePoolName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -781,7 +781,7 @@ bool RdbmsCatalogue::archiveFileIdExists(rdbms::PooledConn &conn, const uint64_t auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -806,7 +806,7 @@ bool RdbmsCatalogue::diskFileIdExists(rdbms::PooledConn &conn, const std::string stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":DISK_FILE_ID", diskFileId); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -831,7 +831,7 @@ bool RdbmsCatalogue::diskFilePathExists(rdbms::PooledConn &conn, const std::stri stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":DISK_FILE_PATH", diskFilePath); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -856,7 +856,7 @@ bool RdbmsCatalogue::diskFileUserExists(rdbms::PooledConn &conn, const std::stri stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":DISK_FILE_USER", diskFileUser); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -881,7 +881,7 @@ bool RdbmsCatalogue::diskFileGroupExists(rdbms::PooledConn &conn, const std::str stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":DISK_FILE_GROUP", diskFileGroup); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -909,7 +909,7 @@ bool RdbmsCatalogue::archiveRouteExists(rdbms::PooledConn &conn, const std::stri stmt->bindString(":STORAGE_CLASS_NAME", storageClassName); stmt->bindUint64(":COPY_NB", copyNb); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -964,19 +964,19 @@ std::list<common::dataStructures::TapePool> RdbmsCatalogue::getTapePools() const auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::TapePool pool; - pool.name = rset->columnString("TAPE_POOL_NAME"); - pool.nbPartialTapes = rset->columnUint64("NB_PARTIAL_TAPES"); - pool.encryption = rset->columnBool("IS_ENCRYPTED"); - pool.comment = rset->columnString("USER_COMMENT"); - pool.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - pool.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - pool.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - pool.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - pool.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - pool.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + pool.name = rset.columnString("TAPE_POOL_NAME"); + pool.nbPartialTapes = rset.columnUint64("NB_PARTIAL_TAPES"); + pool.encryption = rset.columnBool("IS_ENCRYPTED"); + pool.comment = rset.columnString("USER_COMMENT"); + pool.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + pool.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + pool.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + pool.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + pool.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + pool.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); pools.push_back(pool); } @@ -1239,20 +1239,20 @@ std::list<common::dataStructures::ArchiveRoute> RdbmsCatalogue::getArchiveRoutes auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::ArchiveRoute route; - route.diskInstanceName = rset->columnString("DISK_INSTANCE_NAME"); - route.storageClassName = rset->columnString("STORAGE_CLASS_NAME"); - route.copyNb = rset->columnUint64("COPY_NB"); - route.tapePoolName = rset->columnString("TAPE_POOL_NAME"); - route.comment = rset->columnString("USER_COMMENT"); - route.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - route.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - route.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - route.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - route.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - route.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + route.diskInstanceName = rset.columnString("DISK_INSTANCE_NAME"); + route.storageClassName = rset.columnString("STORAGE_CLASS_NAME"); + route.copyNb = rset.columnUint64("COPY_NB"); + route.tapePoolName = rset.columnString("TAPE_POOL_NAME"); + route.comment = rset.columnString("USER_COMMENT"); + route.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + route.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + route.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + route.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + route.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + route.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); routes.push_back(route); } @@ -1423,7 +1423,7 @@ bool RdbmsCatalogue::logicalLibraryExists(rdbms::PooledConn &conn, const std::st auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":LOGICAL_LIBRARY_NAME", logicalLibraryName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -1477,17 +1477,17 @@ std::list<common::dataStructures::LogicalLibrary> auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::LogicalLibrary lib; - lib.name = rset->columnString("LOGICAL_LIBRARY_NAME"); - lib.comment = rset->columnString("USER_COMMENT"); - lib.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - lib.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - lib.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - lib.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - lib.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - lib.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + lib.name = rset.columnString("LOGICAL_LIBRARY_NAME"); + lib.comment = rset.columnString("USER_COMMENT"); + lib.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + lib.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + lib.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + lib.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + lib.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + lib.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); libs.push_back(lib); } @@ -1654,7 +1654,7 @@ bool RdbmsCatalogue::tapeExists(rdbms::PooledConn &conn, const std::string &vid) auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":VID", vid); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -1793,31 +1793,31 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::PooledCo if(searchCriteria.lbp) stmt->bindBool(":LBP_IS_ON", searchCriteria.lbp.value()); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::Tape tape; - tape.vid = rset->columnString("VID"); - tape.logicalLibraryName = rset->columnString("LOGICAL_LIBRARY_NAME"); - tape.tapePoolName = rset->columnString("TAPE_POOL_NAME"); - tape.encryptionKey = rset->columnOptionalString("ENCRYPTION_KEY"); - tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); - tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); - tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnBool("IS_DISABLED"); - tape.full = rset->columnBool("IS_FULL"); - tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); - - tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); - tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); - tape.lastWriteLog = getTapeLogFromRset(*rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); - - tape.comment = rset->columnString("USER_COMMENT"); - tape.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - tape.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - tape.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - tape.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - tape.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - tape.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + tape.vid = rset.columnString("VID"); + tape.logicalLibraryName = rset.columnString("LOGICAL_LIBRARY_NAME"); + tape.tapePoolName = rset.columnString("TAPE_POOL_NAME"); + tape.encryptionKey = rset.columnOptionalString("ENCRYPTION_KEY"); + tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES"); + tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES"); + tape.lastFSeq = rset.columnUint64("LAST_FSEQ"); + tape.disabled = rset.columnBool("IS_DISABLED"); + tape.full = rset.columnBool("IS_FULL"); + tape.lbp = rset.columnOptionalBool("LBP_IS_ON"); + + tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME"); + tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); + tape.lastWriteLog = getTapeLogFromRset(rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); + + tape.comment = rset.columnString("USER_COMMENT"); + tape.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + tape.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + tape.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + tape.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + tape.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + tape.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); tapes.push_back(tape); } @@ -1893,31 +1893,31 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se } auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::Tape tape; - tape.vid = rset->columnString("VID"); - tape.logicalLibraryName = rset->columnString("LOGICAL_LIBRARY_NAME"); - tape.tapePoolName = rset->columnString("TAPE_POOL_NAME"); - tape.encryptionKey = rset->columnOptionalString("ENCRYPTION_KEY"); - tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); - tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); - tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnBool("IS_DISABLED"); - tape.full = rset->columnBool("IS_FULL"); - tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); - - tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); - tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); - tape.lastWriteLog = getTapeLogFromRset(*rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); - - tape.comment = rset->columnString("USER_COMMENT"); - tape.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - tape.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - tape.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - tape.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - tape.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - tape.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + tape.vid = rset.columnString("VID"); + tape.logicalLibraryName = rset.columnString("LOGICAL_LIBRARY_NAME"); + tape.tapePoolName = rset.columnString("TAPE_POOL_NAME"); + tape.encryptionKey = rset.columnOptionalString("ENCRYPTION_KEY"); + tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES"); + tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES"); + tape.lastFSeq = rset.columnUint64("LAST_FSEQ"); + tape.disabled = rset.columnBool("IS_DISABLED"); + tape.full = rset.columnBool("IS_FULL"); + tape.lbp = rset.columnOptionalBool("LBP_IS_ON"); + + tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME"); + tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); + tape.lastWriteLog = getTapeLogFromRset(rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); + + tape.comment = rset.columnString("USER_COMMENT"); + tape.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + tape.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + tape.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + tape.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + tape.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + tape.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); vidToTapeMap[tape.vid] = tape; } @@ -2685,19 +2685,19 @@ std::list<common::dataStructures::RequesterMountRule> RdbmsCatalogue::getRequest auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while(rset->next()) { + while(rset.next()) { common::dataStructures::RequesterMountRule rule; - rule.diskInstance = rset->columnString("DISK_INSTANCE_NAME"); - rule.name = rset->columnString("REQUESTER_NAME"); - rule.mountPolicy = rset->columnString("MOUNT_POLICY_NAME"); - rule.comment = rset->columnString("USER_COMMENT"); - rule.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - rule.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - rule.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - rule.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - rule.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - rule.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + rule.diskInstance = rset.columnString("DISK_INSTANCE_NAME"); + rule.name = rset.columnString("REQUESTER_NAME"); + rule.mountPolicy = rset.columnString("MOUNT_POLICY_NAME"); + rule.comment = rset.columnString("USER_COMMENT"); + rule.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + rule.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + rule.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + rule.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + rule.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + rule.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); rules.push_back(rule); } @@ -2854,26 +2854,26 @@ common::dataStructures::MountPolicy *RdbmsCatalogue::getRequesterGroupMountPolic stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":REQUESTER_GROUP_NAME", requesterGroupName); auto rset = stmt->executeQuery(); - if(rset->next()) { + if(rset.next()) { auto policy = cta::make_unique<common::dataStructures::MountPolicy>(); - policy->name = rset->columnString("MOUNT_POLICY_NAME"); + policy->name = rset.columnString("MOUNT_POLICY_NAME"); - policy->archivePriority = rset->columnUint64("ARCHIVE_PRIORITY"); - policy->archiveMinRequestAge = rset->columnUint64("ARCHIVE_MIN_REQUEST_AGE"); + policy->archivePriority = rset.columnUint64("ARCHIVE_PRIORITY"); + policy->archiveMinRequestAge = rset.columnUint64("ARCHIVE_MIN_REQUEST_AGE"); - policy->retrievePriority = rset->columnUint64("RETRIEVE_PRIORITY"); - policy->retrieveMinRequestAge = rset->columnUint64("RETRIEVE_MIN_REQUEST_AGE"); + policy->retrievePriority = rset.columnUint64("RETRIEVE_PRIORITY"); + policy->retrieveMinRequestAge = rset.columnUint64("RETRIEVE_MIN_REQUEST_AGE"); - policy->maxDrivesAllowed = rset->columnUint64("MAX_DRIVES_ALLOWED"); + policy->maxDrivesAllowed = rset.columnUint64("MAX_DRIVES_ALLOWED"); - policy->comment = rset->columnString("USER_COMMENT"); - policy->creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - policy->creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - policy->creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - policy->lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - policy->lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - policy->lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + policy->comment = rset.columnString("USER_COMMENT"); + policy->creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + policy->creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + policy->creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + policy->lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + policy->lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + policy->lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); return policy.release(); } else { @@ -2912,20 +2912,20 @@ std::list<common::dataStructures::RequesterGroupMountRule> RdbmsCatalogue::getRe auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while(rset->next()) { + while(rset.next()) { common::dataStructures::RequesterGroupMountRule rule; - rule.diskInstance = rset->columnString("DISK_INSTANCE_NAME"); - rule.name = rset->columnString("REQUESTER_GROUP_NAME"); - rule.mountPolicy = rset->columnString("MOUNT_POLICY_NAME"); + rule.diskInstance = rset.columnString("DISK_INSTANCE_NAME"); + rule.name = rset.columnString("REQUESTER_GROUP_NAME"); + rule.mountPolicy = rset.columnString("MOUNT_POLICY_NAME"); - rule.comment = rset->columnString("USER_COMMENT"); - rule.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - rule.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - rule.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - rule.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - rule.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - rule.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + rule.comment = rset.columnString("USER_COMMENT"); + rule.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + rule.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + rule.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + rule.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + rule.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + rule.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); rules.push_back(rule); } @@ -2980,7 +2980,7 @@ bool RdbmsCatalogue::mountPolicyExists(rdbms::PooledConn &conn, const std::strin auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":MOUNT_POLICY_NAME", mountPolicyName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -3004,7 +3004,7 @@ bool RdbmsCatalogue::requesterMountRuleExists(rdbms::PooledConn &conn, const std stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":REQUESTER_NAME", requesterName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -3052,29 +3052,29 @@ common::dataStructures::MountPolicy *RdbmsCatalogue::getRequesterMountPolicy( stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":REQUESTER_NAME", requesterName); auto rset = stmt->executeQuery(); - if(rset->next()) { + if(rset.next()) { auto policy = cta::make_unique<common::dataStructures::MountPolicy>(); - policy->name = rset->columnString("MOUNT_POLICY_NAME"); + policy->name = rset.columnString("MOUNT_POLICY_NAME"); - policy->archivePriority = rset->columnUint64("ARCHIVE_PRIORITY"); - policy->archiveMinRequestAge = rset->columnUint64("ARCHIVE_MIN_REQUEST_AGE"); + policy->archivePriority = rset.columnUint64("ARCHIVE_PRIORITY"); + policy->archiveMinRequestAge = rset.columnUint64("ARCHIVE_MIN_REQUEST_AGE"); - policy->retrievePriority = rset->columnUint64("RETRIEVE_PRIORITY"); - policy->retrieveMinRequestAge = rset->columnUint64("RETRIEVE_MIN_REQUEST_AGE"); + policy->retrievePriority = rset.columnUint64("RETRIEVE_PRIORITY"); + policy->retrieveMinRequestAge = rset.columnUint64("RETRIEVE_MIN_REQUEST_AGE"); - policy->maxDrivesAllowed = rset->columnUint64("MAX_DRIVES_ALLOWED"); + policy->maxDrivesAllowed = rset.columnUint64("MAX_DRIVES_ALLOWED"); - policy->comment = rset->columnString("USER_COMMENT"); + policy->comment = rset.columnString("USER_COMMENT"); - policy->creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - policy->creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - policy->creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); + policy->creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + policy->creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + policy->creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); common::dataStructures::EntryLog updateLog; - policy->lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - policy->lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - policy->lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + policy->lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + policy->lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + policy->lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); return policy.release(); } else { @@ -3104,7 +3104,7 @@ bool RdbmsCatalogue::requesterGroupMountRuleExists(rdbms::PooledConn &conn, cons stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":REQUESTER_GROUP_NAME", requesterGroupName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } catch (exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -3165,28 +3165,28 @@ std::list<common::dataStructures::MountPolicy> RdbmsCatalogue::getMountPolicies( auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { common::dataStructures::MountPolicy policy; - policy.name = rset->columnString("MOUNT_POLICY_NAME"); + policy.name = rset.columnString("MOUNT_POLICY_NAME"); - policy.archivePriority = rset->columnUint64("ARCHIVE_PRIORITY"); - policy.archiveMinRequestAge = rset->columnUint64("ARCHIVE_MIN_REQUEST_AGE"); + policy.archivePriority = rset.columnUint64("ARCHIVE_PRIORITY"); + policy.archiveMinRequestAge = rset.columnUint64("ARCHIVE_MIN_REQUEST_AGE"); - policy.retrievePriority = rset->columnUint64("RETRIEVE_PRIORITY"); - policy.retrieveMinRequestAge = rset->columnUint64("RETRIEVE_MIN_REQUEST_AGE"); + policy.retrievePriority = rset.columnUint64("RETRIEVE_PRIORITY"); + policy.retrieveMinRequestAge = rset.columnUint64("RETRIEVE_MIN_REQUEST_AGE"); - policy.maxDrivesAllowed = rset->columnUint64("MAX_DRIVES_ALLOWED"); + policy.maxDrivesAllowed = rset.columnUint64("MAX_DRIVES_ALLOWED"); - policy.comment = rset->columnString("USER_COMMENT"); + policy.comment = rset.columnString("USER_COMMENT"); - policy.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - policy.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - policy.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); + policy.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + policy.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + policy.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); - policy.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - policy.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - policy.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + policy.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + policy.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + policy.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); policies.push_back(policy); } @@ -3675,11 +3675,11 @@ std::list<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveFilesFo while(archiveFiles.size() <= maxNbArchiveFiles) { // Break the archive file loop if there are no more tape files - if(!rset->next()) { + if(!rset.next()) { break; } - const uint64_t archiveFileId = rset->columnUint64("ARCHIVE_FILE_ID"); + const uint64_t archiveFileId = rset.columnUint64("ARCHIVE_FILE_ID"); // If the current tape file is for the next archive file if(archiveFiles.empty() || archiveFiles.back().archiveFileID != archiveFileId) { @@ -3692,18 +3692,18 @@ std::list<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveFilesFo common::dataStructures::ArchiveFile archiveFile; archiveFile.archiveFileID = archiveFileId; - archiveFile.diskInstance = rset->columnString("DISK_INSTANCE_NAME"); - archiveFile.diskFileId = rset->columnString("DISK_FILE_ID"); - archiveFile.diskFileInfo.path = rset->columnString("DISK_FILE_PATH"); - archiveFile.diskFileInfo.owner = rset->columnString("DISK_FILE_USER"); - archiveFile.diskFileInfo.group = rset->columnString("DISK_FILE_GROUP"); - archiveFile.diskFileInfo.recoveryBlob = rset->columnString("DISK_FILE_RECOVERY_BLOB"); - archiveFile.fileSize = rset->columnUint64("SIZE_IN_BYTES"); - archiveFile.checksumType = rset->columnString("CHECKSUM_TYPE"); - archiveFile.checksumValue = rset->columnString("CHECKSUM_VALUE"); - archiveFile.storageClass = rset->columnString("STORAGE_CLASS_NAME"); - archiveFile.creationTime = rset->columnUint64("ARCHIVE_FILE_CREATION_TIME"); - archiveFile.reconciliationTime = rset->columnUint64("RECONCILIATION_TIME"); + archiveFile.diskInstance = rset.columnString("DISK_INSTANCE_NAME"); + archiveFile.diskFileId = rset.columnString("DISK_FILE_ID"); + archiveFile.diskFileInfo.path = rset.columnString("DISK_FILE_PATH"); + archiveFile.diskFileInfo.owner = rset.columnString("DISK_FILE_USER"); + archiveFile.diskFileInfo.group = rset.columnString("DISK_FILE_GROUP"); + archiveFile.diskFileInfo.recoveryBlob = rset.columnString("DISK_FILE_RECOVERY_BLOB"); + archiveFile.fileSize = rset.columnUint64("SIZE_IN_BYTES"); + archiveFile.checksumType = rset.columnString("CHECKSUM_TYPE"); + archiveFile.checksumValue = rset.columnString("CHECKSUM_VALUE"); + archiveFile.storageClass = rset.columnString("STORAGE_CLASS_NAME"); + archiveFile.creationTime = rset.columnUint64("ARCHIVE_FILE_CREATION_TIME"); + archiveFile.reconciliationTime = rset.columnUint64("RECONCILIATION_TIME"); archiveFiles.push_back(archiveFile); } @@ -3711,18 +3711,18 @@ std::list<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveFilesFo common::dataStructures::ArchiveFile &archiveFile = archiveFiles.back(); // If there is a tape file - if(!rset->columnIsNull("VID")) { + if(!rset.columnIsNull("VID")) { common::dataStructures::TapeFile tapeFile; - tapeFile.vid = rset->columnString("VID"); - tapeFile.fSeq = rset->columnUint64("FSEQ"); - tapeFile.blockId = rset->columnUint64("BLOCK_ID"); - tapeFile.compressedSize = rset->columnUint64("COMPRESSED_SIZE_IN_BYTES"); - tapeFile.copyNb = rset->columnUint64("COPY_NB"); - tapeFile.creationTime = rset->columnUint64("TAPE_FILE_CREATION_TIME"); + tapeFile.vid = rset.columnString("VID"); + tapeFile.fSeq = rset.columnUint64("FSEQ"); + tapeFile.blockId = rset.columnUint64("BLOCK_ID"); + tapeFile.compressedSize = rset.columnUint64("COMPRESSED_SIZE_IN_BYTES"); + tapeFile.copyNb = rset.columnUint64("COPY_NB"); + tapeFile.creationTime = rset.columnUint64("TAPE_FILE_CREATION_TIME"); tapeFile.checksumType = archiveFile.checksumType; // Duplicated for convenience tapeFile.checksumValue = archiveFile.checksumValue; // Duplicated for convenience - archiveFile.tapeFiles[rset->columnUint64("COPY_NB")] = tapeFile; + archiveFile.tapeFiles[rset.columnUint64("COPY_NB")] = tapeFile; } } @@ -3848,14 +3848,14 @@ common::dataStructures::ArchiveFileSummary RdbmsCatalogue::getTapeFileSummary( stmt->bindString(":TAPE_POOL_NAME", searchCriteria.tapePool.value()); } auto rset = stmt->executeQuery(); - if(!rset->next()) { + if(!rset.next()) { throw exception::Exception("SELECT COUNT statement did not returned a row"); } common::dataStructures::ArchiveFileSummary summary; - summary.totalBytes = rset->columnUint64("TOTAL_BYTES"); - summary.totalCompressedBytes = rset->columnUint64("TOTAL_COMPRESSED_BYTES"); - summary.totalFiles = rset->columnUint64("TOTAL_FILES"); + summary.totalBytes = rset.columnUint64("TOTAL_BYTES"); + summary.totalCompressedBytes = rset.columnUint64("TOTAL_COMPRESSED_BYTES"); + summary.totalFiles = rset.columnUint64("TOTAL_FILES"); return summary; } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); @@ -3987,9 +3987,9 @@ common::dataStructures::TapeCopyToPoolMap RdbmsCatalogue::getTapeCopyToPoolMap(r stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":STORAGE_CLASS_NAME", storageClassName); auto rset = stmt->executeQuery(); - while (rset->next()) { - const uint64_t copyNb = rset->columnUint64("COPY_NB"); - const std::string tapePoolName = rset->columnString("TAPE_POOL_NAME"); + while (rset.next()) { + const uint64_t copyNb = rset.columnUint64("COPY_NB"); + const std::string tapePoolName = rset.columnString("TAPE_POOL_NAME"); copyToPoolMap[copyNb] = tapePoolName; } @@ -4017,10 +4017,10 @@ uint64_t RdbmsCatalogue::getExpectedNbArchiveRoutes(rdbms::PooledConn &conn, con stmt->bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt->bindString(":STORAGE_CLASS_NAME", storageClassName); auto rset = stmt->executeQuery(); - if(!rset->next()) { + if(!rset.next()) { throw exception::Exception("Result set of SELECT COUNT(*) is empty"); } - return rset->columnUint64("NB_ROUTES"); + return rset.columnUint64("NB_ROUTES"); } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -4237,24 +4237,24 @@ RequesterAndGroupMountPolicies RdbmsCatalogue::getMountPolicies( auto rset = stmt->executeQuery(); RequesterAndGroupMountPolicies policies; - while(rset->next()) { + while(rset.next()) { common::dataStructures::MountPolicy policy; - policy.name = rset->columnString("MOUNT_POLICY_NAME"); - policy.archivePriority = rset->columnUint64("ARCHIVE_PRIORITY"); - policy.archiveMinRequestAge = rset->columnUint64("ARCHIVE_MIN_REQUEST_AGE"); - policy.retrievePriority = rset->columnUint64("RETRIEVE_PRIORITY"); - policy.retrieveMinRequestAge = rset->columnUint64("RETRIEVE_MIN_REQUEST_AGE"); - policy.maxDrivesAllowed = rset->columnUint64("MAX_DRIVES_ALLOWED"); - policy.comment = rset->columnString("USER_COMMENT"); - policy.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - policy.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - policy.creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); - policy.lastModificationLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - policy.lastModificationLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - policy.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME"); - - if(rset->columnString("RULE_TYPE") == "REQUESTER") { + policy.name = rset.columnString("MOUNT_POLICY_NAME"); + policy.archivePriority = rset.columnUint64("ARCHIVE_PRIORITY"); + policy.archiveMinRequestAge = rset.columnUint64("ARCHIVE_MIN_REQUEST_AGE"); + policy.retrievePriority = rset.columnUint64("RETRIEVE_PRIORITY"); + policy.retrieveMinRequestAge = rset.columnUint64("RETRIEVE_MIN_REQUEST_AGE"); + policy.maxDrivesAllowed = rset.columnUint64("MAX_DRIVES_ALLOWED"); + policy.comment = rset.columnString("USER_COMMENT"); + policy.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + policy.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + policy.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + policy.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + policy.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + policy.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); + + if(rset.columnString("RULE_TYPE") == "REQUESTER") { policies.requesterMountPolicies.push_back(policy); } else { policies.requesterGroupMountPolicies.push_back(policy); @@ -4289,7 +4289,7 @@ bool RdbmsCatalogue::userIsAdmin(rdbms::PooledConn &conn, const std::string &use auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":ADMIN_USER_NAME", userName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } //------------------------------------------------------------------------------ @@ -4306,7 +4306,7 @@ bool RdbmsCatalogue::hostIsAdmin(rdbms::PooledConn &conn, const std::string &hos auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":ADMIN_HOST_NAME", hostName); auto rset = stmt->executeQuery(); - return rset->next(); + return rset.next(); } //------------------------------------------------------------------------------ @@ -4335,13 +4335,13 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string & auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":LOGICAL_LIBRARY_NAME", logicalLibraryName); auto rset = stmt->executeQuery(); - while (rset->next()) { + while (rset.next()) { TapeForWriting tape; - tape.vid = rset->columnString("VID"); - tape.tapePool = rset->columnString("TAPE_POOL_NAME"); - tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); - tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); - tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); + tape.vid = rset.columnString("VID"); + tape.tapePool = rset.columnString("TAPE_POOL_NAME"); + tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES"); + tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES"); + tape.lastFSeq = rset.columnUint64("LAST_FSEQ"); tapes.push_back(tape); } @@ -4438,8 +4438,8 @@ uint64_t RdbmsCatalogue::getTapeLastFSeq(rdbms::PooledConn &conn, const std::str auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); stmt->bindString(":VID", vid); auto rset = stmt->executeQuery(); - if(rset->next()) { - return rset->columnUint64("LAST_FSEQ"); + if(rset.next()) { + return rset.columnUint64("LAST_FSEQ"); } else { throw exception::Exception(std::string("No such tape with vid=") + vid); } @@ -4485,39 +4485,39 @@ std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveF stmt->bindUint64(":ARCHIVE_FILE_ID", archiveFileId); auto rset = stmt->executeQuery(); std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile; - while (rset->next()) { + while (rset.next()) { if(nullptr == archiveFile.get()) { archiveFile = cta::make_unique<common::dataStructures::ArchiveFile>(); - archiveFile->archiveFileID = rset->columnUint64("ARCHIVE_FILE_ID"); - archiveFile->diskInstance = rset->columnString("DISK_INSTANCE_NAME"); - archiveFile->diskFileId = rset->columnString("DISK_FILE_ID"); - archiveFile->diskFileInfo.path = rset->columnString("DISK_FILE_PATH"); - archiveFile->diskFileInfo.owner = rset->columnString("DISK_FILE_USER"); - archiveFile->diskFileInfo.group = rset->columnString("DISK_FILE_GROUP"); - archiveFile->diskFileInfo.recoveryBlob = rset->columnString("DISK_FILE_RECOVERY_BLOB"); - archiveFile->fileSize = rset->columnUint64("SIZE_IN_BYTES"); - archiveFile->checksumType = rset->columnString("CHECKSUM_TYPE"); - archiveFile->checksumValue = rset->columnString("CHECKSUM_VALUE"); - archiveFile->storageClass = rset->columnString("STORAGE_CLASS_NAME"); - archiveFile->creationTime = rset->columnUint64("ARCHIVE_FILE_CREATION_TIME"); - archiveFile->reconciliationTime = rset->columnUint64("RECONCILIATION_TIME"); + archiveFile->archiveFileID = rset.columnUint64("ARCHIVE_FILE_ID"); + archiveFile->diskInstance = rset.columnString("DISK_INSTANCE_NAME"); + archiveFile->diskFileId = rset.columnString("DISK_FILE_ID"); + archiveFile->diskFileInfo.path = rset.columnString("DISK_FILE_PATH"); + archiveFile->diskFileInfo.owner = rset.columnString("DISK_FILE_USER"); + archiveFile->diskFileInfo.group = rset.columnString("DISK_FILE_GROUP"); + archiveFile->diskFileInfo.recoveryBlob = rset.columnString("DISK_FILE_RECOVERY_BLOB"); + archiveFile->fileSize = rset.columnUint64("SIZE_IN_BYTES"); + archiveFile->checksumType = rset.columnString("CHECKSUM_TYPE"); + archiveFile->checksumValue = rset.columnString("CHECKSUM_VALUE"); + archiveFile->storageClass = rset.columnString("STORAGE_CLASS_NAME"); + archiveFile->creationTime = rset.columnUint64("ARCHIVE_FILE_CREATION_TIME"); + archiveFile->reconciliationTime = rset.columnUint64("RECONCILIATION_TIME"); } // If there is a tape file - if(!rset->columnIsNull("VID")) { + if(!rset.columnIsNull("VID")) { // Add the tape file to the archive file's in-memory structure common::dataStructures::TapeFile tapeFile; - tapeFile.vid = rset->columnString("VID"); - tapeFile.fSeq = rset->columnUint64("FSEQ"); - tapeFile.blockId = rset->columnUint64("BLOCK_ID"); - tapeFile.compressedSize = rset->columnUint64("COMPRESSED_SIZE_IN_BYTES"); - tapeFile.copyNb = rset->columnUint64("COPY_NB"); - tapeFile.creationTime = rset->columnUint64("TAPE_FILE_CREATION_TIME"); + tapeFile.vid = rset.columnString("VID"); + tapeFile.fSeq = rset.columnUint64("FSEQ"); + tapeFile.blockId = rset.columnUint64("BLOCK_ID"); + tapeFile.compressedSize = rset.columnUint64("COMPRESSED_SIZE_IN_BYTES"); + tapeFile.copyNb = rset.columnUint64("COPY_NB"); + tapeFile.creationTime = rset.columnUint64("TAPE_FILE_CREATION_TIME"); tapeFile.checksumType = archiveFile->checksumType; // Duplicated for convenience tapeFile.checksumValue = archiveFile->checksumValue; // Duplicated for convenience - archiveFile->tapeFiles[rset->columnUint64("COPY_NB")] = tapeFile; + archiveFile->tapeFiles[rset.columnUint64("COPY_NB")] = tapeFile; } } diff --git a/catalogue/SqliteCatalogue.cpp b/catalogue/SqliteCatalogue.cpp index dab72ab113cc8c704eea72870c9b3acd48504f15..47785d9e52275e92d96535c01428122441a188c3 100644 --- a/catalogue/SqliteCatalogue.cpp +++ b/catalogue/SqliteCatalogue.cpp @@ -117,11 +117,11 @@ uint64_t SqliteCatalogue::getNextArchiveFileId(rdbms::PooledConn &conn) { "ARCHIVE_FILE_ID"; auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - if(!rset->next()) { + if(!rset.next()) { throw exception::Exception("ARCHIVE_FILE_ID table is empty"); } - archiveFileId = rset->columnUint64("ID"); - if(rset->next()) { + archiveFileId = rset.columnUint64("ID"); + if(rset.next()) { throw exception::Exception("Found more than one ID counter in the ARCHIVE_FILE_ID table"); } } @@ -178,46 +178,46 @@ common::dataStructures::Tape SqliteCatalogue::selectTape(const rdbms::Stmt::Auto auto stmt = conn.createStmt(sql, autocommitMode); stmt->bindString(":VID", vid); auto rset = stmt->executeQuery(); - if (!rset->next()) { + if (!rset.next()) { throw exception::Exception(std::string("The tape with VID " + vid + " does not exist")); } common::dataStructures::Tape tape; - tape.vid = rset->columnString("VID"); - tape.logicalLibraryName = rset->columnString("LOGICAL_LIBRARY_NAME"); - tape.tapePoolName = rset->columnString("TAPE_POOL_NAME"); - tape.encryptionKey = rset->columnOptionalString("ENCRYPTION_KEY"); - tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); - tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); - tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnBool("IS_DISABLED"); - tape.full = rset->columnBool("IS_FULL"); - tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); + tape.vid = rset.columnString("VID"); + tape.logicalLibraryName = rset.columnString("LOGICAL_LIBRARY_NAME"); + tape.tapePoolName = rset.columnString("TAPE_POOL_NAME"); + tape.encryptionKey = rset.columnOptionalString("ENCRYPTION_KEY"); + tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES"); + tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES"); + tape.lastFSeq = rset.columnUint64("LAST_FSEQ"); + tape.disabled = rset.columnBool("IS_DISABLED"); + tape.full = rset.columnBool("IS_FULL"); + tape.lbp = rset.columnOptionalBool("LBP_IS_ON"); - tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); - tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); - tape.lastWriteLog = getTapeLogFromRset(*rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); + tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME"); + tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); + tape.lastWriteLog = getTapeLogFromRset(rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME"); - tape.comment = rset->columnString("USER_COMMENT"); + tape.comment = rset.columnString("USER_COMMENT"); common::dataStructures::UserIdentity creatorUI; - creatorUI.name = rset->columnString("CREATION_LOG_USER_NAME"); + creatorUI.name = rset.columnString("CREATION_LOG_USER_NAME"); common::dataStructures::EntryLog creationLog; - creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); - creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); - creationLog.time = rset->columnUint64("CREATION_LOG_TIME"); + creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); tape.creationLog = creationLog; common::dataStructures::UserIdentity updaterUI; - updaterUI.name = rset->columnString("LAST_UPDATE_USER_NAME"); + updaterUI.name = rset.columnString("LAST_UPDATE_USER_NAME"); common::dataStructures::EntryLog updateLog; - updateLog.username = rset->columnString("LAST_UPDATE_USER_NAME"); - updateLog.host = rset->columnString("LAST_UPDATE_HOST_NAME"); - updateLog.time = rset->columnUint64("LAST_UPDATE_TIME"); + updateLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + updateLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + updateLog.time = rset.columnUint64("LAST_UPDATE_TIME"); tape.lastModificationLog = updateLog; diff --git a/rdbms/CMakeLists.txt b/rdbms/CMakeLists.txt index d96294db9bd6bb9756f3fbd54cc98a2d6b63ea6d..ec40223603599e8a71bd2b30a5a564b006059e0c 100644 --- a/rdbms/CMakeLists.txt +++ b/rdbms/CMakeLists.txt @@ -45,6 +45,7 @@ set (RDBMS_LIB_SRC_FILES Login.cpp LoginFactory.cpp Rset.cpp + RsetImpl.cpp Stmt.cpp NullDbValue.cpp ParamNameToIdx.cpp @@ -52,7 +53,7 @@ set (RDBMS_LIB_SRC_FILES Sqlite.cpp SqliteConn.cpp SqliteConnFactory.cpp - SqliteRset.cpp + SqliteRsetImpl.cpp SqliteStmt.cpp) if (OCCI_SUPPORT) @@ -64,7 +65,7 @@ if (OCCI_SUPPORT) OcciConnFactory.cpp OcciEnv.cpp OcciEnvSingleton.cpp - OcciRset.cpp + OcciRsetImpl.cpp OcciStmt.cpp) else (OCCI_SUPPORT) set (RDBMS_LIB_SRC_FILES diff --git a/rdbms/OcciConn.cpp b/rdbms/OcciConn.cpp index ce3dbd3750f56d72d3ceeb554939d240dfeeff9f..36702ed5ccedad612c8ee5f9a2423d3b91ac5150 100644 --- a/rdbms/OcciConn.cpp +++ b/rdbms/OcciConn.cpp @@ -141,8 +141,8 @@ std::list<std::string> OcciConn::getTableNames() { "TABLE_NAME"; auto stmt = createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { - names.push_back(rset->columnString("TABLE_NAME")); + while (rset.next()) { + names.push_back(rset.columnString("TABLE_NAME")); } return names; @@ -166,8 +166,8 @@ std::list<std::string> OcciConn::getSequenceNames() { "SEQUENCE_NAME"; auto stmt = createStmt(sql, rdbms::Stmt::AutocommitMode::OFF); auto rset = stmt->executeQuery(); - while (rset->next()) { - names.push_back(rset->columnString("SEQUENCE_NAME")); + while (rset.next()) { + names.push_back(rset.columnString("SEQUENCE_NAME")); } return names; diff --git a/rdbms/OcciRset.cpp b/rdbms/OcciRsetImpl.cpp similarity index 91% rename from rdbms/OcciRset.cpp rename to rdbms/OcciRsetImpl.cpp index d84030e5ff7f930420620443e9452e8b9f266654..12b11d90573976df1cd05e37cc602ae2814dfa17 100644 --- a/rdbms/OcciRset.cpp +++ b/rdbms/OcciRsetImpl.cpp @@ -17,7 +17,7 @@ */ #include "NullDbValue.hpp" -#include "OcciRset.hpp" +#include "OcciRsetImpl.hpp" #include "OcciStmt.hpp" #include "common/exception/Exception.hpp" #include "common/utils/utils.hpp" @@ -32,7 +32,7 @@ namespace rdbms { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -OcciRset::OcciRset(OcciStmt &stmt, oracle::occi::ResultSet *const rset): +OcciRsetImpl::OcciRsetImpl(OcciStmt &stmt, oracle::occi::ResultSet *const rset): m_stmt(stmt), m_rset(rset) { try { @@ -49,7 +49,7 @@ OcciRset::OcciRset(OcciStmt &stmt, oracle::occi::ResultSet *const rset): //------------------------------------------------------------------------------ // populateColNameToIdx //------------------------------------------------------------------------------ -void OcciRset::populateColNameToIdxMap() { +void OcciRsetImpl::populateColNameToIdxMap() { using namespace oracle; try { @@ -69,7 +69,7 @@ void OcciRset::populateColNameToIdxMap() { //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -OcciRset::~OcciRset() throw() { +OcciRsetImpl::~OcciRsetImpl() throw() { try { close(); // Idempotent close() } catch(...) { @@ -80,14 +80,14 @@ OcciRset::~OcciRset() throw() { //------------------------------------------------------------------------------ // getSql //------------------------------------------------------------------------------ -const std::string &OcciRset::getSql() const { +const std::string &OcciRsetImpl::getSql() const { return m_stmt.getSql(); } //------------------------------------------------------------------------------ // next //------------------------------------------------------------------------------ -bool OcciRset::next() { +bool OcciRsetImpl::next() { using namespace oracle; try { @@ -102,7 +102,7 @@ bool OcciRset::next() { //------------------------------------------------------------------------------ // columnIsNull //------------------------------------------------------------------------------ -bool OcciRset::columnIsNull(const std::string &colName) const { +bool OcciRsetImpl::columnIsNull(const std::string &colName) const { try { const int colIdx = m_colNameToIdx.getIdx(colName); return m_rset->isNull(colIdx); @@ -116,7 +116,7 @@ bool OcciRset::columnIsNull(const std::string &colName) const { //------------------------------------------------------------------------------ // close //------------------------------------------------------------------------------ -void OcciRset::close() { +void OcciRsetImpl::close() { threading::Mutex locker(m_mutex); if(nullptr != m_rset) { @@ -128,7 +128,7 @@ void OcciRset::close() { //------------------------------------------------------------------------------ // columnOptionalString //------------------------------------------------------------------------------ -optional<std::string> OcciRset::columnOptionalString(const std::string &colName) const { +optional<std::string> OcciRsetImpl::columnOptionalString(const std::string &colName) const { try { const int colIdx = m_colNameToIdx.getIdx(colName); const std::string stringValue = m_rset->getString(colIdx); @@ -148,7 +148,7 @@ optional<std::string> OcciRset::columnOptionalString(const std::string &colName) //------------------------------------------------------------------------------ // columnOptionalUint64 //------------------------------------------------------------------------------ -optional<uint64_t> OcciRset::columnOptionalUint64(const std::string &colName) const { +optional<uint64_t> OcciRsetImpl::columnOptionalUint64(const std::string &colName) const { try { threading::Mutex locker(m_mutex); diff --git a/rdbms/OcciRset.hpp b/rdbms/OcciRsetImpl.hpp similarity index 93% rename from rdbms/OcciRset.hpp rename to rdbms/OcciRsetImpl.hpp index 42679543d0026a49b21d5a70602a40590e6d5e28..d6cc3ca54827c2a849398b88f2473209ead03213 100644 --- a/rdbms/OcciRset.hpp +++ b/rdbms/OcciRsetImpl.hpp @@ -20,7 +20,7 @@ #include "common/threading/Mutex.hpp" #include "rdbms/ColumnNameToIdx.hpp" -#include "rdbms/Rset.hpp" +#include "rdbms/RsetImpl.hpp" #include <memory> #include <occi.h> @@ -37,7 +37,7 @@ class OcciStmt; /** * A convenience wrapper around an OCCI result set. */ -class OcciRset: public Rset { +class OcciRsetImpl: public RsetImpl { public: /** @@ -49,12 +49,12 @@ public: * @param stmt The OCCI statement. * @param rset The OCCI result set. */ - OcciRset(OcciStmt &stmt, oracle::occi::ResultSet *const rset); + OcciRsetImpl(OcciStmt &stmt, oracle::occi::ResultSet *const rset); /** * Destructor. */ - virtual ~OcciRset() throw() override; + virtual ~OcciRsetImpl() throw() override; /** * Returns the SQL statement. @@ -131,7 +131,7 @@ private: */ void populateColNameToIdxMap(); -}; // class OcciRset +}; // class OcciRsetImpl } // namespace rdbms } // namespace cta diff --git a/rdbms/OcciStmt.cpp b/rdbms/OcciStmt.cpp index 6c0a8d601fb3e52dedc6e9715c0480f073769951..320be053b6f8e77b2d2ddf80b3e85bfd8e01a78d 100644 --- a/rdbms/OcciStmt.cpp +++ b/rdbms/OcciStmt.cpp @@ -21,7 +21,7 @@ #include "common/threading/MutexLocker.hpp" #include "rdbms/OcciColumn.hpp" #include "rdbms/OcciConn.hpp" -#include "rdbms/OcciRset.hpp" +#include "rdbms/OcciRsetImpl.hpp" #include "rdbms/OcciStmt.hpp" #include <cstring> @@ -170,11 +170,11 @@ void OcciStmt::bindOptionalString(const std::string ¶mName, const optional<s //------------------------------------------------------------------------------ // executeQuery //------------------------------------------------------------------------------ -std::unique_ptr<Rset> OcciStmt::executeQuery() { +Rset OcciStmt::executeQuery() { using namespace oracle; try { - return cta::make_unique<OcciRset>(*this, m_stmt->executeQuery()); + return Rset(new OcciRsetImpl(*this, m_stmt->executeQuery())); } catch(occi::SQLException &ex) { if(connShouldBeClosed(ex)) { // Close the statement first and then the connection diff --git a/rdbms/OcciStmt.hpp b/rdbms/OcciStmt.hpp index 4dfc7b89bcc773600181f74906328a72bcd5cfeb..a180db9f3d877c0bec3f85af5415e75c5c45cd33 100644 --- a/rdbms/OcciStmt.hpp +++ b/rdbms/OcciStmt.hpp @@ -38,7 +38,7 @@ class OcciConn; * Forward declaration to avoid a circular dependency between OcciStmt and * OcciRset. */ -class OcciRset; +class OcciRsetImpl; class OcciColumn; @@ -120,10 +120,9 @@ public: /** * Executes the statement and returns the result set. * - * @return The result set. Please note that it is the responsibility of the - * caller to free the memory associated with the result set. + * @return The result set. */ - std::unique_ptr<Rset> executeQuery() override; + Rset executeQuery() override; /** * Executes the statement. diff --git a/rdbms/Rset.cpp b/rdbms/Rset.cpp index ca9a030c6099bb1f4500eee601dd520d707c9611..1d91b1f046a33e57de442b9459e60fe3d47310ba 100644 --- a/rdbms/Rset.cpp +++ b/rdbms/Rset.cpp @@ -17,15 +17,51 @@ */ #include "Rset.hpp" +#include "RsetImpl.hpp" #include "NullDbValue.hpp" namespace cta { namespace rdbms { +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +Rset::Rset(): + m_impl(nullptr) { +} + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +Rset::Rset(RsetImpl *const impl): + m_impl(impl) { + if(nullptr == impl) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: Pointer to implementation object is null"); + } +} + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +Rset::Rset(Rset &&other): + m_impl(other.m_impl) { + other.m_impl = nullptr; +} + //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -Rset::~Rset() throw() { +Rset::~Rset() { + delete m_impl; +} + +//------------------------------------------------------------------------------ +// operator= +//------------------------------------------------------------------------------ +Rset &Rset::operator=(Rset &&rhs) { + m_impl = rhs.m_impl; + rhs.m_impl = nullptr; + return *this; } //------------------------------------------------------------------------------ @@ -33,6 +69,10 @@ Rset::~Rset() throw() { //------------------------------------------------------------------------------ std::string Rset::columnString(const std::string &colName) const { try { + if(nullptr == m_impl) { + throw exception::Exception("This result set is invalid"); + } + const optional<std::string> col = columnOptionalString(colName); if(col) { return col.value(); @@ -49,6 +89,10 @@ std::string Rset::columnString(const std::string &colName) const { //------------------------------------------------------------------------------ uint64_t Rset::columnUint64(const std::string &colName) const { try { + if(nullptr == m_impl) { + throw exception::Exception("This result set is invalid"); + } + const optional<uint64_t> col = columnOptionalUint64(colName); if(col) { return col.value(); @@ -65,6 +109,10 @@ uint64_t Rset::columnUint64(const std::string &colName) const { //------------------------------------------------------------------------------ bool Rset::columnBool(const std::string &colName) const { try { + if(nullptr == m_impl) { + throw exception::Exception("This result set is invalid"); + } + const optional<bool> col = columnOptionalBool(colName); if(col) { return col.value(); @@ -81,6 +129,10 @@ bool Rset::columnBool(const std::string &colName) const { //------------------------------------------------------------------------------ optional<bool> Rset::columnOptionalBool(const std::string &colName) const { try { + if(nullptr == m_impl) { + throw exception::Exception("This result set is invalid"); + } + const auto column = columnOptionalUint64(colName); if(column) { return optional<bool>(column.value() != 0 ? true : false); @@ -92,5 +144,60 @@ optional<bool> Rset::columnOptionalBool(const std::string &colName) const { } } +//------------------------------------------------------------------------------ +// getSql +//------------------------------------------------------------------------------ +const std::string &Rset::getSql() const { + if(nullptr == m_impl) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + "This result set is invalid"); + } + return m_impl->getSql(); +} + +//------------------------------------------------------------------------------ +// next +//------------------------------------------------------------------------------ +bool Rset::next() { + if(nullptr == m_impl) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + "This result set is invalid"); + } + return m_impl->next(); +} + +//------------------------------------------------------------------------------ +// columnIsNull +//------------------------------------------------------------------------------ +bool Rset::columnIsNull(const std::string &colName) const { + if(nullptr == m_impl) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + "This result set is invalid"); + } + return m_impl->columnIsNull(colName); +} + +//------------------------------------------------------------------------------ +// columnOptionalString +//------------------------------------------------------------------------------ +optional<std::string> Rset::columnOptionalString(const std::string &colName) const { + if(nullptr == m_impl) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + "This result set is invalid"); + } + return m_impl->columnOptionalString(colName); +} + +//------------------------------------------------------------------------------ +// columnOptionalUint64 +//------------------------------------------------------------------------------ +optional<uint64_t> Rset::columnOptionalUint64(const std::string &colName) const { + if(nullptr == m_impl) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + "This result set is invalid"); + } + return m_impl->columnOptionalUint64(colName); +} + } // namespace rdbms } // namespace cta diff --git a/rdbms/Rset.hpp b/rdbms/Rset.hpp index 5aa3adfd2566df463eff9c56b18b322abc6de5b5..caa23d5443e3eb6424da58381df32093b1daf5b0 100644 --- a/rdbms/Rset.hpp +++ b/rdbms/Rset.hpp @@ -27,22 +27,64 @@ namespace cta { namespace rdbms { /** - * Abstract class specificing the interface to the result set of an sql query. + * Forward declarartion. + */ +class RsetImpl; + +/** + * A wrapper around an object that iterators over a result set from the + * execution of a database query. + * + * This wrapper permits the user of the rdbms::Stmt::executeQuery() method to + * use different result set implementations whilst only using a result set type. */ class Rset { public: + /** + * Constructor. + */ + Rset(); + + /** + * Constructor. + * + * @param impl The object actually implementing this result set. + */ + Rset(RsetImpl *const impl); + + /** + * Deletion of copy constructor. + */ + Rset(const Rset &) = delete; + + /** + * Move constructor. + * + * @param other The other object to be moved. + */ + Rset(Rset &&other); /** * Destructor. */ - virtual ~Rset() throw() = 0; + ~Rset() throw(); + + /** + * Deletion of copy assignment. + */ + Rset &operator=(const Rset &) = delete; + + /** + * Move assignment. + */ + Rset &operator=(Rset &&rhs); /** * Returns the SQL statement. * * @return The SQL statement. */ - virtual const std::string &getSql() const = 0; + const std::string &getSql() const; /** * Attempts to get the next row of the result set. @@ -50,7 +92,7 @@ public: * @return True if a row has been retrieved else false if there are no more * rows in the result set. */ - virtual bool next() = 0; + bool next(); /** * Returns true if the specified column contains a null value. @@ -58,7 +100,7 @@ public: * @param colName The name of the column. * @return True if the specified column contains a null value. */ - virtual bool columnIsNull(const std::string &colName) const = 0; + bool columnIsNull(const std::string &colName) const; /** * Returns the value of the specified column as a string. @@ -79,7 +121,7 @@ public: * @param colName The name of the column. * @return The string value of the specified column. */ - virtual optional<std::string> columnOptionalString(const std::string &colName) const = 0; + optional<std::string> columnOptionalString(const std::string &colName) const; /** * Returns the value of the specified column as an integer. @@ -114,7 +156,7 @@ public: * @param colName The name of the column. * @return The value of the specified column. */ - virtual optional<uint64_t> columnOptionalUint64(const std::string &colName) const = 0; + optional<uint64_t> columnOptionalUint64(const std::string &colName) const; /** * Returns the value of the specified column as a boolean. @@ -127,7 +169,14 @@ public: * @param colName The name of the column. * @return The value of the specified column. */ - virtual optional<bool> columnOptionalBool(const std::string &colName) const; + optional<bool> columnOptionalBool(const std::string &colName) const; + +private: + + /** + * The object actually implementing this result set. + */ + RsetImpl *m_impl; }; // class Rset diff --git a/rdbms/RsetImpl.cpp b/rdbms/RsetImpl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6eb67a189cb3c47d91b1fa85adef93a08470ba82 --- /dev/null +++ b/rdbms/RsetImpl.cpp @@ -0,0 +1,31 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "rdbms/RsetImpl.hpp" + +namespace cta { +namespace rdbms { + +//------------------------------------------------------------------------------ +// destructor +//------------------------------------------------------------------------------ +RsetImpl::~RsetImpl() throw() { +} + +} // namespace rdbms +} // namespace cta diff --git a/rdbms/RsetImpl.hpp b/rdbms/RsetImpl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..72db6ed246e8dbd6eb9a4a9bbb3d763c0dcaa8d0 --- /dev/null +++ b/rdbms/RsetImpl.hpp @@ -0,0 +1,87 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include "common/optional.hpp" + +#include <stdint.h> +#include <string> + +namespace cta { +namespace rdbms { + +/** + * Abstract class specifying the interface to an implementation of the result + * set of an sql query. + */ +class RsetImpl { +public: + + /** + * Destructor. + */ + virtual ~RsetImpl() throw() = 0; + + /** + * Returns the SQL statement. + * + * @return The SQL statement. + */ + virtual const std::string &getSql() const = 0; + + /** + * Attempts to get the next row of the result set. + * + * @return True if a row has been retrieved else false if there are no more + * rows in the result set. + */ + virtual bool next() = 0; + + /** + * Returns true if the specified column contains a null value. + * + * @param colName The name of the column. + * @return True if the specified column contains a null value. + */ + virtual bool columnIsNull(const std::string &colName) const = 0; + + /** + * Returns the value of the specified column as a string. + * + * This method will return a null column value as an optional with no value. + * + * @param colName The name of the column. + * @return The string value of the specified column. + */ + virtual optional<std::string> columnOptionalString(const std::string &colName) const = 0; + + /** + * Returns the value of the specified column as an integer. + * + * This method will return a null column value as an optional with no value. + * + * @param colName The name of the column. + * @return The value of the specified column. + */ + virtual optional<uint64_t> columnOptionalUint64(const std::string &colName) const = 0; + +}; // class RsetImpl + +} // namespace rdbms +} // namespace cta diff --git a/rdbms/SqliteConn.cpp b/rdbms/SqliteConn.cpp index 36b5cdb26f567967d163dcc341b95d228a8aecc5..3b08df7341d0cdb16c54a427f0f3907ed93be97f 100644 --- a/rdbms/SqliteConn.cpp +++ b/rdbms/SqliteConn.cpp @@ -174,9 +174,9 @@ void SqliteConn::printSchema(std::ostream &os) { auto rset = stmt->executeQuery(); os << "NAME, TYPE" << std::endl; os << "==========" << std::endl; - while (rset->next()) { - const std::string name = rset->columnString("NAME"); - const std::string type = rset->columnString("TYPE"); + while (rset.next()) { + const std::string name = rset.columnString("NAME"); + const std::string type = rset.columnString("TYPE"); os << name << ", " << type << std::endl; } } catch(exception::Exception &ex) { @@ -201,8 +201,8 @@ std::list<std::string> SqliteConn::getTableNames() { auto stmt = createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); std::list<std::string> names; - while (rset->next()) { - names.push_back(rset->columnString("NAME")); + while (rset.next()) { + names.push_back(rset.columnString("NAME")); } return names; } catch(exception::Exception &ex) { diff --git a/rdbms/SqliteRset.cpp b/rdbms/SqliteRsetImpl.cpp similarity index 93% rename from rdbms/SqliteRset.cpp rename to rdbms/SqliteRsetImpl.cpp index 577aada06f6cac7ef287c3f9718eb35d929c874a..f16144e65dc01c403e2a1468d92b965b53176260 100644 --- a/rdbms/SqliteRset.cpp +++ b/rdbms/SqliteRsetImpl.cpp @@ -18,7 +18,7 @@ #include "NullDbValue.hpp" #include "Sqlite.hpp" -#include "SqliteRset.hpp" +#include "SqliteRsetImpl.hpp" #include "SqliteStmt.hpp" #include "common/exception/Exception.hpp" #include "common/exception/Errnum.hpp" @@ -120,31 +120,31 @@ private: */ std::map<std::string, IdxAndType> m_nameToIdxAndType; -}; // class SqliteRset::ColNameToIdx +}; // class SqliteRsetImpl::ColNameToIdx //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -SqliteRset::SqliteRset(SqliteStmt &stmt): m_stmt(stmt) { +SqliteRsetImpl::SqliteRsetImpl(SqliteStmt &stmt): m_stmt(stmt) { } //------------------------------------------------------------------------------ // destructor. //------------------------------------------------------------------------------ -SqliteRset::~SqliteRset() throw() { +SqliteRsetImpl::~SqliteRsetImpl() throw() { } //------------------------------------------------------------------------------ // getSql //------------------------------------------------------------------------------ -const std::string &SqliteRset::getSql() const { +const std::string &SqliteRsetImpl::getSql() const { return m_stmt.getSql(); } //------------------------------------------------------------------------------ // next //------------------------------------------------------------------------------ -bool SqliteRset::next() { +bool SqliteRsetImpl::next() { try { const int stepRc = sqlite3_step(m_stmt.get()); @@ -167,7 +167,7 @@ bool SqliteRset::next() { //------------------------------------------------------------------------------ // clearAndPopulateColNameToIdxMap //------------------------------------------------------------------------------ -void SqliteRset::clearAndPopulateColNameToIdxAndTypeMap() { +void SqliteRsetImpl::clearAndPopulateColNameToIdxAndTypeMap() { try { m_colNameToIdxAndType.clear(); @@ -197,7 +197,7 @@ void SqliteRset::clearAndPopulateColNameToIdxAndTypeMap() { //------------------------------------------------------------------------------ // columnIsNull //------------------------------------------------------------------------------ -bool SqliteRset::columnIsNull(const std::string &colName) const { +bool SqliteRsetImpl::columnIsNull(const std::string &colName) const { try { const ColumnNameToIdxAndType::IdxAndType idxAndType = m_colNameToIdxAndType.getIdxAndType(colName); return SQLITE_NULL == idxAndType.colType; @@ -209,7 +209,7 @@ bool SqliteRset::columnIsNull(const std::string &colName) const { //------------------------------------------------------------------------------ // columnOptionalString //------------------------------------------------------------------------------ -optional<std::string> SqliteRset::columnOptionalString(const std::string &colName) const { +optional<std::string> SqliteRsetImpl::columnOptionalString(const std::string &colName) const { try { const ColumnNameToIdxAndType::IdxAndType idxAndType = m_colNameToIdxAndType.getIdxAndType(colName); if(SQLITE_NULL == idxAndType.colType) { @@ -232,7 +232,7 @@ optional<std::string> SqliteRset::columnOptionalString(const std::string &colNam //------------------------------------------------------------------------------ // columnOptionalUint64 //------------------------------------------------------------------------------ -optional<uint64_t> SqliteRset::columnOptionalUint64(const std::string &colName) const { +optional<uint64_t> SqliteRsetImpl::columnOptionalUint64(const std::string &colName) const { try { const ColumnNameToIdxAndType::IdxAndType idxAndType = m_colNameToIdxAndType.getIdxAndType(colName); if(SQLITE_NULL == idxAndType.colType) { diff --git a/rdbms/SqliteRset.hpp b/rdbms/SqliteRsetImpl.hpp similarity index 93% rename from rdbms/SqliteRset.hpp rename to rdbms/SqliteRsetImpl.hpp index 11af72470616a40ee4d22e277f770ecb0db6b7bc..8aaee093ec3fe6b053184b488e1e027fb9cb834b 100644 --- a/rdbms/SqliteRset.hpp +++ b/rdbms/SqliteRsetImpl.hpp @@ -18,8 +18,8 @@ #pragma once -#include "ColumnNameToIdxAndType.hpp" -#include "Rset.hpp" +#include "rdbms/ColumnNameToIdxAndType.hpp" +#include "rdbms/RsetImpl.hpp" #include <memory> #include <stdint.h> @@ -36,7 +36,7 @@ class SqliteStmt; /** * The result set of an sql query. */ -class SqliteRset: public Rset { +class SqliteRsetImpl: public RsetImpl { public: /** @@ -44,12 +44,12 @@ public: * * @param stmt The prepared statement. */ - SqliteRset(SqliteStmt &stmt); + SqliteRsetImpl(SqliteStmt &stmt); /** * Destructor. */ - ~SqliteRset() throw() override; + ~SqliteRsetImpl() throw() override; /** * Returns the SQL statement. diff --git a/rdbms/SqliteStmt.cpp b/rdbms/SqliteStmt.cpp index e08de8237faead19ba492c4c28b721539eaaf032..76b61a37945e315e273b180a4b93e1a5d49447f0 100644 --- a/rdbms/SqliteStmt.cpp +++ b/rdbms/SqliteStmt.cpp @@ -21,7 +21,7 @@ #include "common/threading/MutexLocker.hpp" #include "rdbms/Sqlite.hpp" #include "rdbms/SqliteConn.hpp" -#include "rdbms/SqliteRset.hpp" +#include "rdbms/SqliteRsetImpl.hpp" #include "rdbms/SqliteStmt.hpp" #include <cstring> @@ -208,8 +208,8 @@ void SqliteStmt::bindOptionalString(const std::string ¶mName, const optional //------------------------------------------------------------------------------ // executeQuery //------------------------------------------------------------------------------ -std::unique_ptr<Rset> SqliteStmt::executeQuery() { - return cta::make_unique<SqliteRset>(*this); +Rset SqliteStmt::executeQuery() { + return Rset(new SqliteRsetImpl(*this)); } //------------------------------------------------------------------------------ diff --git a/rdbms/SqliteStmt.hpp b/rdbms/SqliteStmt.hpp index 9f1212625faf71ee9bd8b68cddf42a6e3a4b5110..3d0cee5ad7a5b209191612883703bedba070efcd 100644 --- a/rdbms/SqliteStmt.hpp +++ b/rdbms/SqliteStmt.hpp @@ -30,7 +30,7 @@ namespace cta { namespace rdbms { class SqliteConn; -class SqliteRset; +class SqliteRsetImpl; /** * A convenience wrapper around an SQLite prepared statement. @@ -113,10 +113,9 @@ public: /** * Executes the statement and returns the result set. * - * @return The result set. Please note that it is the responsibility of the - * caller to free the memory associated with the result set. + * @return The result set. */ - std::unique_ptr<Rset> executeQuery() override; + Rset executeQuery() override; /** * Executes the statement. diff --git a/rdbms/SqliteStmtTest.cpp b/rdbms/SqliteStmtTest.cpp index 655fa7597d27a6ada56219cadb73cef68aa120a2..9aaadca885731648adaf24faded12dc3479d12bf 100644 --- a/rdbms/SqliteStmtTest.cpp +++ b/rdbms/SqliteStmtTest.cpp @@ -17,7 +17,7 @@ */ #include "SqliteConn.hpp" -#include "SqliteRset.hpp" +#include "SqliteRsetImpl.hpp" #include "SqliteStmt.hpp" #include <gtest/gtest.h> @@ -51,10 +51,10 @@ TEST_F(cta_rdbms_SqliteStmtTest, create_table) { "TYPE = 'table';"; auto stmt = conn.createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); - ASSERT_TRUE(rset->next()); - const uint64_t nbTables = rset->columnUint64("NB_TABLES"); + ASSERT_TRUE(rset.next()); + const uint64_t nbTables = rset.columnUint64("NB_TABLES"); ASSERT_EQ(0, nbTables); - ASSERT_FALSE(rset->next()); + ASSERT_FALSE(rset.next()); ASSERT_TRUE(conn.getTableNames().empty()); } @@ -80,10 +80,10 @@ TEST_F(cta_rdbms_SqliteStmtTest, create_table) { "TYPE = 'table';"; auto stmt = conn.createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); - ASSERT_TRUE(rset->next()); - const uint64_t nbTables = rset->columnUint64("NB_TABLES"); + ASSERT_TRUE(rset.next()); + const uint64_t nbTables = rset.columnUint64("NB_TABLES"); ASSERT_EQ(1, nbTables); - ASSERT_FALSE(rset->next()); + ASSERT_FALSE(rset.next()); ASSERT_EQ(1, conn.getTableNames().size()); ASSERT_EQ("TEST1", conn.getTableNames().front()); } @@ -110,10 +110,10 @@ TEST_F(cta_rdbms_SqliteStmtTest, create_table) { "TYPE = 'table';"; auto stmt = conn.createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); - ASSERT_TRUE(rset->next()); - const uint64_t nbTables = rset->columnUint64("NB_TABLES"); + ASSERT_TRUE(rset.next()); + const uint64_t nbTables = rset.columnUint64("NB_TABLES"); ASSERT_EQ(1, nbTables); - ASSERT_FALSE(rset->next()); + ASSERT_FALSE(rset.next()); const auto tableNames = conn.getTableNames(); ASSERT_EQ(2, tableNames.size()); auto nameItor = tableNames.begin(); @@ -156,7 +156,7 @@ TEST_F(cta_rdbms_SqliteStmtTest, select_from_empty_table) { "TEST;"; auto stmt = conn.createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); - ASSERT_FALSE(rset->next()); + ASSERT_FALSE(rset.next()); } } @@ -206,17 +206,17 @@ TEST_F(cta_rdbms_SqliteStmtTest, insert_without_bind) { "TEST;"; auto stmt = conn.createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); - ASSERT_TRUE(rset->next()); + ASSERT_TRUE(rset.next()); - const std::string col1 = rset->columnString("COL1"); - const std::string col2 = rset->columnString("COL2"); - const uint64_t col3 = rset->columnUint64("COL3"); + const std::string col1 = rset.columnString("COL1"); + const std::string col2 = rset.columnString("COL2"); + const uint64_t col3 = rset.columnUint64("COL3"); ASSERT_EQ("one", col1); ASSERT_EQ("two", col2); ASSERT_EQ((uint64_t)3, col3); - ASSERT_FALSE(rset->next()); + ASSERT_FALSE(rset.next()); } } @@ -270,17 +270,17 @@ TEST_F(cta_rdbms_SqliteStmtTest, insert_with_bind) { "TEST;"; auto stmt = conn.createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); - ASSERT_TRUE(rset->next()); + ASSERT_TRUE(rset.next()); - const std::string col1 = rset->columnString("COL1"); - const std::string col2 = rset->columnString("COL2"); - const uint64_t col3 = rset->columnUint64("COL3"); + const std::string col1 = rset.columnString("COL1"); + const std::string col2 = rset.columnString("COL2"); + const uint64_t col3 = rset.columnUint64("COL3"); ASSERT_EQ("one", col1); ASSERT_EQ("two", col2); ASSERT_EQ((uint64_t)3, col3); - ASSERT_FALSE(rset->next()); + ASSERT_FALSE(rset.next()); } } @@ -332,13 +332,13 @@ TEST_F(cta_rdbms_SqliteStmtTest, isolated_transaction) { "TEST;"; auto stmt = connForSelect.createStmt(sql, Stmt::AutocommitMode::ON); auto rset = stmt->executeQuery(); - ASSERT_TRUE(rset->next()); + ASSERT_TRUE(rset.next()); - const uint64_t nbRows = rset->columnUint64("NB_ROWS"); + const uint64_t nbRows = rset.columnUint64("NB_ROWS"); ASSERT_EQ((uint64_t)1, nbRows); - ASSERT_FALSE(rset->next()); + ASSERT_FALSE(rset.next()); } } diff --git a/rdbms/Stmt.hpp b/rdbms/Stmt.hpp index 9e05ff785d0b1bf2d40787bd28605c9bdedfdcdb..8aa49c5c4dea4626b31ef547a8e6a201f2b55e51 100644 --- a/rdbms/Stmt.hpp +++ b/rdbms/Stmt.hpp @@ -162,10 +162,9 @@ public: /** * Executes the statement and returns the result set. * - * @return The result set. Please note that it is the responsibility of the - * caller to free the memory associated with the result set. + * @return The result set. */ - virtual std::unique_ptr<Rset> executeQuery() = 0; + virtual Rset executeQuery() = 0; /** * Executes the statement.