ThePrez / DotEnv-Java-IBMi

A `.env` implementation with convenience functions for IBM i
Apache License 2.0
5 stars 1 forks source link

DotEnv-Java-IBMi

A .env implementation with convenience functions for IBM i

This is a thin wrapper around the well-designed dotenv-java project.

The objectives of this library are:

Installation

Maven Users

add the following to your pom.xml file (substitute version number to the latest available):

<dependency>
    <groupId>io.github.theprez</groupId>
    <artifactId>dotenv-java-ibmi</artifactId>
    <version>0.0.2</version>
</dependency>

Non-Maven Users

Download the -with-dependencies.jar file from Maven Central and add to your classpath.

Usage

Access of .env data is done through use of the Dotenv object. The Dotenv class is provided by the underlying implementation, but, but instances should be acquired through the IBMiDotEnv.getDotEnv() helper function for consistent behavior with the IBM i helper functions in this library.

IBMiDotEnv.getDotEnv();

This assumes a .env file exists in your current working directory. The .env file is in the common KEY=VALUE format. Note: values can also be specified in environment variables.

Getting new IBM i connections through this library

Currently, this library provides two convenience functions:

The above convenience functions are implemented assuming the following values in your .env file:

These functions take a single parameter (_starCurrentIfPossible). When this parameter is set to true, the API will return an AS400 object with the username and password set to *CURRENT if:

Example

// Function to get a JDBC Connection object
private Connection getConnection() throws SQLException, IOException, AS400SecurityException {
    final AS400 as400 = IBMiDotEnv.getCachedSystemConnection(true);
    AS400JDBCDataSource ds = new AS400JDBCDataSource(as400);
    return ds.getConnection();
}