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_ATTR_DBI_H_
23 #define _U2_ATTR_DBI_H_
24 
25 #include <U2Core/U2Attribute.h>
26 #include <U2Core/U2Dbi.h>
27 #include <U2Core/U2Type.h>
28 
29 namespace U2 {
30 
31 /**
32     A configuration for sorting by attribute operation
33 */
34 class U2DbiSortConfig {
35 public:
U2DbiSortConfig()36     U2DbiSortConfig()
37         : ascending(true) {
38     }
39 
40     /** Sort column*/
41     QString sortColumnName;
42 
43     /** Type of the sort column: Integer, Real or String attribute type*/
44     U2DataType columnType;
45 
46     /** Tells  if sorting is ascending or descending */
47     bool ascending;
48 
49     /** Folder to localize sorting. If empty all folders are processed  */
50     QString folder;
51 };
52 
53 /**
54     An interface to obtain access to object attributes
55 */
56 class U2AttributeDbi : public U2ChildDbi {
57 protected:
U2AttributeDbi(U2Dbi * rootDbi)58     U2AttributeDbi(U2Dbi *rootDbi)
59         : U2ChildDbi(rootDbi) {
60     }
61 
62 public:
63     /** Returns all attribute names available in the database */
64     virtual QStringList getAvailableAttributeNames(U2OpStatus &os) = 0;
65 
66     /**
67         Returns ids of all attributes with a name 'attributeName' for the object referenced by 'objectId'.
68         If 'attributeName' is empty returns all object attributes.
69     */
70     virtual QList<U2DataId> getObjectAttributes(const U2DataId &objectId, const QString &attributeName, U2OpStatus &os) = 0;
71 
72     /**
73         Returns ids of all attributes with a childId 'childId' and a name 'attributeName'
74         for the object referenced by 'objectId'.
75         If 'attributeName' is empty returns ids of all object attributes with a specified childId.
76     */
77     virtual QList<U2DataId> getObjectPairAttributes(const U2DataId &objectId, const U2DataId &childId, const QString &attributeName, U2OpStatus &os) = 0;
78 
79     /**
80         Loads integer attribute by id.
81         If there is no integer attribute with the specified id returns
82     */
83     virtual U2IntegerAttribute getIntegerAttribute(const U2DataId &attributeId, U2OpStatus &os) = 0;
84 
85     /** Loads real attribute by id */
86     virtual U2RealAttribute getRealAttribute(const U2DataId &attributeId, U2OpStatus &os) = 0;
87 
88     /** Loads String attribute by id */
89     virtual U2StringAttribute getStringAttribute(const U2DataId &attributeId, U2OpStatus &os) = 0;
90 
91     /** Loads byte attribute by id */
92     virtual U2ByteArrayAttribute getByteArrayAttribute(const U2DataId &attributeId, U2OpStatus &os) = 0;
93 
94     /** Sorts all objects in database according to U2DbiSortConfig provided
95         Requires U2DbiFeature_AttributeSorting support
96     */
97     virtual QList<U2DataId> sort(const U2DbiSortConfig &sc, qint64 offset, qint64 count, U2OpStatus &os) = 0;
98 
99     /**
100         Removes attributes from database
101         Requires U2DbiFeature_WriteAttribute feature support
102     */
103     virtual void removeAttributes(const QList<U2DataId> &attributeIds, U2OpStatus &os) = 0;
104 
105     /**
106         Removes all attributes associated with the object
107         Requires U2DbiFeature_WriteAttribute feature support
108     */
109     virtual void removeObjectAttributes(const U2DataId &objectId, U2OpStatus &os) = 0;
110 
111     /**
112         Creates int64 attribute in database. ObjectId must be already set in attribute and present in the same database
113         Requires U2DbiFeature_WriteAttribute feature support
114 
115         NOTE: When you create a new attribute, do not forget to add it to the clone method of the corresponding object!
116     */
117     virtual void createIntegerAttribute(U2IntegerAttribute &a, U2OpStatus &os) = 0;
118 
119     /**
120         Creates real64 attribute in database. ObjectId must be already set in attribute and present in the same database
121         Requires U2DbiFeature_WriteAttribute feature support
122 
123         NOTE: When you create a new attribute, do not forget to add it to the clone method of the corresponding object!
124     */
125     virtual void createRealAttribute(U2RealAttribute &a, U2OpStatus &os) = 0;
126 
127     /**
128         Creates String attribute in database. ObjectId must be already set in attribute and present in the same database
129         Requires U2DbiFeature_WriteAttribute feature support
130 
131         NOTE: When you create a new attribute, do not forget to add it to the clone method of the corresponding object!
132     */
133     virtual void createStringAttribute(U2StringAttribute &a, U2OpStatus &os) = 0;
134 
135     /**
136         Creates Byte attribute in database. ObjectId must be already set in attribute and present in the same database
137         Requires U2DbiFeature_WriteAttribute feature support
138 
139         NOTE: When you create a new attribute, do not forget to add it to the clone method of the corresponding object!
140     */
141     virtual void createByteArrayAttribute(U2ByteArrayAttribute &a, U2OpStatus &os) = 0;
142 };
143 
144 }  // namespace U2
145 
146 #endif
147