I'm interested in this topic, too and have given it a bit of
thought.  I think a good (I'll leave elegance to the eye of the
beholder) solution would have four parts: 

* a specialized version of deftemplate that specifies the database
specifics, the columns of the relation, and the key fields.

* a specialized matcher that, when encountering a "database-backed"
fact, performs a query to retrieve all matching rows. You would be
required to supply at least one value in a key field. Each row would
be turned into an assertion and then matching would proceed normally.

* a modification to assert that would send database updates when
assert and retract are called.

* a cache that managed the database-related assertions so they didn't
become too numerous. Anything purged from the cache could always be
recovered by making another select call to the database.

I'd be interested to see what the performance characteristics of such
a solution would be. You would obviously want to have as many
variables bound as possible before doing the match. A more
sophisticated version might not assert all of the matching rows at
once, but only assert them one at a time as pattern matching
proceeds. 

One problem with this solution is that it only works if JESS is the
only process that can modify the database. Otherwise, there's no way
to know if cached assertions are valid or not. For my application,
JESS would be the only database user so this would be OK. 

A general solution would be more complex. To handle the consistency
problem, you'd need a trigger that would set some kind of "dirty bit"
on the relation that has been modified, and a check in the matcher
that would test for cleanliness before used any cached information
from a relation. SQL Server has this kind of stored procedure: I'm
assuming most other databases do too. This starts to look pretty
inefficient, though, since you have to do a database call (to test the
dirty bit) every time you call the matcher.

I'm interested in other thoughts about this.

-- 

robin
=:-{)
University of California, Irvine
Information and Computer Science Dept.

http://www.ics.uci.edu/~burke/

"The universe is made of stories, not of atoms" - Muriel Rukeyser
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to