///////////////////////////////////////////////////////////////////////////////

    Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

///////////////////////////////////////////////////////////////////////////////

= CDI extension for HikariCP
:description: Helidon CDI extension for HikariCP
:keywords: helidon, java, microservices, microprofile, extensions, cdi, hikaricp
:hikaricp-project-url: http://brettwooldridge.github.io/HikariCP/
:hikaricp-datasource-api-url: https://static.javadoc.io/com.zaxxer/HikariCP/2.7.8/com/zaxxer/hikari/HikariDataSource.html
:hikaricp-props-url: https://github.com/brettwooldridge/HikariCP/blob/dev/README.md#configuration-knobs-baby
:cdi-extension-api-url: https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#spi
:cdi-applicationscoped-api-url: http://docs.jboss.org/cdi/api/2.0/javax/enterprise/context/ApplicationScoped.html

This link:{cdi-extension-api-url}[CDI portable extension] provides support for
 injecting link:{hikaricp-project-url}[HikariCP data sources] in your Helidon
 MicroProfile applications.

== Prerequisites

Declare the following dependency in your project:

[source,xml]
----
<dependency>
    <groupId>io.helidon.integrations.cdi</groupId>
    <artifactId>helidon-integrations-cdi-datasource-hikaricp</artifactId>
</dependency>
----

== Injecting a HikariCP data source

The following examples show how to create a `DataSource` named `orders` in your
 application.

[source,java]
.Field-injection example
----
 @Inject
 @Named("orders")
 private DataSource ordersDataSource;
----

[source,java]
.Constructor-injection example
----
 private final DataSource ds;
 @Inject
 public YourConstructor(@Named("orders") DataSource ds) {
   super();
   this.ds = ds;
 }
----

The extension implements this injection point by creating a
 link:{hikaricp-datasource-api-url}[HikariDataSource] object in the
 link:{cdi-applicationscoped-api-url}[application scope].

You can configure the object using
 <<microprofile/02_server-configuration.adoc, MicroProfile config>>. For example,
 the data source created above can be configured as follows:

[source, properties]
.META-INF/microprofile-config.properties
----
javax.sql.DataSource.orders.dataSourceClassName=oracle.jdbc.pool.OracleDataSource
javax.sql.DataSource.orders.dataSource.url = jdbc:oracle:thin:@localhost:1521:ORCL
javax.sql.DataSource.orders.dataSource.user = sys as sysoper
javax.sql.DataSource.orders.dataSource.password = Oracle
----

Property names that start with `javax.sql.DataSource.dataSourceName.` are parsed,
 and the remaining portion of each name is treated as a
 link:{hikaricp-props-url}[Hikari connection pool property].
