SMACS

smacs.find
Class InsertInto

java.lang.Object
  extended bysmacs.find.InsertInto

public class InsertInto
extends Object

derived from earlier SelinsCode - 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 InsertInto.Rule
          a compact notation to pass around parts of a SelIns rule
 
Field Summary
static String InsertIntoStatement
           
static String IntoTableClause
           
protected static Logger log
           
static String ScriptRoot
           
static String Selector
           
static String SelectStatement
           
 
Constructor Summary
InsertInto()
           
 
Method Summary
 String getRuleScript(SimpleNode tree)
          scan rules from tree and generate jdbc core script.
 Vector getSelectInsertRuleVector(SimpleNode tree)
          Rule-Vector as copied from Rules in the parsing 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 InsertInto.Rule newRuleFromInsertIntoStatement(SimpleNode statement)
          build new Rule from sql statement.
 SqlWriter newSqlWriter()
          overriding this one is the easiest way to generate some slightly different output code
 String strInsertCode(JavaWriter jj, SqlWriter qq, SimpleNode tree)
          SQL'INSERT into JDBC-string
 String strRuleScript(JavaWriter jj, SqlWriter qq, SimpleNode tree)
          generating glue code around getSelectInsertRuleVector(SimpleNode) result
 String strSelectCode(JavaWriter jj, SqlWriter qq, SimpleNode tree)
          SQL'SELECT into JDBC-string
 String strSelectInsertRule(JavaWriter jj, SqlWriter qq, InsertInto.Rule rule)
          SQL'SELECT'INSERT into JDBC-string
 String strSelectInsertRules(JavaWriter jj, SqlWriter qq, SimpleNode tree)
          parse Rules from ParsingTree and create JDBC script from all of them.
protected  String strThisClass()
          helper
static String toRuleScript(SimpleNode tree)
          scan rules from tree and generate jdbc core script.
 
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

IntoTableClause

public static final String IntoTableClause
See Also:
Constant Field Values

SelectStatement

public static final String SelectStatement
See Also:
Constant Field Values

InsertIntoStatement

public static final String InsertIntoStatement
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

InsertInto

public InsertInto()
Method Detail

newRuleFromInsertIntoStatement

public static InsertInto.Rule newRuleFromInsertIntoStatement(SimpleNode statement)
build new Rule from sql statement. May return null for invalid sql items.


getSelectInsertRuleVector

public Vector getSelectInsertRuleVector(SimpleNode tree)
Rule-Vector as copied from Rules in the parsing tree


strSelectCode

public String strSelectCode(JavaWriter jj,
                            SqlWriter qq,
                            SimpleNode tree)
SQL'SELECT into JDBC-string


strInsertCode

public String strInsertCode(JavaWriter jj,
                            SqlWriter qq,
                            SimpleNode tree)
SQL'INSERT into JDBC-string


strSelectInsertRule

public String strSelectInsertRule(JavaWriter jj,
                                  SqlWriter qq,
                                  InsertInto.Rule rule)
SQL'SELECT'INSERT into JDBC-string


strSelectInsertRules

public String strSelectInsertRules(JavaWriter jj,
                                   SqlWriter qq,
                                   SimpleNode tree)
parse Rules from ParsingTree and create JDBC script from all of them.


strThisClass

protected String strThisClass()
helper


strRuleScript

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


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)
scan rules from tree and generate jdbc core script.

strRuleScript(smacs.find.JavaWriter, smacs.tree.SqlWriter, smacs.tree.SimpleNode)


toRuleScript

public static String toRuleScript(SimpleNode tree)
scan rules from tree and generate jdbc core script.

getRuleScript(smacs.tree.SimpleNode)


main

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


SMACS