org.sandev.generator
Class SQLQueryProcessorGenerator

java.lang.Object
  extended by org.sandev.generator.GeneratorCommon
      extended by org.sandev.generator.AggregateGeneratorBase
          extended by org.sandev.generator.AggregateMappedGeneratorBase
              extended by org.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)
          When reading a Date from the result set, using a Calendar with the TimeZone for the field ends up double converting.
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 platfozm.
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 writeMiscUtils(java.io.PrintStream out)
          Write any additional miscellaneous utility methods
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 writeSubselectClause(java.io.PrintStream out, com.sun.javadoc.ClassDoc cd, com.sun.javadoc.FieldDoc[] fields)
          Write the subselect needed for the given field.
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, 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, findStructDeclByShortname, getDeclaredFields, getFields, getInheritanceHierarchy, getLastAppProject, getLastUtilDir, getLongInstanceName, getPrintStream, getSandProject, getShortInstanceName, getUtilPackage, getVisibleFields, hasSubStructs, isArray, 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 platfozm.

Overrides:
getFileSpec in class org.sandev.generator.AggregateGeneratorBase

writeFile

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

Overrides:
writeFile in class org.sandev.generator.AggregateGeneratorBase
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".


writeSubselectClause

protected void writeSubselectClause(java.io.PrintStream out,
                                    com.sun.javadoc.ClassDoc cd,
                                    com.sun.javadoc.FieldDoc[] fields)
                             throws org.sandev.sandbuild.SandGeneratorException
Write the subselect needed for the given field.

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)
When reading a Date from the result set, using a Calendar with the TimeZone for the field ends up double converting. Essentially the database (at least PostgreSQL) reads the stored server time, converts it to UTC, then converts it to the target time. So if you stored using no time zone, with a target of UTC, you end up being off by the UTC twice (e.g. 5+5=10 hours for eastern time). So we read directly, then do the offset conversion ourselves.


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)

writeMiscUtils

protected void writeMiscUtils(java.io.PrintStream out)
Write any additional miscellaneous utility methods