Intercalate Logo
Intercalate is a concept, a mind set, an analytical precept.
Intercalate sifts features from uniformity, differences from similarity, value from variety.

Example 2 Intercalate as a maintenance tool  (continued)

Let's look once more at the property list and template introduced on the previous page, with models for Person and Vehicle, and their generated Java classes. Suppose we encounter a new requirement, to record where each vehicle is garaged. We create a new Garage model which identifies the location and owner of the garage, and associate it with a vehicle by adding a garage identifier to the Vehicle model.

Property List

{
 javatype = "$sql2java.type$";
 sql2java = {
  char = "String";
  number = "Integer";
 };
 tables = (
  {
   table = "Person";
   columns = (
    { column = "Name"; type = "char"; size = "100"; },
    { column = "ID"; type = "number"; primary_key = ""; }
   );
  },
  {
   table = "Vehicle";
   columns = (
    { column = "VIN"; type = "number"; primary_key = ""; },
    { column = "make"; type = "char"; size = "100"; },
    { column = "owner_ID"; type = "number"; },
    { column = "garage_ID"; type = "number"; }
   );
  },
  {
   table = "Garage";
   columns = (
    { column = "Location"; type = "char"; size = "100"; },
    { column = "owner_ID"; type = "number"; },
    { column = "ID"; type = "number"; primary_key = ""; }
   );
  }
 );
}

With no change whatsoever to the template, we can then generate the new Java class representing the garage, and at the same time update the class for the vehicle. All generated code remains synchronized with the model.

Person.java

public class Person
{
 private String Name;
 private Integer ID;

 public String getName() {
  return Name;
 }
 public Integer getID() {
  return ID;
 }
}

Vehicle.java

public class Vehicle
{
 private Integer VIN;
 private String make;
 private Integer owner_ID;
 private Integer garage_ID;

 public Integer getVIN() {
  return VIN;
 }
 public String getMake() {
  return make;
 }
 public Integer getOwner_ID() {
  return owner_ID;
 }
 public Integer getGarage_ID() {
  return garage_ID;
 }
}

Garage.java

public class Garage
{
 private String Location;
 private Integer owner_ID;
 private Integer ID;

 public String getLocation() {
  return Location;
 }
 public Integer getOwner_ID() {
  return owner_ID;
 }
 public Integer getID() {
  return ID;
 }
}

Adding a template

After your database schema and Java applications have been deployed, you discover an existing spreadsheet containing person, vehicle, and garage information. Your requirement is to find an efficient way to import this data to use with your new system. You decide to export the data from the spreadsheet into comma-delimited text files, then use a loader application to import them to the corresponding database tables. The loader requires a control file describing the parameters of each import.

With Intercalate, it's simple to add a new template to generate these control files from the existing model.

Loader template

$for tables$$write table.ctl$
options (skip=1)
load data
infile '$table(lowercase)$.csv'
append
into table $table$
fields terminated by ','
optionally enclosed by '"'
(
$for columns$ $column$$unless _last$,$end$
$end$)
$end$

With no change whatsoever to the model, we are able to generate control files to load data into all the tables in the schema.

Person.ctl

options (skip=1)
load data
infile 'person.csv'
append
into table Person
fields terminated by ','
optionally enclosed by '"'
(
 ID,
 Name
)

Vehicle.ctl

options (skip=1)
load data
infile 'vehicle.csv'
append
into table Vehicle
fields terminated by ','
optionally enclosed by '"'
(
 VIN,
 make,
 owner_ID,
 garage_ID
)

Garage.ctl

options (skip=1)
load data
infile 'garage.csv'
append
into table Garage
fields terminated by ','
optionally enclosed by '"'
(
 ID,
 Location,
 owner_ID
)

Not shown in this example, but in a similar fashion  a template can be used to create the SQL that generates these tables in the first place. All of the realizations flow from the one Property List automatically and in a  fully consistent fashion. Imagine the effort it would have taken to create and synchronize changes to each file individually. With a few tables and infrequent modifications the manual effort might be irksome, but when the schema grows to dozens of tables and the requirements are fluid, maintenance becomes a nightmare. Intercalate relieves you of that concern.
 

XML format

In addition to the property list and template formats described here, Intercalate also supports XML representations for both kinds of documents.  In fact, the two formats are completely interchangeable and can be freely mixed and matched. The Intercalate tools support conversion between them.
 
Alodar Systems