| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "COntologyRevisionMultiPersistencer.h" |
| 22 |
#include "CNameBasedOntologyRevisionPersistencerFactory.h" |
| 23 |
|
| 24 |
|
| 25 |
namespace Konclude { |
| 26 |
|
| 27 |
namespace Reasoner { |
| 28 |
|
| 29 |
namespace Revision { |
| 30 |
|
| 31 |
namespace Persistence { |
| 32 |
|
| 33 |
COntologyRevisionMultiPersistencer::COntologyRevisionMultiPersistencer(CConfiguration* config) : CLogIdentifier("::Konclude::Reasoner::Persistence::MultiPersistencer", this) { |
| 34 |
mConfig = config; |
| 35 |
QStringList persistencerList = CConfigDataReader::readConfigStringList(mConfig, "Konclude.Persistence.MultiPersistencer.PersisterList"); |
| 36 |
|
| 37 |
for (QString persistencerName : persistencerList) { |
| 38 |
CNameBasedOntologyRevisionPersistencerFactory factory(persistencerName, mConfig); |
| 39 |
COntologyRevisionPersistencer* persistencer = factory.createOntologyRevisionPersistencer(); |
| 40 |
mPersisterList.append(persistencer); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
COntologyRevisionMultiPersistencer::~COntologyRevisionMultiPersistencer() { |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
bool COntologyRevisionMultiPersistencer::persistOntologyRevision(COntologyRevision* ontoRev, COntologyRevision* prevOntoRev) { |
| 52 |
bool successfullyWritten = true; |
| 53 |
for (COntologyRevisionPersistencer* persister : mPersisterList) { |
| 54 |
successfullyWritten &= persister->persistOntologyRevision(ontoRev, prevOntoRev); |
| 55 |
} |
| 56 |
return successfullyWritten; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
bool COntologyRevisionMultiPersistencer::hasOntologyPersisted(const QString& ontologyName) { |
| 65 |
for (COntologyRevisionPersistencer* persister : mPersisterList) { |
| 66 |
if (persister->hasOntologyPersisted(ontologyName)) { |
| 67 |
return true; |
| 68 |
} |
| 69 |
} |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
bool COntologyRevisionMultiPersistencer::deletePersistedOntology(const QString& ontologyName) { |
| 76 |
bool successfullyDeleted = true; |
| 77 |
for (COntologyRevisionPersistencer* persister : mPersisterList) { |
| 78 |
successfullyDeleted &= persister->deletePersistedOntology(ontologyName); |
| 79 |
} |
| 80 |
return successfullyDeleted; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
bool COntologyRevisionMultiPersistencer::hasNewOntologyRevision(const QString& ontologyName, COntologyRevision* ontoRev) { |
| 85 |
for (COntologyRevisionPersistencer* persister : mPersisterList) { |
| 86 |
if (persister->hasNewOntologyRevision(ontologyName, ontoRev)) { |
| 87 |
return true; |
| 88 |
} |
| 89 |
} |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
bool COntologyRevisionMultiPersistencer::loadLatestOntologyRevision(const QString& ontologyName, COntologyRevision* ontoRev) { |
| 96 |
bool successfullyLoaded = true; |
| 97 |
for (COntologyRevisionPersistencer* persister : mPersisterList) { |
| 98 |
if (persister->hasNewOntologyRevision(ontologyName, ontoRev)) { |
| 99 |
successfullyLoaded &= persister->deletePersistedOntology(ontologyName); |
| 100 |
} |
| 101 |
} |
| 102 |
return successfullyLoaded; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
}; // end namespace Persistence |
| 107 |
|
| 108 |
}; // end namespace Revision |
| 109 |
|
| 110 |
}; // end namespace Reasoner |
| 111 |
|
| 112 |
}; // end namespace Konclude |