1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program 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 General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 /** 23 Default DBI implementations 24 */ 25 26 #ifndef _U2_ABSTRACT_DBI_H_ 27 #define _U2_ABSTRACT_DBI_H_ 28 29 #include <U2Core/U2AssemblyDbi.h> 30 #include <U2Core/U2AttributeDbi.h> 31 #include <U2Core/U2CrossDatabaseReferenceDbi.h> 32 #include <U2Core/U2DbiUpgrader.h> 33 #include <U2Core/U2DbiUtils.h> 34 #include <U2Core/U2FeatureDbi.h> 35 #include <U2Core/U2ModDbi.h> 36 #include <U2Core/U2MsaDbi.h> 37 #include <U2Core/U2ObjectDbi.h> 38 #include <U2Core/U2ObjectRelationsDbi.h> 39 #include <U2Core/U2SafePoints.h> 40 #include <U2Core/U2SequenceDbi.h> 41 #include <U2Core/U2VariantDbi.h> 42 #include <U2Core/UdrDbi.h> 43 44 namespace U2 { 45 46 /** Default (empty) implementation for optional DBI methods */ 47 class U2AbstractDbi : public U2Dbi { 48 protected: U2AbstractDbi(const U2DbiFactoryId & fid)49 U2AbstractDbi(const U2DbiFactoryId &fid) { 50 state = U2DbiState_Void; 51 factoryId = fid; 52 } 53 ~U2AbstractDbi()54 ~U2AbstractDbi() { 55 qDeleteAll(upgraders); 56 } 57 58 public: flush(U2OpStatus &)59 virtual bool flush(U2OpStatus &) { 60 return true; 61 } 62 getState()63 virtual U2DbiState getState() const { 64 return state; 65 } 66 getDbiId()67 virtual U2DbiId getDbiId() const { 68 return dbiId; 69 } 70 getFactoryId()71 virtual U2DbiFactoryId getFactoryId() const { 72 return factoryId; 73 } 74 getFeatures()75 virtual const QSet<U2DbiFeature> &getFeatures() const { 76 return features; 77 } 78 getInitProperties()79 virtual QHash<QString, QString> getInitProperties() const { 80 return initProperties; 81 } 82 getDbiMetaInfo(U2OpStatus &)83 virtual QHash<QString, QString> getDbiMetaInfo(U2OpStatus &) { 84 return metaInfo; 85 } 86 getSequenceDbi()87 virtual U2SequenceDbi *getSequenceDbi() { 88 return nullptr; 89 } 90 getFeatureDbi()91 virtual U2FeatureDbi *getFeatureDbi() { 92 return nullptr; 93 } 94 getMsaDbi()95 virtual U2MsaDbi *getMsaDbi() { 96 return nullptr; 97 } 98 getAssemblyDbi()99 virtual U2AssemblyDbi *getAssemblyDbi() { 100 return nullptr; 101 } 102 getAttributeDbi()103 virtual U2AttributeDbi *getAttributeDbi() { 104 return nullptr; 105 } 106 getObjectDbi()107 virtual U2ObjectDbi *getObjectDbi() { 108 return nullptr; 109 } 110 getObjectRelationsDbi()111 virtual U2ObjectRelationsDbi *getObjectRelationsDbi() { 112 return nullptr; 113 } 114 getVariantDbi()115 virtual U2VariantDbi *getVariantDbi() { 116 return nullptr; 117 } 118 getModDbi()119 virtual U2ModDbi *getModDbi() { 120 return nullptr; 121 } 122 getCrossDatabaseReferenceDbi()123 virtual U2CrossDatabaseReferenceDbi *getCrossDatabaseReferenceDbi() { 124 return nullptr; 125 } 126 getUdrDbi()127 virtual UdrDbi *getUdrDbi() { 128 return nullptr; 129 } 130 getEntityTypeById(const U2DataId &)131 virtual U2DataType getEntityTypeById(const U2DataId &) const { 132 return U2Type::Unknown; 133 } 134 getProperty(const QString &,const QString & defaultValue,U2OpStatus & os)135 virtual QString getProperty(const QString &, const QString &defaultValue, U2OpStatus &os) { 136 U2DbiUtils::logNotSupported(U2DbiFeature_ReadProperties, this, os); 137 return defaultValue; 138 } 139 setProperty(const QString &,const QString &,U2OpStatus & os)140 virtual void setProperty(const QString &, const QString &, U2OpStatus &os) { 141 U2DbiUtils::logNotSupported(U2DbiFeature_WriteProperties, this, os); 142 } 143 upgrade(U2OpStatus & os)144 virtual void upgrade(U2OpStatus &os) { 145 std::sort(upgraders.begin(), upgraders.end()); 146 foreach (const U2DbiUpgrader *upgrader, upgraders) { 147 if (upgrader->isAppliable(Version::parseVersion(getProperty(U2DbiOptions::APP_MIN_COMPATIBLE_VERSION, "0.0.0", os)))) { 148 upgrader->upgrade(os); 149 CHECK_OP(os, ); 150 } 151 } 152 } 153 isTransactionActive()154 bool isTransactionActive() const { 155 return false; 156 } 157 158 protected: 159 U2DbiState state; 160 U2DbiId dbiId; 161 U2DbiFactoryId factoryId; 162 QSet<U2DbiFeature> features; 163 QHash<QString, QString> initProperties; 164 QHash<QString, QString> metaInfo; 165 QList<U2DbiUpgrader *> upgraders; 166 }; 167 168 /** Default no-op implementation for write methods of U2ObjectDbi */ 169 class U2SimpleObjectDbi : public U2ObjectDbi { 170 protected: U2SimpleObjectDbi(U2Dbi * rootDbi)171 U2SimpleObjectDbi(U2Dbi *rootDbi) 172 : U2ObjectDbi(rootDbi) { 173 } 174 175 public: getObject(U2Object &,const U2DataId &,U2OpStatus & os)176 virtual void getObject(U2Object &, const U2DataId &, U2OpStatus &os) { 177 U2DbiUtils::logNotSupported(U2DbiFeature_RemoveObjects, getRootDbi(), os); 178 } 179 getObject(qint64 objectId,U2OpStatus & os)180 virtual U2DataId getObject(qint64 objectId, U2OpStatus &os) { 181 Q_UNUSED(objectId) 182 U2DbiUtils::logNotSupported(U2DbiFeature_RemoveObjects, getRootDbi(), os); 183 return U2DataId(); 184 } 185 getObjectFolders(U2OpStatus & os)186 virtual QHash<U2Object, QString> getObjectFolders(U2OpStatus &os) { 187 U2DbiUtils::logNotSupported(U2DbiFeature_RemoveObjects, getRootDbi(), os); 188 return QHash<U2Object, QString>(); 189 } 190 getObjectFolders(const U2DataId &,U2OpStatus & os)191 virtual QStringList getObjectFolders(const U2DataId &, U2OpStatus &os) { 192 U2DbiUtils::logNotSupported(U2DbiFeature_RemoveObjects, getRootDbi(), os); 193 return QStringList(); 194 } 195 removeObject(const U2DataId &,bool,U2OpStatus & os)196 virtual bool removeObject(const U2DataId &, bool, U2OpStatus &os) { 197 U2DbiUtils::logNotSupported(U2DbiFeature_RemoveObjects, getRootDbi(), os); 198 return false; 199 } 200 removeObjects(const QList<U2DataId> &,bool,U2OpStatus & os)201 virtual bool removeObjects(const QList<U2DataId> &, bool, U2OpStatus &os) { 202 U2DbiUtils::logNotSupported(U2DbiFeature_RemoveObjects, getRootDbi(), os); 203 return false; 204 } 205 createFolder(const QString &,U2OpStatus & os)206 virtual void createFolder(const QString &, U2OpStatus &os) { 207 U2DbiUtils::logNotSupported(U2DbiFeature_ChangeFolders, getRootDbi(), os); 208 } 209 removeFolder(const QString &,U2OpStatus & os)210 virtual bool removeFolder(const QString &, U2OpStatus &os) { 211 U2DbiUtils::logNotSupported(U2DbiFeature_ChangeFolders, getRootDbi(), os); 212 return false; 213 } 214 renameFolder(const QString &,const QString &,U2OpStatus & os)215 virtual void renameFolder(const QString &, const QString &, U2OpStatus &os) { 216 U2DbiUtils::logNotSupported(U2DbiFeature_ChangeFolders, getRootDbi(), os); 217 } 218 getFolderPreviousPath(const QString &,U2OpStatus & os)219 virtual QString getFolderPreviousPath(const QString &, U2OpStatus &os) { 220 U2DbiUtils::logNotSupported(U2DbiFeature_ChangeFolders, getRootDbi(), os); 221 return ""; 222 } 223 addObjectsToFolder(const QList<U2DataId> &,const QString &,U2OpStatus & os)224 virtual void addObjectsToFolder(const QList<U2DataId> &, const QString &, U2OpStatus &os) { 225 U2DbiUtils::logNotSupported(U2DbiFeature_ChangeFolders, getRootDbi(), os); 226 } 227 moveObjects(const QList<U2DataId> &,const QString &,const QString &,U2OpStatus & os,bool)228 virtual void moveObjects(const QList<U2DataId> &, const QString &, const QString &, U2OpStatus &os, bool) { 229 U2DbiUtils::logNotSupported(U2DbiFeature_ChangeFolders, getRootDbi(), os); 230 } 231 restoreObjects(const QList<U2DataId> &,U2OpStatus & os)232 virtual QStringList restoreObjects(const QList<U2DataId> &, U2OpStatus &os) { 233 U2DbiUtils::logNotSupported(U2DbiFeature_ChangeFolders, getRootDbi(), os); 234 return QStringList(); 235 } 236 getTrackModType(const U2DataId &,U2OpStatus & os)237 virtual U2TrackModType getTrackModType(const U2DataId &, U2OpStatus &os) { 238 U2DbiUtils::logNotSupported(U2DbiFeature_ReadModifications, getRootDbi(), os); 239 return NoTrack; 240 } 241 setTrackModType(const U2DataId &,U2TrackModType,U2OpStatus & os)242 virtual void setTrackModType(const U2DataId &, U2TrackModType, U2OpStatus &os) { 243 U2DbiUtils::logNotSupported(U2DbiFeature_WriteModifications, getRootDbi(), os); 244 } 245 undo(const U2DataId &,U2OpStatus & os)246 virtual void undo(const U2DataId &, U2OpStatus &os) { 247 U2DbiUtils::logNotSupported(U2DbiFeature_UndoRedo, getRootDbi(), os); 248 } 249 redo(const U2DataId &,U2OpStatus & os)250 virtual void redo(const U2DataId &, U2OpStatus &os) { 251 U2DbiUtils::logNotSupported(U2DbiFeature_UndoRedo, getRootDbi(), os); 252 } 253 canUndo(const U2DataId &,U2OpStatus & os)254 virtual bool canUndo(const U2DataId & /*msaId*/, U2OpStatus &os) { 255 U2DbiUtils::logNotSupported(U2DbiFeature_UndoRedo, getRootDbi(), os); 256 return false; 257 } 258 canRedo(const U2DataId &,U2OpStatus & os)259 virtual bool canRedo(const U2DataId & /*objId*/, U2OpStatus &os) { 260 U2DbiUtils::logNotSupported(U2DbiFeature_UndoRedo, getRootDbi(), os); 261 return false; 262 } 263 }; 264 265 /** Default no-op implementation for write methods of U2AssemblyDbi */ 266 class U2SimpleAssemblyDbi : public U2AssemblyDbi { 267 protected: U2SimpleAssemblyDbi(U2Dbi * rootDbi)268 U2SimpleAssemblyDbi(U2Dbi *rootDbi) 269 : U2AssemblyDbi(rootDbi) { 270 } 271 272 public: createAssemblyObject(U2Assembly &,const QString &,U2DbiIterator<U2AssemblyRead> *,U2AssemblyReadsImportInfo &,U2OpStatus & os)273 virtual void createAssemblyObject(U2Assembly &, const QString &, U2DbiIterator<U2AssemblyRead> *, U2AssemblyReadsImportInfo &, U2OpStatus &os) { 274 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAssembly, getRootDbi(), os); 275 } 276 finalizeAssemblyObject(U2Assembly &,U2OpStatus & os)277 virtual void finalizeAssemblyObject(U2Assembly & /*assembly*/, U2OpStatus &os) { 278 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAssembly, getRootDbi(), os); 279 } 280 removeAssemblyData(const U2DataId &,U2OpStatus & os)281 virtual void removeAssemblyData(const U2DataId &, U2OpStatus &os) { 282 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAssembly, getRootDbi(), os); 283 } 284 updateAssemblyObject(U2Assembly &,U2OpStatus & os)285 virtual void updateAssemblyObject(U2Assembly &, U2OpStatus &os) { 286 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAssembly, getRootDbi(), os); 287 } 288 removeReads(const U2DataId &,const QList<U2DataId> &,U2OpStatus & os)289 virtual void removeReads(const U2DataId &, const QList<U2DataId> &, U2OpStatus &os) { 290 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAssembly, getRootDbi(), os); 291 } 292 addReads(const U2DataId &,U2DbiIterator<U2AssemblyRead> *,U2OpStatus & os)293 virtual void addReads(const U2DataId &, U2DbiIterator<U2AssemblyRead> *, U2OpStatus &os) { 294 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAssembly, getRootDbi(), os); 295 } 296 pack(const U2DataId &,U2AssemblyPackStat &,U2OpStatus & os)297 virtual void pack(const U2DataId &, U2AssemblyPackStat &, U2OpStatus &os) { 298 U2DbiUtils::logNotSupported(U2DbiFeature_AssemblyReadsPacking, getRootDbi(), os); 299 } 300 calculateCoverage(const U2DataId &,const U2Region &,U2AssemblyCoverageStat &,U2OpStatus & os)301 virtual void calculateCoverage(const U2DataId &, const U2Region &, U2AssemblyCoverageStat &, U2OpStatus &os) { 302 U2DbiUtils::logNotSupported(U2DbiFeature_AssemblyCoverageStat, getRootDbi(), os); 303 } 304 }; 305 306 /** Default no-op implementation for write methods of U2AttributeDbi */ 307 class U2SimpleAttributeDbi : public U2AttributeDbi { 308 protected: U2SimpleAttributeDbi(U2Dbi * rootDbi)309 U2SimpleAttributeDbi(U2Dbi *rootDbi) 310 : U2AttributeDbi(rootDbi) { 311 } 312 313 public: removeAttributes(const QList<U2DataId> &,U2OpStatus & os)314 virtual void removeAttributes(const QList<U2DataId> &, U2OpStatus &os) { 315 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAttributes, getRootDbi(), os); 316 } 317 removeObjectAttributes(const U2DataId &,U2OpStatus & os)318 virtual void removeObjectAttributes(const U2DataId &, U2OpStatus &os) { 319 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAttributes, getRootDbi(), os); 320 } 321 createIntegerAttribute(U2IntegerAttribute &,U2OpStatus & os)322 virtual void createIntegerAttribute(U2IntegerAttribute &, U2OpStatus &os) { 323 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAttributes, getRootDbi(), os); 324 } 325 createRealAttribute(U2RealAttribute &,U2OpStatus & os)326 virtual void createRealAttribute(U2RealAttribute &, U2OpStatus &os) { 327 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAttributes, getRootDbi(), os); 328 } 329 createStringAttribute(U2StringAttribute &,U2OpStatus & os)330 virtual void createStringAttribute(U2StringAttribute &, U2OpStatus &os) { 331 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAttributes, getRootDbi(), os); 332 } 333 createByteArrayAttribute(U2ByteArrayAttribute &,U2OpStatus & os)334 virtual void createByteArrayAttribute(U2ByteArrayAttribute &, U2OpStatus &os) { 335 U2DbiUtils::logNotSupported(U2DbiFeature_WriteAttributes, getRootDbi(), os); 336 } 337 }; 338 339 } // namespace U2 340 341 #endif 342