use of org.drools.core.spi.ObjectType in project drools by kiegroup.
the class PatternBuilder method getSettableProperties.
protected List<String> getSettableProperties(RuleBuildContext context, PatternDescr patternDescr, Pattern pattern) {
ObjectType patternType = pattern.getObjectType();
if (!(patternType instanceof ClassObjectType)) {
return null;
}
Class<?> patternClass = patternType.getClassType();
TypeDeclaration typeDeclaration = getTypeDeclaration(pattern, context);
if (!typeDeclaration.isPropertyReactive()) {
registerDescrBuildError(context, patternDescr, "Wrong usage of @" + Watch.class.getSimpleName() + " annotation on class " + patternClass.getName() + " that is not annotated as @PropertyReactive");
}
typeDeclaration.setTypeClass(patternClass);
return typeDeclaration.getAccessibleProperties();
}
use of org.drools.core.spi.ObjectType in project drools by kiegroup.
the class QueryTest method testDroolsQueryCleanup.
@Test
public void testDroolsQueryCleanup() throws Exception {
KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_QueryMemoryLeak.drl"));
KieSession session = createKieSession(kbase);
KieSession ksession = kbase.newKieSession();
String workerId = "B1234";
Worker worker = new Worker();
worker.setId(workerId);
FactHandle handle = ksession.insert(worker);
ksession.fireAllRules();
assertNotNull(handle);
Object retractedWorker = null;
for (int i = 0; i < 100; i++) {
retractedWorker = (Object) ksession.getQueryResults("getWorker", new Object[] { workerId });
}
assertNotNull(retractedWorker);
StatefulKnowledgeSessionImpl sessionImpl = (StatefulKnowledgeSessionImpl) ksession;
Collection<EntryPointNode> entryPointNodes = sessionImpl.getKnowledgeBase().getRete().getEntryPointNodes().values();
EntryPointNode defaultEntryPointNode = null;
for (EntryPointNode epNode : entryPointNodes) {
if (epNode.getEntryPoint().getEntryPointId().equals("DEFAULT")) {
defaultEntryPointNode = epNode;
break;
}
}
assertNotNull(defaultEntryPointNode);
Map<ObjectType, ObjectTypeNode> obnodes = defaultEntryPointNode.getObjectTypeNodes();
ObjectType key = new ClassObjectType(DroolsQuery.class);
ObjectTypeNode droolsQueryNode = obnodes.get(key);
Iterator<InternalFactHandle> it = ((ObjectTypeNodeMemory) sessionImpl.getNodeMemory(droolsQueryNode)).iterator();
assertFalse(it.hasNext());
}
use of org.drools.core.spi.ObjectType in project drools by kiegroup.
the class LogicTransformerTest method testNotExistsTransformation.
/**
* Exists inside a not is redundant and should be eliminated
*
* (Not (exists (A) ) )
*
* <pre>
* Not
* |
* Exists
* |
* And
* / \
* a b
* </pre>
*
* Should become:
*
* <pre>
* Not
* |
* And
* / \
* a b
* </pre>
*/
@Test
public void testNotExistsTransformation() throws InvalidPatternException {
final ObjectType type = new ClassObjectType(String.class);
final Pattern a = new Pattern(0, type, "a");
final Pattern b = new Pattern(1, type, "b");
final GroupElement not = GroupElementFactory.newNotInstance();
final GroupElement exists = GroupElementFactory.newExistsInstance();
final GroupElement and = GroupElementFactory.newAndInstance();
not.addChild(exists);
exists.addChild(and);
and.addChild(a);
and.addChild(b);
GroupElement[] transformed = LogicTransformer.getInstance().transform(not, Collections.EMPTY_MAP);
GroupElement wrapper = transformed[0];
GroupElement notR = (GroupElement) wrapper.getChildren().get(0);
assertTrue(notR.isNot());
assertEquals(1, notR.getChildren().size());
assertTrue(notR.getChildren().get(0) instanceof GroupElement);
GroupElement andR = (GroupElement) notR.getChildren().get(0);
assertTrue(andR.isAnd());
assertEquals(2, andR.getChildren().size());
assertTrue(andR.getChildren().get(0) instanceof Pattern);
assertTrue(andR.getChildren().get(1) instanceof Pattern);
final Pattern a1 = (Pattern) andR.getChildren().get(0);
final Pattern b1 = (Pattern) andR.getChildren().get(1);
assertEquals(a, a1);
assertEquals(b, b1);
}
use of org.drools.core.spi.ObjectType in project drools by kiegroup.
the class LogicTransformerTest method testCloneable.
@Test
public void testCloneable() {
final ObjectType type = new ClassObjectType(String.class);
final Pattern a = new Pattern(0, type, "a");
final Pattern b = new Pattern(1, type, "b");
final Pattern c = new Pattern(2, type, "c");
final Pattern d = new Pattern(3, type, "d");
final Pattern e = new Pattern(4, type, "e");
final Pattern f = new Pattern(5, type, "f");
final Pattern g = new Pattern(6, type, "g");
final Pattern h = new Pattern(7, type, "h");
// Test against a known false tree
final GroupElement and = GroupElementFactory.newAndInstance();
and.addChild(a);
and.addChild(b);
final GroupElement or = GroupElementFactory.newOrInstance();
or.addChild(c);
or.addChild(d);
and.addChild(or);
final GroupElement and2 = GroupElementFactory.newAndInstance();
and2.addChild(e);
and2.addChild(f);
or.addChild(and2);
final GroupElement not = GroupElementFactory.newNotInstance();
and.addChild(not);
final GroupElement or2 = GroupElementFactory.newOrInstance();
not.addChild(or2);
or2.addChild(g);
or2.addChild(h);
final GroupElement cloned = (GroupElement) and.clone();
assertEquals(and, cloned);
}
use of org.drools.core.spi.ObjectType in project drools by kiegroup.
the class LogicTransformerTest method testMultipleOrAndOrTransformation.
/**
* (a||b)&&c
*
* <pre>
* And
* /|\ \__
* _/ | \_ \_
* / | \ \
* or | or not
* / \ | / \ |
* a b c d e f
* </pre>
*
* Should become (a&&c)||(b&&c)
*
* <pre>
* /\
* _/ \_
* / \
* _/| |\_
* __/ | | \__
* __/ | | \__
* / | | \
* and and and and
* /||\ /||\ /||\ /||\
* a cd Not a ce Not b cd Not b ce Not
* | | | |
* f f f f
* </pre>
*/
@Test
public void testMultipleOrAndOrTransformation() throws InvalidPatternException {
final ObjectType type = new ClassObjectType(String.class);
final Pattern a = new Pattern(0, type, "a");
final Pattern b = new Pattern(1, type, "b");
final Pattern c = new Pattern(2, type, "c");
final Pattern d = new Pattern(3, type, "d");
final Pattern e = new Pattern(4, type, "e");
final Pattern f = new Pattern(5, type, "f");
final GroupElement parent = GroupElementFactory.newAndInstance();
final GroupElement or = GroupElementFactory.newOrInstance();
or.addChild(a);
or.addChild(b);
parent.addChild(or);
parent.addChild(c);
final GroupElement or2 = GroupElementFactory.newOrInstance();
or2.addChild(d);
or2.addChild(e);
parent.addChild(or2);
final GroupElement not = GroupElementFactory.newNotInstance();
not.addChild(f);
parent.addChild(not);
LogicTransformer.getInstance().applyOrTransformation(parent);
assertEquals(GroupElement.Type.OR, parent.getType());
assertLength(4, parent.getChildren());
assertEquals(GroupElement.class, parent.getChildren().get(0).getClass());
assertEquals(GroupElement.class, parent.getChildren().get(1).getClass());
assertEquals(GroupElement.class, parent.getChildren().get(2).getClass());
assertEquals(GroupElement.class, parent.getChildren().get(3).getClass());
GroupElement and1 = (GroupElement) parent.getChildren().get(0);
assertTrue(and1.isAnd());
assertLength(4, and1.getChildren());
assertEquals(a, and1.getChildren().get(0));
assertEquals(c, and1.getChildren().get(1));
assertEquals(d, and1.getChildren().get(2));
assertEquals(not, and1.getChildren().get(3));
and1 = (GroupElement) parent.getChildren().get(1);
assertTrue(and1.isAnd());
assertLength(4, and1.getChildren());
assertEquals(a, and1.getChildren().get(0));
assertEquals(c, and1.getChildren().get(1));
assertEquals(e, and1.getChildren().get(2));
assertEquals(not, and1.getChildren().get(3));
and1 = (GroupElement) parent.getChildren().get(2);
assertTrue(and1.isAnd());
assertLength(4, and1.getChildren());
assertEquals(b, and1.getChildren().get(0));
assertEquals(c, and1.getChildren().get(1));
assertEquals(d, and1.getChildren().get(2));
assertEquals(not, and1.getChildren().get(3));
and1 = (GroupElement) parent.getChildren().get(3);
assertTrue(and1.isAnd());
assertLength(4, and1.getChildren());
assertEquals(b, and1.getChildren().get(0));
assertEquals(c, and1.getChildren().get(1));
assertEquals(e, and1.getChildren().get(2));
assertEquals(not, and1.getChildren().get(3));
}
Aggregations