recursive.codes


The Personal Blog of Todd Sharp

Oracle Universal Connection Pool (UCP) Support Added To Micronaut

Posted By: Todd Sharp on 4/28/2020 6:16 GMT
Tagged: Cloud, Java

The Micronaut framework includes several options for connection pooling since it launched and today there is a new option available for your microservice applications: Oracle Universal Connection Pool (UCP). In this post, I'd like to show you how to use this new feature in your application.

Add The Dependency

To get started, you must first include the dependency in your build.gradle file:

If you're using Maven:

Configure The Datasource

Next, you'll need to create a datasource in your application.yaml file. All of the properties from PoolDataSource are valid here and will be passed to the pool instance at runtime. For example:

Create The Service

You're now ready to add a service to query your datasource. If you're using Micronaut Data, you're all ready to go. Otherwise, you can create a service and inject the DataSource:

Add a method to get a connection from the pool, create and execute the query:

And a private helper to convert the ResultSet into a List of HashMap objects:

Add Controller Method

The only thing left to do is inject the UserService into our controller and add an endpoint to retrieve the users and return them:

Summary

In this post, we looked at how to utilize the new support for Oracle UCP in Micronaut. For further information, please check the docs or leave a question below!.

Photo by Humphrey Muleba on Unsplash



Related Posts

Building Cross Platform Native Images With GraalVM

Building Cross Platform Native Images With GraalVM

A few weeks ago, I blogged about a utility that I created that helps you debug your serverless functions in the Oracle Cloud. The code behind that project...

Cloud Cost Cutting: Autoscaling Your Dev/QA Environments

Cloud Cost Cutting: Autoscaling Your Dev/QA Environments

I've worked on many software projects over the last 16 years, and one thing that each of those projects had in common was the existence of an environment...

Simple Serverless Logging For Oracle Functions

Simple Serverless Logging For Oracle Functions

Working with serverless functions represents a new way of thinking for many developers. Dealing with stateless functions, for example, can be a challenge...

Note: Comments are currently closed on this blog. Disqus is simply too bloated to justify its use with the low volume of comments on this blog. Please visit my contact page if you have something to say!