Annotation Type DataSourceDefinition


@Target(TYPE) @Retention(RUNTIME) @Repeatable(DataSourceDefinitions.class) public @interface DataSourceDefinition
Defines a data source for dependency injection via the Resource annotation. This annotation allows developers to declaratively specify the properties of a JDBC data source, including connection details, pool sizing, and transactional behavior. The container creates and manages the data source based on the specified configuration, making it available for injection into application components.
Since:
Common Annotations 1.1
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Specifies the fully qualified class name of the JDBC driver or the Jakarta Connector connection factory class that implements this data source.
    Specifies the JNDI name under which the data source will be registered.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specifies the name of the database to connect to.
    Provides a human-readable description of the data source for documentation and administrative purposes.
    int
    Specifies the number of connections to create when the connection pool is initialized.
    int
    Specifies the transaction isolation level for connections from this data source, using the constants defined in Connection.
    int
    Specifies the maximum time in seconds that the driver will wait when attempting to connect to the database.
    int
    Specifies the maximum idle time in seconds before a connection is closed and removed from the pool.
    int
    Specifies the maximum number of connections that the pool may create.
    int
    Specifies the maximum number of prepared statements that may be cached per connection in the pool.
    int
    Specifies the minimum number of connections that the pool must maintain.
    Specifies the password for the database user account used to establish connections.
    int
    Specifies the network port number on which the database server is listening.
    Specifies additional connection properties in the form "name=value" strings.
    Specifies the host name or IP address of the database server.
    boolean
    Indicates whether connections from this data source support container-managed transactions.
    Specifies the JDBC connection URL for the database.
    Specifies the database user name used to establish connections.
  • Element Details

    • className

      String className
      Specifies the fully qualified class name of the JDBC driver or the Jakarta Connector connection factory class that implements this data source.
      Returns:
      the fully qualified class name of the data source implementation
    • name

      String name
      Specifies the JNDI name under which the data source will be registered. This is the lookup name used for dependency injection or explicit JNDI lookup of the data source.
      Returns:
      the JNDI name for the data source
    • description

      String description
      Provides a human-readable description of the data source for documentation and administrative purposes.
      Returns:
      the description of the data source
      Default:
      ""
    • url

      String url
      Specifies the JDBC connection URL for the database. This URL is used by the driver to establish connections to the database server.
      Returns:
      the JDBC connection URL
      Default:
      ""
    • user

      String user
      Specifies the database user name used to establish connections.
      Returns:
      the database user name
      Default:
      ""
    • password

      String password
      Specifies the password for the database user account used to establish connections.
      Returns:
      the database password
      Default:
      ""
    • databaseName

      String databaseName
      Specifies the name of the database to connect to. This is used in conjunction with the server name and port number to locate the target database.
      Returns:
      the database name
      Default:
      ""
    • portNumber

      int portNumber
      Specifies the network port number on which the database server is listening. A value of -1 indicates the default port for the database type.
      Returns:
      the database server port number, or -1 for the default
      Default:
      -1
    • serverName

      String serverName
      Specifies the host name or IP address of the database server.
      Returns:
      the database server host name, defaulting to "localhost"
      Default:
      "localhost"
    • isolationLevel

      int isolationLevel
      Specifies the transaction isolation level for connections from this data source, using the constants defined in Connection. A value of -1 indicates the database default isolation level should be used.
      Returns:
      the transaction isolation level, or -1 for the database default
      Default:
      -1
    • transactional

      boolean transactional
      Indicates whether connections from this data source support container-managed transactions. When true, the data source participates in Jakarta Transactions.
      Returns:
      true if the data source participates in container-managed transactions
      Default:
      true
    • initialPoolSize

      int initialPoolSize
      Specifies the number of connections to create when the connection pool is initialized. A value of -1 indicates the container default should be used.
      Returns:
      the initial number of connections in the pool, or -1 for default
      Default:
      -1
    • maxPoolSize

      int maxPoolSize
      Specifies the maximum number of connections that the pool may create. A value of -1 indicates the container default should be used.
      Returns:
      the maximum pool size, or -1 for the container default
      Default:
      -1
    • minPoolSize

      int minPoolSize
      Specifies the minimum number of connections that the pool must maintain. A value of -1 indicates the container default should be used.
      Returns:
      the minimum pool size, or -1 for the container default
      Default:
      -1
    • maxIdleTime

      int maxIdleTime
      Specifies the maximum idle time in seconds before a connection is closed and removed from the pool. A value of -1 indicates no idle timeout.
      Returns:
      the maximum idle time in seconds, or -1 for no timeout
      Default:
      -1
    • maxStatements

      int maxStatements
      Specifies the maximum number of prepared statements that may be cached per connection in the pool. A value of -1 indicates the container default.
      Returns:
      the maximum cached prepared statements per connection, or -1 for default
      Default:
      -1
    • properties

      String[] properties
      Specifies additional connection properties in the form "name=value" strings. These properties are passed to the JDBC driver during connection establishment.
      Returns:
      the array of additional connection properties
      Default:
      {}
    • loginTimeout

      int loginTimeout
      Specifies the maximum time in seconds that the driver will wait when attempting to connect to the database. A value of 0 means no timeout.
      Returns:
      the login timeout in seconds, or 0 for no timeout
      Default:
      0