Use Case: Building a database

Abstract

DataClass is a compiler that let's you organize and test the instructions for building a database into source files and then converts those source files into a .NET assembly or a java JAR file. Among other things, the resulting assembly (or JAR file) knows how to construct a database. It is the developer's responsibility to integrate those classes into their deployment mechanism of choice. You do not need to build both a JAR file and a DLL in order to build a database - you only need one. However, in this example, we will build both so that you can see how to use your platform of choice.

Body

Imagine you want to build the following database using DataClass:

CREATE TABLE Tacos(Cheese BIT, Meat BIT, Lettuce BIT);
        

The first step is to wrap it in a database class. We'll start by stubbing out the class itself:

You can click on keywords and concepts in blue.
// TacoDB.dbc
handdatabase TacoDB { }

Next, compile that file using DataClass:

dbcc /license license.txt /dll Database.dll /jar database.jar TacoDB.dbc

That will produce a file named "Database.dll" with a class in it named "TacoDB." It will also produce a JAR file ("database.jar") with a class of the same name. Now it's time to add a version with some construction logic in it to build your database.

You can click on keywords and concepts in blue.
// TacoDB.dbc
handdatabase TacoDB
{
  version 1.0 : initialized
  {
    construction
    {
      step sql { CREATE TABLE Tacos(Cheese BIT, Meat BIT, Lettuce BIT); }
    }
  }
}

Recompiling will produce a new Database.dll and JAR file with a new TacoDB class in it. To build a database, you will need to write some .NET code along the lines of the following:

// get a connection to the target database
var connection = GetAdoNetConnection();

// get the TacoDB database builder
var tacoDBBuilder = TacoDB.GetInstance();

// upgrade the target database instance to the current version of TacoDB
tacoDBBuilder.BuildToCurrentVersion(connection);

DotNetClient.cs

Or you can use Java code along the lines of what follows:

// get a connection to the target database
Connection connection = getJDBCNetConnection();

// get the TacoDB database builder
TacoDB tacoDBBuilder = TacoDB.getInstance();

// upgrade the target database instance to the current version of TacoDB
tacoDBBuilder.buildToCurrentVersion(connection);

JavaClient.cs

Most commonly, this code would be written in an EXE that had some means of discovering the appropriate connection string. This little bit of infrastructure costs almost nothing to write and only has to be written once per deployment mechanism. As you improve the TacoDB database, your database upgrade tool will automatically benefit from your changes.

Related Concepts

Related Keywords

Other Actions

documentation | all examples | use cases | concepts | keywords