[jboss-svn-commits] JBL Code SVN: r17379 - in labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools: base/evaluators and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Dec 23 02:53:26 EST 2007
Author: haruki_zaemon
Date: 2007-12-23 02:53:26 -0500 (Sun, 23 Dec 2007)
New Revision: 17379
Modified:
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/BaseEvaluator.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/Operator.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ContextEntry.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/GroupElement.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Evaluator.java
Log:
Sabre performance tests now pass. Still have failing unit tests.
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/BaseEvaluator.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/BaseEvaluator.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/BaseEvaluator.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -2,13 +2,13 @@
/*
* 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.
@@ -20,20 +20,29 @@
import org.drools.common.InternalFactHandle;
import org.drools.spi.Evaluator;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
/**
* BaseEvaluator is an Object Comparator that is operator aware
- *
+ *
* @author mproctor
- *
+ *
*/
public abstract class BaseEvaluator
implements
- Evaluator {
+ Evaluator,
+ Externalizable {
- private final Operator operator;
+ private Operator operator;
- private final ValueType type;
+ private ValueType type;
+ protected BaseEvaluator() {
+ }
+
public BaseEvaluator(final ValueType type,
final Operator operator) {
this.type = type;
@@ -55,7 +64,7 @@
public Object prepareObject(InternalFactHandle handle) {
return handle.getObject();
}
-
+
public boolean equals(final Object object) {
if ( this == object ) {
return true;
@@ -72,4 +81,13 @@
return (this.getValueType().hashCode()) ^ (this.getOperator().hashCode()) ^ (this.getClass().hashCode());
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(operator);
+ out.writeObject(type);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ operator = (Operator) in.readObject();
+ type = (ValueType) in.readObject();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -1,12 +1,12 @@
/*
* Copyright 2007 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.
@@ -18,11 +18,15 @@
package org.drools.base.evaluators;
import java.util.Date;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import org.drools.base.BaseEvaluator;
import org.drools.base.ShadowProxy;
import org.drools.base.ValueType;
import org.drools.common.InternalWorkingMemory;
+import org.drools.common.Resolvable;
import org.drools.rule.VariableRestriction.BooleanVariableContextEntry;
import org.drools.rule.VariableRestriction.CharVariableContextEntry;
import org.drools.rule.VariableRestriction.DoubleVariableContextEntry;
@@ -37,11 +41,11 @@
/**
* This class defines the default built in equality
* evaluators == and !=
- *
+ *
* @author etirelli
*/
public class EqualityEvaluatorsDefinition implements EvaluatorDefinition {
-
+
private static final String[] SUPPORTED_IDS = { Operator.EQUAL.getOperatorString(), Operator.NOT_EQUAL.getOperatorString() };
private EvaluatorCache evaluators = new EvaluatorCache() {
private static final long serialVersionUID = 4782368623L;
@@ -94,7 +98,7 @@
addEvaluator( ValueType.STRING_TYPE, Operator.NOT_EQUAL, StringNotEqualEvaluator.INSTANCE );
}
};
-
+
/**
* @inheridDoc
*/
@@ -137,12 +141,12 @@
public boolean supportsType(ValueType type) {
return this.evaluators.supportsType( type );
}
-
+
/* *********************************************************
* Evaluator Implementations
* *********************************************************
*/
-
+
static class ArrayEqualEvaluator extends BaseEvaluator {
private static final long serialVersionUID = 400L;
@@ -211,7 +215,7 @@
static class ArrayNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new ArrayNotEqualEvaluator();
@@ -278,7 +282,7 @@
static class BigDecimalEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new BigDecimalEqualEvaluator();
@@ -337,7 +341,7 @@
static class BigDecimalNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new BigDecimalNotEqualEvaluator();
@@ -395,7 +399,7 @@
static class BigIntegerEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new BigIntegerEqualEvaluator();
@@ -453,7 +457,7 @@
static class BigIntegerNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new BigIntegerNotEqualEvaluator();
@@ -527,7 +531,7 @@
} else if ( object2.isNull() ) {
return false;
}
-
+
return extractor.getBooleanValue( workingMemory, object1 ) == object2.getBooleanValue();
}
@@ -538,7 +542,7 @@
} else if ( context.isRightNull() ) {
return false;
}
-
+
return context.declaration.getExtractor().getBooleanValue( workingMemory, left ) == ((BooleanVariableContextEntry) context).right;
}
@@ -549,7 +553,7 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
return context.extractor.getBooleanValue( workingMemory, object2 ) == ((BooleanVariableContextEntry) context).left;
}
@@ -562,7 +566,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
return extractor1.getBooleanValue( workingMemory, object1 ) == extractor2.getBooleanValue( workingMemory, object2 );
}
@@ -574,7 +578,7 @@
static class BooleanNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new BooleanNotEqualEvaluator();
@@ -592,7 +596,7 @@
} else if ( object2.isNull() ) {
return true;
}
-
+
return extractor.getBooleanValue( workingMemory, object1 ) != object2.getBooleanValue();
}
@@ -613,7 +617,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
return context.extractor.getBooleanValue( workingMemory, object2 ) != ((BooleanVariableContextEntry) context).left;
}
@@ -626,7 +630,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
return extractor1.getBooleanValue( workingMemory, object1 ) != extractor1.getBooleanValue( workingMemory, object2 );
}
@@ -637,7 +641,7 @@
static class ByteEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new ByteEqualEvaluator();
@@ -655,7 +659,7 @@
} else if ( object2.isNull() ) {
return false;
}
-
+
return extractor.getByteValue( workingMemory, object1 ) == object2.getByteValue();
}
@@ -666,7 +670,7 @@
} else if ( context.isRightNull() ) {
return false;
}
-
+
return context.declaration.getExtractor().getByteValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
}
@@ -677,7 +681,7 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
return ((LongVariableContextEntry) context).left == context.extractor.getByteValue( workingMemory, right );
}
@@ -690,7 +694,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
return extractor1.getByteValue( workingMemory, object1 ) == extractor2.getByteValue( workingMemory, object2 );
}
@@ -702,7 +706,7 @@
static class ByteNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new ByteNotEqualEvaluator();
@@ -720,7 +724,7 @@
} else if ( object2.isNull() ) {
return true;
}
-
+
return extractor.getByteValue( workingMemory, object1 ) != object2.getByteValue();
}
@@ -731,7 +735,7 @@
} else if ( context.isRightNull() ) {
return true;
}
-
+
return context.declaration.getExtractor().getByteValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
}
@@ -742,7 +746,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
return ((LongVariableContextEntry) context).left != context.extractor.getByteValue( workingMemory, object2 );
}
@@ -755,7 +759,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
return extractor1.getByteValue( workingMemory, object1 ) != extractor2.getByteValue( workingMemory, object2 );
}
@@ -766,7 +770,7 @@
static class CharacterEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new CharacterEqualEvaluator();
@@ -784,7 +788,7 @@
} else if ( object2.isNull() ) {
return false;
}
-
+
return extractor.getCharValue( workingMemory, object1 ) == object2.getCharValue();
}
@@ -795,7 +799,7 @@
} else if ( context.isRightNull() ) {
return false;
}
-
+
return context.declaration.getExtractor().getCharValue( workingMemory, left ) == ((CharVariableContextEntry) context).right;
}
@@ -806,7 +810,7 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
return ((CharVariableContextEntry) context).left == context.extractor.getCharValue( workingMemory, right );
}
@@ -819,7 +823,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
return extractor1.getCharValue( workingMemory, object1 ) == extractor2.getCharValue( workingMemory, object2 );
}
@@ -830,7 +834,7 @@
static class CharacterNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new CharacterNotEqualEvaluator();
@@ -848,7 +852,7 @@
} else if ( object2.isNull() ) {
return true;
}
-
+
return extractor.getCharValue( workingMemory, object1 ) != object2.getCharValue();
}
@@ -859,7 +863,7 @@
} else if ( context.isRightNull() ) {
return true;
}
-
+
return context.declaration.getExtractor().getCharValue( workingMemory, left ) != ((CharVariableContextEntry) context).right;
}
@@ -870,7 +874,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
return ((CharVariableContextEntry) context).left != context.extractor.getCharValue( workingMemory, right );
}
@@ -883,7 +887,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
return extractor1.getCharValue( workingMemory, object1 ) != extractor2.getCharValue( workingMemory, object2 );
}
@@ -894,7 +898,7 @@
static class DateEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DateEqualEvaluator();
@@ -967,7 +971,7 @@
static class DateNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DateNotEqualEvaluator();
@@ -1039,7 +1043,7 @@
static class DoubleEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DoubleEqualEvaluator();
@@ -1079,7 +1083,7 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return ((DoubleVariableContextEntry) context).left == context.extractor.getDoubleValue( workingMemory, right );
}
@@ -1093,7 +1097,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return extractor1.getDoubleValue( workingMemory, object1 ) == extractor2.getDoubleValue( workingMemory, object2 );
}
@@ -1105,7 +1109,7 @@
static class DoubleNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DoubleNotEqualEvaluator();
@@ -1123,7 +1127,7 @@
} else if ( object2.isNull() ) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return extractor.getDoubleValue( workingMemory, object1 ) != object2.getDoubleValue();
}
@@ -1135,7 +1139,7 @@
} else if ( context.isRightNull() ) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return context.declaration.getExtractor().getDoubleValue( workingMemory, left ) != ((DoubleVariableContextEntry) context).right;
}
@@ -1147,7 +1151,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return ((DoubleVariableContextEntry) context).left != context.extractor.getDoubleValue( workingMemory, right );
}
@@ -1161,7 +1165,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return extractor1.getDoubleValue( workingMemory, object1 ) != extractor2.getDoubleValue( workingMemory, object2 );
}
@@ -1173,7 +1177,7 @@
static class FactTemplateEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new FactTemplateEqualEvaluator();
@@ -1232,7 +1236,7 @@
static class FactTemplateNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new FactTemplateNotEqualEvaluator();
@@ -1287,7 +1291,7 @@
return "FactTemplate !=";
}
}
-
+
static class FloatEqualEvaluator extends BaseEvaluator {
private static final long serialVersionUID = 400L;
@@ -1306,7 +1310,7 @@
} else if ( object2.isNull() ) {
return false;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return extractor.getFloatValue( workingMemory, object1 ) == object2.getFloatValue();
}
@@ -1318,7 +1322,7 @@
} else if ( context.isRightNull() ) {
return false;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return context.declaration.getExtractor().getFloatValue( workingMemory, left ) == ((DoubleVariableContextEntry) context).right;
}
@@ -1330,7 +1334,7 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return ((DoubleVariableContextEntry) context).left == context.extractor.getFloatValue( workingMemory, right );
}
@@ -1344,7 +1348,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return extractor1.getFloatValue( workingMemory, object1 ) == extractor2.getFloatValue( workingMemory, object2 );
}
@@ -1356,7 +1360,7 @@
static class FloatNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new FloatNotEqualEvaluator();
@@ -1374,7 +1378,7 @@
} else if ( object2.isNull() ) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return extractor.getFloatValue( workingMemory, object1 ) != object2.getFloatValue();
}
@@ -1386,7 +1390,7 @@
} else if ( context.isRightNull() ) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return context.declaration.getExtractor().getFloatValue( workingMemory, left ) != ((DoubleVariableContextEntry) context).right;
}
@@ -1398,7 +1402,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return ((DoubleVariableContextEntry) context).left != context.extractor.getFloatValue( workingMemory, right );
}
@@ -1412,7 +1416,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
// TODO: we are not handling delta right now... maybe we should
return extractor1.getFloatValue( workingMemory, object1 ) != extractor2.getFloatValue( workingMemory, object2 );
}
@@ -1424,7 +1428,7 @@
static class IntegerEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new IntegerEqualEvaluator();
@@ -1442,7 +1446,7 @@
} else if ( object2.isNull() ) {
return false;
}
-
+
return extractor.getIntValue( workingMemory, object1 ) == object2.getIntValue();
}
@@ -1453,8 +1457,8 @@
} else if ( context.isRightNull() ) {
return false;
}
-
- return context.declaration.getExtractor().getIntValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
+
+ return context.declaration.getExtractor().getIntValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
}
public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory,
@@ -1464,20 +1468,20 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
return context.extractor.getIntValue( workingMemory, object2 ) == ((LongVariableContextEntry) context).left;
}
public boolean evaluate(InternalWorkingMemory workingMemory,
final Extractor extractor1,
final Object object1,
- final Extractor extractor2, final Object object2) {
+ final Extractor extractor2, final Object object2) {
if (extractor1.isNullValue( workingMemory, object1 )) {
return extractor2.isNullValue( workingMemory, object2 );
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
return extractor1.getIntValue( workingMemory, object1 ) == extractor2.getIntValue( workingMemory, object2 );
}
@@ -1489,7 +1493,7 @@
static class IntegerNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new IntegerNotEqualEvaluator();
@@ -1501,13 +1505,13 @@
public boolean evaluate(InternalWorkingMemory workingMemory,
final Extractor extractor,
- final Object object1, final FieldValue object2) {
+ final Object object1, final FieldValue object2) {
if ( extractor.isNullValue( workingMemory, object1 ) ) {
return !object2.isNull();
} else if ( object2.isNull() ) {
return true;
}
-
+
return extractor.getIntValue( workingMemory, object1 ) != object2.getIntValue();
}
@@ -1518,7 +1522,7 @@
} else if ( context.isRightNull() ) {
return true;
}
-
+
return context.declaration.getExtractor().getIntValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
}
@@ -1529,7 +1533,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
return context.extractor.getIntValue( workingMemory, object2 ) != ((LongVariableContextEntry) context).left;
}
@@ -1542,7 +1546,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
return extractor1.getIntValue( workingMemory, object1 ) != extractor2.getIntValue( workingMemory, object2 );
}
@@ -1553,7 +1557,7 @@
static class LongEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new LongEqualEvaluator();
@@ -1571,7 +1575,7 @@
} else if ( object2.isNull() ) {
return false;
}
-
+
return extractor.getLongValue( workingMemory, object1 ) == object2.getLongValue();
}
@@ -1582,7 +1586,7 @@
} else if ( context.isRightNull() ) {
return false;
}
-
+
return context.declaration.getExtractor().getLongValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
}
@@ -1593,7 +1597,7 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
return ((LongVariableContextEntry) context).left == context.extractor.getLongValue( workingMemory, right );
}
@@ -1606,7 +1610,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
return extractor1.getLongValue( workingMemory, object1 ) == extractor2.getLongValue( workingMemory, object2 );
}
@@ -1617,7 +1621,7 @@
static class LongNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new LongNotEqualEvaluator();
@@ -1635,7 +1639,7 @@
} else if ( object2.isNull() ) {
return true;
}
-
+
return extractor.getLongValue( workingMemory, object1 ) != object2.getLongValue();
}
@@ -1646,7 +1650,7 @@
} else if ( context.isRightNull() ) {
return true;
}
-
+
return context.declaration.getExtractor().getLongValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
}
@@ -1657,7 +1661,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
return ((LongVariableContextEntry) context).left != context.extractor.getLongValue( workingMemory, right );
}
@@ -1670,7 +1674,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
return extractor1.getLongValue( workingMemory, object1 ) != extractor2.getLongValue( workingMemory, object2 );
}
@@ -1681,12 +1685,12 @@
static class ObjectEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new ObjectEqualEvaluator();
- private static final ObjectEqualsComparator comparator = new ObjectEqualsComparator();
-
+ private static final ObjectEqualsComparator comparator = new ObjectEqualsComparator();
+
private ObjectEqualEvaluator() {
super( ValueType.OBJECT_TYPE,
Operator.EQUAL );
@@ -1753,11 +1757,11 @@
static class ObjectNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new ObjectNotEqualEvaluator();
- private static final ObjectEqualsComparator comparator = new ObjectEqualsComparator();
+ private static final ObjectEqualsComparator comparator = new ObjectEqualsComparator();
private ObjectNotEqualEvaluator() {
super( ValueType.OBJECT_TYPE,
@@ -1824,7 +1828,7 @@
static class ShortEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
private static final Evaluator INSTANCE = new ShortEqualEvaluator();
@@ -1842,7 +1846,7 @@
} else if ( object2.isNull() ) {
return false;
}
-
+
return extractor.getShortValue( workingMemory, object1 ) == object2.getShortValue();
}
@@ -1853,7 +1857,7 @@
} else if ( context.isRightNull() ) {
return false;
}
-
+
return context.declaration.getExtractor().getShortValue( workingMemory, left ) == ((LongVariableContextEntry) context).right;
}
@@ -1864,7 +1868,7 @@
} else if ( context.isLeftNull() ) {
return false;
}
-
+
return ((LongVariableContextEntry) context).left == context.extractor.getShortValue( workingMemory, right );
}
@@ -1877,7 +1881,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return false;
}
-
+
return extractor1.getShortValue( workingMemory, object1 ) == extractor2.getShortValue( workingMemory, object2 );
}
@@ -1888,7 +1892,7 @@
static class ShortNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
private static final Evaluator INSTANCE = new ShortNotEqualEvaluator();
@@ -1906,7 +1910,7 @@
} else if ( object2.isNull() ) {
return true;
}
-
+
return extractor.getShortValue( workingMemory, object1 ) != object2.getShortValue();
}
@@ -1917,7 +1921,7 @@
} else if ( context.isRightNull() ) {
return true;
}
-
+
return context.declaration.getExtractor().getShortValue( workingMemory, left ) != ((LongVariableContextEntry) context).right;
}
@@ -1928,7 +1932,7 @@
} else if ( context.isLeftNull() ) {
return true;
}
-
+
return ((LongVariableContextEntry) context).left != context.extractor.getShortValue( workingMemory, right );
}
@@ -1941,7 +1945,7 @@
} else if (extractor2.isNullValue( workingMemory, object2 )) {
return true;
}
-
+
return extractor1.getShortValue( workingMemory, object1 ) != extractor2.getShortValue( workingMemory, object2 );
}
@@ -1950,18 +1954,16 @@
}
}
- static class StringEqualEvaluator extends BaseEvaluator {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- public final static Evaluator INSTANCE = new StringEqualEvaluator();
+ static class StringEqualEvaluator extends BaseEvaluator implements Resolvable {
+ public final static Evaluator INSTANCE = new StringEqualEvaluator(ValueType.STRING_TYPE, Operator.EQUAL);
private StringEqualEvaluator() {
- super( ValueType.STRING_TYPE,
- Operator.EQUAL );
}
+ private StringEqualEvaluator(ValueType type, Operator operator) {
+ super(type, operator);
+ }
+
public boolean evaluate(InternalWorkingMemory workingMemory,
final Extractor extractor,
final Object object1, final FieldValue object2) {
@@ -2007,6 +2009,15 @@
return "String ==";
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ }
+
+ public Object readResolve() {
+ return INSTANCE;
+ }
}
static class StringNotEqualEvaluator extends BaseEvaluator {
@@ -2087,8 +2098,8 @@
} else {
throw new ClassCastException( "Not possible to convert "+arg1.getClass()+" into a double value to compare it to "+arg0.getClass() );
}
- return val0 == val1; // in the future we may need to handle rounding errors
- }
+ return val0 == val1; // in the future we may need to handle rounding errors
+ }
if( arg0 instanceof String ) {
return arg0.equals( arg1.toString() );
}
@@ -2105,6 +2116,6 @@
return arg0.equals( arg1 );
}
}
-
+
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/Operator.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/Operator.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/evaluators/Operator.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -1,18 +1,19 @@
package org.drools.base.evaluators;
-import java.io.Serializable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.drools.RuntimeDroolsException;
+import org.drools.common.Resolvable;
public class Operator
implements
- Serializable {
+ Resolvable {
- private static final long serialVersionUID = 400L;
-
// a static private cache so that pluggable operator can register their implementations
// it is automatically initialized with common operator implementations
private static final Map<String, Operator> CACHE = Collections.synchronizedMap( new HashMap<String, Operator>() );
@@ -34,12 +35,12 @@
false );
/**
- * Creates a new Operator instance for the given parameters,
+ * Creates a new Operator instance for the given parameters,
* adds it to the registry and return it
- *
+ *
* @param operatorId the identification symbol of the operator
* @param isNegated true if it is negated
- *
+ *
* @return the newly created operator
*/
public static Operator addOperatorToRegistry(final String operatorId,
@@ -54,10 +55,10 @@
/**
* Returns the operator instance for the given parameters
- *
+ *
* @param operatorId the identification symbol of the operator
* @param isNegated true if it is negated
- *
+ *
* @return the operator in case it exists
*/
public static Operator determineOperator(final String operatorId,
@@ -79,17 +80,15 @@
private String operator;
private boolean isNegated;
+ private Operator() {
+ }
+
private Operator(final String operator,
final boolean isNegated) {
this.operator = operator;
this.isNegated = isNegated;
}
- private Object readResolve() throws java.io.ObjectStreamException {
- return determineOperator( this.operator,
- this.isNegated );
- }
-
public String toString() {
return "Operator = '" + this.operator + "'";
}
@@ -97,7 +96,7 @@
public String getOperatorString() {
return this.operator;
}
-
+
public boolean isNegated() {
return this.isNegated;
}
@@ -124,4 +123,17 @@
return true;
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(operator);
+ out.writeBoolean(isNegated);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ operator = (String) in.readObject();
+ isNegated = in.readBoolean();
+ }
+
+ public Object readResolve() {
+ return determineOperator(this.operator, this.isNegated);
+ }
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -33,6 +33,7 @@
public DroolsObjectInputStream(InputStream stream, ClassLoader classLoader) {
super(stream);
this.classLoader = classLoader;
+ this.extractorFactory = ClassFieldExtractorCache.getInstance();
}
public ClassLoader getClassLoader() {
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ContextEntry.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ContextEntry.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ContextEntry.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -1,14 +1,10 @@
package org.drools.rule;
-import java.io.Serializable;
-
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
-public interface ContextEntry
- extends
- Serializable {
+public interface ContextEntry {
public ContextEntry getNext();
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/GroupElement.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/GroupElement.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/GroupElement.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -2,13 +2,13 @@
/*
* 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.
@@ -16,7 +16,10 @@
* limitations under the License.
*/
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -25,33 +28,32 @@
import java.util.Map;
import org.drools.RuntimeDroolsException;
+import org.drools.common.Resolvable;
-public class GroupElement extends ConditionalElement {
+public class GroupElement extends ConditionalElement implements Externalizable {
- private static final long serialVersionUID = 400L;
-
public static final Type AND = new AndType();
public static final Type OR = new OrType();
public static final Type EXISTS = new ExistsType();
public static final Type NOT = new NotType();
- private Type type = null;
- private final List children = new ArrayList();
+ private Type type;
+ private List children;
- public GroupElement() {
- this( AND );
+ private GroupElement() {
}
public GroupElement(final Type type) {
this.type = type;
+ this.children = new ArrayList();
}
/**
* Adds a child to the current GroupElement.
- *
+ *
* Restrictions are:
* NOT/EXISTS: can have only one child, either a single Pattern or another CE
- *
+ *
* @param child
*/
public void addChild(final RuleConditionElement child) {
@@ -62,7 +64,7 @@
}
/**
- * Adds the given child as the (index)th child of the this GroupElement
+ * Adds the given child as the (index)th child of the this GroupElement
* @param index
* @param rce
*/
@@ -101,14 +103,14 @@
* Optimize the group element subtree by removing redundancies
* like an AND inside another AND, OR inside OR, single branches
* AND/OR, etc.
- *
+ *
* LogicTransformer does further, more complicated, transformations
*/
public void pack() {
// we must clone, since we want to iterate only over the original list
final Object[] clone = this.children.toArray();
for ( int i = 0; i < clone.length; i++ ) {
- // if child is also a group element, there may be
+ // if child is also a group element, there may be
// some possible clean up / optimizations to be done
if ( clone[i] instanceof GroupElement ) {
final GroupElement childGroup = (GroupElement) clone[i];
@@ -158,7 +160,7 @@
if ( child instanceof GroupElement ) {
final int previousSize = parent.getChildren().size();
((GroupElement) child).pack( parent );
- // in case the child also added elements to the parent,
+ // in case the child also added elements to the parent,
// we need to compensate
index += (parent.getChildren().size() - previousSize);
}
@@ -183,7 +185,7 @@
this.pack();
}
- // also pack itself if it is a NOT
+ // also pack itself if it is a NOT
} else {
this.pack();
}
@@ -192,7 +194,7 @@
/**
* Traverses two trees and checks that they are structurally equal at all
* levels
- *
+ *
* @param e1
* @param e2
* @return
@@ -238,7 +240,7 @@
/**
* Clones all Conditional Elements but references the non ConditionalElement
* children
- *
+ *
* @param e1
* @param e2
* @return
@@ -255,6 +257,7 @@
}
cloned.setType( this.getType() );
+ cloned.children = new ArrayList(); // FIXME haruki_zaemon HACK!
for ( final Iterator it = this.children.iterator(); it.hasNext(); ) {
RuleConditionElement re = (RuleConditionElement) it.next();
@@ -294,17 +297,25 @@
public String toString() {
return this.type.toString() + this.children.toString();
}
-
+
public List getNestedElements() {
return this.children;
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(type);
+ out.writeObject(children);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ type = (Type) in.readObject();
+ children = (List) in.readObject();
+ }
+
/**
* A public interface for CE types
*/
- public static interface Type
- extends
- Serializable {
+ public static interface Type {
/**
* Returns true if this CE type is an AND
@@ -341,10 +352,9 @@
private static abstract class AbstractType
implements
- Type {
+ Type,
+ Resolvable {
- private static final long serialVersionUID = 400L;
-
/**
* @inheritDoc
*/
@@ -384,6 +394,12 @@
}
return declarations;
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ }
}
/**
@@ -391,8 +407,6 @@
*/
private static class AndType extends AbstractType {
- private static final long serialVersionUID = 400L;
-
AndType() {
}
@@ -427,6 +441,9 @@
return "AND";
}
+ public Object readResolve() {
+ return AND;
+ }
}
/**
@@ -434,8 +451,6 @@
*/
private static class OrType extends AbstractType {
- private static final long serialVersionUID = 400L;
-
OrType() {
}
@@ -469,6 +484,10 @@
public String toString() {
return "OR";
}
+
+ public Object readResolve() {
+ return OR;
+ }
}
/**
@@ -476,8 +495,6 @@
*/
private static class NotType extends AbstractType {
- private static final long serialVersionUID = 400L;
-
NotType() {
}
@@ -518,6 +535,10 @@
public String toString() {
return "NOT";
}
+
+ public Object readResolve() {
+ return NOT;
+ }
}
/**
@@ -525,8 +546,6 @@
*/
private static class ExistsType extends AbstractType {
- private static final long serialVersionUID = 400L;
-
ExistsType() {
}
@@ -567,6 +586,10 @@
public String toString() {
return "EXISTS";
}
+
+ public Object readResolve() {
+ return EXISTS;
+ }
}
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -148,13 +148,16 @@
private static class LiteralContextEntry
implements
- ContextEntry {
+ ContextEntry,
+ Externalizable {
- private static final long serialVersionUID = 2621864784428098347L;
public FieldExtractor extractor;
public Object object;
public ContextEntry next;
+ private LiteralContextEntry() {
+ }
+
public LiteralContextEntry(final FieldExtractor extractor) {
this.extractor = extractor;
}
@@ -185,6 +188,17 @@
// nothing to do
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(extractor);
+ out.writeObject(object);
+ out.writeObject(next);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ extractor = (FieldExtractor) in.readObject();
+ object = in.readObject();
+ next = (ContextEntry) in.readObject();
+ }
}
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -49,11 +49,6 @@
implements
Externalizable {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
-
private static final ProtectionDomain PROTECTION_DOMAIN;
private Map invokerLookups;
@@ -126,6 +121,7 @@
if (input instanceof DroolsObjectInputStream ) {
DroolsObjectInputStream droolsStream = (DroolsObjectInputStream) input;
initClassLoader( droolsStream.getClassLoader() );
+ droolsStream.setClassLoader(this.classLoader);
} else {
initClassLoader( Thread.currentThread().getContextClassLoader() );
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Evaluator.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Evaluator.java 2007-12-23 07:01:28 UTC (rev 17378)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Evaluator.java 2007-12-23 07:53:26 UTC (rev 17379)
@@ -2,13 +2,13 @@
/*
* 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.
@@ -27,31 +27,29 @@
/**
* A public interface to be implemented by all evaluators
*/
-public interface Evaluator
- extends
- Serializable {
+public interface Evaluator {
/**
* Returns the type of the values this evaluator operates upon.
- *
+ *
* @return
*/
public ValueType getValueType();
/**
* Returns the operator representation object for this evaluator
- *
+ *
* @return
*/
public Operator getOperator();
-
+
/**
* Returns the value type this evaluator will coerce
* operands to, during evaluation. This is useful for
* operators like "memberOf", that always convert to
* Object when evaluating, independently of the source
* operand value type.
- *
+ *
* @return
*/
public ValueType getCoercedValueType();
@@ -59,27 +57,27 @@
/**
* There are evaluators that operate on fact attributes and
* there are evaluators that operato on fact handle attributes
- * (metadata).
- *
+ * (metadata).
+ *
* This method allows the evaluator to prepare the object
* to be evaluated. That includes, unwrapping the object if needed.
- *
+ *
* @param handle
* @return
*/
public Object prepareObject( InternalFactHandle handle );
-
+
/**
- * This method will extract the value from the object1 using the
+ * This method will extract the value from the object1 using the
* extractor and compare it with the object2.
* @param workingMemory TODO
- * @param extractor
+ * @param extractor
* The extractor used to get the source value from the object
* @param object1
* The source object to evaluate
* @param object2
* The actual value to compare to
- *
+ *
* @return Returns true if evaluation is successfull. false otherwise.
*/
public boolean evaluate(InternalWorkingMemory workingMemory,
More information about the jboss-svn-commits
mailing list