You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.1 KiB
C++
103 lines
3.1 KiB
C++
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
/*
|
|
* File: ConnectionPool.h
|
|
* Author: shjd
|
|
*
|
|
* Created on 2018年3月30日, 上午10:09
|
|
*/
|
|
|
|
#ifndef CONNECTIONPOOL_H
|
|
#define CONNECTIONPOOL_H
|
|
#include <QtSql>
|
|
#include <QQueue>
|
|
#include <QString>
|
|
#include <QMutex>
|
|
#include <QMutexLocker>
|
|
#include <QSettings>//配置文件
|
|
|
|
class ConnectionPool {
|
|
public:
|
|
static void release(); // 关闭所有的数据库连接
|
|
static QSqlDatabase openConnection(); // 获取数据库连接
|
|
static void closeConnection(QSqlDatabase connection); // 释放数据库连接回连接池
|
|
static QString getlfp(); //获取本地文件路径
|
|
static QString getrfp(); //获取远端文件路径
|
|
static QString getcomtradftpip();
|
|
static QString getcomtradftpuid();
|
|
static QString getcomtradftppsw();
|
|
static QString getcomtradfilepath();
|
|
static int getcomtradftpport();
|
|
static int gettempmeasureinterval();
|
|
static int getsf6interval();
|
|
static int getpdinterval();
|
|
static int getmicroweatherinterval();
|
|
static int getironcoreinterval();
|
|
static int getmoainterval();
|
|
static int getyspinterval();
|
|
static int getyspinterval1();
|
|
static int getyspinterval2();
|
|
static int getjyinterval();
|
|
static int getscurinterval();
|
|
static int getdlginterval();
|
|
static int getjdwinterval();
|
|
~ConnectionPool();
|
|
private:
|
|
static ConnectionPool& getInstance();
|
|
|
|
ConnectionPool();
|
|
ConnectionPool(const ConnectionPool &other);
|
|
ConnectionPool& operator=(const ConnectionPool &other);
|
|
QSqlDatabase createConnection(const QString &connectionName); // 创建数据库连接
|
|
|
|
QQueue<QString> usedConnectionNames; // 已使用的数据库连接名
|
|
QQueue<QString> unusedConnectionNames; // 未使用的数据库连接名
|
|
|
|
// 配置信息
|
|
QString hostName;
|
|
QString databaseName;
|
|
QString username;
|
|
QString password;
|
|
QString databaseType;
|
|
int port;
|
|
QString localfilepath;
|
|
QString remotefilepath;
|
|
QString comtradftpip;
|
|
QString comtradftpuid;
|
|
QString comtradftppsw;
|
|
QString comtradfilepath;
|
|
int comtradftpport;
|
|
int tempmeasureinterval;
|
|
int sf6interval;
|
|
int pdinterval;
|
|
int microweatherinterval;
|
|
int ironcoreinterval;
|
|
int moainterval;
|
|
int yspinterval;
|
|
int yspinterval1;//油色谱(无载气)
|
|
int yspinterval2;//油色谱(混合气体)
|
|
int jyinterval;
|
|
int scurinterval;
|
|
int dlginterval;//电缆沟
|
|
int jdwinterval;//接地網
|
|
|
|
bool testOnBorrow; // 取得连接的时候验证连接是否有效
|
|
QString testOnBorrowSql; // 测试访问数据库的 SQL
|
|
|
|
int maxWaitTime; // 获取连接最大等待时间
|
|
int waitInterval; // 尝试获取连接时等待间隔时间
|
|
int maxConnectionCount; // 最大连接数
|
|
|
|
static QMutex mutex;
|
|
static QWaitCondition waitConnection;
|
|
static ConnectionPool *instance;
|
|
|
|
};
|
|
|
|
#endif /* CONNECTIONPOOL_H */
|
|
|