(Available since v1.1)
The @DBAware class-level and package-level annotation tells other db-aware annotations how to get a database connection in order to do their job. @DBAware is a bind-time annotation, and as such, all the work it does is carried out when the class shell is created, and not during validation or assignment time.
Javadoc Ref :
@DBAware
Input Types 1 |
N/A (bind-time annotation) |
Output Types |
N/A (bind-time annotation) |
Only one of the arguments may be assigned at any time:
jndiDataSource |
Specifies the JNDI name of a DataSource to use |
jndiEntityManager |
Specifies the JNDI name of an EntityManager to use |
jndiEntityManagerFactory |
Specifies the JNDI name of an EntityManagerFactory to use |
jdbcConnectionString |
Specifies a JDBC connection string to use to manually connect to the database |
providerFieldName |
Specifies the name of a field from which the database interaction object can be read. The field type can be either Connection, DataSource, EntityManager o EntityManagerFactory. Depending on the type,the appropriate mechanism will be used. |
@DBAware( jndiDataSource="java:comp/env/jdbc/MySQLDS" )
public class Customer {
.. // uses db-aware annotations
}
It's usually useful to have a single @DBAware annotation at package level (placed in a package-info.java file in the same package), since generally an application has the same connection settings across classes:
@com.planetalia.dynject.validation.dbaware.DBAWare( jndiDataSource = "...")
package com.foo.mypackage;