Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Fix and improve documentation #12

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,13 @@ Finally, you instantiate a `RuleUnitInstance` using `RuleUnitProvider` to execut
public void test() {
MeasurementUnit measurementUnit = new MeasurementUnit();

RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
...

List<Measurement> queryResult = instance.executeQuery("FindColor").stream().map(tuple -> (Measurement) tuple.get("$m")).collect(toList());
...

} finally {
instance.dispose();
}
} // instance.close() is called automatically
}
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,12 @@ Using Rule Unit APIs, the resulting Java snippet would be like this:
[source,java]
----
MeasurementUnit measurementUnit = new MeasurementUnit();
RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
measurementUnit.getMeasurements().add(new Measurement("color", "green"));

instance.fire();
} finally {
instance.dispose();
}
} // instance.close() is called automatically
----

In Rule Unit, instantiate `RuleUnitInstance` instead of `KieSession`. Add facts to `DataSource` property instead of `insert`. Generic KIE API calls (e.g. `KieServices`, `KieContainer`, `KieBase` ... ) are no longer needed. Instead, one more class `Unit` has to be defined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public void test() {
LOG.info("Creating RuleUnit");
MeasurementUnit measurementUnit = new MeasurementUnit();

RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
LOG.info("Insert data");
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
measurementUnit.getMeasurements().add(new Measurement("color", "green"));
Expand All @@ -74,8 +73,6 @@ public void test() {
assertTrue("contains red", measurementUnit.getControlSet().contains("red"));
assertTrue("contains green", measurementUnit.getControlSet().contains("green"));
assertTrue("contains blue", measurementUnit.getControlSet().contains("blue"));
} finally {
instance.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void test() {
LOG.info("Creating RuleUnit");
MeasurementUnit measurementUnit = new MeasurementUnit();

RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
LOG.info("Insert data");
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
measurementUnit.getMeasurements().add(new Measurement("color", "green"));
Expand All @@ -54,8 +53,6 @@ public void test() {
assertTrue("contains red", measurementUnit.getControlSet().contains("red"));
assertTrue("contains green", measurementUnit.getControlSet().contains("green"));
assertTrue("contains blue", measurementUnit.getControlSet().contains("blue"));
} finally {
instance.close();
}
}
}
Loading