Board index » delphi » PD-DM Query Interface

PD-DM Query Interface

Since the PD object shouldn't know anything about the DM interface, but
needs to be able to query values from the database, what is the "right" OO
method for handling user queries?

Example:
    TCustomer = class(TPDObject)
    public
        constructor Create; // Creates a blank customer
        procedure FindByName(Name: string); // Should I do this?
        procedure Find(Criteria: string); // Or this?
    end;

and given the above, since the PD object should know nothing about the
database (DM object), then how does the PD object pass the query to the DM
object to get data?

Is there a better way or examples of how to accomplish this?

I've thought about using an separate "lookup" class, unique to each
PDObject, but that seems a little clunky and I'd like to keep the interface
clean so that I can just call Person.FindByLastName('Bubba');  Putting
multiple search criteria is also a little problem.  If I want to search by
first AND last name, the "FindByLastName" method won't really cut the
mustard.

I envision a query class (TPDQuery?) that has "properties" and "values"
added to it for search criteria.  Something like this...

TPDQueryFunction = (qAND, qOR, qNOT);
procedure TPDQuery.Select(Function: TPDQueryFunction; const Property:
string; const Value: Integer); overload;
procedure TPDQuery.Select(Function: TPDQueryFunction; const Property:
string; const Value: string); overload;
procedure TPDQuery.Select(Function: TPDQueryFunction; const Property:
string; const Value: TDateTime); overload;

This object could be created and passed to a generic "Find" interface of the
PD Object, which would work.  I'm just not quite sure which direction is the
right way to go.

Comments?

Eric

 

Re:PD-DM Query Interface


Quote
Eric Hill <e...@ijack.net> wrote in message news:3c501cb3_1@dnews...
> Since the PD object shouldn't know anything about the DM interface, but
> needs to be able to query values from the database, what is the "right" OO
> method for handling user queries?

> Example:
>     TCustomer = class(TPDObject)
>     public
>         constructor Create; // Creates a blank customer
>         procedure FindByName(Name: string); // Should I do this?
>         procedure Find(Criteria: string); // Or this?
>     end;

> and given the above, since the PD object should know nothing about the
> database (DM object), then how does the PD object pass the query to the DM
> object to get data?

Eric

First, I don't believe that the PDO should know nothing about the DM. It
does not need to know any details of the DM, but it must know of a common
interface into the DM object. Any descendents of the root DM must implement
this interface.

In answer to your question, the most common method would be to create these
same methods in the DM and simply pass the call through. For example, in the
FindByName method of the PDO:

procedure TPDO.FindByName(const Name: string);
begin
    DM.LoadByName(Name);
end;

The DM then implements the actual search and load. The PDO should not know
how to search, that is the job of the DM.

One final thought, you might consider changing the Find procedures to
functions so that the PDO can signal success or failure.

function TPDO.FindByName(const Name: string): boolean;
begin
    Result := DM.LoadByName(Name);
end;

HTH
Jeff Eib
www.GarrettLiners.com

Re:PD-DM Query Interface


Quote
"Eric Hill" <e...@ijack.net> wrote in message news:3c501cb3_1@dnews...
> Since the PD object shouldn't know anything about the DM interface, but
> needs to be able to query values from the database, what is the "right" OO
> method for handling user queries?

> Example:
>     TCustomer = class(TPDObject)
>     public
>         constructor Create; // Creates a blank customer
>         procedure FindByName(Name: string); // Should I do this?
>         procedure Find(Criteria: string); // Or this?
>     end;

> and given the above, since the PD object should know nothing about the
> database (DM object), then how does the PD object pass the query to the DM
> object to get data?

> Is there a better way or examples of how to accomplish this?

Well, I'd say modeling a Customer in UML with no search operations, and then
designing a query dialog where users can specify whatever search criteria
they need. Then collect the criteria into an OCL expression
(Customer.allInstances->select(name='%s' and age = %d), evaluate it (either
in core or by utilizing the capabilities of the DB backend) and receive a
list of customers that can be displayed in the GUI.

All this can be done without letting anyone know too much, and actually with
very little coding in the product Bold for Delphi (www.boldsoft.com).

Best regards,

Jesper Hogstrom
Boldsoft

Other Threads