400 likes | 471 Views
Intercalate. Modeling with Templates. Alodar Systems, Inc. The Object Explosion. Domain Objects + Views = Representations. Gene. SQL. Target. O/R Mapping. Sequence. Molecule. Java. Order. HTML. Scientist. etc. The Intercalate Process. Modeling Production. Dictionary.
E N D
Intercalate Modeling with Templates Alodar Systems, Inc.
The Object Explosion Domain Objects + Views = Representations Gene SQL Target O/R Mapping Sequence Molecule Java Order HTML Scientist etc.
The Intercalate Process • Modeling • Production Dictionary Prototype Template Dictionary Result Template
Intercalate Benefits • Structured representation of domain • Powerful expression semantics • Synchronization • Maintainability and reuse
Structured Representation • Template$key$ • Dictionarykey = value; • Resultvalue
Powerful Semantics • For Iterate over a list • If Test condition • Unless Test negated condition • Write Redirect output • Include Redirect input
Synchronization • If a domain object changes, all its representations change with it. • If a template changes, all domain objects immediately incorporate the new functionality. • Inadvertent editing errors are eliminated • Object representations remain consistent
Maintainability and Reuse • Corrections to domain objects or templates are automatically distributed throughout the system • New domain objects can be added and immediately function in all contexts • New templates can be added and all domain objects immediately work in the new context
Building a Template • The initial template is an example of the desired output • Move values from template to dictionary, leaving keys behind as place holders • Add control keywords to iterate over lists and generate text conditionally • Add directives to redirect output and input.
Identify occurrences of the table name • Prototypecreate table Person ( Name char(100), ID number);alter table Person add primary key (ID);
Insert the table name in the model dictionary • Dictionarytable = Person;
Replace the table name with its dictionary key • Templatecreate table $table$ ( Name char(100), ID number);alter table $table$ add primary key (ID);
Identify attributes of the first column • Templatecreate table $table$ (Namechar(100), ID number);alter table $table$ add primary key (ID);
Insert column attributes in the dictionary • Dictionarytable = Person;column = Name;type = char;size = 100;
Replace column attributes with dictionary keys • Templatecreate table $table$ ($column$$type$($size$), ID number);alter table $table$ add primary key (ID);
Identify attributes of the second column • Templatecreate table $table$ ($column$$type$($size$),IDnumber);alter table $table$ add primary key (ID);
Make a list of columns in the dictionary • Dictionarytable = Person;columns = ( {column = Name; type = char; size = 100;}, {column = ID; type = number;});
Iterate over the entries in the columns list • Templatecreate table $table$ ($for columns$$column$$type$($size$),$end$);alter table $table$ add primary key (ID);
Not all columns can use the same template Shouldn’t have parentheses or comma • Resultscreate table Person ( Name char(100), ID number(),);alter table Person add primary key (ID);
Test conditions to produce text only when needed • Templatecreate table $table$ ($for columns$$column$$type$$if size$($size$)$end$$unless _last$,$end$$end$);alter table $table$ add primary key (ID);
What We’ve Learned • Move values to the dictionary • Insert keys in the template • Iterate over a list of entries $for key$ … $end$ • Test conditions$if key$ … $end$$unless key$ … $end$
Identify special usage of one or more columns • Templatecreate table $table$ ($for columns$$column$$type$$if size$($size$)$end$$unless _last$,$end$$end$);alter table $table$ add primary key (ID); Primary key
Indicate special usage in the dictionary • Dictionarytable = Person;columns = ( {column = Name; type = char; size = 100;}, {column = ID; type = number;primary_key = ;});
Restrict iteration using the special key • Templatecreate table $table$ ( … );alter table $table$ add primary key ($for columns(select primary_key)$$column$$unless _last$, $end$$end$);
Test a condition having nested keys • Templatecreate table $table$ ( … );$if columns.primary_key$alter table $table$ add primary key ($for columns(select primary_key)$$column$$unless _last$, $end$$end$);$end$
What We’ve Learned (2) • Indicate special usage with a distinct key • Restrict iteration $for key(select subkey)$ … $end$ • Test nested conditions$if key1.key2$ … $end$
A Java example • Prototypepublic class Person { private String Name; private Integer ID; public String getName() { return Name; } public Integer getID() { return ID; }}
Build a Java template • Templatepublic class $table$ {$for columns$ private $javatype$$column$;$end$$for columns$ public $javatype$ get$column$() { return $column$; }$end$}
Create a lookup table for the Java data type • Dictionaryjavatype = $sql2java.type$;sql2java = { char = String; number = Integer;};table = Person;columns = ( … );
Override general defaultin special cases • Dictionaryjavatype = $sql2java.type$;…table = Person;columns = ( ... {column = ID; type = number; primary_key = ;javatype = BigInteger; });
What We’ve Learned (3) • Use a dictionary with a new template • Use a lookup table for systematic translation of values • Override default values in special cases
Make a list of tables in the dictionary • Dictionarytables = ( {table = Person; … }, {table = Vehicle; columns = ( {column = VIN; … }, {column = make; … }, {column = owner_id; … } ); });
Create SQL for tables in the tables list • Template$for tables$create table $table$ ( … );$if columns.primary_key$alter table $table$ add primary key ( … );$end$$end$
Create Java for tablesin the tables list • Template$for tables$public class $table$ {…}$end$
Each Java class goes in its own file • Template$for tables$$write table.java$public class $table$ {…}$end$$write$
Include other templates • Template$for tables$$write table.java$public class $table$ {…$include table.extras$}$end$$write$
What We’ve Learned (4) • Nested iteration • Redirect output to one or more files$write key.ext$ • Restore output to standard out$write$ • Import other templates$include key.ext$
The Intercalate Process • The initial template is an example of the desired output • Move values from template to dictionary, leaving keys behind as place holders • Add control keywords to iterate over lists and generate text conditionally • Add directives to redirect output and input.
Intercalate Benefits • Structured representation of domain • Powerful expression semantics • Synchronization • Maintainability and reuse
Additional Resources • Alodar Systems, Inc.19616 Redbeam AvenueTorrance, California 90503 • Voice: 310-370-4557 • Fax: 310-371-4103 • Email: info@alodar.com