2
* UGENE - Integrated Bioinformatics Tools.
3
* Copyright (C) 2008-2011 UniPro <ugene@unipro.ru>
4
* http://ugene.unipro.ru
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.
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.
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,
22
#ifndef _U2_DBI_UTILS_H_
23
#define _U2_DBI_UTILS_H_
25
#include <U2Core/U2Dbi.h>
26
#include <U2Core/Task.h>
33
Helper class that allocates connection in constructor and automatically releases it in the destructor
34
It uses app-global connection pool.
36
Note: DbiHandle caches U2OpStatus and reuses it in destructor on DBI release. Ensure that
37
U2OpStatus live range contains DbiHandle live range
39
class U2CORE_EXPORT DbiHandle {
41
/** Opens connection to existing DBI */
42
DbiHandle(U2DbiFactoryId id, const QString& url, U2OpStatus& os);
44
/** Opens connection to existing DBI or create news DBI*/
45
DbiHandle(U2DbiFactoryId id, const QString& url, bool create, U2OpStatus& os);
47
DbiHandle(const DbiHandle & dbiHandle_);
54
DbiHandle & operator=(const DbiHandle & DbiHandle_);
59
Iterator over buffered data set
61
template<class T> class BufferedDbiIterator : public U2DbiIterator<T> {
63
BufferedDbiIterator(const QList<T>& _buffer, const T& _errValue = T()) : buffer(_buffer), pos(0), errValue(_errValue) {}
65
/** returns true if there are more reads to iterate*/
66
virtual bool hasNext() {
67
return pos < buffer.size();
70
/** returns next read and shifts one element*/
75
const T& res = buffer.at(pos);
80
/** returns next read without shifting*/
85
return buffer.at(pos);
96
class U2CORE_EXPORT U2DbiUtils : public QObject{
100
Logs that operation called is not supported by DBI
101
If U2OpStatus has no error set, sets the error message
103
static void logNotSupported(U2DbiFeature f, U2Dbi* dbi, U2OpStatus& os);
105
template<class T> static QList<T> toList(U2DbiIterator<T>* it);
109
template<class T> QList<T> U2DbiUtils::toList(U2DbiIterator<T>* it) {
111
while (it->hasNext()) {
112
result << it->next();