Connection Pool is a convenient way to deal with JDBC connections and provide nice and efficient performance to the application at all. ViburDBCP is an impressively fast and lightweight Database Connection Pool which Kikaha's Database module provides tight integration with. Include kikaha-db
module on your project in order to have this feature enabled.
<dependency>
<groupId>io.skullabs.kikaha</groupId>
<artifactId>kikaha-db</artifactId>
</dependency>
All DataSource configurations are made through the server.db.datasources
entry point at the application.conf
. Note that, on 2.0.x and earlier versions this configuration were available at server.datasources
.
server:
db:
datasources:
default:
log-query-execution-longer-than-ms: 20
log-stacktrace-for-long-query-execution: false
default-auto-commit: true
jdbc-url: "jdbc:mysql://db.corp.com/test_db"
username: "username"
password: "p@5zw0rd"
production:
jdbc-url: "jdbc:mysql://db.corp.com/test_db"
username: "username"
password: "p@5zw0rd"
development:
jdbc-url: "jdbc:mysql://localhost/test_db"
username: "root"
password: ""
Above we have a sample DataSource configuration named production
, another one named development
, and a third one named default
. As you can see, both have the jdbc-url
, username
and password
attributes defined: they are required parameters. Any other parameter is optional as it uses Vibur's default values.
The code bellow makes use from the production
DataSource.
import kikaha.core.api.*;
import javax.inject.*;
import javax.sql.*;
@Singleton
public class EmployeeSearchService {
@Inject
@Named("production") // could be omitted if using the 'default' one.
DataSource db;
public void printAllEmployees()
{
try (Connection con = ds.getConnection())
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select empid, name from Employee");
while(rs.next()){
String msg = "Employee ID="+rs.getInt("empid")+", Name="+rs.getString("name");
System.out.println( msg );
}
}
}
}
You can notice that, in order to inject "production" DataSource, you should specify the source name through the @javax.inject.Named
annotation. You will have to use that annotation for every DataSource injection point, except when you intent to inject the default
DataSource - in this case, the @Named
annotation is optional.
Most of Viburs configuration was brought to the Kikaha Database module and are available to developers use. Bellow is a list of available parameters and its default values. For more informations, please refer to the Vibur's documentation.
WELCOME About Kikaha philosophy
GETTING STARTED Getting started in 1 minute Creating a Kikaha maven project Architecture overview
TUTORIALS Logging configuration Configuring the server Creating your first HTTP route Kikaha's command line interface Configuring your favorite IDE Wro4j Integration
CORE FEATURES HTTP and HTTPS Routing static assets Dependency injection Authentication and authorization Smart routes
ESSENTIAL MODULES μRouting API WebSocket Routing Database Connection Pool JSON with Jackson Protobuf Mustache Templates Rocker Templates BCrypt
CLOUD MODULES Overview of Cloud Modules Consul.io Codahale's Metrics Auth0 Single Sign-On μWorkers - Actor-like API Hazelcast
AWS-RELATED MODULES Overview of AWS-Related Modules Deploying Applications on AWS AWS IAM Credentials AWS EC2 AWS SQS queues AWS CloudWatch metrics AWS Application Load Balancer AWS Lambda functions AWS X-Ray
ADVANCED TOPICS Creating custom modules Routing with Undertow's API Creating custom cloud modules