Questo contenuto non è disponibile nella lingua selezionata.
3.2. JBoss Rules Theory
3.2.1. Methods in JBoss Rules Copia collegamentoCollegamento copiato negli appunti!
3.2.2. Method Example Copia collegamentoCollegamento copiato negli appunti!
public void helloWorld(Person person) {
if ( person.getName().equals( "Chuck" ) ) {
System.out.println( "Hello Chuck" );
}
}
3.2.3. Rule Example Copia collegamentoCollegamento copiato negli appunti!
rule "Hello World"
when
Person( name == "Chuck" )
then
System.out.println( "Hello Chuck" );
end
3.2.4. Cross-Products Copia collegamentoCollegamento copiato negli appunti!
3.2.5. Cross-Product Constraining Copia collegamentoCollegamento copiato negli appunti!
Procedure 3.6. Task
- To prevent a rule from outputting a huge amount of cross-products, you should constrain the cross-products themselves. Do this using the variable constraint seen below:
rule when $room : Room() $sprinkler : Sprinkler( room == $room ) then System.out.println( "room:" + $room.getName() + " sprinkler:" + $sprinkler.getRoom().getName() ); endThe following output will be displayed:room:office sprinkler:office room:kitchen sprinkler:kitchen room:livingroom sprinkler:livingroom room:bedroom sprinkler:bedroom
Only four rows are outputted with the correct sprinkler for each room. Without this variable, every row in the Room table would have been joined with every row in the Sprinkler table resulting in many lines of output.
3.2.6. The Inference Engine Copia collegamentoCollegamento copiato negli appunti!
3.2.7. Inference Example Copia collegamentoCollegamento copiato negli appunti!
rule "Infer Adult"
when
$p : Person( age >= 18 )
then
insert( new IsAdult( $p ) )
end
$p : Person()
IsAdult( person == $p )