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:
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.
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.
Currently, this library provides two convenience functions:
getNewSystemConnection()
, which will return a new AS400
object. The object will not be cachedgetCachedSystemConnection()
, which will return a cached AS400
object if one is available. If
a cached object is not available, a new one will be constructed and cached. The above convenience functions are implemented assuming the following values in your .env
file:
IBMI_HOSTNAME
IBMI_USERNAME
IBMI_PASSWORD
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:
// 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();
}