Re: elegent way to handle "pluggable" backend servers?
From: Steven Lembark (lembark_at_wrkhors.com)
Date: 02/27/05
- Next message: Susan Lam: "parsing a file"
- Previous message: Bill Kurland: "ODBC Transaction Processing"
- In reply to: Jon Lapham: "elegent way to handle "pluggable" backend servers?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 26 Feb 2005 18:53:16 -0500 To: lapham@jandr.org, dbi-users@perl.org
> Any opinions? Is there another approach that I should think about? Has
> anyone encountered this situation before?
For most selects it isn't that hard to turn metadata
about the query into vendor SQL. The simplest fix may
be hiding the queries behind another object that takes
in generic selects and spits out SQL appropriate for
the particular DBD::Foobar.
I should have an alpha version of Plugin::Installer and
Plugin::Language::DML avaialble in a week. The plugins
could be various collections of metadata indexed by common
names (a.k.a. hash keys). You then use something like:
my $dblink = $dbhandler_class->construct;
...
$dblink->frobnicate( @argz );
With the various handler classes defining the
metadata-to-query handler for that particular
database. You only store the metadata once,
the if-logic is isolated into a single place.
That can easily be shoved into a single factory
class:
sub construct
{
shift;
my $connect_meta = shift;
my $handler_class =
do
{
if( ... )
{
'Oracle::Query'
}
elsif( ... )
{
'MySQL::Query'
}
else
{
croak "Bogus query: unable to determine class from:",
@$connect_meta;
}
};
# caller gets back whatever the appropriate
# class constructs with the connection data.
$handler_class->construct( @$connect_meta );
}
The handler classes all implement a few hooks like
"run_query" and "commit":
my $handler = Factory->construct;
...
$handler->run_query( query_name => [ query argz ] );
$handler->commit;
The run_query could either construct SQL from scratch
or munge ANSI to handle special cases.
-- Steven Lembark 85-09 90th Street Workhorse Computing Woodhaven, NY 11421 lembark@wrkhors.com 1 888 359 3508
- Next message: Susan Lam: "parsing a file"
- Previous message: Bill Kurland: "ODBC Transaction Processing"
- In reply to: Jon Lapham: "elegent way to handle "pluggable" backend servers?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|