-
Notifications
You must be signed in to change notification settings - Fork 0
Docs Database Configuration
To configure the database connection pool you can use the config/rdbms.ini file:
[default] dsn="mysql:host=localhost;dbname=example" username="root" password="foo" initialQuery="set names utf8" connectionClassName="net::stubbles::rdbms::pdo::stubDatabasePDOConnection"
The section name is the name to be used for the @Named annotation to get such a database connection injected. While dsn, username and password should be self explanatory the initialQuery setting can be used to configure the connection to fire this as first query against the database, in this example to tell the database it should return all data in UTF-8.
The connectionClassName property tells which specific connection implementation should be used. This might be useful for cases where you do not want to use the PDO based implementation provided by Stubbles.
Of all those properties only the dsn property is required, all other are optional. However, your database connection might require a user and a password, even if both are not mandatory in the config file.
Please note: this type of configuration is deprecated since Stubbles 1.1.0 and support for it was removed with Stubbles 1.2.0.
To configure the database connection pool you can use the net::stubbles::rdbms::stubDatabaseXJConfInitializer. It reads a configuration file from config/xml/rdbms.xml.
This is how a fully configured file may look like:
#xml
<?xml version="1.0" encoding="iso-8859-1"?>
<xj:configuration
xmlns:xj="http://xjconf.net/XJConf"
xmlns="http://stubbles.net/rdbms">
<connections>
<connection id="__default">
<connectionClassName>net::stubbles::rdbms::pdo::stubDatabasePDOConnection</connectionclassname>
<dsn>mysql:host=localhost;dbname=test</dsn>
<userName>bar</username>
<password>baz</password>
<driverOptions>
<driverOption name="foo">bar</driveroption>
<driverOption name="bar">baz</driveroption>
</driveroptions>
</connection>
<connection id="foo">
[...]
</connection>
[... more connections ...]
</connections>
</xj:configuration>
The database pool can hold several connections which are distinguished by their id. If you omit the id it will be __default. If you have several connection configurations with the same id only the last one is used.
The connectionClassName states which class should be used to establish the connection. If omitted, it defaults to net::stubbles::rdbms::pdo::stubDatabasePDOConnection. If an application has its own connection class and this implements the net::stubbles::rdbms::stubDatabaseConnection interface this may be used as well. (See description of connection.)
The dsn, userName and password fields are required. The dsn should look like mysql:host=localhost;dbname=test. However the dsn may look different if another database connection class is used, you should refer to its documentation.
The driverOptions are optional and store driver specific data which can be used by the connection instance.
This is an example for the smallest possible configuration:
#xml
<?xml version="1.0" encoding="iso-8859-1"?>
<xj:configuration
xmlns:xj="http://xjconf.net/XJConf"
xmlns="http://stubbles.net/rdbms">
<connections>
<connection id="__default">
<dsn>mysql:host=localhost;dbname=test</dsn>
<userName>bar</username>
<password>baz</password>
</connection>
</connections>
</xj:configuration>