[jboss-jira] [JBoss JIRA] (DROOLS-1021) Allow to retrieve the KieBase and KieSession models from the KieContainer
Mario Fusco (JIRA)
issues at jboss.org
Thu Jan 7 09:18:01 EST 2016
[ https://issues.jboss.org/browse/DROOLS-1021?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mario Fusco updated DROOLS-1021:
--------------------------------
Summary: Allow to retrieve the KieBase and KieSession models from the KieContainer (was: Add method on KieContainer to get the KieBase for an ksessionName (without instantiating the KieSession))
> Allow to retrieve the KieBase and KieSession models from the KieContainer
> -------------------------------------------------------------------------
>
> Key: DROOLS-1021
> URL: https://issues.jboss.org/browse/DROOLS-1021
> Project: Drools
> Issue Type: Enhancement
> Components: core engine
> Affects Versions: 6.3.0.Final
> Reporter: Geoffrey De Smet
> Assignee: Mario Fusco
>
> OptaPlanner is switching from using KieBase (with a drl classpath resource to retrieve the rules) to KContainer (with ksessionName to retrieve the rules), so it can function as part of a kjar.
> During bootstrap, it needs to check the rules if a specific Global is defined.
> Currently *it needs to instantiate a throwaway KieSession* to do that which is bad:
> {code}
> KieSession kieSession = kieContainer.newKieSession(ksessionName); // BAD
> KieBase kieBase = kieSession.getKieBase();
> checkIfGlobalScoreHolderExists(kieBase);
> {code}
> It would be much nicer if we could do this instead:
> {code}
> KieBase kieBase = kieContainer.getKieBaseForKsessionName(ksessionName);
> checkIfGlobalScoreHolderExists(kieBase);
> {code}
> So the proposal is to add that new method kieContainer.getKieBaseForKsessionName(String ksessionName)
> For the record, here's that check method that's being called at bootstrap:
> {code}
> protected void checkIfGlobalScoreHolderExists(KieBase kieBase) {
> boolean hasGlobalScoreHolder = false;
> for (KiePackage kiePackage : kieBase.getKiePackages()) {
> for (Global global : kiePackage.getGlobalVariables()) {
> if (DroolsScoreDirector.GLOBAL_SCORE_HOLDER_KEY.equals(global.getName())) {
> hasGlobalScoreHolder = true;
> break;
> }
> }
> }
> if (!hasGlobalScoreHolder) {
> throw new IllegalArgumentException("The kieBase with kiePackages (" + kieBase.getKiePackages()
> + ") has no global field called " + DroolsScoreDirector.GLOBAL_SCORE_HOLDER_KEY + ".\n"
> + "Check if the rule files are found and if the global field is spelled correctly.");
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the jboss-jira
mailing list