SMACS

smacs.find
Class InsertFrom

java.lang.Object
  extended bysmacs.find.InsertFrom
Direct Known Subclasses:
InsertFromTree

public class InsertFrom
extends Object

derived from earlier {link smacs.find.Selins}. - described as follows...

The usual way to transfer data from one database to another is in using a combination of SELECT (to get some records) with an INSERT (to put some records) in an sql statement. In actual essence a VIEW definition will look very similar which we will be checking for in another place. Here we want to be able to scan real world (handwritten) code for transfer rules - so we can implant them later into a larger schema mapping application.

Essentially, we try to find (a) an sql statement (b) with both an INSERT and SELECT subrule (c) which are embedded and close to each other - after having detected it we want to (x) split the embedded SELECT subrule getter from the INSERT setter part (y) create a jdbc/sqlj database cursor with the getter subrule and (z) create a java loop that execs an INSERT on the target for each record current on the cursor created with the SELECT.

The real compiler generation is being done in another part of this project. The example executions in here will handle very simple variants with a known set of statements in a known example transfer script. Let's try to keep it simple here to let a later developer know the code flow of the project ;-)

Author:
Copyright (C) 2004, Guido Draheim. All rights reserved. Part of SMACS project.

Nested Class Summary
static class InsertFrom.Rule
          a compact notation to pass around parts of a SelIns rule
 
Field Summary
static String FromClause
           
static String InsertFromStatement
           
static String InsertIntoClause
           
static String IntoTableClause
           
protected static Logger log
           
static String ScriptRoot
           
static String Selector
           
static String SelectWhereClause
           
static String WhereClause
           
 
Constructor Summary
InsertFrom()
           
 
Method Summary
 String getRuleScript(SimpleNode tree)
          generating glue code around getRules() javacode
 Vector getSelectInsertRuleVector(SimpleNode tree)
           
static void main(String[] args)
          self test
 JavaWriter newJavaWriter()
          overriding this one is the easiest way to generate some slightly different output code
static Vector newRuleFromInsertFromStatement(SimpleNode statement)
          build new Rule(s) from sql statement.
 SqlWriter newSqlWriter()
          overriding this one is the easiest way to generate some slightly different output code
 String strFromTableCode(JavaWriter jj, SqlWriter qq, SimpleNode tree)
           
 String strIntoTableCode(JavaWriter jj, SqlWriter qq, SimpleNode tree)
           
 String strRuleScript(JavaWriter jj, SqlWriter qq, SimpleNode tree)
          generating glue code around getRules() javacode
 String strSelectCode(JavaWriter jj, SqlWriter qq, SimpleNode tree)
           
 String strSelectInsertRule(JavaWriter jj, SqlWriter qq, InsertFrom.Rule rule)
           
 String strSelectInsertRules(JavaWriter jj, SqlWriter qq, SimpleNode tree)
           
 String strWhereCode(JavaWriter jj, SqlWriter qq, SimpleNode tree)
           
static String toRuleScript(SimpleNode tree)
          generating glue code around getRules() javacode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final Logger log

InsertFromStatement

public static final String InsertFromStatement
See Also:
Constant Field Values

SelectWhereClause

public static final String SelectWhereClause
See Also:
Constant Field Values

WhereClause

public static final String WhereClause
See Also:
Constant Field Values

FromClause

public static final String FromClause
See Also:
Constant Field Values

InsertIntoClause

public static final String InsertIntoClause
See Also:
Constant Field Values

IntoTableClause

public static final String IntoTableClause
See Also:
Constant Field Values

ScriptRoot

public static final String ScriptRoot
See Also:
Constant Field Values

Selector

public static final String Selector
See Also:
Constant Field Values
Constructor Detail

InsertFrom

public InsertFrom()
Method Detail

newRuleFromInsertFromStatement

public static Vector newRuleFromInsertFromStatement(SimpleNode statement)
build new Rule(s) from sql statement. May return null for invalid sql items.


getSelectInsertRuleVector

public Vector getSelectInsertRuleVector(SimpleNode tree)

strIntoTableCode

public String strIntoTableCode(JavaWriter jj,
                               SqlWriter qq,
                               SimpleNode tree)

strFromTableCode

public String strFromTableCode(JavaWriter jj,
                               SqlWriter qq,
                               SimpleNode tree)

strSelectCode

public String strSelectCode(JavaWriter jj,
                            SqlWriter qq,
                            SimpleNode tree)

strWhereCode

public String strWhereCode(JavaWriter jj,
                           SqlWriter qq,
                           SimpleNode tree)

strSelectInsertRule

public String strSelectInsertRule(JavaWriter jj,
                                  SqlWriter qq,
                                  InsertFrom.Rule rule)

strSelectInsertRules

public String strSelectInsertRules(JavaWriter jj,
                                   SqlWriter qq,
                                   SimpleNode tree)

strRuleScript

public String strRuleScript(JavaWriter jj,
                            SqlWriter qq,
                            SimpleNode tree)
generating glue code around getRules() javacode


newJavaWriter

public JavaWriter newJavaWriter()
overriding this one is the easiest way to generate some slightly different output code


newSqlWriter

public SqlWriter newSqlWriter()
overriding this one is the easiest way to generate some slightly different output code


getRuleScript

public String getRuleScript(SimpleNode tree)
generating glue code around getRules() javacode


toRuleScript

public static String toRuleScript(SimpleNode tree)
generating glue code around getRules() javacode


main

public static void main(String[] args)
self test


SMACS