Re: Decline of Science: Computer Science and Databases

From: Carl Rosenberger <carl_at_db4o.com>
Date: Fri, 8 Nov 2002 23:05:54 +0100
Message-ID: <aqhc1j$9jj$02$1_at_news.t-online.com>


Lauri Pietarinen wrote:
> OK, how would you make a query that retrieves data
> from several tables (or objects) at once.

In OO-speech you would call it "classes" or "interfaces". Query q;

q.constrain(YourClass1.class);
q.constrain(YourClass2.class);
...

Add as many as you wish.

> How would you formulate the following SQL-queries:

...
[group by and sum()]
...

The way we have set up S.O.D.A. for a start, it is only possible to retrieve objects of existing classes and it is not supported to aggregate values or rearrange object members to new structures.

Working in OO, it is common to use less dynamic data generation and more business logic that executes while you modify objects. For your example it would be a typical approach to store a summation object with the customer that knows the sums, even before the query is executed.

Of course you have made a nice point:
Summations and groups like the example that you have posted will need to be a feature for S.O.D.A., if we want to use it as a basis to build an SQL query parser on top.

I don't want to bore you with a workaround that would currently be possible already:
You could store a reference to a "query data collector" object with every customer and update it in an Evaluation. The code would not look nice.

Let's quickly construct a design on the fly as a brainstorm for possible future S.O.D.A. functionality:

// Internal implementation class to support abstract class Group extends Vector implements Evaluation{   void first(Candidate candidate){
  }
  void last(Candidate candidate){

    // internal db implementation:
    // use reflection to take a snapshot of all declared
    // variables and add() an entry to this Vector
  }
}

Query q = db.query();

q.constrain(Order.class);
q.descend("customer").groupBy().orderAscending();
q.descend("product").groupBy();

Group group = new Group(){
  String customerName;
  String productName;
  int totalQuantity;
  double totalPrice;

  void first(Candidate candidate){
    Order order = (Order)candidate;
    customerName = order.customer.name;
    productName = oder.product.name;
  }

  void evaluate(Candidate candidate){
    Order order = (Order)candidate;
    totalQuantity += order.quantity;
    totalPrice += order.quantitiy * order.product.price;   }
}

q.constrain(group);
q.execute();

> How do you express integrity constraints? Say
> "every order must belong to a customer and have
> a valid product"

We want to do this by using patterns:

Order order = new Order();
order.customer = new Customer();
order.product = new Product();

db.configure().ensureIntegrity(order);

This is only design yet also.
Example patterns like the above will be used for:

- instantiating objects
- updating objects
- refreshing objects
- deep deletes
- locking
- fetch groups, for better C/S performance


[human language as an example for the ideal programming language]
> > You build up a temporary context of small "objects" and
> > refer to them in subsequent "methods". The "object" context
> > is temporary and get's overridden by subsequent "objects"
> > that overload meanings.

>

> Funny thing though that modern mathematics is 100% based
> on the notion of sets and relations. I think computer systems
> have more to do with mathematics than with natural
> language.

You may be right for computers but computer programs are still written by humans and not by computers.

Human language as in speech is the most powerful language we have invented so far. If we can get computers to understand it, we will be more efficient programmers.

And again:
Human language is object-oriented.
It cetainly is not relational.

Kind regards,
Carl

--
Carl Rosenberger
db4o - database for objects - http://www.db4o.com
Received on Fri Nov 08 2002 - 23:05:54 CET

Original text of this message