[rules-users] Drools with Hibernate, with dynamic types

Gabor Szokoli szocske at gmail.com
Thu Jan 20 09:58:10 EST 2011


Hi,

I'm gathering the requirements for an odd system project, and I have a
design idea that is centered around Drools. I'd like to hear everyones
opinion.

The project is in a really early stage of conceptual analysis, and I'm
also near the start on the winding road exploring Drools.

The requirements call for a generic service application that performs
database operations in response to service requests.
Service logic should be editable by domain experts, not programmers.
(Enter Drools Flow due to the procedural nature of the domain logic.)

Trouble is, the exact database schema, thus the entity types are not
known at compile time, only at the time of deployment. (In fact may
differ across deployments.)

So here's the idea:
At deployment time I can convert the local database schema and domain
logic description into both Drools rules/processes with type
definitions, and matching hibernate/ibatis/JPA mappings for the java
types defined via Drools.

Drools would do the runtime bytecode generation for the entities and
request objects its rules/process steps will operate on at deployment
time.
Then the ORM can instantiate the object network of entities from the
database. (a few thousand entities, not a real big database.)
All entities are inserted as facts in a forever-running session.*
At each service request, the service connector would use reflection to
create and populate a request object, and trigger a short-lived Drools
Process.
The user defined logic is executed, and if all went well, entity state
is persisted back into the database for Durability.
Servicing the requests sequentially is acceptable, so I'm not thinking
about concurrency and Isolation yet.
(I can always throw more worker threads at the problem with separate
Working Memories, coupled by the L2 cache of the ORM I guess.)

*: It's of course not critical for the KnowledgeSession to live
forever: The working memory can be re-created from the database at any
time.


Does this sound doable? Is there any obvious flaw you guys can spot
right away maybe?


The alternative would be reading the database contents into Maps
instead of typed entities with dynamically generated types, but that
would drain all the elegance out of the Drools rules:
when
	$p = PalpusztaiCheese(smell>11)
then
	modify($p) { setQA("pass"); }
end


becomes


when
	$m = Map()
	eval( "PalpusztaiChese".equals($m.get("type")) )
	eval((Integer)$m.get("smell") > 11 )
then
	modify($m) { set("QA","pass"); }
end


(A DSL could completely hide this difference though, couldn't it?)



Thanks for any ideas!

Gabor Szokoli



More information about the rules-users mailing list