org.sandev.generator
Class SQLQueryProcessorGenerator

java.lang.Object
  extended byorg.sandev.generator.GeneratorCommon
      extended byorg.sandev.generator.AggregateGeneratorBase
          extended byorg.sandev.generator.AggregateMappedGeneratorBase
              extended byorg.sandev.generator.SQLQueryProcessorGenerator
All Implemented Interfaces:
org.sandev.sandbuild.SandGenerator

public class SQLQueryProcessorGenerator
extends AggregateMappedGeneratorBase
implements org.sandev.sandbuild.SandGenerator

Generate the query processor.


Field Summary
 
Fields inherited from class org.sandev.generator.AggregateMappedGeneratorBase
structmap, structPrefix
 
Fields inherited from class org.sandev.generator.AggregateGeneratorBase
extra
 
Fields inherited from class org.sandev.generator.GeneratorCommon
CONTEXT_CONFIGURATION, CONTEXT_CONTROL, CONTEXT_FRAMEWORK, CONTEXT_MESSAGING, CONTEXT_PERSISTENCE, CONTEXT_UI, DEFAULT_LINE_LENGTH, MESSAGE_INTERFACES
 
Constructor Summary
SQLQueryProcessorGenerator()
           
 
Method Summary
protected  void dumpFields(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, java.lang.String name, boolean recursiveCall)
          If recursiveCall is false, then we have no trailing comma after the last field.
protected  void dumpJoinExpr(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, com.sun.javadoc.FieldDoc fduid, boolean recursiveCall)
          This is the join statement being inserted after a "WHERE", and we are working off a "preceding AND" model when creating conditions.
protected  void dumpRefArrayFills(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, java.lang.String name)
          Dump out the reference array population code.
protected  void dumpResultSetCalls(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, java.lang.String name, boolean trailingComma)
           
protected  void dumpTables(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, boolean recursiveCall)
          If recursiveCall is false, then we have no trailing comma after the table name.
protected  com.sun.javadoc.ClassDoc findClassDocForName(java.lang.String name)
          Return the ClassDoc corresponding to the reference name.
static com.sun.javadoc.ClassDoc findFieldOwnerClassDoc(com.sun.javadoc.ClassDoc cd, com.sun.javadoc.FieldDoc fd)
          Return the ClassDoc this field is actually part of, within the inheritance tree of the given ClassDoc.
protected  com.sun.javadoc.FieldDoc findUniqueIDField(com.sun.javadoc.FieldDoc[] fields)
           
protected  java.lang.String getFileSpec(java.io.File baseDir)
          Return "gen_base/src/org/sandev/tools/JDBC/QueryProcessor.java" or the equivalent filespec for the given platform.
protected  boolean isAbstractPersistentClass(java.lang.String name)
          Return true if the given name is an abstract persistent class.
protected  void writeArrayFieldSetterCall(java.io.PrintStream out, com.sun.javadoc.FieldDoc fd)
           
protected  void writeClassSubselect(java.io.PrintStream out, com.sun.javadoc.ClassDoc[] classes)
           
protected  void writeCollBuilder(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, java.lang.String name)
           
protected  void writeDoQuery(java.io.PrintStream out, com.sun.javadoc.ClassDoc[] classes)
           
protected  void writeFile(java.io.PrintStream out, org.sandev.sandbuild.SandDecl[] decls)
          Write the SchemaVerifier source file
protected  void writeGetAggregateFunctionSQL(java.io.PrintStream out)
           
protected  void writeLoadRefArray(java.io.PrintStream out)
           
protected  void writeMatchExprToSQL(java.io.PrintStream out)
           
protected  void writePostamble(java.io.PrintStream out)
          Write the end of the file.
protected  void writePreamble(java.io.PrintStream out, org.sandev.sandbuild.SandDecl[] decls)
           
protected  void writeQueryProc(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, java.lang.String name)
           
protected  void writeSetFunctionResult(java.io.PrintStream out)
           
protected  void writeSQLGenerator(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, java.lang.String name)
          Write the base SQL.
protected  void writeSQLPreamble(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, java.lang.String name)
           
protected  void writeStreamTokerMethods(java.io.PrintStream out)
           
protected  void writeSubselectClauseMapDecls(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, com.sun.javadoc.FieldDoc[] fields)
          Here we are writing out maps for each of the reference fields the query could possibly refer to.
protected  void writeSubselectClauseProcessing(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, com.sun.javadoc.FieldDoc[] fields)
          Here we are populating our reference maps with any references to them.
protected  void writeSubselectClauseSubselect(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, com.sun.javadoc.FieldDoc[] fields, java.lang.String name)
          Here we write the subselects based on the contents of the maps we have declared and populated earlier.
protected  void writeUtils(java.io.PrintStream out)
           
protected  void writeWorkingMethods(java.io.PrintStream out, org.sandev.sandbuild.SandDecl[] decls)
           
 
Methods inherited from class org.sandev.generator.AggregateMappedGeneratorBase
getMappedFieldName, getMappedFieldRelation, getMappedFieldRelationChild, getMappedFieldRelationIndex, getMappedFieldRelationParent, getMappedFieldType, getMappedStructName, loadStructMapper, loadStructMapper
 
Methods inherited from class org.sandev.generator.AggregateGeneratorBase
addSandAttrValToDecls, cleanup, cleanupSecondaryFiles, generate, getExtra, setExtra, writeSecondaryFiles
 
Methods inherited from class org.sandev.generator.GeneratorCommon
capitalize, copyfile, deletefile, filterHTMLLine, getDeclaredFields, getFields, getInheritanceHierarchy, getLastAppProject, getLastUtilDir, getLongInstanceName, getPrintStream, getSandProject, getShortInstanceName, getUtilPackage, getVisibleFields, isBasic, isLongReferenceArray, isMessageInterface, isParentAbstract, isPrimitive, isRootStruct, isVowel, log, nextToken, pluralize, rangeEscape, removePlatformDecls, trackFileDelete, trackFileWrite, uncapitalize, writeDefaultCtor, writeDescription, writeHTMLContents, writeMessageImports, writeSectionName, writeStandardCommentID, writeXHTMLFooter, writeXHTMLFooter, writeXHTMLHeader, writeXHTMLHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.sandev.sandbuild.SandGenerator
cleanup, generate
 

Constructor Detail

SQLQueryProcessorGenerator

public SQLQueryProcessorGenerator()
Method Detail

findClassDocForName

protected com.sun.javadoc.ClassDoc findClassDocForName(java.lang.String name)
Return the ClassDoc corresponding to the reference name.


isAbstractPersistentClass

protected boolean isAbstractPersistentClass(java.lang.String name)
Return true if the given name is an abstract persistent class.


getFileSpec

protected java.lang.String getFileSpec(java.io.File baseDir)
Return "gen_base/src/org/sandev/tools/JDBC/QueryProcessor.java" or the equivalent filespec for the given platform.


writeFile

protected void writeFile(java.io.PrintStream out,
                         org.sandev.sandbuild.SandDecl[] decls)
                  throws org.sandev.sandbuild.SandGeneratorException
Write the SchemaVerifier source file

Throws:
org.sandev.sandbuild.SandGeneratorException

writePreamble

protected void writePreamble(java.io.PrintStream out,
                             org.sandev.sandbuild.SandDecl[] decls)

writePostamble

protected void writePostamble(java.io.PrintStream out)
Write the end of the file.


writeWorkingMethods

protected void writeWorkingMethods(java.io.PrintStream out,
                                   org.sandev.sandbuild.SandDecl[] decls)
                            throws org.sandev.sandbuild.SandGeneratorException
Throws:
org.sandev.sandbuild.SandGeneratorException

writeDoQuery

protected void writeDoQuery(java.io.PrintStream out,
                            com.sun.javadoc.ClassDoc[] classes)
                     throws org.sandev.sandbuild.SandGeneratorException
Throws:
org.sandev.sandbuild.SandGeneratorException

writeQueryProc

protected void writeQueryProc(java.io.PrintStream out,
                              com.sun.javadoc.ClassDoc cd,
                              java.lang.String name)
                       throws org.sandev.sandbuild.SandGeneratorException
Throws:
org.sandev.sandbuild.SandGeneratorException

dumpRefArrayFills

protected void dumpRefArrayFills(java.io.PrintStream out,
                                 com.sun.javadoc.ClassDoc cd,
                                 java.lang.String name)
Dump out the reference array population code. While other methods only call to retrieve inherited fields when the parent is abstract, in this case we actually want to get all the fields, since any inherited reference array field will need to get loaded here.


writeSQLGenerator

protected void writeSQLGenerator(java.io.PrintStream out,
                                 com.sun.javadoc.ClassDoc cd,
                                 java.lang.String name)
                          throws org.sandev.sandbuild.SandGeneratorException
Write the base SQL. Assumptions:
  1. The SELECT and FROM parts of the statement are always the same since we are fetching all the fields to reconstruct a complete object instance.
  2. We don't need to alias the table names in the statement since we are joining down through the class inheritance hierarchy and all those names are unique. If someone maps two different struct definitions in the inheritance hierarchy into the same table then they have other problems.
  3. We don't need to disambiguate any of the table fields, since the fields must each be unique across the inherited struct definitions. If someone maps two fields to the same name, within the same inheritance tree then they have other problems.
  4. The autogenerated persistence fields are only placed into the the root table. Tables representing child messages reference back to the root via their uniqueID.

Throws:
org.sandev.sandbuild.SandGeneratorException

findUniqueIDField

protected com.sun.javadoc.FieldDoc findUniqueIDField(com.sun.javadoc.FieldDoc[] fields)

writeSQLPreamble

protected void writeSQLPreamble(java.io.PrintStream out,
                                com.sun.javadoc.ClassDoc cd,
                                java.lang.String name)

dumpFields

protected void dumpFields(java.io.PrintStream out,
                          com.sun.javadoc.ClassDoc cd,
                          java.lang.String name,
                          boolean recursiveCall)
If recursiveCall is false, then we have no trailing comma after the last field. Otherwise we do.


dumpTables

protected void dumpTables(java.io.PrintStream out,
                          com.sun.javadoc.ClassDoc cd,
                          boolean recursiveCall)
If recursiveCall is false, then we have no trailing comma after the table name. Otherwise we do.


dumpJoinExpr

protected void dumpJoinExpr(java.io.PrintStream out,
                            com.sun.javadoc.ClassDoc cd,
                            com.sun.javadoc.FieldDoc fduid,
                            boolean recursiveCall)
This is the join statement being inserted after a "WHERE", and we are working off a "preceding AND" model when creating conditions. So the first thing we do is insert a base test to "AND" off of. Then all joins have a preceding "AND".


writeSubselectClauseMapDecls

protected void writeSubselectClauseMapDecls(java.io.PrintStream out,
                                            com.sun.javadoc.ClassDoc cd,
                                            com.sun.javadoc.FieldDoc[] fields)
Here we are writing out maps for each of the reference fields the query could possibly refer to. That includes inherited fields.


writeSubselectClauseProcessing

protected void writeSubselectClauseProcessing(java.io.PrintStream out,
                                              com.sun.javadoc.ClassDoc cd,
                                              com.sun.javadoc.FieldDoc[] fields)
Here we are populating our reference maps with any references to them. We are still using the untranslated field names.


writeSubselectClauseSubselect

protected void writeSubselectClauseSubselect(java.io.PrintStream out,
                                             com.sun.javadoc.ClassDoc cd,
                                             com.sun.javadoc.FieldDoc[] fields,
                                             java.lang.String name)
                                      throws org.sandev.sandbuild.SandGeneratorException
Here we write the subselects based on the contents of the maps we have declared and populated earlier. We are appending the generated SQL to a cumulative buffer, which is passed on downwards into the child table SQL generator calls. Essentially we are traversing our way downward through any drilldown references with these calls.

This is also where we translate the field names into their mapped database equivalent values.

Throws:
org.sandev.sandbuild.SandGeneratorException

findFieldOwnerClassDoc

public static com.sun.javadoc.ClassDoc findFieldOwnerClassDoc(com.sun.javadoc.ClassDoc cd,
                                                              com.sun.javadoc.FieldDoc fd)
Return the ClassDoc this field is actually part of, within the inheritance tree of the given ClassDoc.


writeCollBuilder

protected void writeCollBuilder(java.io.PrintStream out,
                                com.sun.javadoc.ClassDoc cd,
                                java.lang.String name)

dumpResultSetCalls

protected void dumpResultSetCalls(java.io.PrintStream out,
                                  com.sun.javadoc.ClassDoc cd,
                                  java.lang.String name,
                                  boolean trailingComma)

writeArrayFieldSetterCall

protected void writeArrayFieldSetterCall(java.io.PrintStream out,
                                         com.sun.javadoc.FieldDoc fd)

writeClassSubselect

protected void writeClassSubselect(java.io.PrintStream out,
                                   com.sun.javadoc.ClassDoc[] classes)
                            throws org.sandev.sandbuild.SandGeneratorException
Throws:
org.sandev.sandbuild.SandGeneratorException

writeUtils

protected void writeUtils(java.io.PrintStream out)

writeLoadRefArray

protected void writeLoadRefArray(java.io.PrintStream out)

writeStreamTokerMethods

protected void writeStreamTokerMethods(java.io.PrintStream out)

writeMatchExprToSQL

protected void writeMatchExprToSQL(java.io.PrintStream out)

writeGetAggregateFunctionSQL

protected void writeGetAggregateFunctionSQL(java.io.PrintStream out)

writeSetFunctionResult

protected void writeSetFunctionResult(java.io.PrintStream out)