Re: How to create a DBMS from scratch?

From: Emmett <emmettwa_at_onebox.com>
Date: 21 Nov 2002 10:03:22 -0800
Message-ID: <e0da462e.0211211003.71d2b539_at_posting.google.com>


Andy Dingley <dingbat_at_codesmiths.com> wrote in message

Andy, you might tell us more about all those fancy buzzwords. RDF, DAML, OIL (not to be confused with the snake version I gather).

> XML is easy, but most of the data we receive (rather than create)
> isn't this well behaved. XML is structured, text is unstructured, and
> the real-world is by and large semi-structured, somewhere in the
> middle. We can represent this structure (RDF) and we can describe this
> representation (DAML) or even explain it (DAML+OIL). What we don't get
> though is prior notice when we build our application of how the data
> it receives in the future wil lbe structured. Our consumer app has to
> "make it up as it goes along" and be enormously fluid, not only about
> what it stores, but what it also permits queries upon.
>
> As it happens, I work on just this problem and have built some big and
> _efficient_ RDF triple stores on top of commercial SQL's.

I don't know about the real world. I just go with the small subset of the applications I'm fortunate enough to write. And there creating data into XML - even when it's not well structured isn't a hard task. Infact, the fact that the data doesn't have to be structured is the reason for using XML in the first place.

OK. So I'm writing in Java. And I'm using JDOM. I convert request variables
to JDOM (see example below). All data stores occur in a relational DB with a column for XML, and all data fetches return XML (JDOM Elements). Instead of JSPs each page is an XSL rendering XHTML.

...

This is what I use to convert requests into XML (JDOM) :

public abstract class Command
{

    protected HttpServletRequest request = null;

    Command() {}

    public Element Create( HttpServletRequest request ) {

        this.request = request;
        Element command = new Element("xml_data");
        Enumeration enum    = request.getParameterNames();
        while ( enum.hasMoreElements()) {
            String sKey = (String) enum.nextElement();
            String [] temp  = (String[])
request.getParameterValues(sKey);
            int iLen        = temp.length;
            for ( int j=0 ; j < iLen ; j++ ){
                String sVal     = temp[j];
                String sName    = sKey;
                if ( sName.length() > 5 &&
"cdata".equalsIgnoreCase((sName.substring(0,5)))) {
                     command.addContent(new
Element(sName).addContent(new CDATA(sVal)));
                } else {
                     command.addContent(new
Element(sName).addContent(sVal));
                }
            }
        }
        return command;

    }

    public Element Execute(Element elm) throws ChainedException {

        return elm;
    }

}

And this is a typical fetch (uses my DB code but you should get the idea) ....

    protected Element DoQuery( String sql ) throws ChainedException {

        DBConnection dbc = null;
        Element xmlData = null;
        try {
            dbc = new DBConnection();
            dbc.ProcessSQL(sql);
            xmlData = new Element("forms");
            while ( dbc.getResultSet().next() ) { // right indent to
make easy to read
int ccnt = dbc.getResultSet().getMetaData().getColumnCount(); Element form = new Element("form");
for( int i = 1 ; i <= ccnt ; i ++ )
{

    String colName =
dbc.getResultSet().getMetaData().getColumnName(i);

    String content = dbc.SQLHelper(dbc.getResultSet().getString(i));     form.addContent(new
Element(colName.toLowerCase()).addContent(content)); }
xmlData.addContent(form);

            }
        } catch ( Exception ex ) {
            throw ( new ChainedException( ex, "DoQuery failed : " +
sql ) );
        }
        finally
        {
            try {
                dbc.closeResultSet();
                dbc.closeStatement();
            } catch ( Exception ex ) {
                throw ( new ChainedException( ex, "SQL Failed : " +
sql ) );
            }
        }
        JDOM.write(xmlData);
        return xmlData;

    } Received on Thu Nov 21 2002 - 19:03:22 CET

Original text of this message