lunedì 27 novembre 2006

Method invocation in queries

In my object persistence engine I expect to be able to submit queries which can call methods on the stored objects:


SELECT Class c WHERE c.method();


Let's try to classify methods by their arguments, return values and side effects: the simplest kind of method I can use in a query is a “const” method (a method which doesn't modify the internal state of the objects) which returns a boolean and doesn't expect any argument. Such a method can be easily and safely be invoked during query execution, as it doesn't modify the object and is quite easy to evaluate. Methods that return something different from a boolean value, could cause problems during the evaluation of the WHERE clause. Also, methods expecting arguments could be difficult to evaluate as the query engine needs a mechanism to choose what argument to pass. But the most problematic type of method is the “non-const”, which modifies its internal state during the execution: this could require the query to re-evaluate some previously evaluated objects, or if the evaluated object modifies some other related object contained in the database could cause a cascade update, which could be difficult to handle. And, even worse, a method could throw an exception! But how to handle it?

  • Constness: if not const, could cause cascade modifications on the persistence layer
  • Return value: if not boolean (or primitive) could cause difficult evaluation
  • Arguments: if needed, could cause difficulties for the query engine to choose which
  • Exceptions: could cause difficulties in the execution thread

1 commento:

Anonimo ha detto...

quello che stavo cercando, grazie