Re: elegent way to handle "pluggable" backend servers?

From: Steven Lembark (lembark_at_wrkhors.com)
Date: 02/27/05


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


Relevant Pages

  • Re: OT: why do web BBSs and blogs get so slow?
    ... As a result I've poked around in the Slashdot SQL ... the list of stories itself, but there are also lists of subsections (Apache, ... > be a fixed length of metadata for each message, ...
    (comp.lang.python)
  • Re: Which one is faster: IMAP server or MySQL server?
    ... I see it has a comment about Zimbra storing metadata to SQL and message ... actually more about metadata than bodies. ... Implementing a well performing IMAP server is mostly about minimizing ...
    (comp.mail.imap)
  • RE: Importing several text file into several tables
    ... Are you using SQL 2000 and DTS? ... How would you handle it if you package only processed one single ... I have many text files on a folder with the same metadata and I need to ... (the format of the files is not known but they have the same format) ...
    (microsoft.public.sqlserver.dts)
  • Re: Documents in SQL Server
    ... You would need to use a SqlBinary reader or something in a .NET ... any tools in SQL or Query Analyzer to do this). ... > update -- I see metadata in the Docs table, ... > "nancyk" wrote in message ...
    (microsoft.public.sharepoint.portalserver)