Skip to content

Commit

Permalink
[KIE-792] introducing prototypes (apache#5639)
Browse files Browse the repository at this point in the history
* [KIE-792] introducing prototype dialect

* implement prototype field setting in consequence

* minor refactor

* rewrite prototype field access in consequence

* add dialect attribute to yaml rule format + test it in quarkus extension

* isolate prototypes in their own module

* introduce new public API for prototypes

* get rid of fact templates

* turn prototype dialect into a KieBase option

* implement access of map values via field notation in the mvel compiler
  • Loading branch information
mariofusco authored and rgdoliveira committed Jan 19, 2024
1 parent d94c2cc commit f512297
Show file tree
Hide file tree
Showing 137 changed files with 3,119 additions and 2,770 deletions.
18 changes: 18 additions & 0 deletions bom/drools-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,24 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-model-prototype</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-model-prototype</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-model-prototype</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<!-- Quarkus Extension -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void setEvent(boolean isEvent) {
}

@Override
public boolean isTemplate() {
public boolean isPrototype() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ public interface ObjectType

boolean hasField(String name);

boolean isTemplate();
boolean isPrototype();
}
8 changes: 4 additions & 4 deletions drools-base/src/main/java/org/drools/base/base/ValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

import org.drools.base.factmodel.traits.Thing;
import org.drools.base.factmodel.traits.Trait;
import org.drools.base.facttemplates.FactTemplate;
import org.drools.util.CoercionUtil;
import org.kie.api.prototype.Prototype;
import org.kie.api.runtime.rule.EventHandle;

public enum ValueType {
Expand Down Expand Up @@ -65,7 +65,7 @@ public enum ValueType {
ARRAY_TYPE( "Array", Object[].class, SimpleValueType.LIST ),
STRING_TYPE( "String", String.class, SimpleValueType.STRING, CoercionUtil::coerceToString ),
OBJECT_TYPE( "Object", Object.class, SimpleValueType.OBJECT ),
FACTTEMPLATE_TYPE( "FactTemplate", FactTemplate.class, SimpleValueType.UNKNOWN ),
PROTOTYPE_TYPE("Prototype", Prototype.class, SimpleValueType.UNKNOWN ),

EVENT_TYPE("Event", EventHandle.class, SimpleValueType.OBJECT ),
QUERY_TYPE("Query", DroolsQuery.class, SimpleValueType.OBJECT ),
Expand Down Expand Up @@ -141,8 +141,8 @@ public static ValueType determineValueType(final Class<?> clazz) {
}

// primitives
if ( clazz == FactTemplate.class ) {
return ValueType.FACTTEMPLATE_TYPE;
if ( clazz == Prototype.class ) {
return ValueType.PROTOTYPE_TYPE;
} else if ( clazz == DroolsQuery.class ) {
return ValueType.QUERY_TYPE;
} else if ( clazz == Character.TYPE ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.drools.base.base.AcceptsClassObjectType;
import org.drools.base.base.ObjectType;
import org.drools.base.definitions.rule.impl.RuleImpl;
import org.drools.base.facttemplates.FactTemplate;
import org.drools.base.rule.DialectRuntimeRegistry;
import org.drools.base.rule.Function;
import org.drools.base.rule.ImportDeclaration;
Expand All @@ -44,6 +43,7 @@
import org.kie.api.definition.process.Process;
import org.kie.api.definition.type.FactType;
import org.kie.api.io.Resource;
import org.kie.api.prototype.Prototype;
import org.kie.api.runtime.rule.AccumulateFunction;
import org.kie.internal.builder.KnowledgeBuilderResult;

Expand Down Expand Up @@ -98,7 +98,7 @@ public interface InternalKnowledgePackage extends KiePackage,

void addTypeDeclaration(TypeDeclaration typeDecl);

void addFactTemplate(FactTemplate factTemplate);
void addPrototype(Prototype prototype);

void addImport(ImportDeclaration importDecl);

Expand Down Expand Up @@ -141,7 +141,7 @@ public interface InternalKnowledgePackage extends KiePackage,

TypeDeclaration getTypeDeclaration(String type);

FactTemplate getFactTemplate(String name);
Prototype getPrototype(String name);

ClassLoader getPackageClassLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.drools.base.definitions.ResourceTypePackageRegistry;
import org.drools.base.definitions.rule.impl.GlobalImpl;
import org.drools.base.definitions.rule.impl.RuleImpl;
import org.drools.base.facttemplates.FactTemplate;
import org.drools.base.rule.DialectRuntimeData;
import org.drools.base.rule.DialectRuntimeRegistry;
import org.drools.base.rule.DuplicateRuleNameException;
Expand All @@ -68,6 +67,7 @@
import org.kie.api.definition.type.FactType;
import org.kie.api.io.Resource;
import org.kie.api.io.ResourceType;
import org.kie.api.prototype.Prototype;
import org.kie.api.runtime.rule.AccumulateFunction;

public class KnowledgePackageImpl
Expand Down Expand Up @@ -103,7 +103,7 @@ public class KnowledgePackageImpl

protected Map<String, Type> globals;

protected Map<String, FactTemplate> factTemplates;
protected Map<String, Prototype> prototypes;

protected DialectRuntimeRegistry dialectRuntimeRegistry;

Expand Down Expand Up @@ -151,7 +151,7 @@ public KnowledgePackageImpl(final String name) {
this.accumulateFunctions = Collections.emptyMap();
this.staticImports = Collections.emptySet();
this.globals = Collections.emptyMap();
this.factTemplates = Collections.emptyMap();
this.prototypes = Collections.emptyMap();
this.functions = Collections.emptyMap();
this.dialectRuntimeRegistry = new DialectRuntimeRegistry();
this.entryPointsIds = Collections.emptySet();
Expand Down Expand Up @@ -243,7 +243,7 @@ public void writeExternal(ObjectOutput stream) throws IOException {
out.writeObject(this.staticImports);
out.writeObject(this.functions);
out.writeObject(this.accumulateFunctions);
out.writeObject(this.factTemplates);
out.writeObject(this.prototypes);
out.writeObject(this.globals);
out.writeBoolean(this.valid);
out.writeBoolean(this.needStreamMode);
Expand Down Expand Up @@ -289,7 +289,7 @@ public void readExternal(ObjectInput stream) throws IOException,
this.staticImports = (Set) in.readObject();
this.functions = (Map<String, Function>) in.readObject();
this.accumulateFunctions = (Map<String, AccumulateFunction>) in.readObject();
this.factTemplates = (Map) in.readObject();
this.prototypes = (Map) in.readObject();
this.globals = (Map<String, Type>) in.readObject();
this.valid = in.readBoolean();
this.needStreamMode = in.readBoolean();
Expand Down Expand Up @@ -445,17 +445,16 @@ public void removeFunction(final String functionName) {
}

@Override
public FactTemplate getFactTemplate(final String name) {
return this.factTemplates.get(name);
public Prototype getPrototype(final String name) {
return this.prototypes.get(name);
}

@Override
public void addFactTemplate(final FactTemplate factTemplate) {
if (this.factTemplates == Collections.EMPTY_MAP) {
this.factTemplates = new HashMap<>(1);
public void addPrototype(final Prototype prototype) {
if (this.prototypes == Collections.EMPTY_MAP) {
this.prototypes = new HashMap<>(1);
}
this.factTemplates.put(factTemplate.getName(),
factTemplate);
this.prototypes.put(prototype.getName(), prototype);
}

/**
Expand Down Expand Up @@ -586,7 +585,7 @@ public void clear() {
this.accumulateFunctions.clear();
this.staticImports.clear();
this.globals.clear();
this.factTemplates.clear();
this.prototypes.clear();
this.typeDeclarations.clear();
this.windowDeclarations.clear();
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit f512297

Please sign in to comment.