DataSource to
be registered with JNDI. The DataSource may be configured by
setting the annotation elements for commonly used DataSource
properties. Additional standard and vendor-specific properties may be
specified using the properties element.
The data source will be registered under the name specified in the
name element. It may be defined to be in any valid
Jakarta EE namespace, which will determine the accessibility of
the data source from other components.
A JDBC driver implementation class of the appropriate type, either
DataSource, ConnectionPoolDataSource, or
XADataSource, must be indicated by the className
element. The availability of the driver class will be assumed at runtime.
DataSource properties should not be specified more than once. If the url annotation element contains a DataSource property that was also specified using the corresponding annotation element or was specified in the properties annotation element, the precedence order is undefined and implementation specific:
@DataSourceDefinition(name="java:global/MyApp/MyDataSource",
className="org.apache.derby.jdbc.ClientDataSource",
url="jdbc:derby://localhost:1527/myDB;user=bill",
user="lance",
password="secret",
databaseName="testDB",
serverName="luckydog"
)// DO NOT DO THIS!!!
In the above example, the databaseName, user
and serverName properties were specified as part of the
url property and using the corresponding
annotation elements. This should be avoided.
If the properties annotation element is used and contains a
DataSource property that was also specified using the corresponding
annotation element, the annotation element value takes precedence.
For example:
@DataSourceDefinition(name="java:global/MyApp/MyDataSource",
className="org.apache.derby.jdbc.ClientDataSource",
user="lance",
password="secret",
databaseName="testDB",
serverName="luckydog",
properties= {"databaseName=myDB", "databaseProp=doThis"}
)// DO NOT DO THIS!!!
This would result in the following values being used when configuring the DataSource:
Vendors are not required to support properties that do not normally
apply to a specific data source type. For example, specifying the
transactional property to be true but supplying
a value for className that implements a data source class
other than XADataSource may not be supported.
Vendor-specific properties may be combined with or used to override standard data source properties defined using this annotation.
DataSource properties that are specified and are not supported
in a given configuration or cannot be mapped to a vendor specific
configuration property may be ignored.
Examples:
@DataSourceDefinition(name="java:global/MyApp/MyDataSource",
className="com.foobar.MyDataSource",
portNumber=6689,
serverName="myserver.com",
user="lance",
password="secret"
)
Using a URL:
@DataSourceDefinition(name="java:global/MyApp/MyDataSource",
className="org.apache.derby.jdbc.ClientDataSource",
url="jdbc:derby://localhost:1527/myDB",
user="lance",
password="secret"
)
An example lookup of the DataSource from an Jakarta Enterprise Beans:
@Stateless
public class MyStatelessEJB {
@Resource(lookup="java:global/MyApp/myDataSource")
DataSource myDB;
...
}
javax.sql.DataSource, javax.sql.XADataSource, javax.sql.ConnectionPoolDataSource
| Modifier and Type | Method and Description |
|---|---|
| public String | className()
Name of a DataSource class that implements
|
| public String | |
| public String | |
| public int | initialPoolSize()
Number of connections that should be created when a connection pool is initialized. |
| public int | |
| public int | loginTimeout()
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. |
| public int | maxIdleTime()
The number of seconds that a physical connection should remain unused in the pool before the connection is closed for a connection pool. |
| public int | maxPoolSize()
Maximum number of connections that should be concurrently allocated for a connection pool. |
| public int | |
| public int | |
| public String | |
| public String | |
| public int | |
| public String[] | properties()
Used to specify vendor-specific properties and less commonly
used
|
| public String | |
| public boolean | |
| public String | |
| public String |
| className | back to summary |
|---|---|
| public String className() Name of a DataSource class that implements
| |
| databaseName | back to summary |
|---|---|
| public String databaseName() Name of a database on a server.
| |
| description | back to summary |
|---|---|
| public String description() Description of this data source
| |
| initialPoolSize | back to summary |
|---|---|
| public int initialPoolSize() Number of connections that should be created when a connection pool is initialized. Default is vendor-specific
| |
| isolationLevel | back to summary |
|---|---|
| public int isolationLevel() Isolation level for connections. The Isolation level must be one of the following:
Default is vendor-specific.
| |
| loginTimeout | back to summary |
|---|---|
| public int loginTimeout() Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. Default is vendor-specific.
| |
| maxIdleTime | back to summary |
|---|---|
| public int maxIdleTime() The number of seconds that a physical connection should remain unused in the pool before the connection is closed for a connection pool. Default is vendor-specific
| |
| maxPoolSize | back to summary |
|---|---|
| public int maxPoolSize() Maximum number of connections that should be concurrently allocated for a connection pool. Default is vendor-specific.
| |
| maxStatements | back to summary |
|---|---|
| public int maxStatements() The total number of statements that a connection pool should keep open. A value of 0 indicates that the caching of statements is disabled for a connection pool. Default is vendor-specific
| |
| minPoolSize | back to summary |
|---|---|
| public int minPoolSize() Minimum number of connections that should be allocated for a connection pool. Default is vendor-specific.
| |
| name | back to summary |
|---|---|
| public String name() JNDI name by which the data source will be registered.
| |
| password | back to summary |
|---|---|
| public String password() Password to use for connection authentication.
| |
| portNumber | back to summary |
|---|---|
| public int portNumber() Port number where a server is listening for requests.
| |
| properties | back to summary |
|---|---|
| public String[] properties() Used to specify vendor-specific properties and less commonly
used
Properties are specified using the format: propertyName=propertyValue with one property per array element.
If a DataSource property is specified in the
| |
| serverName | back to summary |
|---|---|
| public String serverName() Database server name.
| |
| transactional | back to summary |
|---|---|
| public boolean transactional() Set to Default is to enlist in a transaction when one is active or becomes active.
| |
| url | back to summary |
|---|---|
| public String url() A JDBC URL. If the
| |
| user | back to summary |
|---|---|
| public String user() User name to use for connection authentication.
| |