Following is the Example taken form the following URL:
http://labs.jboss.com/file-access/default/members/jbossrules/freezone/doc...
But this rule is not working for me. If anyone know the logic behind the
rule, please explain me.
Example:
Imagine we have two classes - Student and Module. Module represents each of
the courses the Student attended for that semester, referenced by the List
collection. At the end of the semester each Module has a score. If the
Student has a Module score below 40 then they will fail that semester - the
existential quantifier can be used used with the "less than 40" open
proposition to check for the existence of a Module that is true for the
specified criteria.
public class Student {
private String name;
private List modules;
...
}
public Class Module {
private String name;
private String studentName;
private int score;
Java is Turing complete in that you can write code, among other things, to
iterate data structures to check for existence. The following should return
a List of students who have failed the semester.
List failedStudents = new ArrayList();
for ( Iterator studentIter = students.iterator(); studentIter.hasNext() {
Student student = ( Student ) studentIter.next();
for ( Iterator it = student.getModules.iterator(); it.hasNext(); ) {
Module module = ( Module ) it.next();
if ( module.getScore() < 40 ) {
failedStudents.add( student ) ;
break;
}
}
}
Early SQL implementations where not Turing complete as they did not provide
quantifiers to asses the structure of data. However modern SQL engines allow
nesting of SQL which can be combined with keywords like 'exists' and
'in':
The following query would return a set of Students who have failed the
semester.
select
*
from
Students s
where exists (
select
*
from
Modules m
where
m.student_name = s.name and
m.score < 40
)
rule
when
exists( $student : Student() && Module( student == $student, score <
40 ) )
--
View this message in context:
http://www.nabble.com/Logic-behind-the-Rule-tf3848998.html#a10902431
Sent from the drools - user mailing list archive at
Nabble.com.