#include "DDataProvider.h" #include "DLog.h" using namespace ccdb; namespace ccdb { DDataProvider::DDataProvider(void): mMaximumErrorsToHold(100) { ClearErrorsOnFunctionStart(); } DDataProvider::~DDataProvider(void) { } bool DDataProvider::ValidateName(const string& name ) { //Validates that name has a-zA-Z0-9_- symbols for(string::const_iterator charIter = name.begin(); charIter'z')&& (letter<'A' || letter>'Z')&& (letter<'0' || letter>'9')&& (letter!='_')&& (letter!='-')) { return false; } } return true; } void DDataProvider::SetObjectLoaded( DStoredObject* obj ) { if(obj!=NULL) { obj->SetIsLoaded(true); obj->SetIsChanged(false); } } vector DDataProvider::SearchDirectories( const string& searchPattern, const string& parentPath/*=""*/, int startWith/*=0*/, int select/*=0*/ ) { vector result; SearchDirectories(result, searchPattern, parentPath, startWith, select); return result; } } DConstantsTypeTable* ccdb::DDataProvider::CreateConstantsTypeTable(const string& name, const string& parentPath, int rowsNumber, map columns, const string& comments/*=""*/) { DLog::Error( CCDB_ERROR_NOT_IMPLEMENTED, "CreateConstantsTypeTable(const string& name, const string& parentPath, int rowsNumber, map columns, const string& comments)", "Method is not implemented"); return NULL; } DConstantsTypeTable* ccdb::DDataProvider::CreateConstantsTypeTable(const string& name, DDirectory* parentDir, int rowsNumber, map columns, const string& comments) { DLog::Error( CCDB_ERROR_NOT_IMPLEMENTED, "DDataProvider::CreateConstantsTypeTable(const string& name, DDirectory* parentDir, int rowsNumber, map columns, const string& comments)", "Method is not implemented"); return NULL; } bool ccdb::DDataProvider::GetRunRanges(vector& resultRunRanges, const string& typeTablePath, const string& variation/*=""*/, int take/*=0*/, int startWith/*=0*/) { DConstantsTypeTable *table=GetConstantsTypeTable(typeTablePath); //dont look for table to be NULL, it will be checked in GetRunRanges; return GetRunRanges(resultRunRanges, table, variation, take, startWith); } DAssignment* ccdb::DDataProvider::CreateAssignment(const vector >& data, const string& path, int runMin, int runMax, const string& variationName, const string& comments) { /* Creates Assignment using related object. * Validation: * If no such run range found, the new will be created (with no name) * No action will be done (and NULL will be returned): * * -- If no type table with such path exists * -- If data is inconsistant with columns number and rows number * -- If no variation with such name found */ DVariation* variation = GetVariation(variationName); if(variation == NULL) { //TODO error message return NULL; } DConstantsTypeTable* table=GetConstantsTypeTable(path); if(!table) { //TODO error message return NULL; } //check that we have right rows number if(data.size()!= table->GetNRows()) { //TODO error message return NULL; } //fill data blob vector vector vectorBlob; for (size_t rowIter=0; rowIter &row = data[rowIter]; if(row.size() != table->GetNColumns()) { //TODO error handle return NULL; } for (int i=0; iSetRawData(DAssignment::VectorToBlob(vectorBlob)); assignment->SetVariation(variation); assignment->BeOwner(variation); assignment->SetRunRange(runRange); assignment->BeOwner(runRange); assignment->SetTypeTable(table); //set this table assignment->BeOwner(table); //new table should be owned by assignment if(CreateAssignment(assignment)) { return assignment; } else { delete assignment; return NULL; } } DAssignment* ccdb::DDataProvider::CreateAssignment( const vector > &data, const string& path, const string& runRangeName, const string& variationName, const string& comments ) { /* Creates Assignment using related object. * Validation: * If no such run range found, the new will be created (with no name) * No action will be done (and NULL will be returned): * * -- If no type table with such path exists * -- If data is inconsistant with columns number and rows number * -- If no variation with such name found */ DVariation* variation = GetVariation(variationName); if(variation == NULL) { //TODO error message return NULL; } DConstantsTypeTable* table=GetConstantsTypeTable(path); if(!table) { //TODO error message return NULL; } //check that we have right rows number if(data.size()!= table->GetNRows()) { //TODO error message return NULL; } //fill data blob vector vector vectorBlob; for (int rowIter=0; rowIter &row = data[rowIter]; if(row.size() != table->GetNColumns()) { //TODO error handle return NULL; } for (int i=0; iSetRawData(DAssignment::VectorToBlob(vectorBlob)); assignment->SetVariation(variation); assignment->BeOwner(variation); assignment->SetRunRange(runRange); assignment->BeOwner(runRange); assignment->SetTypeTable(table); //set this table assignment->BeOwner(table); //new table should be owned by assignment if(CreateAssignment(assignment)) { return assignment; } else { delete assignment; return NULL; } } bool ccdb::DDataProvider::GetAssignments(vector& assingments, const string& path, int run, const string& variation, time_t date, int take, int startWith) { return GetAssignments(assingments, path, run, run,"",variation, 0, date, take, startWith); } bool ccdb::DDataProvider::GetVariations(vector& resultVariations, const string& path, int run, int take, int startWith) { DConstantsTypeTable* table = GetConstantsTypeTable(path); return GetVariations(resultVariations, table, run, take, startWith); } int ccdb::DDataProvider::GetNErrors() { //Get number of errors return mLastErrors.size(); } const vector& ccdb::DDataProvider::GetErrors() { //Get vector of last errors return mLastErrors; } int ccdb::DDataProvider::GetLastError() { //Gets last of the last error return mLastError; } void ccdb::DDataProvider::Error(int errorCode, const string& module, const string& message) { //Logs error //add error mLastErrors.push_back(errorCode); mLastError = errorCode; //cut array if needed while(mLastErrors.size()> mMaximumErrorsToHold) mLastErrors.erase(mLastErrors.begin()); //do log error DLog::Error(errorCode, module, message); } void ccdb::DDataProvider::ClearErrorsOnFunctionStart() { //Clear error state on start of each function that emmits error mLastErrors.clear(); mLastError = CCDB_NO_ERRORS; }