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 #ifndef _U2_SQLITE_FEATURE_DBI_H_ 23 #define _U2_SQLITE_FEATURE_DBI_H_ 24 25 #include <U2Core/U2FeatureDbi.h> 26 #include <U2Core/U2FeatureKeys.h> 27 28 #include "SQLiteDbi.h" 29 30 namespace U2 { 31 32 class SQLiteFeatureDbi : public U2FeatureDbi, public SQLiteChildDBICommon { 33 public: 34 SQLiteFeatureDbi(SQLiteDbi *dbi); 35 36 void initSqlSchema(U2OpStatus &os); 37 /** 38 * Creates a DB representation of AnnotationTableObject 39 * @table has to be fully initialized except of the id field. 40 */ 41 void createAnnotationTableObject(U2AnnotationTable &table, const QString &folder, U2OpStatus &os); 42 /** 43 * Returns a DB representation of AnnotationTableObject having supplied @tableId. 44 */ 45 U2AnnotationTable getAnnotationTableObject(const U2DataId &tableId, U2OpStatus &os); 46 /** 47 * Removes a DB representation of AnnotationTableObject having supplied @tableId. 48 */ 49 void removeAnnotationTableData(const U2DataId &tableId, U2OpStatus &os); 50 /** 51 * Reads feature data by id 52 */ 53 U2Feature getFeature(const U2DataId &featureId, U2OpStatus &os); 54 /** 55 * Counts features that matched the query 56 */ 57 qint64 countFeatures(const FeatureQuery &fq, U2OpStatus &os); 58 /** 59 * Returns features that matched the query. Returns NULL if error occurs 60 */ 61 U2DbiIterator<U2Feature> *getFeatures(const FeatureQuery &q, U2OpStatus &os); 62 /** 63 * Returns all keys of a specified feature 64 */ 65 QList<U2FeatureKey> getFeatureKeys(const U2DataId &featureId, U2OpStatus &os); 66 /** 67 * Returns all the features and keys belonging to the same annotation table with @rootFeatureId as a root feature 68 */ 69 QList<FeatureAndKey> getFeatureTable(const U2DataId &rootFeatureId, U2OpStatus &os); 70 /** 71 * Creates new feature in database. Uses all fields in 'feature' param 72 * and assign database id to it as the result 73 * Requires: U2DbiFeature_WriteFeature feature support 74 */ 75 void createFeature(U2Feature &feature, const QList<U2FeatureKey> &keys, U2OpStatus &os); 76 /** 77 * Adds key to feature 78 * Requires: U2DbiFeature_WriteFeature feature support 79 */ 80 void addKey(const U2DataId &featureId, const U2FeatureKey &key, U2OpStatus &os); 81 /** 82 * Removes all feature keys with a specified name 83 * Requires: U2DbiFeature_WriteFeature feature support 84 */ 85 void removeAllKeys(const U2DataId &featureId, const QString &keyName, U2OpStatus &os); 86 /** 87 * Removes all feature keys with a specified name and value 88 * Requires: U2DbiFeature_WriteFeature feature support 89 */ 90 void removeKey(const U2DataId &featureId, const U2FeatureKey &key, U2OpStatus &os); 91 /** 92 * Updates feature key. 93 * Requires: U2DbiFeature_WriteFeature feature support 94 */ 95 void updateKeyValue(const U2DataId &featureId, const U2FeatureKey &key, U2OpStatus &os); 96 /** 97 * After the invocation @key.value contains the value of a feature's key with name @key.name. 98 * Returning value specifies whether the key with name @key.name exists for a given feature. 99 */ 100 bool getKeyValue(const U2DataId &featureId, U2FeatureKey &key, U2OpStatus &os); 101 /** 102 * Updates feature location. Features with U2Region(0,0) have no specified location 103 * Requires: U2DbiFeature_WriteFeature feature support 104 */ 105 void updateLocation(const U2DataId &featureId, const U2FeatureLocation &location, U2OpStatus &os); 106 /** 107 * Updates feature type 108 * Requires: U2DbiFeature_WriteFeature feature support 109 */ 110 void updateType(const U2DataId &featureId, U2FeatureType newType, U2OpStatus &os); 111 /** 112 * Updates feature name 113 * Requires: U2DbiFeature_WriteFeature feature support 114 */ 115 void updateName(const U2DataId &featureId, const QString &newName, U2OpStatus &os); 116 /** 117 * Updates feature parent 118 * Requires: U2DbiFeature_WriteFeature feature support 119 */ 120 void updateParentId(const U2DataId &featureId, const U2DataId &parentId, U2OpStatus &os); 121 /** 122 * Updates feature sequence 123 * Requires: U2DbiFeature_WriteFeature feature support 124 */ 125 void updateSequenceId(const U2DataId &featureId, const U2DataId &seqId, U2OpStatus &os); 126 /** 127 * Removes the feature from database 128 * Requires: U2DbiFeature_WriteFeature feature support 129 */ 130 void removeFeature(const U2DataId &featureId, U2OpStatus &os); 131 /** 132 * Removes subfeatures along with their parent feature from database 133 * Requires: U2DbiFeature_WriteFeature feature support 134 */ 135 void removeFeaturesByParent(const U2DataId &parentId, U2OpStatus &os, SubfeatureSelectionMode mode); 136 /** 137 * Removes subfeatures along with their parent features from database 138 * Requires: U2DbiFeature_WriteFeature feature support 139 */ 140 void removeFeaturesByParents(const QList<U2DataId> &parentIds, U2OpStatus &os); 141 /** 142 * Removes subfeatures along with their root feature from database 143 * Requires: U2DbiFeature_WriteFeature feature support 144 */ 145 void removeFeaturesByRoot(const U2DataId &rootId, U2OpStatus &os, SubfeatureSelectionMode mode); 146 /** 147 * Returns features that matched the query. Returns NULL if error occurs 148 */ 149 U2DbiIterator<U2Feature> *getFeaturesByRegion(const U2Region ®, const U2DataId &rootId, const QString &featureName, const U2DataId &seqId, U2OpStatus &os, bool contains); 150 151 U2DbiIterator<U2Feature> *getFeaturesByParent(const U2DataId &parentId, const QString &featureName, const U2DataId &seqId, U2OpStatus &os, SubfeatureSelectionMode includeParent); 152 153 U2DbiIterator<U2Feature> *getFeaturesByRoot(const U2DataId &rootId, const FeatureFlags &types, U2OpStatus &os); 154 155 U2DbiIterator<U2Feature> *getFeaturesBySequence(const QString &featureName, const U2DataId &seqId, U2OpStatus &os); 156 157 U2DbiIterator<U2Feature> *getFeaturesByName(const U2DataId &rootId, const QString &name, const FeatureFlags &types, U2OpStatus &os); 158 159 QMap<U2DataId, QStringList> getAnnotationTablesByFeatureKey(const QStringList &values, U2OpStatus &os); 160 161 private: 162 QSharedPointer<SQLiteQuery> createFeatureQuery(const QString &selectPart, const FeatureQuery &fq, bool useOrder, U2OpStatus &os, SQLiteTransaction *trans = nullptr); 163 }; 164 165 } // namespace U2 166 167 #endif 168