I'd just instanceof test the Collection against List and cast. Second, consider an issue requiring support for error checking with this additive kind of build.
If all of your rules are in the same package, consider concatenating the rules strings in a string builder and feed the results to the KB instance. Mapping accumulated line counts to rules will enable you to associate error messages to rules. As you wrote, you can also build each rule separately and add individual packages to the knowledge base. What's wrong with this approach? You might also keep track of correct rules in your DB: once it has been compiled individually, mark it as "OK". New/modified rules lose the mark. -W On 10 June 2012 12:50, Sandeep Bandela <[email protected]> wrote: > yeah the internal impl is arraylist but the interface is a > collection<KnowledgeBuilderErrors>, so everytime I had to convert it to > array and keep counter of last-error-index and fetch new > KnowledgeBuilderErrors on the collection, or use iterator to iterate the > last-error-index and continue till the end of the collection. > the knowledge builder dosent return any package if it has atleast one failed > package. > But I want the successfully-compiled rules to be in the kBase and log the > failed rules with the unique identifier of it. > so the author of the rule is notified and rest all rules work without any > issue. > > creating new kBuilder for every rule (drl string) in the db and adding its > packages to the kBase is the only way? > may be something like kBuilder.remove(failedResource) or > getSuccessfulKnowledgePackages(); > > On Sun, Jun 10, 2012 at 10:58 AM, Wolfgang Laun <[email protected]> > wrote: >> >> If the list of errors is extended by errors detected during another >> kb.add(): why not just keep track of the last size() of the list? New errors >> are bound to appear at the end of the list. >> -W >> >> On 10 June 2012 01:44, Sandeep Bandela <[email protected]> wrote: >>> >>> Hi, >>> I have rules (drl format strings) stored in a database column in a schema >>> like MyRules(rule_id integer, name text, rule text, enabled boolean ... ) >>> I query the db to get them and iterate over the rows and add using >>> KnowledgeBuilder.add() using String.getBytes. (I dont want to move to guvnor >>> as of now) >>> some rules might have compilation errors, hence the >>> KnowledgeBuilder.hasErrors() is set to true. >>> those will not be added to the package by the PackageBuilder. >>> >>> My problem is to log the error causing rule_id and the error message. >>> KnowledgeBuilderErrors dosent expose the internal errors list so that I >>> could see if any new errors are in the arraylist from the last time error >>> seen time and log them. >>> But only solution i could think of is using the low level api of using >>> DrlParser to pre-parse it to check for errors+log and add to the kBuilder if >>> its not failed. >>> >>> is there any elegant way to do this? >>> >>> I am using drools-5.2.0.final >>> >>> >>> >>> >>> -- >>> Regards, >>> Sandeep Bandela. >>> >>> >>> _______________________________________________ >>> rules-users mailing list >>> [email protected] >>> https://lists.jboss.org/mailman/listinfo/rules-users >>> >> >> >> _______________________________________________ >> rules-users mailing list >> [email protected] >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > > > -- > Regards, > Sandeep Bandela. > > > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users > _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
