Re: Decline of Science: Computer Science and Databases
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"
And again:
Human language is object-oriented.
It cetainly is not relational.
Kind regards,
Carl
-- Carl Rosenberger db4o - database for objects - http://www.db4o.comReceived on Fri Nov 08 2002 - 23:05:54 CET