This class represents a connection to the database server.
This is the abstract base class for Postgres (and any other database interface classes we implement). It's responsible for validating the database configuration, maintaining a pool of database handles, and accepting queries into a common queue via submit().
Adds d to the pool of active database connections.
Creates desired connections to the database.
Returns the address of the database server (db-address).
Cancels the given query if it is being executed by this database object. Does nothing otherwise.
This function issues a cancel request for the query q, if it is currently being executed. If not, it does nothing.
This function checks that the server doesn't have privileged access to the database. It notifies owner when the check is complete. A disaster is logged if the server is connected to the database as an unduly privileged user.
The function expects to be called from ::main() after Database::checkSchema().
This function is called by a database client to ensure that the schema is as they expect; for the moment all it does is to check that the revision matches the latest known. owner is notified when the check is completed.
Returns an nonzero positive integer which is unique to this database handler.
This static function returns the schema revision current at the time this server was compiled.
This extremely evil function shuts down all Database handles. It's used only by lib/installer to reconnect to the database. Once it's done, setup() may be called again with an appropriately altered configuration.
Don't try this at home, kids.
Removes a submitted transaction from the global list and returns a list contains just that transaction.
If transactionOK is true, the list is permitted to start a Transaction. If not, only standalone queries are considered.
Returns an empty list if no suitable queries can be found.
Returns the number of handles we think we need at this time. Mostly computed based on recent workload.
Returns true if all database handles are idle and there's no queued work for them. Returns false in all other cases.
Returns the number of completely idle handles at the moment.
This function returns DbOwner or DbUser, as specified in the call to Database::setup().
Returns the configured database name (db-name).
Instructs the database system to call h once as soon as the database system becomes completely idle (no queries queued or executing).
h is not executed right away, even if the database is currently idle, but rather the next time the database system becomes idle.
Returns the number of database handles currently connected to the database.
Returns the configured database password (db-password or db-owner-password).
Returns the database server port (db-port).
Instructs the Database object to send any queries whose state is Query::Submitted to the server.
This static function records the time at which a Database subclass issues a query to the database server. It is used to manage the creation of new database handles.
Removes d from the pool of active database connections.
This private function is used to make idle handles process the queue of queries, and is called by the two variants of submit().
Sets the state of this Database handle to s, which must be one of Connecting, Idle, InTransaction, FailedTransaction.
This function is provided as a convenience for the (majority of) callers that use the default values for desired (0) and login (Database::DbUser). It infers the correct username and password and forwards the call to setup() with the appropriate parameters.
This setup function reads and validates the database configuration to the best of its limited ability (since connection negotiation must be left to subclasses). It logs a disaster if it fails.
It creates desired database handles at startup and will log in as user with the password pass.
This function expects to be called from ::main().
Returns the current state of this Database object.
Adds the queries in the list q to the queue of submitted queries, and sets their state to Query::Submitted. The first available handle will process them (but it's not guaranteed that the same handle will process them all. Use a Transaction if you depend on ordering).
Adds q to the queue of submitted queries and sets its state to Query::Submitted. The first available handle will process it.
Returns the configured Database type, which may currently be only postgres.
Returns true if this Database handle is currently able to process queries, and false if it's busy processing queries, is shutting down, or for any other reason unwilling to process new queries. The default implementation always returns true; subclasses may override that behaviour.
Returns the database username used for this connection, as specified to (or inferred by) setup().
This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.