FOSSology  4.4.0
Open Source License Compliance by Open Source Software
libfossAgentDatabaseHandler.cc
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2013-2014 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
9 #include "libfossUtils.hpp"
10 
11 extern "C" {
12 #include "libfossagent.h"
13 }
14 
25  dbManager(_dbManager)
26 {
27 }
28 
33  dbManager(other.dbManager)
34 {
35 }
36 
41 {
42 }
43 
50 {
51  return dbManager.begin();
52 }
53 
60 {
61  return dbManager.commit();
62 }
63 
70 {
71  return dbManager.rollback();
72 }
73 
80 char* fo::AgentDatabaseHandler::getPFileNameForFileId(unsigned long pfileId) const
81 {
82  return queryPFileForFileId(dbManager.getStruct_dbManager(), pfileId);
83 }
84 
92 std::vector<unsigned long> fo::AgentDatabaseHandler::queryFileIdsVectorForUpload(int uploadId, bool ignoreFilesWithMimeType) const
93 {
94  QueryResult queryResult(queryFileIdsForUpload(dbManager.getStruct_dbManager(), uploadId, ignoreFilesWithMimeType));
95  return queryResult.getSimpleResults(0, fo::stringToUnsignedLong);
96 }
97 
107  int uploadId, int agentId, bool ignoreFilesWithMimeType) const
108 {
109  QueryResult queryResult(
110  getSelectedPFiles(dbManager.getConnection(), uploadId, agentId,
111  ignoreFilesWithMimeType));
112  return queryResult.getSimpleResults(0, fo::stringToUnsignedLong);
113 }
114 
121 {
122  return std::string(getUploadTreeTableName(dbManager.getStruct_dbManager(), uploadId));
123 }
Database handler for agents.
std::vector< unsigned long > queryFileIdsVectorForUpload(int uploadId, bool ignoreFilesWithMimeType) const
Get pfile ids for a given upload id.
std::string queryUploadTreeTableName(int uploadId)
Get the upload tree table name for a given upload id.
AgentDatabaseHandler(DbManager dbManager)
bool commit() const
COMMIT a transaction block in DB.
bool begin() const
BEGIN a transaction block in DB.
char * getPFileNameForFileId(unsigned long pfileId) const
Get the file name of a give pfile id.
bool rollback() const
ROLLBACK a transaction block in DB.
DB wrapper for agents.
Wrapper for DB result.
std::vector< T > getSimpleResults(int columnN, T(functionP)(const char *)) const
Get vector of a single column from query result.
DB utility functions for agents.
General utility functions for CPP.
char * queryPFileForFileId(fo_dbManager *dbManager, long fileId)
Get the pfile name for a given file ID.
Definition: libfossagent.c:122
char * getUploadTreeTableName(fo_dbManager *dbManager, int uploadId)
Get the upload tree table name for a given upload.
Definition: libfossagent.c:25
PGresult * queryFileIdsForUpload(fo_dbManager *dbManager, int uploadId, bool ignoreFilesWithMimeType)
Get all file IDs (pfile_fk) for a given upload.
Definition: libfossagent.c:61
PGresult * getSelectedPFiles(PGconn *pgConn, int uploadPk, int agentPk, bool ignoreFilesWithMimeType)
Get the upload_pk, agent_pk and ignoreFilesWithMimeType to get all the file Ids for nomos.
Definition: libfossagent.c:469
DB wrapper for agents.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
unsigned long stringToUnsignedLong(const char *string)
Definition: libfossUtils.cc:20