[jboss-svn-commits] JBL Code SVN: r30135 - in labs/jbossrules/branches/effective_dated: drools-compiler/src/main/java/org/drools/compiler and 15 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 12 16:05:51 EST 2009


Author: tirelli
Date: 2009-11-12 16:05:50 -0500 (Thu, 12 Nov 2009)
New Revision: 30135

Added:
   labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/EffectiveDatedFactsTest.java
   labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_EffectiveDatedFacts.drl
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffDatedFactHandle.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffectiveDateOverlapsConstraint.java
Removed:
   labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/TemporalFactsTest.java
   labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_TemporalFacts.drl
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/TemporalFactHandle.java
Modified:
   labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
   labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java
   labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/Coverage.java
   labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/EmployeeStatus.java
   labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/base/ClassObjectType.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AgendaItem.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/management/KnowledgeBaseMonitoring.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/Package.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/ObjectType.java
   labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/Tuple.java
   labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java
   labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/spi/MockObjectType.java
   labs/jbossrules/branches/effective_dated/pom.xml
Log:
JBRULES-2330: Implementing propper support for effective date on 'positive' rules. Still need to work on 'negative' rules.

Modified: labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -996,40 +996,15 @@
                 }
             }
 
-            String timestamp = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_TIMESTAMP );
-            if ( timestamp != null ) {
-                type.setStartTimestampAttribute( timestamp );
-                ClassDefinition cd = type.getTypeClassDef();
-                ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
-                InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
-                                                                  timestamp,
-                                                                  type.new StartTimestampAccessorSetter() );
+            if( type.getRole().equals( TypeDeclaration.Role.EVENT ) ) {
+                parseEventMetadata( pkgRegistry,
+                                    typeDescr,
+                                    type );
+            } else if( type.getRole().equals( TypeDeclaration.Role.EFFDATED ) ) {
+                parseEffectiveDatedMetadata( pkgRegistry,
+                                             typeDescr,
+                                             type );
             }
-            String duration = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_DURATION );
-            if ( duration != null ) {
-                type.setDurationAttribute( duration );
-                ClassDefinition cd = type.getTypeClassDef();
-                ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
-                InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
-                                                                  duration,
-                                                                  type.new DurationAccessorSetter() );
-            }
-            String endTimestamp = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_END_TIMESTAMP );
-            if ( timestamp != null ) {
-                type.setEndTimestampAttribute( endTimestamp );
-                ClassDefinition cd = type.getTypeClassDef();
-                ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
-                InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
-                                                                  endTimestamp,
-                                                                  type.new EndTimestampAccessorSetter() );
-            }
-            String expiration = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_EXPIRE );
-            if ( expiration != null ) {
-                if ( timeParser == null ) {
-                    timeParser = new TimeIntervalParser();
-                }
-                type.setExpirationOffset( timeParser.parse( expiration )[0].longValue() );
-            }
 
             boolean dynamic = typeDescr.getMetaAttributes().containsKey( TypeDeclaration.ATTR_PROP_CHANGE_SUPPORT );
             type.setDynamic( dynamic );
@@ -1038,6 +1013,68 @@
         }
     }
 
+    private void parseEventMetadata(PackageRegistry pkgRegistry,
+                                    TypeDeclarationDescr typeDescr,
+                                    TypeDeclaration type) {
+        String timestamp = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_TIMESTAMP );
+        if ( timestamp != null ) {
+            type.setStartTimestampAttribute( timestamp );
+            ClassDefinition cd = type.getTypeClassDef();
+            ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
+            InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
+                                                              timestamp,
+                                                              type.new StartTimestampAccessorSetter() );
+        }
+        String duration = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_DURATION );
+        if ( duration != null ) {
+            type.setDurationAttribute( duration );
+            ClassDefinition cd = type.getTypeClassDef();
+            ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
+            InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
+                                                              duration,
+                                                              type.new DurationAccessorSetter() );
+        }
+        String endTimestamp = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_END_TIMESTAMP );
+        if ( timestamp != null ) {
+            type.setEndTimestampAttribute( endTimestamp );
+            ClassDefinition cd = type.getTypeClassDef();
+            ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
+            InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
+                                                              endTimestamp,
+                                                              type.new EndTimestampAccessorSetter() );
+        }
+        String expiration = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_EXPIRE );
+        if ( expiration != null ) {
+            if ( timeParser == null ) {
+                timeParser = new TimeIntervalParser();
+            }
+            type.setExpirationOffset( timeParser.parse( expiration )[0].longValue() );
+        }
+    }
+
+    private void parseEffectiveDatedMetadata(PackageRegistry pkgRegistry,
+                                             TypeDeclarationDescr typeDescr,
+                                             TypeDeclaration type) {
+        String effts = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_EFF_DATE );
+        if ( effts != null ) {
+            type.setStartTimestampAttribute( effts );
+            ClassDefinition cd = type.getTypeClassDef();
+            ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
+            InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
+                                                              effts,
+                                                              type.new StartTimestampAccessorSetter() );
+        }
+        String expts = typeDescr.getMetaAttribute( TypeDeclaration.ATTR_EXP_DATE );
+        if ( expts != null ) {
+            type.setEndTimestampAttribute( expts );
+            ClassDefinition cd = type.getTypeClassDef();
+            ClassFieldAccessorStore store = pkgRegistry.getPackage().getClassFieldAccessorStore();
+            InternalReadAccessor extractor = store.getReader( type.getTypeClass().getName(),
+                                                              expts,
+                                                              type.new EndTimestampAccessorSetter() );
+        }
+    }
+
     /**
      * 
      * @param pkgRegistry 

Modified: labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -71,6 +71,7 @@
 import org.drools.rule.RuleConditionElement;
 import org.drools.rule.SlidingLengthWindow;
 import org.drools.rule.SlidingTimeWindow;
+import org.drools.rule.TypeDeclaration;
 import org.drools.rule.VariableConstraint;
 import org.drools.rule.VariableRestriction;
 import org.drools.rule.builder.dialect.mvel.MVELDialect;
@@ -138,9 +139,9 @@
         } else {
             try {
                 final Class userProvidedClass = context.getDialect().getTypeResolver().resolveType( patternDescr.getObjectType() );
-                final boolean isEvent = context.getPkg().isEvent( userProvidedClass );
+                final TypeDeclaration.Role role = context.getPkg().getRole( userProvidedClass );
                 objectType = new ClassObjectType( userProvidedClass,
-                                                  isEvent );
+                                                  role );
             } catch ( final ClassNotFoundException e ) {
                 context.getErrors().add( new DescrBuildError( context.getParentDescr(),
                                                               patternDescr,

Modified: labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/Coverage.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/Coverage.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/Coverage.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -6,8 +6,8 @@
     
     private String employeeId;
     private String type;
-    private Date start;
-    private Date end;
+    private Date effDate;
+    private Date expDate;
     
     public Coverage() {
         super();
@@ -15,13 +15,13 @@
     
     public Coverage(String employeeId,
                     String type,
-                    Date start,
+                    Date effDate,
                     Date end) {
         super();
         this.employeeId = employeeId;
         this.type = type;
-        this.start = start;
-        this.end = end;
+        this.effDate = effDate;
+        this.expDate = end;
     }
     
     public String getEmployeeId() {
@@ -38,22 +38,22 @@
     public void setType(String type) {
         this.type = type;
     }
-    public Date getStart() {
-        return start;
+    public Date getEffDate() {
+        return effDate;
     }
-    public void setStart(Date start) {
-        this.start = start;
+    public void setEffDate(Date effDate) {
+        this.effDate = effDate;
     }
-    public Date getEnd() {
-        return end;
+    public Date getExpDate() {
+        return expDate;
     }
-    public void setEnd(Date end) {
-        this.end = end;
+    public void setExpDate(Date expDate) {
+        this.expDate = expDate;
     }
     
     @Override
     public String toString() {
-        return "Coverage( id="+employeeId+" type="+type+" start="+start+" end="+end+" )";
+        return "Coverage( id="+employeeId+" type="+type+" effdt="+effDate+" expdt="+expDate+" )";
     }
 
 }

Modified: labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/EmployeeStatus.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/EmployeeStatus.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/EmployeeStatus.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -6,8 +6,8 @@
     
     private String employeeId;
     private String status;
-    private Date startDate;
-    private Date endDate;
+    private Date effDate;
+    private Date expDate;
     
     public EmployeeStatus() {
         super();
@@ -15,13 +15,13 @@
     
     public EmployeeStatus(String employeeId,
                           String status,
-                          Date startDate,
-                          Date endDate) {
+                          Date effDate,
+                          Date expDate) {
         super();
         this.employeeId = employeeId;
         this.status = status;
-        this.startDate = startDate;
-        this.endDate = endDate;
+        this.effDate = effDate;
+        this.expDate = expDate;
     }
     
     public String getEmployeeId() {
@@ -36,22 +36,22 @@
     public void setStatus(String status) {
         this.status = status;
     }
-    public Date getStartDate() {
-        return startDate;
+    public Date getEffDate() {
+        return effDate;
     }
-    public void setStartDate(Date startDate) {
-        this.startDate = startDate;
+    public void setEffDate(Date effDate) {
+        this.effDate = effDate;
     }
-    public Date getEndDate() {
-        return endDate;
+    public Date getExpDate() {
+        return expDate;
     }
-    public void setEndDate(Date endDate) {
-        this.endDate = endDate;
+    public void setExpDate(Date expDate) {
+        this.expDate = expDate;
     }
     
     @Override
     public String toString() {
-        return "EmployeeStatus( id="+employeeId+" status="+status+" start="+startDate+" end="+endDate+" )";
+        return "EmployeeStatus( id="+employeeId+" status="+status+" effdt="+effDate+" expdt="+expDate+" )";
     }    
 
 }

Modified: labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -1687,17 +1687,17 @@
             return 0;
         }
 
-        public long getEndTimestamp() {
+        public long getEffectiveTimestamp() {
             // TODO Auto-generated method stub
             return 0;
         }
 
-        public long getStartTimestamp() {
+        public long getExpirationTimestamp() {
             // TODO Auto-generated method stub
             return 0;
         }
 
-        public boolean isTemporal() {
+        public boolean isEffectiveDated() {
             // TODO Auto-generated method stub
             return false;
         }

Added: labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/EffectiveDatedFactsTest.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/EffectiveDatedFactsTest.java	                        (rev 0)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/EffectiveDatedFactsTest.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -0,0 +1,277 @@
+/**
+ * 
+ */
+package org.drools.integrationtests;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.Calendar;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.drools.Coverage;
+import org.drools.EmployeeStatus;
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.base.EffectiveRangeAgendaFilter;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderFactory;
+import org.drools.builder.ResourceType;
+import org.drools.common.EffDatedFactHandle;
+import org.drools.event.rule.ActivationCancelledEvent;
+import org.drools.event.rule.ActivationCreatedEvent;
+import org.drools.event.rule.AfterActivationFiredEvent;
+import org.drools.event.rule.AgendaEventListener;
+import org.drools.event.rule.ObjectInsertedEvent;
+import org.drools.event.rule.WorkingMemoryEventListener;
+import org.drools.io.ResourceFactory;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.rule.FactHandle;
+import org.mockito.ArgumentCaptor;
+
+/**
+ * @author etirelli
+ *
+ */
+public class EffectiveDatedFactsTest extends TestCase {
+
+    private StatefulKnowledgeSession createSession(final String rulesFile) {
+        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+        kbuilder.add( ResourceFactory.newInputStreamResource( getClass().getResourceAsStream( rulesFile ) ),
+                      ResourceType.DRL );
+
+        assertFalse( kbuilder.getErrors().toString(),
+                     kbuilder.hasErrors() );
+
+        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
+        return ksession;
+    }
+
+    public void testEffectiveDatedFactCreation() {
+        StatefulKnowledgeSession ksession = createSession( "test_EffectiveDatedFacts.drl" );
+
+        // creating mock objects to check successful execution
+        final AgendaEventListener agendaListener = mock( AgendaEventListener.class );
+        final WorkingMemoryEventListener wmListener = mock( WorkingMemoryEventListener.class );
+
+        ksession.addEventListener( agendaListener );
+        ksession.addEventListener( wmListener );
+
+        // input data
+        Calendar start = Calendar.getInstance();
+        start.set( 2009,
+                   07,
+                   10 );
+        Calendar end = Calendar.getInstance();
+        end.set( 2009,
+                 10,
+                 25 );
+
+        EmployeeStatus es1 = new EmployeeStatus( "e1",
+                                                 "full time",
+                                                 start.getTime(),
+                                                 end.getTime() );
+
+        FactHandle handle = ksession.insert( es1 );
+
+        // checking results
+        assertNotNull( handle );
+        assertTrue( handle instanceof EffDatedFactHandle );
+        EffDatedFactHandle thandle = (EffDatedFactHandle) handle;
+        assertEquals( start.getTimeInMillis(),
+                      thandle.getEffectiveTimestamp() );
+        assertEquals( end.getTimeInMillis(),
+                      thandle.getExpirationTimestamp() );
+
+        ksession.fireAllRules();
+
+        // checking compliance
+        verify( agendaListener,
+                never() ).activationCreated( any( ActivationCreatedEvent.class ) );
+        verify( wmListener ).objectInserted( any( ObjectInsertedEvent.class ) );
+
+    }
+
+    public void testEffectiveDatedMatching() {
+        StatefulKnowledgeSession ksession = createSession( "test_EffectiveDatedFacts.drl" );
+
+        // creating mock objects to check successful execution
+        final AgendaEventListener agendaListener = mock( AgendaEventListener.class );
+        final WorkingMemoryEventListener wmListener = mock( WorkingMemoryEventListener.class );
+
+        ksession.addEventListener( agendaListener );
+        ksession.addEventListener( wmListener );
+
+        // input data
+        Calendar t1 = Calendar.getInstance();
+        t1.set( 2009,
+                9,
+                1 );
+        Calendar t2 = Calendar.getInstance();
+        t2.set( 2009,
+                9,
+                15 );
+        Calendar t3 = Calendar.getInstance();
+        t3.set( 2009,
+                10,
+                7 );
+        Calendar t4 = Calendar.getInstance();
+        t4.set( 2009,
+                10,
+                25 );
+        Calendar t5 = Calendar.getInstance();
+        t5.set( 2009,
+                10,
+                30 );
+        Calendar t6 = Calendar.getInstance();
+        t6.set( 2009,
+                11,
+                12 );
+        Calendar t7 = Calendar.getInstance();
+        t7.set( 2009,
+                11,
+                20 );
+
+        EmployeeStatus es1 = new EmployeeStatus( "e1",
+                                                 "full time",
+                                                 t1.getTime(),
+                                                 t3.getTime() );
+        EmployeeStatus es2 = new EmployeeStatus( "e1",
+                                                 "full time",
+                                                 t5.getTime(),
+                                                 t7.getTime() );
+        Coverage c1 = new Coverage( "e1",
+                                    "A",
+                                    t2.getTime(),
+                                    t4.getTime() );
+        Coverage c2 = new Coverage( "e1",
+                                    "A",
+                                    t5.getTime(),
+                                    t6.getTime() );
+
+        ksession.insert( es1 );
+        ksession.insert( es2 );
+        ksession.insert( c1 );
+        ksession.insert( c2 );
+
+        // checking compliance
+        verify( wmListener,
+                times( 4 ) ).objectInserted( any( ObjectInsertedEvent.class ) );
+        verify( agendaListener,
+                times( 2 ) ).activationCreated( any( ActivationCreatedEvent.class ) );
+
+        ksession.fireAllRules();
+
+        ArgumentCaptor<AfterActivationFiredEvent> argument = ArgumentCaptor.forClass( AfterActivationFiredEvent.class );
+        verify( agendaListener,
+                times( 2 ) ).afterActivationFired( argument.capture() );
+
+        List<AfterActivationFiredEvent> events = argument.getAllValues();
+        AfterActivationFiredEvent evt1 = events.get( 0 );
+        AfterActivationFiredEvent evt2 = events.get( 1 );
+
+        assertEquals( t5.getTimeInMillis(),
+                      evt1.getActivation().getStartTimestamp() );
+        assertEquals( t6.getTimeInMillis(),
+                      evt1.getActivation().getEndTimestamp() );
+
+        assertEquals( t2.getTimeInMillis(),
+                      evt2.getActivation().getStartTimestamp() );
+        assertEquals( t3.getTimeInMillis(),
+                      evt2.getActivation().getEndTimestamp() );
+
+    }
+
+    public void testEffectiveDatedAgendaFilter() {
+        StatefulKnowledgeSession ksession = createSession( "test_EffectiveDatedFacts.drl" );
+
+        // creating mock objects to check successful execution
+        final AgendaEventListener agendaListener = mock( AgendaEventListener.class );
+        final WorkingMemoryEventListener wmListener = mock( WorkingMemoryEventListener.class );
+
+        ksession.addEventListener( agendaListener );
+        ksession.addEventListener( wmListener );
+
+        Calendar t1 = Calendar.getInstance();
+        t1.set( 2009,
+                9,
+                1 );
+        Calendar t2 = Calendar.getInstance();
+        t2.set( 2009,
+                9,
+                15 );
+        Calendar t3 = Calendar.getInstance();
+        t3.set( 2009,
+                10,
+                7 );
+        Calendar t4 = Calendar.getInstance();
+        t4.set( 2009,
+                10,
+                25 );
+        Calendar t5 = Calendar.getInstance();
+        t5.set( 2009,
+                10,
+                30 );
+        Calendar t6 = Calendar.getInstance();
+        t6.set( 2009,
+                11,
+                12 );
+        Calendar t7 = Calendar.getInstance();
+        t7.set( 2009,
+                11,
+                20 );
+
+        EmployeeStatus es1 = new EmployeeStatus( "e1",
+                                                 "full time",
+                                                 t1.getTime(),
+                                                 t3.getTime() );
+        EmployeeStatus es2 = new EmployeeStatus( "e1",
+                                                 "full time",
+                                                 t5.getTime(),
+                                                 t7.getTime() );
+        Coverage c1 = new Coverage( "e1",
+                                    "A",
+                                    t2.getTime(),
+                                    t4.getTime() );
+        Coverage c2 = new Coverage( "e1",
+                                    "A",
+                                    t5.getTime(),
+                                    t6.getTime() );
+
+        ksession.insert( es1 );
+        ksession.insert( es2 );
+        ksession.insert( c1 );
+        ksession.insert( c2 );
+
+        // checking compliance
+        verify( wmListener,
+                times( 4 ) ).objectInserted( any( ObjectInsertedEvent.class ) );
+        verify( agendaListener,
+                times( 2 ) ).activationCreated( any( ActivationCreatedEvent.class ) );
+
+        ksession.fireAllRules( new EffectiveRangeAgendaFilter( t1.getTime(),
+                                                               t4.getTime() ) );
+
+        ArgumentCaptor<AfterActivationFiredEvent> argument = ArgumentCaptor.forClass( AfterActivationFiredEvent.class );
+        verify( agendaListener,
+                times( 1 ) ).afterActivationFired( argument.capture() );
+        verify( agendaListener,
+                times( 1 ) ).activationCancelled( any( ActivationCancelledEvent.class ) );
+
+        AfterActivationFiredEvent evt1 = argument.getValue();
+
+        assertEquals( t2.getTimeInMillis(),
+                      evt1.getActivation().getStartTimestamp() );
+        assertEquals( t3.getTimeInMillis(),
+                      evt1.getActivation().getEndTimestamp() );
+
+    }
+}

Deleted: labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/TemporalFactsTest.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/TemporalFactsTest.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/test/java/org/drools/integrationtests/TemporalFactsTest.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -1,205 +0,0 @@
-/**
- * 
- */
-package org.drools.integrationtests;
-
-import java.util.Calendar;
-
-import junit.framework.TestCase;
-
-import org.drools.Coverage;
-import org.drools.EmployeeStatus;
-import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseFactory;
-import org.drools.base.EffectiveRangeAgendaFilter;
-import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.ResourceType;
-import org.drools.common.TemporalFactHandle;
-import org.drools.io.ResourceFactory;
-import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.rule.FactHandle;
-
-/**
- * @author etirelli
- *
- */
-public class TemporalFactsTest extends TestCase {
-
-    public void testTemporalFactCreation() {
-        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-        kbuilder.add( ResourceFactory.newInputStreamResource( getClass().getResourceAsStream( "test_TemporalFacts.drl" ) ),
-                      ResourceType.DRL );
-
-        assertFalse( kbuilder.getErrors().toString(),
-                     kbuilder.hasErrors() );
-
-        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
-        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
-        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
-
-        Calendar start = Calendar.getInstance();
-        start.set( 2009,
-                   07,
-                   10 );
-        Calendar end = Calendar.getInstance();
-        end.set( 2009,
-                 10,
-                 25 );
-
-        EmployeeStatus es1 = new EmployeeStatus( "e1",
-                                                 "full time",
-                                                 start.getTime(),
-                                                 end.getTime() );
-
-        FactHandle handle = ksession.insert( es1 );
-
-        assertNotNull( handle );
-        assertTrue( handle instanceof TemporalFactHandle );
-        TemporalFactHandle thandle = (TemporalFactHandle) handle;
-        assertEquals( start.getTimeInMillis(),
-                      thandle.getStartTimestamp() );
-        assertEquals( end.getTimeInMillis(),
-                      thandle.getEndTimestamp() );
-        assertEquals( end.getTimeInMillis() - start.getTimeInMillis(),
-                      thandle.getDuration() );
-        
-        ksession.fireAllRules();
-
-    }
-    
-    public void testTemporalMatching() {
-        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-        kbuilder.add( ResourceFactory.newInputStreamResource( getClass().getResourceAsStream( "test_TemporalFacts.drl" ) ),
-                      ResourceType.DRL );
-
-        assertFalse( kbuilder.getErrors().toString(),
-                     kbuilder.hasErrors() );
-
-        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
-        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
-        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
-
-        Calendar t1 = Calendar.getInstance();
-        t1.set( 2009,
-                   9,
-                   1 );
-        Calendar t2 = Calendar.getInstance();
-        t2.set( 2009,
-                 9,
-                 15 );
-        Calendar t3 = Calendar.getInstance();
-        t3.set( 2009,
-                 10,
-                 7 );
-        Calendar t4 = Calendar.getInstance();
-        t4.set( 2009,
-                 10,
-                 25 );
-        Calendar t5 = Calendar.getInstance();
-        t5.set( 2009,
-                 10,
-                 30 );
-        Calendar t6 = Calendar.getInstance();
-        t6.set( 2009,
-                 11,
-                 12 );
-        Calendar t7 = Calendar.getInstance();
-        t7.set( 2009,
-                 11,
-                 20 );
-
-        EmployeeStatus es1 = new EmployeeStatus( "e1",
-                                                 "full time",
-                                                 t1.getTime(),
-                                                 t3.getTime() );
-        EmployeeStatus es2 = new EmployeeStatus( "e1",
-                                                 "full time",
-                                                 t5.getTime(),
-                                                 t7.getTime() );
-        Coverage c1 = new Coverage("e1",
-                                   "A",
-                                   t2.getTime(),
-                                   t4.getTime() );
-        Coverage c2 = new Coverage("e1",
-                                   "A",
-                                   t5.getTime(),
-                                   t6.getTime() );
-
-        ksession.insert( es1 );
-        ksession.insert( es2 );
-        ksession.insert( c1 );
-        ksession.insert( c2 );
-        
-        ksession.fireAllRules();
-    }
-
-    public void testTemporalAgendaFilter() {
-        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-        kbuilder.add( ResourceFactory.newInputStreamResource( getClass().getResourceAsStream( "test_TemporalFacts.drl" ) ),
-                      ResourceType.DRL );
-
-        assertFalse( kbuilder.getErrors().toString(),
-                     kbuilder.hasErrors() );
-
-        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
-        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
-        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
-
-        Calendar t1 = Calendar.getInstance();
-        t1.set( 2009,
-                   9,
-                   1 );
-        Calendar t2 = Calendar.getInstance();
-        t2.set( 2009,
-                 9,
-                 15 );
-        Calendar t3 = Calendar.getInstance();
-        t3.set( 2009,
-                 10,
-                 7 );
-        Calendar t4 = Calendar.getInstance();
-        t4.set( 2009,
-                 10,
-                 25 );
-        Calendar t5 = Calendar.getInstance();
-        t5.set( 2009,
-                 10,
-                 30 );
-        Calendar t6 = Calendar.getInstance();
-        t6.set( 2009,
-                 11,
-                 12 );
-        Calendar t7 = Calendar.getInstance();
-        t7.set( 2009,
-                 11,
-                 20 );
-
-        EmployeeStatus es1 = new EmployeeStatus( "e1",
-                                                 "full time",
-                                                 t1.getTime(),
-                                                 t3.getTime() );
-        EmployeeStatus es2 = new EmployeeStatus( "e1",
-                                                 "full time",
-                                                 t5.getTime(),
-                                                 t7.getTime() );
-        Coverage c1 = new Coverage("e1",
-                                   "A",
-                                   t2.getTime(),
-                                   t4.getTime() );
-        Coverage c2 = new Coverage("e1",
-                                   "A",
-                                   t5.getTime(),
-                                   t6.getTime() );
-
-        ksession.insert( es1 );
-        ksession.insert( es2 );
-        ksession.insert( c1 );
-        ksession.insert( c2 );
-        
-        ksession.fireAllRules(new EffectiveRangeAgendaFilter( t1.getTime(), t4.getTime() ));
-    }
-}

Added: labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_EffectiveDatedFacts.drl
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_EffectiveDatedFacts.drl	                        (rev 0)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_EffectiveDatedFacts.drl	2009-11-12 21:05:50 UTC (rev 30135)
@@ -0,0 +1,26 @@
+package org.drools
+
+import java.util.Date
+
+declare EmployeeStatus
+    @role( effective-dated )
+    @effDate( effDate )
+    @expDate( expDate )
+end
+
+declare Coverage
+    @role( effective-dated )
+    @effDate( effDate )
+    @expDate( expDate )
+end
+
+rule "Employee is full time worker"
+when
+    $e : EmployeeStatus( status == "full time" )
+    $c : Coverage( employeeId == $e.employeeId, type == "A" )
+then
+    System.out.println( $e ); 
+    System.out.println( $c );
+    System.out.println( "Start = "+new Date(drools.getActivation().getStartTimestamp()) );
+    System.out.println( "End   = "+new Date(drools.getActivation().getEndTimestamp()) );
+end
\ No newline at end of file

Deleted: labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_TemporalFacts.drl
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_TemporalFacts.drl	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-compiler/src/test/resources/org/drools/integrationtests/test_TemporalFacts.drl	2009-11-12 21:05:50 UTC (rev 30135)
@@ -1,26 +0,0 @@
-package org.drools
-
-import java.util.Date
-
-declare EmployeeStatus
-    @role( temporal )
-    @timestamp( startDate )
-    @endTimestamp( endDate )
-end
-
-declare Coverage
-    @role( temporal )
-    @timestamp( start )
-    @endTimestamp( end )
-end
-
-rule "Employee is full time worker"
-when
-    $e : EmployeeStatus( status == "full time" )
-    $c : Coverage( employeeId == $e.employeeId, type == "A" )
-then
-    System.out.println( $e ); 
-    System.out.println( $c );
-    System.out.println( "Start = "+new Date(drools.getActivation().getStartTimestamp()) );
-    System.out.println( "End   = "+new Date(drools.getActivation().getEndTimestamp()) );
-end
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/base/ClassObjectType.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/base/ClassObjectType.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/base/ClassObjectType.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -22,6 +22,7 @@
 import java.io.ObjectOutput;
 
 import org.drools.RuntimeDroolsException;
+import org.drools.rule.TypeDeclaration;
 import org.drools.spi.ObjectType;
 
 /**
@@ -36,19 +37,15 @@
     ObjectType,
     Externalizable {
 
-    /**
-     *
-     */
-    private static final long serialVersionUID = 400L;
+    private static final long    serialVersionUID = 400L;
 
-    /** Java object class. */
-    protected Class<?>        cls;
+    protected Class< ? >         cls;
 
-    protected String          clsName;
+    protected String             clsName;
 
-    protected ValueType       valueType;
+    protected ValueType          valueType;
 
-    private boolean           isEvent;
+    private TypeDeclaration.Role role;
 
     // ------------------------------------------------------------
     // Constructors
@@ -63,9 +60,9 @@
      * @param objectTypeClass
      *            Java object class.
      */
-    public ClassObjectType(final Class<?> objectTypeClass) {
+    public ClassObjectType(final Class< ? > objectTypeClass) {
         this( objectTypeClass,
-              false );
+              TypeDeclaration.Role.FACT );
     }
 
     /**
@@ -74,24 +71,14 @@
      * @param objectTypeClass the class represented by this class object type
      * @param isEvent true if it is an event class, false otherwise
      */
-    public ClassObjectType(final Class<?> objectTypeClass,
-                           final boolean isEvent) {
+    public ClassObjectType(final Class< ? > objectTypeClass,
+                           final TypeDeclaration.Role role) {
         this.cls = objectTypeClass;
-        this.isEvent = isEvent;
-        //if (objectTypeClass != null)
+        this.role = role;
         this.clsName = this.cls.getName();
         this.valueType = ValueType.determineValueType( objectTypeClass );
     }
 
-    public ClassObjectType(final String className,
-                           final boolean isEvent) {
-        this.isEvent = isEvent;
-        this.clsName = this.cls.getName();
-        //        if (objectTypeClass != null)
-        //
-        //            this.valueType = ValueType.determineValueType( objectTypeClass );        
-    }
-
     public void readExternal(ObjectInput in) throws IOException,
                                             ClassNotFoundException {
         this.clsName = in.readUTF();
@@ -102,15 +89,13 @@
             } catch ( ClassNotFoundException e ) {
                 throw new RuntimeDroolsException( "Unable to resolve class '" + clsName + "'" );
             }
-        }        
-//        this.valueType = (ValueType) in.readObject();
-        this.isEvent = in.readBoolean();
+        }
+        this.role = (TypeDeclaration.Role) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
         out.writeUTF( clsName );
-//        out.writeObject( valueType );
-        out.writeBoolean( isEvent );
+        out.writeObject( role );
     }
 
     /**
@@ -118,7 +103,7 @@
      *
      * @return The Java object class.
      */
-    public Class<?> getClassType() {
+    public Class< ? > getClassType() {
         return this.cls;
     }
 
@@ -126,47 +111,11 @@
         return this.clsName;
     }
 
-    public void setClassType(Class<?> cls) {
+    public void setClassType(Class< ? > cls) {
         this.cls = cls;
         this.valueType = ValueType.determineValueType( cls );
     }
 
-    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-    // org.drools.spi.ObjectType
-    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-    //    /**
-    //     * Determine if the passed <code>Class</code> matches to the object type
-    //     * defined by this <code>objectType</code> instance.
-    //     *
-    //     * @param clazz
-    //     *            The <code>Class</code> to test.
-    //     *
-    //     * @return <code>true</code> if the <code>Class</code> matches this
-    //     *         object type, else <code>false</code>.
-    //     */
-    //    public boolean matchesClass(final Class clazz) {
-    //        return getClassType().isAssignableFrom( clazz );
-    //    }
-    //
-    //    /**
-    //     * Determine if the passed <code>Object</code> belongs to the object type
-    //     * defined by this <code>objectType</code> instance.
-    //     *
-    //     * @param object
-    //     *            The <code>Object</code> to test.
-    //     *
-    //     * @return <code>true</code> if the <code>Object</code> matches this
-    //     *         object type, else <code>false</code>.
-    //     */
-    //    public boolean matches(final Object object) {
-    //        return getClassType().isInstance( object );
-    //    }
-    //
-    //    public boolean isAssignableFrom(Object object) {
-    //        return this.objectTypeClass.isAssignableFrom( (Class) object );
-    //    }
-
     public boolean isAssignableFrom(ObjectType objectType) {
         if ( !(objectType instanceof ClassObjectType) ) {
             return false;
@@ -180,15 +129,15 @@
     }
 
     public boolean isEvent() {
-        return isEvent;
+        return role.equals( TypeDeclaration.Role.EVENT );
     }
 
-    public void setEvent(boolean isEvent) {
-        this.isEvent = isEvent;
+    public boolean isEffectiveDated() {
+        return role.equals( TypeDeclaration.Role.EFFDATED );
     }
 
     public String toString() {
-        return "[ClassObjectType " + (this.isEvent ? "event=" : "class=") + getClassType().getName() + "]";
+        return "[ClassObjectType class=" + getClassType().getName() + " role="+ role +"]";
     }
 
     /**
@@ -209,11 +158,11 @@
             return false;
         }
 
-        return this.clsName.equals( ((ClassObjectType) object).clsName );
+        return this.role.equals( ((ClassObjectType)object).role ) && this.clsName.equals( ((ClassObjectType) object).clsName );
     }
 
     public int hashCode() {
-        return this.clsName.hashCode();
+        return this.clsName.hashCode() | (this.role.hashCode() * 31);
     }
 
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -609,17 +609,24 @@
                 pkg.addProcess( flow );
             }
         }
-
-        //        // this handles re-wiring any dirty Packages, it's done lazily to allow incremental 
-        //        // additions without incurring the repeated cost.
-        //        if ( this.reloadPackageCompilationData == null ) {
-        //            this.reloadPackageCompilationData = new ReloadPackageCompilationData();
-        //        }
-        //        this.reloadPackageCompilationData.addDialectDatas( pkg.getDialectRuntimeRegistry() );
     }
 
-    public TypeDeclaration getTypeDeclaration(Class< ? > clazz) {
-        return this.classTypeDeclaration.get( clazz );
+    public TypeDeclaration getTypeDeclaration(final Class< ? > clazz) {
+        TypeDeclaration type = null;
+        Class<?> aux = clazz;
+        while( type == null && aux != null ) {
+            type = this.classTypeDeclaration.get( aux );
+            aux = aux.getSuperclass();  
+        }
+        if( type == null ) {
+            for( Class<?> intfc : clazz.getInterfaces() ) {
+                type = getTypeDeclaration( intfc );
+                if( type != null ) {
+                    break;
+                }
+            }
+        }
+        return type;
     }
 
     public Collection<TypeDeclaration> getTypeDeclarations() {
@@ -875,15 +882,6 @@
         return this.eventSupport.getEventListeners();
     }
 
-    public boolean isEvent(Class clazz) {
-        for ( Package pkg : this.pkgs.values() ) {
-            if ( pkg.isEvent( clazz ) ) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     public FactType getFactType(final String name) {
         for ( Package pkg : this.pkgs.values() ) {
             FactType type = pkg.getFactType( name );

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AgendaItem.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AgendaItem.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/AgendaItem.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -315,14 +315,14 @@
     }
 
     public long getEndTimestamp() {
-        return tuple.getEndTimestamp();
+        return tuple.getExpirationTimestamp();
     }
 
     public long getStartTimestamp() {
-        return tuple.getStartTimestamp();
+        return tuple.getEffectiveTimestamp();
     }
 
     public boolean isTemporal() {
-        return tuple.isTemporal();
+        return tuple.isEffectiveDated();
     }
 }

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -227,15 +227,15 @@
         return clone;
     }
 
-    public long getEndTimestamp() {
+    public long getExpirationTimestamp() {
         return Long.MAX_VALUE;
     }
 
-    public long getStartTimestamp() {
+    public long getEffectiveTimestamp() {
         return Long.MIN_VALUE;
     }
 
-    public boolean isTemporal() {
+    public boolean isEffectiveDated() {
         return false;
     }
 }

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/DisconnectedFactHandle.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -115,15 +115,15 @@
         return "0:" + this.id + ":" + this.identityHashCode + ":" + this.objectHashCode + ":" + this.recency;
     }
 
-    public long getEndTimestamp() {
+    public long getExpirationTimestamp() {
         throw new UnsupportedOperationException( "DisonnectedFactHandle does not support this method" );
     }
 
-    public long getStartTimestamp() {
+    public long getEffectiveTimestamp() {
         throw new UnsupportedOperationException( "DisonnectedFactHandle does not support this method" );
     }
 
-    public boolean isTemporal() {
+    public boolean isEffectiveDated() {
         throw new UnsupportedOperationException( "DisonnectedFactHandle does not support this method" );
     }
 

Added: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffDatedFactHandle.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffDatedFactHandle.java	                        (rev 0)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffDatedFactHandle.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -0,0 +1,131 @@
+package org.drools.common;
+
+import org.drools.FactHandle;
+import org.drools.spi.ReadAccessor;
+
+/**
+ * An effective dated fact handle wraps a fact that is valid only
+ * during a given period of time defined by it's own attributes.
+ * 
+ * @author etirelli
+ */
+public class EffDatedFactHandle extends DefaultFactHandle {
+
+    private static final long serialVersionUID = 5997141759543399455L;
+
+    private ReadAccessor      effTimestamp;
+    private ReadAccessor      expTimestamp;
+
+    // ----------------------------------------------------------------------
+    // Constructors
+    // ----------------------------------------------------------------------
+
+    public EffDatedFactHandle() {
+        this( 0,
+              null,
+              0 );
+    }
+
+    public EffDatedFactHandle(final int id,
+                              final Object object) {
+        this( id,
+              object,
+              id );
+    }
+
+    /**
+     * Construct.
+     *
+     * @param id
+     *            Handle id.
+     */
+    public EffDatedFactHandle(final int id,
+                              final Object object,
+                              final long recency) {
+        super( id,
+               object,
+               recency );
+    }
+
+    /**
+     * Creates a new event fact handle.
+     *
+     * @param id this fact handle's ID
+     * @param object the fact object encapsulated in this fact handle
+     * @param recency the recency of this event fact handle
+     * @param effTimestamp the field accessor to the effective date for this fact
+     * @param expTimestamp the field accessor to the expiration date for this fact
+     * @param duration the duration of this event. May be 0 (zero) in case this is a primitive event.
+     */
+    public EffDatedFactHandle(final int id,
+                              final Object object,
+                              final long recency,
+                              final ReadAccessor effTimestamp,
+                              final ReadAccessor expTimestamp ) {
+        super( id,
+               object,
+               recency );
+        this.effTimestamp = effTimestamp;
+        this.expTimestamp = expTimestamp;
+    }
+
+    /**
+     * @see FactHandle
+     */
+    public String toExternalForm() {
+        return "[effDated fid:" + getId() + ":" + getRecency() + ":" + getObject() + " effDate="+ getEffectiveTimestamp()+" expDate="+getExpirationTimestamp()+"]";
+    }
+
+    /**
+     * @see Object
+     */
+    public String toString() {
+        return toExternalForm();
+    }
+
+    /**
+     * Always returns false, since the EffectiveDatedFactHandle is
+     * not used for Events
+     */
+    public boolean isEvent() {
+        return false;
+    }
+
+    /**
+     * Returns the effective timestamp for this fact.
+     * @return
+     */
+    @Override
+    public long getEffectiveTimestamp() {
+        return ( effTimestamp != null && !effTimestamp.isNullValue( getObject() ) ) ? effTimestamp.getLongValue( getObject() ) : Long.MIN_VALUE;
+    }
+
+    /**
+     * Returns the expiration timestamp for this fact.
+     *
+     * @return
+     */
+    @Override
+    public long getExpirationTimestamp() {
+        return ( expTimestamp != null && !expTimestamp.isNullValue( getObject() ) ) ? expTimestamp.getLongValue( getObject() ) : Long.MAX_VALUE;
+    }
+
+    public EffDatedFactHandle clone() {
+        EffDatedFactHandle clone = new EffDatedFactHandle( getId(),
+                                                           getObject(),
+                                                           getRecency(),
+                                                           effTimestamp,
+                                                           expTimestamp );
+        clone.setEntryPoint( getEntryPoint() );
+        clone.setEqualityKey( getEqualityKey() );
+        clone.setLeftTuple( getLeftTuple() );
+        clone.setRightTuple( getRightTuple() );
+        clone.setObjectHashCode( getObjectHashCode() );
+        return clone;
+    }
+    
+    @Override
+    public boolean isEffectiveDated() {
+        return true;
+    }
+}

Added: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffectiveDateOverlapsConstraint.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffectiveDateOverlapsConstraint.java	                        (rev 0)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/EffectiveDateOverlapsConstraint.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.common;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.drools.reteoo.LeftTuple;
+import org.drools.rule.ContextEntry;
+import org.drools.rule.Declaration;
+import org.drools.spi.BetaNodeFieldConstraint;
+
+/**
+ * This constraint checks for overlaps in the effective/expiration dates
+ * for the handle and the tuple.
+ * 
+ * This constraint is used in conjunction with effective dated facts.
+ *
+ * @author <a href="mailto:tirelli at post.com">Edson Tirelli</a>
+ *
+ * @version $Id$
+ */
+
+public class EffectiveDateOverlapsConstraint
+    implements
+    BetaNodeFieldConstraint {
+
+    private static final long                            serialVersionUID  = 510L;
+
+    private static final Declaration[]                   EMPTY_DECLARATION = new Declaration[0];
+
+    // this is a fly-weight
+    public static final EffectiveDateOverlapsConstraint POSITIVE_INSTANCE = new EffectiveDateOverlapsConstraint( false );
+    public static final EffectiveDateOverlapsConstraint NEGATIVE_INSTANCE = new EffectiveDateOverlapsConstraint( true );
+    
+    private boolean negative;
+
+    private EffectiveDateOverlapsConstraint( final boolean negative ) {
+        this.negative = negative;
+    }
+
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        negative = in.readBoolean();
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeBoolean( negative );
+    }
+
+    public Declaration[] getRequiredDeclarations() {
+        return EMPTY_DECLARATION;
+    }
+
+    public void replaceDeclaration(Declaration oldDecl,
+                                   Declaration newDecl) {
+    }
+
+    public boolean isTemporal() {
+        return false;
+    }
+
+    public ContextEntry createContextEntry() {
+        return new EffectiveDateOverlapsContextEntry();
+    }
+
+    public boolean isAllowedCachedLeft(final ContextEntry context,
+                                       final InternalFactHandle handle) {
+        LeftTuple leftTuple = ((EffectiveDateOverlapsContextEntry) context).left;
+        return isThereEffDateOverlap( handle,
+                                      leftTuple );
+    }
+
+    public boolean isAllowedCachedRight(final LeftTuple leftTuple,
+                                        final ContextEntry context) {
+        final InternalFactHandle handle = ((EffectiveDateOverlapsContextEntry) context).right;
+        return isThereEffDateOverlap( handle,
+                                      leftTuple );
+    }
+
+    private boolean isThereEffDateOverlap(final InternalFactHandle handle,
+                                          LeftTuple leftTuple) {
+        if ( leftTuple.isEffectiveDated() || handle.isEffectiveDated() ) {
+            return negative ^ (leftTuple.getEffectiveTimestamp() >= handle.getEffectiveTimestamp() && leftTuple.getEffectiveTimestamp() <= handle.getExpirationTimestamp())
+                   || (leftTuple.getExpirationTimestamp() >= handle.getEffectiveTimestamp() && leftTuple.getExpirationTimestamp() <= handle.getExpirationTimestamp());
+        }
+        return negative ^ true;
+    }
+
+    public String toString() {
+        return "[EffectiveDateOverlapsConstraint ]";
+    }
+
+    public ConstraintType getType() {
+        return ConstraintType.BETA;
+    }
+
+    public Object clone() {
+        // this is a fly-weight
+        return negative ? NEGATIVE_INSTANCE : POSITIVE_INSTANCE;
+    }
+
+    public int hashCode() {
+        // this is a fly-weight
+        return negative ? 31 : 17;
+    }
+
+    public boolean equals(final Object object) {
+        if ( object == null || !(object instanceof EffectiveDateOverlapsConstraint) ) {
+            return false;
+        }
+        return negative == ((EffectiveDateOverlapsConstraint)object).negative;
+    }
+
+    public static class EffectiveDateOverlapsContextEntry
+        implements
+        ContextEntry {
+
+        private static final long serialVersionUID = 510L;
+
+        public LeftTuple          left;
+        public InternalFactHandle right;
+
+        // this is s linked list
+        private ContextEntry      entry;
+
+        public EffectiveDateOverlapsContextEntry() {
+        }
+
+        public void readExternal(ObjectInput in) throws IOException,
+                                                ClassNotFoundException {
+            left = (LeftTuple) in.readObject();
+            right = (InternalFactHandle) in.readObject();
+            entry = (ContextEntry) in.readObject();
+        }
+
+        public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject( left );
+            out.writeObject( right );
+            out.writeObject( entry );
+        }
+
+        public ContextEntry getNext() {
+            return this.entry;
+        }
+
+        public void setNext(final ContextEntry entry) {
+            this.entry = entry;
+        }
+
+        public void updateFromTuple(final InternalWorkingMemory workingMemory,
+                                    final LeftTuple tuple) {
+            this.left = tuple;
+        }
+
+        public void updateFromFactHandle(final InternalWorkingMemory workingMemory,
+                                         final InternalFactHandle handle) {
+            this.right = handle;
+        }
+
+        public void resetTuple() {
+            this.left = null;
+        }
+
+        public void resetFactHandle() {
+            this.right = null;
+        }
+    }
+
+}

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalFactHandle.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -71,10 +71,10 @@
     
     public String toExternalForm();
 
-    public boolean isTemporal();
+    public boolean isEffectiveDated();
     
-    public long getStartTimestamp();
+    public long getEffectiveTimestamp();
     
-    public long getEndTimestamp();
+    public long getExpirationTimestamp();
     
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalRuleBase.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/InternalRuleBase.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -110,18 +110,14 @@
     
     public Process[] getProcesses();
     
-    /**
-     * Returns true if clazz represents an Event class. False otherwise.
-     *  
-     * @param clazz
-     * @return
-     */
-    public boolean isEvent( Class<?> clazz );
-	
 	public int getNodeCount();
 
 	/**
-	 * Returns the type declaration associated to the given class
+	 * Returns the most specific type declaration associated to the given class,
+	 * i.e., starting from the concrete class, looks for a type declaration for it
+	 * or for its parents in sequence. If not found for any of the parents, looks
+	 * for type declarations for its interfaces. Returns the first (i.e. most specific)
+	 * type declaration.
 	 * 
 	 * @param clazz
 	 * @return

Deleted: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/TemporalFactHandle.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/TemporalFactHandle.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/common/TemporalFactHandle.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -1,141 +0,0 @@
-package org.drools.common;
-
-import org.drools.FactHandle;
-import org.drools.spi.ReadAccessor;
-
-public class TemporalFactHandle extends DefaultFactHandle {
-
-    private static final long serialVersionUID = 5997141759543399455L;
-
-    private ReadAccessor      startTimestamp;
-    private ReadAccessor      endTimestamp;
-    private ReadAccessor      duration;
-
-    // ----------------------------------------------------------------------
-    // Constructors
-    // ----------------------------------------------------------------------
-
-    public TemporalFactHandle() {
-        this( 0,
-              null,
-              0 );
-    }
-
-    public TemporalFactHandle(final int id,
-                              final Object object) {
-        this( id,
-              object,
-              id );
-    }
-
-    /**
-     * Construct.
-     *
-     * @param id
-     *            Handle id.
-     */
-    public TemporalFactHandle(final int id,
-                              final Object object,
-                              final long recency) {
-        super( id,
-               object,
-               recency );
-    }
-
-    /**
-     * Creates a new event fact handle.
-     *
-     * @param id this event fact handle ID
-     * @param object the event object encapsulated in this event fact handle
-     * @param recency the recency of this event fact handle
-     * @param startTimestamp the field accessor to the start timestamp of the occurrence of this event
-     * @param endTimestamp the field accessor to the end timestamp of the occurrence of this event
-     * @param duration the duration of this event. May be 0 (zero) in case this is a primitive event.
-     */
-    public TemporalFactHandle(final int id,
-                              final Object object,
-                              final long recency,
-                              final ReadAccessor startTimestamp,
-                              final ReadAccessor endTimestamp,
-                              final ReadAccessor duration) {
-        super( id,
-               object,
-               recency );
-        this.startTimestamp = startTimestamp;
-        this.endTimestamp = endTimestamp;
-        this.duration = duration;
-    }
-
-    /**
-     * @see FactHandle
-     */
-    public String toExternalForm() {
-        return "[temporal fid:" + getId() + ":" + getRecency() + ":" + getObject() + " start="+ getStartTimestamp()+" duration="+getDuration()+"]";
-    }
-
-    /**
-     * @see Object
-     */
-    public String toString() {
-        return toExternalForm();
-    }
-
-    /**
-     * Always returns false, since the TemporalFactHandle is
-     * not used for Events
-     */
-    public boolean isEvent() {
-        return false;
-    }
-
-    /**
-     * Returns the start timestamp of the occurrence of this temporal fact.
-     * @return
-     */
-    @Override
-    public long getStartTimestamp() {
-        return startTimestamp != null ? startTimestamp.getLongValue( getObject() ) : Long.MIN_VALUE;
-    }
-
-    /**
-     * Returns the duration of this temporal fact. 
-     *
-     * @return
-     */
-    public long getDuration() {
-        return duration != null ? duration.getLongValue( getObject() ) : ( getEndTimestamp() - getStartTimestamp() );
-    }
-
-    /**
-     * Returns the end timestamp for this temporal fact.
-     *
-     * startTimestamp + duration
-     *
-     * @return
-     */
-    @Override
-    public long getEndTimestamp() {
-        return endTimestamp != null ? endTimestamp.getLongValue( getObject() ) : 
-               ((duration != null) ? getStartTimestamp() + getDuration() : Long.MAX_VALUE );
-    }
-
-    public TemporalFactHandle clone() {
-        TemporalFactHandle clone = new TemporalFactHandle( getId(),
-                                                           getObject(),
-                                                           getRecency(),
-                                                           startTimestamp,
-                                                           endTimestamp,
-                                                           duration );
-        clone.setEntryPoint( getEntryPoint() );
-        clone.setEqualityKey( getEqualityKey() );
-        clone.setLeftTuple( getLeftTuple() );
-        clone.setRightTuple( getRightTuple() );
-        clone.setObjectHashCode( getObjectHashCode() );
-        return clone;
-    }
-    
-    @Override
-    public boolean isTemporal() {
-        return true;
-    }
-}

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/facttemplates/FactTemplateObjectType.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -40,6 +40,8 @@
 
     private boolean           isEvent;
 
+    private boolean           isEffDated;
+
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
@@ -126,7 +128,15 @@
         this.isEvent = isEvent;
     }
 
-   public String toString() {
+    public void setEffectiveDated(boolean isEffDated) {
+        this.isEffDated = isEffDated;
+    }
+
+    public boolean isEffectiveDated() {
+        return isEffDated;
+    }
+
+    public String toString() {
         return "[FactTemplateObjectType "+( this.isEvent ? "event=" : "template=") + this.factTemplate.getName() + "]";
     }
 
@@ -156,4 +166,5 @@
     public int hashCode() {
         return this.factTemplate.hashCode();
     }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/management/KnowledgeBaseMonitoring.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/management/KnowledgeBaseMonitoring.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/management/KnowledgeBaseMonitoring.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -51,7 +51,6 @@
 import org.drools.reteoo.EntryPointNode;
 import org.drools.reteoo.ObjectTypeNode;
 import org.drools.reteoo.ReteooRuleBase;
-import org.drools.rule.Package;
 
 /**
  * An implementation for the KnowledgeBaseMBean

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -68,11 +68,9 @@
         this.entryPoint = entryPoint;
         this.typeDecl = ruleBase.getTypeDeclaration( clazz );
         this.role = ( typeDecl != null ) ? typeDecl.getRole() : TypeDeclaration.Role.FACT;
-        final boolean isEvent = role == TypeDeclaration.Role.EVENT;
-        
 
         ObjectType objectType = ((AbstractRuleBase) ruleBase).getClassFieldAccessorCache().getClassObjectType( new ClassObjectType( clazz,
-                                                                                                                                    isEvent ) );
+                                                                                                                                    role ) );
 
         this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType );
         if ( this.concreteObjectTypeNode == null ) {

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -113,64 +113,17 @@
             final InternalFactHandle handle = rightTuple.getFactHandle();
             if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
                                                        handle ) ) {
-                if ( thereIsTemporalOverlap( leftTuple,
-                                             handle ) ) {
-                    this.sink.propagateAssertLeftTuple( leftTuple,
-                                                        rightTuple,
-                                                        context,
-                                                        workingMemory,
-                                                        this.tupleMemoryEnabled );
-
-                }
+                this.sink.propagateAssertLeftTuple( leftTuple,
+                                                    rightTuple,
+                                                    context,
+                                                    workingMemory,
+                                                    this.tupleMemoryEnabled );
             }
         }
 
         this.constraints.resetTuple( memory.getContext() );
     }
 
-    private boolean thereIsTemporalOverlap(final LeftTuple leftTuple,
-                                           final InternalFactHandle handle) {
-        boolean result = true;
-        if ( leftTuple.isTemporal() || handle.isTemporal() ) {
-            result = (leftTuple.getStartTimestamp() >= handle.getStartTimestamp() && leftTuple.getStartTimestamp() <= handle.getEndTimestamp())
-                     || (leftTuple.getEndTimestamp() >= handle.getStartTimestamp() && leftTuple.getEndTimestamp() <= handle.getEndTimestamp());
-        }
-        return result;
-    }
-
-    //    public void assertLeftTuple(final LeftTuple leftTuple,
-    //                                RightTuple rightTuple,
-    //                                final PropagationContext context,
-    //                                final InternalWorkingMemory workingMemory) {
-    //        final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-    //
-    //        if ( this.tupleMemoryEnabled ) {
-    //            memory.getLeftTupleMemory().add( leftTuple );
-    //        }
-    //
-    //        this.constraints.updateFromTuple( memory.getContext(),
-    //                                          workingMemory,
-    //                                          leftTuple );
-    //        if ( rightTuple == null ) {
-    //            rightTuple = memory.getRightTupleMemory().getFirst( leftTuple );
-    //        }
-    //        
-    //        boolean suspend = false;
-    //        for ( ;rightTuple != null && !suspend; rightTuple = (RightTuple) rightTuple.getNext() ) {
-    //            final InternalFactHandle handle = rightTuple.getFactHandle();
-    //            if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
-    //                                                       handle ) ) {
-    //                this.sink.propagateAssertLeftTuple( leftTuple,
-    //                                                    rightTuple,
-    //                                                    context,
-    //                                                    workingMemory,
-    //                                                    this.tupleMemoryEnabled );
-    //            }
-    //        }
-    //
-    //        this.constraints.resetTuple( memory.getContext() );
-    //    }    
-
     /**
      * Assert a new <code>FactHandleImpl</code>. The left input of
      * <code>ReteTuple</code>s is iterated and joins attemped, via the
@@ -218,15 +171,11 @@
         for ( LeftTuple leftTuple = memory.getLeftTupleMemory().getFirst( rightTuple ); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
             if ( this.constraints.isAllowedCachedRight( memory.getContext(),
                                                         leftTuple ) ) {
-                // wm.marshaller.write( i, leftTuple )
-                if ( thereIsTemporalOverlap( leftTuple,
-                                             rightTuple.getFactHandle() ) ) {
-                    this.sink.propagateAssertLeftTuple( leftTuple,
-                                                        rightTuple,
-                                                        context,
-                                                        workingMemory,
-                                                        this.tupleMemoryEnabled );
-                }
+                this.sink.propagateAssertLeftTuple( leftTuple,
+                                                    rightTuple,
+                                                    context,
+                                                    workingMemory,
+                                                    this.tupleMemoryEnabled );
             }
             i++;
         }

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -47,15 +47,15 @@
     private LeftTupleSink      sink;
 
     // temporal info
-    private long               startTimestamp;
-    private long               endTimestamp;
+    private long               effectiveTimestamp;
+    private long               expirationTimestamp;
 
     public LeftTuple() {
         // constructor needed for serialisation
         
         // by default start and end timestamps are -INFINITY and +INFINITY respectively
-        this.startTimestamp = Long.MIN_VALUE;
-        this.endTimestamp = Long.MAX_VALUE;
+        this.effectiveTimestamp = Long.MIN_VALUE;
+        this.expirationTimestamp = Long.MAX_VALUE;
     }
 
     // ------------------------------------------------------------
@@ -128,13 +128,13 @@
     }
 
     private void adjustTimeRange() {
-        if( handle.isTemporal() ) {
+        if( handle.isEffectiveDated() ) {
             if( parent != null ) {
-                this.startTimestamp = Math.max( parent.getStartTimestamp(), handle.getStartTimestamp() );
-                this.endTimestamp = Math.min( parent.getEndTimestamp(), handle.getEndTimestamp() );
+                this.effectiveTimestamp = Math.max( parent.getEffectiveTimestamp(), handle.getEffectiveTimestamp() );
+                this.expirationTimestamp = Math.min( parent.getExpirationTimestamp(), handle.getExpirationTimestamp() );
             } else {
-                this.startTimestamp = handle.getStartTimestamp();
-                this.endTimestamp = handle.getEndTimestamp();
+                this.effectiveTimestamp = handle.getEffectiveTimestamp();
+                this.expirationTimestamp = handle.getExpirationTimestamp();
             }
         }
     }
@@ -475,16 +475,16 @@
         return parent;
     }
     
-    public long getStartTimestamp() {
-        return startTimestamp;
+    public long getEffectiveTimestamp() {
+        return effectiveTimestamp;
     }
 
-    public long getEndTimestamp() {
-        return endTimestamp;
+    public long getExpirationTimestamp() {
+        return expirationTimestamp;
     }
     
-    public boolean isTemporal() {
-        return handle.isTemporal() || (parent != null && parent.isTemporal() );
+    public boolean isEffectiveDated() {
+        return handle.isEffectiveDated() || (parent != null && parent.isEffectiveDated() );
     }
 
 }

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/ReteooFactHandleFactory.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -23,7 +23,7 @@
 import org.drools.common.EventFactHandle;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
-import org.drools.common.TemporalFactHandle;
+import org.drools.common.EffDatedFactHandle;
 import org.drools.rule.TypeDeclaration;
 import org.drools.rule.TypeDeclaration.Role;
 import org.drools.spi.FactHandleFactory;
@@ -41,7 +41,7 @@
         super( id,
                counter );
     }
-
+ 
     /* (non-Javadoc)
      * @see org.drools.reteoo.FactHandleFactory#newFactHandle(long)
      */
@@ -50,7 +50,7 @@
                                                      final long recency,
                                                      final ObjectTypeConf conf,
                                                      final InternalWorkingMemory workingMemory) {
-        if ( conf != null && conf.isEvent() ) {
+        if ( conf != null && conf.getRole().equals( Role.EVENT ) ) {
             TypeDeclaration type = conf.getTypeDeclaration();
             long timestamp;
             if ( type.getStartTimestampExtractor() != null ) {
@@ -74,14 +74,13 @@
                                         recency,
                                         timestamp,
                                         duration );
-        } else if( conf != null && conf.getRole().equals( Role.TEMPORAL ) ) {
+        } else if( conf != null && conf.getRole().equals( Role.EFFDATED ) ) {
             TypeDeclaration type = conf.getTypeDeclaration();
-            return new TemporalFactHandle( id,
+            return new EffDatedFactHandle( id,
                                         object,
                                         recency,
                                         type.getStartTimestampExtractor(),
-                                        type.getEndTimestampExtractor(),
-                                        type.getDurationExtractor() );
+                                        type.getEndTimestampExtractor() );
         } else {
             return new DefaultFactHandle( id,
                                           object,

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -47,6 +47,8 @@
                       final RuleConditionElement rce) {
         final Accumulate accumulate = (Accumulate) rce;
         boolean existSubNetwort = false;
+        
+        final boolean isEffectiveDated = context.isEffectiveDated();
 
         final List resultBetaConstraints = context.getBetaconstraints();
         final List resultAlphaConstraints = context.getAlphaConstraints();
@@ -113,6 +115,7 @@
         context.setObjectSource( null );
         context.setCurrentPatternOffset( currentPatternIndex );
         context.setBehaviors( Collections.EMPTY_LIST );
+        context.setEffectiveDated( isEffectiveDated );
     }
 
     /**

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -100,6 +100,8 @@
     /** the calculate temporal distance matrix */
     private TemporalDependencyMatrix         temporal;
 
+    private boolean isEffectiveDated;
+
     public BuildContext(final InternalRuleBase rulebase,
                         final ReteooBuilder.IdGenerator idGenerator) {
         this.rulebase = rulebase;
@@ -445,4 +447,13 @@
         }
     }
 
+    public boolean isEffectiveDated() {
+        return isEffectiveDated;
+    }
+    
+    public void setEffectiveDated( boolean effDated ) {
+        this.isEffectiveDated = effDated;
+    }
+    
+
 }

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -50,6 +50,7 @@
         boolean existSubNetwort = false;
         final Collect collect = (Collect) rce;
 
+        final boolean isEffectiveDated = context.isEffectiveDated();
         final List resultBetaConstraints = context.getBetaconstraints();
         final List resultAlphaConstraints = context.getAlphaConstraints();
         final List resultBehaviors = context.getBehaviors();
@@ -113,6 +114,7 @@
         context.setObjectSource( null );
         context.setCurrentPatternOffset( currentPatternIndex );
         context.setBehaviors( Collections.EMPTY_LIST );
+        context.setEffectiveDated( isEffectiveDated );
     }
 
     /**

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -221,6 +221,7 @@
             // NOT must save some context info to restore it later
             final int currentPatternIndex = context.getCurrentPatternOffset();
             final LeftTupleSource tupleSource = context.getTupleSource();
+            final boolean isEffectiveDated = context.isEffectiveDated();
 
             // get child
             final RuleConditionElement child = (RuleConditionElement) not.getChildren().get( 0 );
@@ -250,7 +251,7 @@
                 final List<TupleStartEqualsConstraint> predicates = new ArrayList<TupleStartEqualsConstraint>();
                 predicates.add( constraint );
                 context.setBetaconstraints( predicates );
-
+                context.setEffectiveDated( isEffectiveDated );
             }
 
             final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
@@ -313,6 +314,7 @@
             // EXISTS must save some context info to restore it later
             final int currentPatternIndex = context.getCurrentPatternOffset();
             final LeftTupleSource tupleSource = context.getTupleSource();
+            final boolean isEffectiveDated = context.isEffectiveDated();
 
             // get child
             final RuleConditionElement child = (RuleConditionElement) exists.getChildren().get( 0 );
@@ -342,7 +344,7 @@
                 final List<TupleStartEqualsConstraint> predicates = new ArrayList<TupleStartEqualsConstraint>();
                 predicates.add( constraint );
                 context.setBetaconstraints( predicates );
-
+                context.setEffectiveDated( isEffectiveDated );
             }
 
             final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -24,6 +24,7 @@
 import org.drools.RuntimeDroolsException;
 import org.drools.base.ClassObjectType;
 import org.drools.base.DroolsQuery;
+import org.drools.common.EffectiveDateOverlapsConstraint;
 import org.drools.common.InstanceNotEqualsConstraint;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.conf.EventProcessingOption;
@@ -150,6 +151,11 @@
         // checks if this pattern is nested inside a NOT CE
         final boolean isNegative = isNegative( context );
         
+        if( context.isEffectiveDated() || pattern.getObjectType().isEffectiveDated() ) {
+            betaConstraints.add( EffectiveDateOverlapsConstraint.POSITIVE_INSTANCE );
+            context.setEffectiveDated( true );
+        }
+        
         for ( final Iterator<?> it = constraints.iterator(); it.hasNext(); ) {
             final Object object = it.next();
             // Check if its a declaration

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/Package.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/Package.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/Package.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -22,13 +22,16 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.drools.RuntimeDroolsException;
 import org.drools.base.ClassFieldAccessorCache;
 import org.drools.base.ClassFieldAccessorStore;
 import org.drools.common.DroolsObjectInputStream;
@@ -36,6 +39,7 @@
 import org.drools.definition.process.Process;
 import org.drools.definition.type.FactType;
 import org.drools.facttemplates.FactTemplate;
+import org.drools.rule.TypeDeclaration.Role;
 
 /**
  * Collection of related <code>Rule</code>s.
@@ -503,27 +507,6 @@
         return this.name.hashCode();
     }
 
-    /**
-     * Returns true if clazz is imported as an Event class in this package
-     * 
-     * @param clazz
-     * @return true if clazz is imported as an Event class in this package
-     */
-    public boolean isEvent(Class clazz) {
-        if ( clazz == null ) {
-            return false;
-        }
-
-        // check if clazz is resolved by any of the type declarations
-        for ( TypeDeclaration type : this.typeDeclarations.values() ) {
-            if ( type.matches( clazz ) && type.getRole() == TypeDeclaration.Role.EVENT ) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
     public void clear() {
         this.rules.clear();
         this.dialectRuntimeRegistry.clear();
@@ -555,4 +538,22 @@
         this.classFieldAccessorStore.setClassFieldAccessorCache( classFieldAccessorCache );
     }
 
+    public Role getRole(Class<?> clazz) {
+        TypeDeclaration.Role role = TypeDeclaration.Role.FACT;
+        List<TypeDeclaration> definedRoles = new ArrayList<TypeDeclaration>(); 
+        // check if clazz is resolved by any of the type declarations
+        for ( TypeDeclaration type : this.typeDeclarations.values() ) {
+            if ( type.matches( clazz ) && type.getRole() != TypeDeclaration.Role.FACT ) {
+                definedRoles.add( type );
+            }
+        }
+
+        if( definedRoles.size() > 1 ) {
+            throw new RuntimeDroolsException("Unable to determine role for "+clazz+" due to multiple conflicting type declarations: "+definedRoles );
+        } else if( definedRoles.size() == 1 ) {
+            return definedRoles.get( 0 ).getRole();
+        }
+        return TypeDeclaration.Role.FACT;
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -52,9 +52,11 @@
     public static final String ATTR_EXPIRE              = "expires";
     public static final String ATTR_PROP_CHANGE_SUPPORT = "propertyChangeSupport";
     public static final String ATTR_END_TIMESTAMP       = "endTimestamp";
+    public static final String ATTR_EFF_DATE            = "effDate";
+    public static final String ATTR_EXP_DATE            = "expDate";
 
     public static enum Role {
-        FACT, EVENT, TEMPORAL;
+        FACT, EVENT, EFFDATED;
 
         public static final String ID = "role";
 
@@ -63,8 +65,8 @@
                 return EVENT;
             } else if ( "fact".equalsIgnoreCase( role ) ) {
                 return FACT;
-            } else if ( "temporal".equalsIgnoreCase( role ) ) {
-                return TEMPORAL;
+            } else if ( "effective-dated".equalsIgnoreCase( role ) ) {
+                return EFFDATED;
             }
             return null;
         }

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/ObjectType.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/ObjectType.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/ObjectType.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -29,20 +29,7 @@
 public interface ObjectType
     extends
     Externalizable {
-//    /**
-//     * Determine if the passed <code>Object</code> belongs to the object type
-//     * defined by this <code>objectType</code> instance.
-//     *
-//     * @param object
-//     *            The <code>Object</code> to test.
-//     *
-//     * @return <code>true</code> if the <code>Object</code> matches this
-//     *         object type, else <code>false</code>.
-//     */
-//    boolean matches(Object object);
 
-//    boolean isAssignableFrom(Object object);
-
     boolean isAssignableFrom(ObjectType objectType);
 
     /**
@@ -53,4 +40,6 @@
     boolean isEvent();
 
     ValueType getValueType();
+
+    boolean isEffectiveDated();
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/Tuple.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/Tuple.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/main/java/org/drools/spi/Tuple.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -65,9 +65,9 @@
      */
     int size();
 
-    public long getStartTimestamp();
+    public long getEffectiveTimestamp();
 
-    public long getEndTimestamp();
+    public long getExpirationTimestamp();
     
-    public boolean isTemporal();
+    public boolean isEffectiveDated();
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -23,6 +23,7 @@
 import org.drools.base.extractors.SelfReferenceClassFieldReader;
 import org.drools.rule.GroupElement;
 import org.drools.rule.Pattern;
+import org.drools.rule.TypeDeclaration;
 import org.drools.rule.VariableConstraint;
 import org.drools.rule.VariableRestriction;
 import org.drools.rule.GroupElement.Type;
@@ -67,7 +68,7 @@
                                         };
 
         AfterEvaluatorDefinition evals = new AfterEvaluatorDefinition();
-        ClassObjectType ot = new ClassObjectType(StockTick.class, true);
+        ClassObjectType ot = new ClassObjectType(StockTick.class, TypeDeclaration.Role.EVENT);
         
         Pattern a = new Pattern( 0, ot, "$a" );
         Pattern b = new Pattern( 1, ot, "$b" );

Modified: labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/spi/MockObjectType.java
===================================================================
--- labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/spi/MockObjectType.java	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/drools-core/src/test/java/org/drools/spi/MockObjectType.java	2009-11-12 21:05:50 UTC (rev 30135)
@@ -112,5 +112,8 @@
     public void setEvent(boolean isEvent) {
         this.isEvent = isEvent;
     }
+    public boolean isEffectiveDated() {
+        return false;
+    }
 
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/effective_dated/pom.xml
===================================================================
--- labs/jbossrules/branches/effective_dated/pom.xml	2009-11-12 13:38:50 UTC (rev 30134)
+++ labs/jbossrules/branches/effective_dated/pom.xml	2009-11-12 21:05:50 UTC (rev 30135)
@@ -860,6 +860,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.8.0</version> 
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.jmock</groupId>
             <artifactId>jmock</artifactId>
             <version>2.5.1</version>



More information about the jboss-svn-commits mailing list