...
See Containers and Resources for a complete list of supported DataSource properties. See DataSource Password Encryption for information on specifying non-plain-text database passwords in your openejb.xml file. See Common DataSource Configurations for a list of the commonly used databases and their driver configurations.
You may also need data partitioning per customer or depending on any other business criteria. That's also an available feature. See Dynamic Datasource for more details.
JNDI names for configured DataSources
...
There are several possible ways to refer to it, as follows.
Injected Name Match
The BY matching variable name actually matches the configured name of the resource.to resource name
Code Block | ||||
---|---|---|---|---|
| ||||
@Stateless public class FooBean { @Resource DataSource myDerbyDatabase; } |
Name Attribute Match
The name attribute of the @Resource annotation matches the configured name of the resource.OR BY matching name
Code Block | ||||
---|---|---|---|---|
| ||||
@Stateless public class FooBean { @Resource(name="myDerbyDatabase") DataSource dataSource; } |
OR BY JNDI
...
lookup
We inject the resource into the JNDI environment using the name attribute of the @Resource to match the configured name of the resource.
Code Block | ||||
---|---|---|---|---|
| ||||
@Resource(name="myDerbyDatabase", type="javax.sql.DataSource".class) @Stateless public class FooBean { public void setSessionContext(SessionContext sessionContext) { DataSource dataSource = (DataSource) sessionContext.lookup("myDerbyDatabase"); } public void someOtherMethod() throws Exception { InitialContext initialContext = new InitialContext(); DataSource dataSource = (DataSource) initialContext.lookup("java:comp/env/myDerbyDatabase"); } } |
...