Reference > Rule Languages > ILOG Rule Language > IRL Keywords > logical (in insert)

Summary

The keyword used to declare a logical type object to be inserted into the working memory. This keyword is used in rule conditions, rule actions, or functions.

Syntax

insert logical object 
[{statement1 ... statementn}] ;

Description

The insert statement creates a new object of a given class, may execute statements on the scope of the object, and then inserts the object into the working memory. The logical keyword indicates that the object is of a logical type. A logical object has two properties: the object is unique, and the validity of the object is maintained.

The uniqueness of the object is specified using the equals method of the Java class Object, which must be redefined in your Java class (see below). First an object is created normally using the specified constructor. This object is then tested, using the equals method, to determine whether an object already exists in the working memory that equals this object.

Maintenance of a logical object means that as long as the condition part of a rule that justified the object remains true, the object is kept in the working memory. If the condition part becomes false, the object will lose a justification. A logical object that loses its last justification is automatically retracted from the working memory.

In order to use the Truth Maintenance System, the equals method of the Java class Object must be redefined in your Java class; for example:

public boolean equals (Object obj)
   {
      if (obj == null || !(obj instanceof className))
         return(false);
         className myObj = (className)obj;
         return (fieldName.equals(myObj.fieldName));
   }

As well, you must define a hashCode method:

public int hashCode()
   {
      return (fieldName.hashCode());
   }

Note
If several fields are used to discriminate the object, they must all be tested using equals and summed for their hashCode.

See Also

insert