Close
Tutorials    
Snapshot   
Basic usage

Getting parameter value

In our first example we will get value of a demo.motor.coverage.position parameter for given coverage code. The definition of the parameter is as follows:

The parameter has two columns. One IN (code) and one OUT (position). For each IN value there is a corresponding OUT value, e.g. COMP -> 7.

To get value from Hyperon engine simply inject Hyperon Engine (part of Hyperon Runtime Library) into your Spring Component/Service:

@Autowired
private HyperonEngine engine;

prepare a context:

HyperonContext ctx = new HyperonContext(
    "coverage.code", "COLL"
);

and execute get method:

ParamValue pv = engine.get("demo.motor.coverage.position", ctx);

The result of the get method is an object of ParamValue class. This class provides convenient accessor methods for individual data types, e.g. getString, getBigDecimal, getDate, getDateTime, getLocalDate, getLocalDateTime, getInteger, getBoolean. The argument for these accessor methods is OUT column code that we are interested in getting.

Integer position = pv.getInteger("position");
LocalDate date = pv.getLocalDate("dateAdded");

Explore more options with examples on GitHub.

While getting parameter value we do not pass input values for each IN column, e.g. for code column. That is responsibility of a context which acts as source of input values for parameters and functions. In our example context provides value for code column. Columns are matched via value source property.

To design robust contexts read carefully Context concept and Implementing execution context.

In the next example let's see how we can handle situation where we expect engine get call to return more than one row. The definition of the parameter is as follows:

prepare a context:

HyperonContext ctx = new HyperonContext(
    "quote.vehicle.productionYear", "1972"
);

and execute get method:

ParamValue matrix = hyperonEngine.get("demo.motor.dict.vehicle.availableMakes", ctx);

Now we can simply iterate over returned matrix:

for (MultiValue row : matrix) {
	String make = matrix.getString("make");
	Integer makeId = matrix.getInteger("make_id");
}

Parameter definition and matrix is loaded from database only once. Subsequent calls to the get method will use cached values. For large parameters' matrices and production environments prefetching can be setup to load parameters into memory while starting-up the application.

More tutorials

Basic usage