BPS C++ API  2.24.4
bpsdatastore.h
Go to the documentation of this file.
1 
4 #ifndef BPSDATASTORE_H
5 #define BPSDATASTORE_H
6 
7 #include "bpssettings.h"
8 #include "bpstypes.h"
9 #include <QObject>
10 #include <QSet>
11 #include <QStringList>
12 
13 class QSqlDatabase;
14 class QSqlRecord;
15 class QSqlIndex;
16 class BpsQuery;
17 
61 {
62  Q_OBJECT
64 
65 public:
66 
71  BpsDatastore(QObject* aParent = nullptr);
72 
73  virtual ~BpsDatastore();
74 
83 
90  void setConnection(const QString& aConnection);
91 
96  QString driver() const;
97 
103  void setDriver(const QString& aDriver);
104 
112  QString host() const;
113 
120  void setHost(const QString& aHost);
121 
127  int port() const;
128 
134  void setPort(int aPort);
135 
143  QString database() const;
144 
150  void setDatabase(const QString& aDatabase);
151 
156  QString schema() const;
157 
162  void setSchema(const QString& aSchema);
163 
168  QString username() const;
169 
175  void setUsername(const QString& aUsername);
176 
181  QString password() const;
182 
186  QString terminal() const;
187 
192 
198  void setPassword(const QString& aPassword);
199 
205  void connect();
206 
211  void disconnect();
212 
218  void transaction();
219 
223  bool inTransaction() const;
224 
232  bool lockTable(const QString& aTable, int aTimeout);
233 
238  void commit();
239 
244  void rollback();
245 
251  QVariant nextIdent(const QString& aSeqenceName);
252 
259  QVariant nextKey(const QString& aTableName);
260 
267  void purgeActors();
268 
273  void touchActor();
274 
284  bool isCheckedIn(const QString& aTerminalName = QString(), const QString& aApplicationName = QString(), bool aSingleTerminalSession = false);
285 
296  void checkin(const QString& aTerminalName = QString(), const QString& aApplicationName = QString(), bool aSingleTerminalSession = false);
297 
302  void checkout();
303 
310 
315  bool isConnected() const;
316 
321  bool isOracle() const;
322 
327  bool isPostgres() const;
328 
335  bool isOwner() const;
336 
341  bool isAdmin() const;
342 
347  bool isDBA() const;
348 
356  bool sequenceExists(const QString& aName, const QString& aSchema = QString());
357 
365  bool tableExists(const QString& aName, const QString& aSchema = QString());
366 
374  bool indexExists(const QString& aName, const QString& aSchema = QString());
375 
383  bool viewExists(const QString& aName, const QString& aSchema = QString());
384 
391 
398 
404  QSqlRecord* record(const QString& aTableName);
405 
411  QSqlIndex* primaryIndex(const QString& aTableName);
412 
419  int userid() const;
420 
426  QVariant userKey() const;
427 
434 
441 
448 
455 
462 
473  bool loadConnection(BpsSettings::Scopes aScopes = BpsSettings::LocalScopes);
474 
483  void saveConnection(BpsSettings::Scopes aScopes = BpsSettings::LocalUserScope);
484 
493  void dropConnection(BpsSettings::Scopes aScopes = BpsSettings::LocalUserScope);
494 
502  void renameConnection(const QString& aConnection, BpsSettings::Scopes aScopes = BpsSettings::LocalUserScope);
503 
510  bool hasPermission(const QString& aPermission);
511 
518  bool hasDivisionAccess(const QVariant& aDivisionKey);
519 
526  bool hasZoneAccess(const QVariant& aZoneKey);
527 
534  Bps::Access reportAccess(const QVariant& aReportKey);
535 
540 
545  QString fromDual() const;
546 
556  QString timestampValue(const QDateTime& aDateTime) const;
557 
596 
601 
606 
611 
615  QVariant setKeys(const QVariantList& aKeys);
616 
621  void clearKeys(const QVariant& aId);
622 
636  QString joinKeys(const QVariant& aId, const QString& aRef);
637 
671  QVariant makeKeytable(const QString& aKeyList);
672 
689  QString joinKeytable(const QVariant& aTableKey, const QString& aRef);
690 
695  void dropKeytable(const QVariant& aTableKey);
696 
725  void upsert(const QString& aTable, const QVariantMap& aKeyVals, const QVariantMap& aUpdVals);
726 
731  BpsTypeLiteral typeNextval(const QString& aSequence) const;
732 
739 
749 
756  static QString quote(const QString& aText);
757 
764  static QString quote(QChar aChar);
765 
766 signals:
767 
771  void connected();
772 
776  void disconnected();
777 
778 };
779 
780 #endif // BPSDATASTORE_H
#define BPSCORE_EXPORT
Declare class to be an import from the shared library.
Definition: bpscore_global.h:22
#define BPS_PRIVATE(Class)
Declare pointer to private object in a public class.
Definition: bpsglobals.h:102
Public include file for BpsSettings class.
BPS datastore class.
Definition: bpsdatastore.h:61
void setDriver(const QString &aDriver)
Set database driver name.
bool isOracle() const
Check if current driver is for Oracle.
Bps::Access reportAccess(const QVariant &aReportKey)
Check access to a certain report.
void commit()
Commit an open transaction.
void setDatabase(const QString &aDatabase)
Set database name.
bool tableExists(const QString &aName, const QString &aSchema=QString())
Check if a certain table exists.
static QStringList connections()
Get all defined connections.
void purgeActors()
Purge actors which are no longer connected.
void connect()
Connect to database server using the current settings in the properties username, password,...
void setSchema(const QString &aSchema)
Set BPS schema.
QVariant setKeys(const QSet< qlonglong > &aKeys)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QSqlRecord * record(const QString &aTableName)
Get the record info for a certain table.
QVariant userKey() const
Returns the user's key (c_key in the t_users table).
static QString quote(QChar aChar)
Quote a char in single quotes to include it in a sql statement.
QString indexTablespace()
Get the tablespace name used for indexes.
bool isDBA() const
Check if the current user has database administrator (Oracle) or superuser (PostgreSQL) privileges re...
void clearKeys(const QVariant &aId)
Delete a key list from table t_keys.
static QStringList tnsnames()
Get a list of all Oracle TNS names.
bool sequenceExists(const QString &aName, const QString &aSchema=QString())
Check if a certain sequence exists.
QDateTime currentTimestamp()
int userid() const
Returns the user id (the numeric bps user identification).
void dropConnection(BpsSettings::Scopes aScopes=BpsSettings::LocalUserScope)
Drop connection.
int port() const
Get host IP port number.
QString password() const
Get database user password.
bool indexExists(const QString &aName, const QString &aSchema=QString())
Check if a certain index exists.
void upsert(const QString &aTable, const QVariantMap &aKeyVals, const QVariantMap &aUpdVals)
Executes a upsert (insert/update) using MERGE on Oracle or INSERT...ON CONFLICT on PostgreSQL.
void transaction()
Start a new transaction.
QString username() const
Get database user name.
bool loadConnection(BpsSettings::Scopes aScopes=BpsSettings::LocalScopes)
Load connection settings.
BpsTypeLiteral typeNextval(const QString &aSequence) const
Get a BpsTypeLiteral representing the next sequence value for use with .
void disconnect()
Disconnect from database server if currently connected.
void saveConnection(BpsSettings::Scopes aScopes=BpsSettings::LocalUserScope)
Save the connection settings.
QVariant nextKey(const QString &aTableName)
Get the next unused key for a table.
bool hasPermission(const QString &aPermission)
Checks if the current user is authorized for the named permission.
QVariant setKeys(const QVariantList &aKeys)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isCheckedIn(const QString &aTerminalName=QString(), const QString &aApplicationName=QString(), bool aSingleTerminalSession=false)
Test if similar actor already checked in.
QString database() const
Get database name for PostgreSQL, or TNS service name or SID for Oracle.
QVariant actorKey() const
Return the actor's key (c_key in the t_actors table).
void setConnection(const QString &aConnection)
Set the connection name.
bool inTransaction() const
bool isPostgres() const
Check if current driver is for PostgreSQL.
void setPort(int aPort)
Set the servers database service IP port number.
void disconnected()
Signal is emitted after disconnection.
bool isAdmin() const
Check if the current user has sufficient database privileges to act as BPS user administrator.
QString joinKeys(const QVariant &aId, const QString &aRef)
Creates a inner join clause to join a given query to the list of keys in t_keys.
bool viewExists(const QString &aName, const QString &aSchema=QString())
Check if a certain view exists.
QVariant sessionId() const
Return the current actors session id (the database internal identifier of the current session).
QStringList tablespaces()
Get a list of all tablespaces.
QStringList users()
Get a list of all database user names.
bool isOwner() const
Check if the current user is the BPS owner.
void setPassword(const QString &aPassword)
Set database user password.
QString fromDual() const
Returns " from dual" for oracle, and an empty string otherwise.
void connected()
Signal is emitted after successful connection.
QString schema() const
Get BPS datastore schema name.
QString timestampValue(const QDateTime &aDateTime) const
Returns a column text representing a constant timestamp without time zone.
QVariant setKeys(const QList< qulonglong > &aKeys)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool lockTable(const QString &aTable, int aTimeout)
Start a transaction with the given table locked in exclusive mode.
QString host() const
Get host IP name or address.
QString terminal() const
bool hasDivisionAccess(const QVariant &aDivisionKey)
Checks if the current user is authorized for the division.
bool isConnected() const
Check current connection status.
QStringList roles()
Get a list of all roles.
void setHost(const QString &aHost)
Set DB server's host name or IP address.
QString tableTablespace()
Get the tablespace name used for tables.
QString connection() const
Get the connection name.
QSqlIndex * primaryIndex(const QString &aTableName)
Get the primary index for a certain table.
QString joinKeytable(const QVariant &aTableKey, const QString &aRef)
Creats a inner join clause to join a given query to the list of keys in the table.
static QString quote(const QString &aText)
Quote a literal text in single quotes to include it in a sql statement.
QVariant nextIdent(const QString &aSeqenceName)
Get the next sequence value.
QString application() const
BpsDatastore(QObject *aParent=nullptr)
Constructor for the BpsDatastore objects.
void checkin(const QString &aTerminalName=QString(), const QString &aApplicationName=QString(), bool aSingleTerminalSession=false)
Check in the user by creating a record in table t_actors.
void dropKeytable(const QVariant &aTableKey)
Drops a record from t_keytables.
QString driver() const
Get driver name.
bool hasZoneAccess(const QVariant &aZoneKey)
Checks if the current user is authorized for the zone.
QVariant setKeys(const QList< qlonglong > &aKeys)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void rollback()
Rollback an open transaction.
QVariant makeKeytable(const QString &aKeyList)
Creats a record in t_keytables from the given list of values.
QVariant setKeys(const QSet< qulonglong > &aKeys)
Insert a key list into table t_keys.
void setUsername(const QString &aUsername)
Set database user name.
void touchActor()
Update the actors timestamp.
QSqlDatabase & link()
Get QSqlDatabase object.
void checkout()
Check out the user by dropping the record in table t_actors.
void renameConnection(const QString &aConnection, BpsSettings::Scopes aScopes=BpsSettings::LocalUserScope)
Rename the connection.
Access
Simple access control.
Definition: bps.h:126
BPS query class.
Definition: bpsquery.h:23
@ LocalUserScope
Settings of the current operating system user on the local machine.
Definition: bpssettings.h:41
@ LocalScopes
All local scopes.
Definition: bpssettings.h:73
Dummy type representing a literal value for SQL operations.
Definition: bpstypes.h:70